From c6208c86a586d745b50b65d047f13ed1c4e55206 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 6 Dec 2024 17:06:18 +0100 Subject: [PATCH 1/2] Temporarily disable completion resolve support for helix --- crates/rust-analyzer/src/bin/main.rs | 12 ++----- crates/rust-analyzer/src/config.rs | 34 +++++++++++++++----- crates/rust-analyzer/src/lsp/capabilities.rs | 6 +++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index e872585c5717..eac33be56646 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -20,7 +20,6 @@ use rust_analyzer::{ config::{Config, ConfigChange, ConfigErrors}, from_json, }; -use semver::Version; use tracing_subscriber::fmt::writer::BoxMakeWriter; use vfs::AbsPathBuf; @@ -204,18 +203,12 @@ fn run_server() -> anyhow::Result<()> { } }; - let mut visual_studio_code_version = None; - if let Some(client_info) = client_info { + if let Some(client_info) = &client_info { tracing::info!( "Client '{}' {}", client_info.name, client_info.version.as_deref().unwrap_or_default() ); - visual_studio_code_version = client_info - .name - .starts_with("Visual Studio Code") - .then(|| client_info.version.as_deref().map(Version::parse).and_then(Result::ok)) - .flatten(); } let workspace_roots = workspace_folders @@ -230,8 +223,7 @@ fn run_server() -> anyhow::Result<()> { }) .filter(|workspaces| !workspaces.is_empty()) .unwrap_or_else(|| vec![root_path.clone()]); - let mut config = - Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version); + let mut config = Config::new(root_path, capabilities, workspace_roots, client_info); if let Some(json) = initialization_options { let mut change = ConfigChange::default(); change.change_client_config(json); diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 0fdc48a0e7a2..a4f9246a5871 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -730,6 +730,12 @@ enum RatomlFile { Crate(LocalConfigInput), } +#[derive(Clone, Debug)] +struct ClientInfo { + name: String, + version: Option, +} + #[derive(Clone)] pub struct Config { /// Projects that have a Cargo.toml or a rust-project.json in a @@ -744,7 +750,7 @@ pub struct Config { caps: ClientCapabilities, root_path: AbsPathBuf, snippets: Vec, - visual_studio_code_version: Option, + client_info: Option, default_config: &'static DefaultConfigData, /// Config node that obtains its initial value during the server initialization and @@ -777,7 +783,7 @@ impl fmt::Debug for Config { .field("caps", &self.caps) .field("root_path", &self.root_path) .field("snippets", &self.snippets) - .field("visual_studio_code_version", &self.visual_studio_code_version) + .field("client_info", &self.client_info) .field("client_config", &self.client_config) .field("user_config", &self.user_config) .field("ratoml_file", &self.ratoml_file) @@ -1335,7 +1341,7 @@ impl Config { root_path: AbsPathBuf, caps: lsp_types::ClientCapabilities, workspace_roots: Vec, - visual_studio_code_version: Option, + client_info: Option, ) -> Self { static DEFAULT_CONFIG_DATA: OnceLock<&'static DefaultConfigData> = OnceLock::new(); @@ -1346,7 +1352,10 @@ impl Config { root_path, snippets: Default::default(), workspace_roots, - visual_studio_code_version, + client_info: client_info.map(|it| ClientInfo { + name: it.name, + version: it.version.as_deref().map(Version::parse).and_then(Result::ok), + }), client_config: (FullConfigInput::default(), ConfigErrors(vec![])), default_config: DEFAULT_CONFIG_DATA.get_or_init(|| Box::leak(Box::default())), source_root_parent_map: Arc::new(FxHashMap::default()), @@ -1446,9 +1455,11 @@ impl Config { limit: self.completion_limit(source_root).to_owned(), enable_term_search: self.completion_termSearch_enable(source_root).to_owned(), term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64, - fields_to_resolve: CompletionFieldsToResolve::from_client_capabilities( - &client_capability_fields, - ), + fields_to_resolve: if self.client_is_helix() { + CompletionFieldsToResolve::empty() + } else { + CompletionFieldsToResolve::from_client_capabilities(&client_capability_fields) + }, } } @@ -2163,7 +2174,14 @@ impl Config { // VSCode is our reference implementation, so we allow ourselves to work around issues by // special casing certain versions pub fn visual_studio_code_version(&self) -> Option<&Version> { - self.visual_studio_code_version.as_ref() + self.client_info + .as_ref() + .filter(|it| it.name.starts_with("Visual Studio Code")) + .and_then(|it| it.version.as_ref()) + } + + pub fn client_is_helix(&self) -> bool { + self.client_info.as_ref().map(|it| it.name == "helix").unwrap_or_default() } } // Deserialization definitions diff --git a/crates/rust-analyzer/src/lsp/capabilities.rs b/crates/rust-analyzer/src/lsp/capabilities.rs index 82e6ae2b49c1..036282120942 100644 --- a/crates/rust-analyzer/src/lsp/capabilities.rs +++ b/crates/rust-analyzer/src/lsp/capabilities.rs @@ -41,7 +41,11 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities { })), hover_provider: Some(HoverProviderCapability::Simple(true)), completion_provider: Some(CompletionOptions { - resolve_provider: Some(config.caps().completions_resolve_provider()), + resolve_provider: if config.client_is_helix() { + None + } else { + Some(config.caps().completions_resolve_provider()) + }, trigger_characters: Some(vec![ ":".to_owned(), ".".to_owned(), From ad01392756adfed1b5f16029907450cc39a7676c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 6 Dec 2024 17:10:24 +0100 Subject: [PATCH 2/2] Temporarily disable completion resolve support for neovim --- crates/rust-analyzer/src/config.rs | 6 +++++- crates/rust-analyzer/src/lsp/capabilities.rs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index a4f9246a5871..dd7351bcf26c 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1455,7 +1455,7 @@ impl Config { limit: self.completion_limit(source_root).to_owned(), enable_term_search: self.completion_termSearch_enable(source_root).to_owned(), term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64, - fields_to_resolve: if self.client_is_helix() { + fields_to_resolve: if self.client_is_helix() || self.client_is_neovim() { CompletionFieldsToResolve::empty() } else { CompletionFieldsToResolve::from_client_capabilities(&client_capability_fields) @@ -2183,6 +2183,10 @@ impl Config { pub fn client_is_helix(&self) -> bool { self.client_info.as_ref().map(|it| it.name == "helix").unwrap_or_default() } + + pub fn client_is_neovim(&self) -> bool { + self.client_info.as_ref().map(|it| it.name == "Neovim").unwrap_or_default() + } } // Deserialization definitions diff --git a/crates/rust-analyzer/src/lsp/capabilities.rs b/crates/rust-analyzer/src/lsp/capabilities.rs index 036282120942..6d73319e67b2 100644 --- a/crates/rust-analyzer/src/lsp/capabilities.rs +++ b/crates/rust-analyzer/src/lsp/capabilities.rs @@ -41,8 +41,8 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities { })), hover_provider: Some(HoverProviderCapability::Simple(true)), completion_provider: Some(CompletionOptions { - resolve_provider: if config.client_is_helix() { - None + resolve_provider: if config.client_is_helix() || config.client_is_neovim() { + config.completion_item_edit_resolve().then_some(true) } else { Some(config.caps().completions_resolve_provider()) },