Merge pull request #18630 from Veykril/push-ystzsxpywnxn

fix: Temporarily disable completion resolve support for helix and neovim
This commit is contained in:
Lukas Wirth 2024-12-07 12:23:21 +00:00 committed by GitHub
commit 02aca112e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 19 deletions

View file

@ -20,7 +20,6 @@ use rust_analyzer::{
config::{Config, ConfigChange, ConfigErrors}, config::{Config, ConfigChange, ConfigErrors},
from_json, from_json,
}; };
use semver::Version;
use tracing_subscriber::fmt::writer::BoxMakeWriter; use tracing_subscriber::fmt::writer::BoxMakeWriter;
use vfs::AbsPathBuf; 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!( tracing::info!(
"Client '{}' {}", "Client '{}' {}",
client_info.name, client_info.name,
client_info.version.as_deref().unwrap_or_default() 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 let workspace_roots = workspace_folders
@ -230,8 +223,7 @@ fn run_server() -> anyhow::Result<()> {
}) })
.filter(|workspaces| !workspaces.is_empty()) .filter(|workspaces| !workspaces.is_empty())
.unwrap_or_else(|| vec![root_path.clone()]); .unwrap_or_else(|| vec![root_path.clone()]);
let mut config = let mut config = Config::new(root_path, capabilities, workspace_roots, client_info);
Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version);
if let Some(json) = initialization_options { if let Some(json) = initialization_options {
let mut change = ConfigChange::default(); let mut change = ConfigChange::default();
change.change_client_config(json); change.change_client_config(json);

View file

@ -730,6 +730,12 @@ enum RatomlFile {
Crate(LocalConfigInput), Crate(LocalConfigInput),
} }
#[derive(Clone, Debug)]
struct ClientInfo {
name: String,
version: Option<Version>,
}
#[derive(Clone)] #[derive(Clone)]
pub struct Config { pub struct Config {
/// Projects that have a Cargo.toml or a rust-project.json in a /// Projects that have a Cargo.toml or a rust-project.json in a
@ -744,7 +750,7 @@ pub struct Config {
caps: ClientCapabilities, caps: ClientCapabilities,
root_path: AbsPathBuf, root_path: AbsPathBuf,
snippets: Vec<Snippet>, snippets: Vec<Snippet>,
visual_studio_code_version: Option<Version>, client_info: Option<ClientInfo>,
default_config: &'static DefaultConfigData, default_config: &'static DefaultConfigData,
/// Config node that obtains its initial value during the server initialization and /// 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("caps", &self.caps)
.field("root_path", &self.root_path) .field("root_path", &self.root_path)
.field("snippets", &self.snippets) .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("client_config", &self.client_config)
.field("user_config", &self.user_config) .field("user_config", &self.user_config)
.field("ratoml_file", &self.ratoml_file) .field("ratoml_file", &self.ratoml_file)
@ -1335,7 +1341,7 @@ impl Config {
root_path: AbsPathBuf, root_path: AbsPathBuf,
caps: lsp_types::ClientCapabilities, caps: lsp_types::ClientCapabilities,
workspace_roots: Vec<AbsPathBuf>, workspace_roots: Vec<AbsPathBuf>,
visual_studio_code_version: Option<Version>, client_info: Option<lsp_types::ClientInfo>,
) -> Self { ) -> Self {
static DEFAULT_CONFIG_DATA: OnceLock<&'static DefaultConfigData> = OnceLock::new(); static DEFAULT_CONFIG_DATA: OnceLock<&'static DefaultConfigData> = OnceLock::new();
@ -1346,7 +1352,10 @@ impl Config {
root_path, root_path,
snippets: Default::default(), snippets: Default::default(),
workspace_roots, 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![])), client_config: (FullConfigInput::default(), ConfigErrors(vec![])),
default_config: DEFAULT_CONFIG_DATA.get_or_init(|| Box::leak(Box::default())), default_config: DEFAULT_CONFIG_DATA.get_or_init(|| Box::leak(Box::default())),
source_root_parent_map: Arc::new(FxHashMap::default()), source_root_parent_map: Arc::new(FxHashMap::default()),
@ -1446,9 +1455,11 @@ impl Config {
limit: self.completion_limit(source_root).to_owned(), limit: self.completion_limit(source_root).to_owned(),
enable_term_search: self.completion_termSearch_enable(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, term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
fields_to_resolve: CompletionFieldsToResolve::from_client_capabilities( fields_to_resolve: if self.client_is_helix() || self.client_is_neovim() {
&client_capability_fields, CompletionFieldsToResolve::empty()
), } else {
CompletionFieldsToResolve::from_client_capabilities(&client_capability_fields)
},
} }
} }
@ -2163,7 +2174,18 @@ impl Config {
// VSCode is our reference implementation, so we allow ourselves to work around issues by // VSCode is our reference implementation, so we allow ourselves to work around issues by
// special casing certain versions // special casing certain versions
pub fn visual_studio_code_version(&self) -> Option<&Version> { 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()
}
pub fn client_is_neovim(&self) -> bool {
self.client_info.as_ref().map(|it| it.name == "Neovim").unwrap_or_default()
} }
} }
// Deserialization definitions // Deserialization definitions

View file

@ -41,7 +41,11 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
})), })),
hover_provider: Some(HoverProviderCapability::Simple(true)), hover_provider: Some(HoverProviderCapability::Simple(true)),
completion_provider: Some(CompletionOptions { completion_provider: Some(CompletionOptions {
resolve_provider: Some(config.caps().completions_resolve_provider()), 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())
},
trigger_characters: Some(vec![ trigger_characters: Some(vec![
":".to_owned(), ":".to_owned(),
".".to_owned(), ".".to_owned(),