mirror of
https://github.com/denoland/deno.git
synced 2025-01-18 11:53:59 -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;
|
let mut ls = self.0.write().await;
|
||||||
if let Ok(configs) = configs_result {
|
if let Ok(configs) = configs_result {
|
||||||
for (value, internal_uri) in
|
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 {
|
match value {
|
||||||
Ok(specifier_settings) => {
|
Ok(specifier_settings) => {
|
||||||
|
|
|
@ -928,143 +928,155 @@ fn lsp_inlay_hints_not_enabled() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lsp_workspace_enable_paths() {
|
fn lsp_workspace_enable_paths() {
|
||||||
let context = TestContextBuilder::new().build();
|
fn run_test(use_trailing_slash: bool) {
|
||||||
// we aren't actually writing anything to the tempdir in this test, but we
|
let context = TestContextBuilder::new().build();
|
||||||
// just need a legitimate file path on the host system so that logic that
|
// we aren't actually writing anything to the tempdir in this test, but we
|
||||||
// tries to convert to and from the fs paths works on all env
|
// just need a legitimate file path on the host system so that logic that
|
||||||
let temp_dir = context.temp_dir();
|
// 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();
|
let mut client = context.new_lsp_command().build();
|
||||||
client.initialize_with_config(
|
client.initialize_with_config(
|
||||||
|builder| {
|
|builder| {
|
||||||
builder
|
builder
|
||||||
.set_enable_paths(vec!["./worker".to_string()])
|
.set_enable_paths(vec!["./worker".to_string()])
|
||||||
.set_root_uri(root_specifier.clone())
|
.set_root_uri(root_specifier.clone())
|
||||||
.set_workspace_folders(vec![lsp::WorkspaceFolder {
|
.set_workspace_folders(vec![lsp::WorkspaceFolder {
|
||||||
uri: root_specifier.clone(),
|
uri: if use_trailing_slash {
|
||||||
name: "project".to_string(),
|
root_specifier.clone()
|
||||||
}])
|
} else {
|
||||||
.set_deno_enable(false);
|
ModuleSpecifier::parse(
|
||||||
},
|
root_specifier.as_str().strip_suffix('/').unwrap(),
|
||||||
json!([{
|
)
|
||||||
"enable": false,
|
.unwrap()
|
||||||
"enablePaths": ["./worker"],
|
},
|
||||||
}]),
|
name: "project".to_string(),
|
||||||
);
|
}])
|
||||||
|
.set_deno_enable(false);
|
||||||
|
},
|
||||||
|
json!([{
|
||||||
|
"enable": false,
|
||||||
|
"enablePaths": ["./worker"],
|
||||||
|
}]),
|
||||||
|
);
|
||||||
|
|
||||||
client.did_open(json!({
|
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!({
|
|
||||||
"textDocument": {
|
"textDocument": {
|
||||||
"uri": root_specifier.join("./file.ts").unwrap(),
|
"uri": root_specifier.join("./file.ts").unwrap(),
|
||||||
},
|
"languageId": "typescript",
|
||||||
"position": { "line": 0, "character": 19 }
|
"version": 1,
|
||||||
}),
|
"text": "console.log(Date.now());\n"
|
||||||
);
|
}
|
||||||
assert_eq!(res, json!(null));
|
}));
|
||||||
|
|
||||||
let res = client.write_request(
|
client.did_open(json!({
|
||||||
"textDocument/hover",
|
|
||||||
json!({
|
|
||||||
"textDocument": {
|
"textDocument": {
|
||||||
"uri": root_specifier.join("./other/file.ts").unwrap(),
|
"uri": root_specifier.join("./other/file.ts").unwrap(),
|
||||||
},
|
"languageId": "typescript",
|
||||||
"position": { "line": 0, "character": 19 }
|
"version": 1,
|
||||||
}),
|
"text": "console.log(Date.now());\n"
|
||||||
);
|
}
|
||||||
assert_eq!(res, json!(null));
|
}));
|
||||||
|
|
||||||
let res = client.write_request(
|
client.did_open(json!({
|
||||||
"textDocument/hover",
|
|
||||||
json!({
|
|
||||||
"textDocument": {
|
"textDocument": {
|
||||||
"uri": root_specifier.join("./worker/file.ts").unwrap(),
|
"uri": root_specifier.join("./worker/file.ts").unwrap(),
|
||||||
},
|
"languageId": "typescript",
|
||||||
"position": { "line": 0, "character": 19 }
|
"version": 1,
|
||||||
}),
|
"text": "console.log(Date.now());\n"
|
||||||
);
|
|
||||||
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(
|
client.did_open(json!({
|
||||||
"textDocument/hover",
|
|
||||||
json!({
|
|
||||||
"textDocument": {
|
"textDocument": {
|
||||||
"uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
|
"uri": root_specifier.join("./worker/subdir/file.ts").unwrap(),
|
||||||
},
|
"languageId": "typescript",
|
||||||
"position": { "line": 0, "character": 19 }
|
"version": 1,
|
||||||
}),
|
"text": "console.log(Date.now());\n"
|
||||||
);
|
|
||||||
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();
|
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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Reference in a new issue