summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/lsp/language_server.rs10
-rw-r--r--cli/tests/integration_tests_lsp.rs62
-rw-r--r--cli/tests/lsp/lib.tsconfig.json5
3 files changed, 69 insertions, 8 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 10bb0478e..9e4e6af14 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -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);
diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs
index 10797a326..b6d9cde54 100644
--- a/cli/tests/integration_tests_lsp.rs
+++ b/cli/tests/integration_tests_lsp.rs
@@ -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,
{
@@ -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) {
@@ -67,6 +74,47 @@ fn lsp_startup_shutdown() {
}
#[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");
did_open(
diff --git a/cli/tests/lsp/lib.tsconfig.json b/cli/tests/lsp/lib.tsconfig.json
new file mode 100644
index 000000000..8d2ae8a8b
--- /dev/null
+++ b/cli/tests/lsp/lib.tsconfig.json
@@ -0,0 +1,5 @@
+{
+ "compilerOptions": {
+ "lib": ["deno.ns", "deno.unstable", "dom"]
+ }
+}