From f9cd45269a729b9a3fe55940ab4fce1e546da53c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 30 Nov 2023 11:38:16 +0200 Subject: [PATCH] Fix eslint diagnostics by passing worktree root during workspace init --- crates/language/src/language.rs | 10 +++++++--- crates/project/src/project.rs | 22 ++++++++++++++++------ crates/zed/src/languages/json.rs | 1 + crates/zed/src/languages/php.rs | 1 - crates/zed/src/languages/tailwind.rs | 6 +++++- crates/zed/src/languages/typescript.rs | 13 +++++++++++-- crates/zed/src/languages/yaml.rs | 6 +++++- crates/zed2/src/languages/php.rs | 1 - crates/zed2/src/languages/typescript.rs | 1 - 9 files changed, 45 insertions(+), 16 deletions(-) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index af7504529cefbee215fb96e53798242da340a4d6..811e54940672ee075993d8cd981c945199409675 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -197,8 +197,12 @@ impl CachedLspAdapter { self.adapter.code_action_kinds() } - pub fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { - self.adapter.workspace_configuration(cx) + pub fn workspace_configuration( + &self, + workspace_root: &Path, + cx: &mut AppContext, + ) -> BoxFuture<'static, Value> { + self.adapter.workspace_configuration(workspace_root, cx) } pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) { @@ -312,7 +316,7 @@ pub trait LspAdapter: 'static + Send + Sync { None } - fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { + fn workspace_configuration(&self, _: &Path, _: &mut AppContext) -> BoxFuture<'static, Value> { futures::future::ready(serde_json::json!({})).boxed() } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a2ad82585eadb9d4e010fe953ae17319ad23728f..59cb736cde62c3f00f9c04be41f0dda3c62343db 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2641,8 +2641,9 @@ impl Project { }); for (adapter, server) in servers { - let workspace_config = - cx.update(|cx| adapter.workspace_configuration(cx)).await; + let workspace_config = cx + .update(|cx| adapter.workspace_configuration(server.root_path(), cx)) + .await; server .notify::( lsp::DidChangeConfigurationParams { @@ -2753,7 +2754,7 @@ impl Project { stderr_capture.clone(), language.clone(), adapter.clone(), - worktree_path, + Arc::clone(&worktree_path), ProjectLspAdapterDelegate::new(self, cx), cx, ) { @@ -2776,6 +2777,7 @@ impl Project { cx.spawn_weak(|this, mut cx| async move { let result = Self::setup_and_insert_language_server( this, + &worktree_path, override_options, pending_server, adapter.clone(), @@ -2891,6 +2893,7 @@ impl Project { async fn setup_and_insert_language_server( this: WeakModelHandle, + worktree_path: &Path, override_initialization_options: Option, pending_server: PendingLanguageServer, adapter: Arc, @@ -2903,6 +2906,7 @@ impl Project { this, override_initialization_options, pending_server, + worktree_path, adapter.clone(), server_id, cx, @@ -2932,11 +2936,14 @@ impl Project { this: WeakModelHandle, override_options: Option, pending_server: PendingLanguageServer, + worktree_path: &Path, adapter: Arc, server_id: LanguageServerId, cx: &mut AsyncAppContext, ) -> Result> { - let workspace_config = cx.update(|cx| adapter.workspace_configuration(cx)).await; + let workspace_config = cx + .update(|cx| adapter.workspace_configuration(worktree_path, cx)) + .await; let language_server = pending_server.task.await?; language_server @@ -2964,11 +2971,14 @@ impl Project { language_server .on_request::({ let adapter = adapter.clone(); + let worktree_path = worktree_path.to_path_buf(); move |params, mut cx| { let adapter = adapter.clone(); + let worktree_path = worktree_path.clone(); async move { - let workspace_config = - cx.update(|cx| adapter.workspace_configuration(cx)).await; + let workspace_config = cx + .update(|cx| adapter.workspace_configuration(&worktree_path, cx)) + .await; Ok(params .items .into_iter() diff --git a/crates/zed/src/languages/json.rs b/crates/zed/src/languages/json.rs index 63f909ae2a2e264ea672dee48e305ba1be82e066..891c25c31f1675f175b032f38d9b82a94df0aeaf 100644 --- a/crates/zed/src/languages/json.rs +++ b/crates/zed/src/languages/json.rs @@ -105,6 +105,7 @@ impl LspAdapter for JsonLspAdapter { fn workspace_configuration( &self, + _workspace_root: &Path, cx: &mut AppContext, ) -> BoxFuture<'static, serde_json::Value> { let action_names = cx.all_action_names().collect::>(); diff --git a/crates/zed/src/languages/php.rs b/crates/zed/src/languages/php.rs index 3096fd16e6b87764a0f9dd127a0dec6eaba0a77a..e3d0f1c6903c58134a0c7ff04742020fedc5892d 100644 --- a/crates/zed/src/languages/php.rs +++ b/crates/zed/src/languages/php.rs @@ -29,7 +29,6 @@ pub struct IntelephenseLspAdapter { impl IntelephenseLspAdapter { const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js"; - #[allow(unused)] pub fn new(node: Arc) -> Self { Self { node } } diff --git a/crates/zed/src/languages/tailwind.rs b/crates/zed/src/languages/tailwind.rs index 6d6006dbd48c3d4ea065e12e909fdbd3cf775e7f..0dfa700b01767745711de9b2b7384a81e1af2ea9 100644 --- a/crates/zed/src/languages/tailwind.rs +++ b/crates/zed/src/languages/tailwind.rs @@ -107,7 +107,11 @@ impl LspAdapter for TailwindLspAdapter { })) } - fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { + fn workspace_configuration( + &self, + _workspace_root: &Path, + _: &mut AppContext, + ) -> BoxFuture<'static, Value> { future::ready(json!({ "tailwindCSS": { "emmetCompletions": true, diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index d259afb05debea950bd767b407d8f77a1a2a2de9..fbb14930fc8e79ee888f58fb804fbff5846886e9 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -205,7 +205,6 @@ pub struct EsLintLspAdapter { impl EsLintLspAdapter { const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js"; - #[allow(unused)] pub fn new(node: Arc) -> Self { EsLintLspAdapter { node } } @@ -213,13 +212,23 @@ impl EsLintLspAdapter { #[async_trait] impl LspAdapter for EsLintLspAdapter { - fn workspace_configuration(&self, _: &mut AppContext) -> BoxFuture<'static, Value> { + fn workspace_configuration( + &self, + workspace_root: &Path, + _: &mut AppContext, + ) -> BoxFuture<'static, Value> { future::ready(json!({ "": { "validate": "on", "rulesCustomizations": [], "run": "onType", "nodePath": null, + "workingDirectory": {"mode": "auto"}, + "workspaceFolder": { + "uri": workspace_root, + "name": workspace_root.file_name() + .unwrap_or_else(|| workspace_root.as_os_str()), + }, } })) .boxed() diff --git a/crates/zed/src/languages/yaml.rs b/crates/zed/src/languages/yaml.rs index 8b438d0949dc0ef1f514f3c315c3eab98174d506..fbed9ba78f0f093145ebfd3b12227879ab8d5617 100644 --- a/crates/zed/src/languages/yaml.rs +++ b/crates/zed/src/languages/yaml.rs @@ -93,7 +93,11 @@ impl LspAdapter for YamlLspAdapter { ) -> Option { get_cached_server_binary(container_dir, &*self.node).await } - fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> { + fn workspace_configuration( + &self, + _workspace_root: &Path, + cx: &mut AppContext, + ) -> BoxFuture<'static, Value> { let tab_size = all_language_settings(None, cx) .language(Some("YAML")) .tab_size; diff --git a/crates/zed2/src/languages/php.rs b/crates/zed2/src/languages/php.rs index 3096fd16e6b87764a0f9dd127a0dec6eaba0a77a..e3d0f1c6903c58134a0c7ff04742020fedc5892d 100644 --- a/crates/zed2/src/languages/php.rs +++ b/crates/zed2/src/languages/php.rs @@ -29,7 +29,6 @@ pub struct IntelephenseLspAdapter { impl IntelephenseLspAdapter { const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js"; - #[allow(unused)] pub fn new(node: Arc) -> Self { Self { node } } diff --git a/crates/zed2/src/languages/typescript.rs b/crates/zed2/src/languages/typescript.rs index 1b96e7e7022d56cf8947906fda67df2604c07471..b1b5e873f34dcf6e4e49552c8296576d31c8c75e 100644 --- a/crates/zed2/src/languages/typescript.rs +++ b/crates/zed2/src/languages/typescript.rs @@ -205,7 +205,6 @@ pub struct EsLintLspAdapter { impl EsLintLspAdapter { const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js"; - #[allow(unused)] pub fn new(node: Arc) -> Self { EsLintLspAdapter { node } }