Skip to content

fix: Temporarily disable completion resolve support for helix and neovim #18630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
38 changes: 30 additions & 8 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,12 @@ enum RatomlFile {
Crate(LocalConfigInput),
}

#[derive(Clone, Debug)]
struct ClientInfo {
name: String,
version: Option<Version>,
}

#[derive(Clone)]
pub struct Config {
/// Projects that have a Cargo.toml or a rust-project.json in a
Expand All @@ -744,7 +750,7 @@ pub struct Config {
caps: ClientCapabilities,
root_path: AbsPathBuf,
snippets: Vec<Snippet>,
visual_studio_code_version: Option<Version>,
client_info: Option<ClientInfo>,

default_config: &'static DefaultConfigData,
/// Config node that obtains its initial value during the server initialization and
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1335,7 +1341,7 @@ impl Config {
root_path: AbsPathBuf,
caps: lsp_types::ClientCapabilities,
workspace_roots: Vec<AbsPathBuf>,
visual_studio_code_version: Option<Version>,
client_info: Option<lsp_types::ClientInfo>,
) -> Self {
static DEFAULT_CONFIG_DATA: OnceLock<&'static DefaultConfigData> = OnceLock::new();

Expand All @@ -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()),
Expand Down Expand Up @@ -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() || self.client_is_neovim() {
CompletionFieldsToResolve::empty()
} else {
CompletionFieldsToResolve::from_client_capabilities(&client_capability_fields)
},
}
}

Expand Down Expand Up @@ -2163,7 +2174,18 @@ 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()
}

pub fn client_is_neovim(&self) -> bool {
self.client_info.as_ref().map(|it| it.name == "Neovim").unwrap_or_default()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this string in one issue in hrsh7th/cmp-nvim-lsp#36, so I'll just hope that that works

}
}
// Deserialization definitions
Expand Down
6 changes: 5 additions & 1 deletion crates/rust-analyzer/src/lsp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() || config.client_is_neovim() {
config.completion_item_edit_resolve().then_some(true)
} else {
Some(config.caps().completions_resolve_provider())
},
trigger_characters: Some(vec![
":".to_owned(),
".".to_owned(),
Expand Down
Loading