mirror of
https://github.com/denoland/deno.git
synced 2024-12-31 11:34:15 -05:00
fix(lsp): ensure enablePaths
works when clients do not provide a trailing slash for workspace dir (#18373)
Closes https://github.com/denoland/vscode_deno/issues/827
This commit is contained in:
parent
f69e4794d2
commit
64f491422b
2 changed files with 133 additions and 121 deletions
|
@ -377,7 +377,7 @@ impl LanguageServer {
|
|||
let mut ls = self.0.write().await;
|
||||
if let Ok(configs) = configs_result {
|
||||
for (value, internal_uri) in
|
||||
configs.into_iter().zip(specifiers.into_iter().map(|s| s.1))
|
||||
configs.into_iter().zip(specifiers.into_iter().map(|s| s.0))
|
||||
{
|
||||
match value {
|
||||
Ok(specifier_settings) => {
|
||||
|
|
|
@ -928,143 +928,155 @@ fn lsp_inlay_hints_not_enabled() {
|
|||
|
||||
#[test]
|
||||
fn lsp_workspace_enable_paths() {
|
||||
let context = TestContextBuilder::new().build();
|
||||
// we aren't actually writing anything to the tempdir in this test, but we
|
||||
// just need a legitimate file path on the host system so that logic that
|
||||
// tries to convert to and from the fs paths works on all env
|
||||
let temp_dir = context.temp_dir();
|
||||
fn run_test(use_trailing_slash: bool) {
|
||||
let context = TestContextBuilder::new().build();
|
||||
// we aren't actually writing anything to the tempdir in this test, but we
|
||||
// just need a legitimate file path on the host system so that logic that
|
||||
// tries to convert to and from the fs paths works on all env
|
||||
let temp_dir = context.temp_dir();
|
||||
|
||||
let root_specifier = temp_dir.uri();
|
||||
let root_specifier = temp_dir.uri();
|
||||
|
||||
let mut client = context.new_lsp_command().build();
|
||||
client.initialize_with_config(
|
||||
|builder| {
|
||||
builder
|
||||
.set_enable_paths(vec!["./worker".to_string()])
|
||||
.set_root_uri(root_specifier.clone())
|
||||
.set_workspace_folders(vec![lsp::WorkspaceFolder {
|
||||
uri: root_specifier.clone(),
|
||||
name: "project".to_string(),
|
||||
}])
|
||||
.set_deno_enable(false);
|
||||
},
|
||||
json!([{
|
||||
"enable": false,
|
||||
"enablePaths": ["./worker"],
|
||||
}]),
|
||||
);
|
||||
let mut client = context.new_lsp_command().build();
|
||||
client.initialize_with_config(
|
||||
|builder| {
|
||||
builder
|
||||
.set_enable_paths(vec!["./worker".to_string()])
|
||||
.set_root_uri(root_specifier.clone())
|
||||
.set_workspace_folders(vec![lsp::WorkspaceFolder {
|
||||
uri: if use_trailing_slash {
|
||||
root_specifier.clone()
|
||||
} else {
|
||||
ModuleSpecifier::parse(
|
||||
root_specifier.as_str().strip_suffix('/').unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
name: "project".to_string(),
|
||||
}])
|
||||
.set_deno_enable(false);
|
||||
},
|
||||
json!([{
|
||||
"enable": false,
|
||||
"enablePaths": ["./worker"],
|
||||
}]),
|
||||
);
|
||||
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./file.ts").unwrap(),
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./other/file.ts").unwrap(),
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/file.ts").unwrap(),
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(res, json!(null));
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./other/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(res, json!(null));
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
}));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
json!({
|
||||
"contents": [
|
||||
{
|
||||
"language": "typescript",
|
||||
"value": "(method) DateConstructor.now(): number",
|
||||
},
|
||||
"Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC)."
|
||||
],
|
||||
"range": {
|
||||
"start": { "line": 0, "character": 17, },
|
||||
"end": { "line": 0, "character": 20, }
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
client.did_open(json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
json!({
|
||||
"contents": [
|
||||
{
|
||||
"language": "typescript",
|
||||
"value": "(method) DateConstructor.now(): number",
|
||||
},
|
||||
"Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC)."
|
||||
],
|
||||
"range": {
|
||||
"start": { "line": 0, "character": 17, },
|
||||
"end": { "line": 0, "character": 20, }
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "console.log(Date.now());\n"
|
||||
}
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
||||
client.shutdown();
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(res, json!(null));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./other/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(res, json!(null));
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
json!({
|
||||
"contents": [
|
||||
{
|
||||
"language": "typescript",
|
||||
"value": "(method) DateConstructor.now(): number",
|
||||
},
|
||||
"Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC)."
|
||||
],
|
||||
"range": {
|
||||
"start": { "line": 0, "character": 17, },
|
||||
"end": { "line": 0, "character": 20, }
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
let res = client.write_request(
|
||||
"textDocument/hover",
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
|
||||
},
|
||||
"position": { "line": 0, "character": 19 }
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
res,
|
||||
json!({
|
||||
"contents": [
|
||||
{
|
||||
"language": "typescript",
|
||||
"value": "(method) DateConstructor.now(): number",
|
||||
},
|
||||
"Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC)."
|
||||
],
|
||||
"range": {
|
||||
"start": { "line": 0, "character": 17, },
|
||||
"end": { "line": 0, "character": 20, }
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
run_test(true);
|
||||
run_test(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue