Skip to content

Commit

Permalink
fix(#10747): cannot read config option in windows (#10791)
Browse files Browse the repository at this point in the history
Fixes #10747
  • Loading branch information
jeiea authored Jun 6, 2021
1 parent 62bf403 commit 633c5aa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
10 changes: 9 additions & 1 deletion cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 447,15 @@ impl Inner {
))
}?;

let config_file = ConfigFile::read(config_url.path())?;
let config_file = {
let buffer = config_url
.to_file_path()
.map_err(|_| anyhow!("Bad uri: \"{}\"", config_url))?;
let path = buffer
.to_str()
.ok_or_else(|| anyhow!("Bad uri: \"{}\"", config_url))?;
ConfigFile::read(path)?
};
let (value, maybe_ignored_options) = config_file.as_compiler_options()?;
tsconfig.merge(&value);
self.maybe_config_uri = Some(config_url);
Expand Down
62 changes: 55 additions & 7 deletions cli/tests/integration_tests_lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,10 @@ fn init(init_path: &str) -> LspClient {
client
}

fn did_open<V>(client: &mut LspClient, params: V)
fn did_open<V>(
client: &mut LspClient,
params: V,
) -> Vec<lsp::PublishDiagnosticsParams>
where
V: Serialize,
{
Expand All @@ -45,12 48,16 @@ where
.write_response(id, json!({ "enable": true }))
.unwrap();

let (method, _) = client.read_notification::<Value>().unwrap();
assert_eq!(method, "textDocument/publishDiagnostics");
let (method, _) = client.read_notification::<Value>().unwrap();
assert_eq!(method, "textDocument/publishDiagnostics");
let (method, _) = client.read_notification::<Value>().unwrap();
assert_eq!(method, "textDocument/publishDiagnostics");
let mut diagnostics = vec![];
for _ in 0..3 {
let (method, response) = client
.read_notification::<lsp::PublishDiagnosticsParams>()
.unwrap();
assert_eq!(method, "textDocument/publishDiagnostics");
diagnostics.push(response.unwrap());
}

diagnostics
}

fn shutdown(client: &mut LspClient) {
Expand All @@ -66,6 73,47 @@ fn lsp_startup_shutdown() {
shutdown(&mut client);
}

#[test]
fn lsp_init_tsconfig() {
let temp_dir = TempDir::new().expect("could not create temp dir");
let mut params: lsp::InitializeParams =
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
let tsconfig =
serde_json::to_vec_pretty(&load_fixture("lib.tsconfig.json")).unwrap();
fs::write(temp_dir.path().join("lib.tsconfig.json"), tsconfig).unwrap();

params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
if let Some(Value::Object(mut map)) = params.initialization_options {
map.insert("config".to_string(), json!("./lib.tsconfig.json"));
params.initialization_options = Some(Value::Object(map));
}

let deno_exe = deno_exe_path();
let mut client = LspClient::new(&deno_exe).unwrap();
client
.write_request::<_, _, Value>("initialize", params)
.unwrap();

client.write_notification("initialized", json!({})).unwrap();

let diagnostics = did_open(
&mut client,
json!({
"textDocument": {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "location.pathname;\n"
}
}),
);

let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics);
assert_eq!(diagnostics.count(), 0);

shutdown(&mut client);
}

#[test]
fn lsp_hover() {
let mut client = init("initialize_params.json");
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/lsp/lib.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
{
"compilerOptions": {
"lib": ["deno.ns", "deno.unstable", "dom"]
}
}

0 comments on commit 633c5aa

Please sign in to comment.