Skip to content

Commit 998f978

Browse files
authored
Merge pull request rust-lang#18630 from Veykril/push-ystzsxpywnxn
fix: Temporarily disable completion resolve support for helix and neovim
2 parents fb79ab7 + 78496f8 commit 998f978

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rust_analyzer::{
2020
config::{Config, ConfigChange, ConfigErrors},
2121
from_json,
2222
};
23-
use semver::Version;
2423
use tracing_subscriber::fmt::writer::BoxMakeWriter;
2524
use vfs::AbsPathBuf;
2625

@@ -204,18 +203,12 @@ fn run_server() -> anyhow::Result<()> {
204203
}
205204
};
206205

207-
let mut visual_studio_code_version = None;
208-
if let Some(client_info) = client_info {
206+
if let Some(client_info) = &client_info {
209207
tracing::info!(
210208
"Client '{}' {}",
211209
client_info.name,
212210
client_info.version.as_deref().unwrap_or_default()
213211
);
214-
visual_studio_code_version = client_info
215-
.name
216-
.starts_with("Visual Studio Code")
217-
.then(|| client_info.version.as_deref().map(Version::parse).and_then(Result::ok))
218-
.flatten();
219212
}
220213

221214
let workspace_roots = workspace_folders
@@ -230,8 +223,7 @@ fn run_server() -> anyhow::Result<()> {
230223
})
231224
.filter(|workspaces| !workspaces.is_empty())
232225
.unwrap_or_else(|| vec![root_path.clone()]);
233-
let mut config =
234-
Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version);
226+
let mut config = Config::new(root_path, capabilities, workspace_roots, client_info);
235227
if let Some(json) = initialization_options {
236228
let mut change = ConfigChange::default();
237229
change.change_client_config(json);

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ enum RatomlFile {
730730
Crate(LocalConfigInput),
731731
}
732732

733+
#[derive(Clone, Debug)]
734+
struct ClientInfo {
735+
name: String,
736+
version: Option<Version>,
737+
}
738+
733739
#[derive(Clone)]
734740
pub struct Config {
735741
/// Projects that have a Cargo.toml or a rust-project.json in a
@@ -744,7 +750,7 @@ pub struct Config {
744750
caps: ClientCapabilities,
745751
root_path: AbsPathBuf,
746752
snippets: Vec<Snippet>,
747-
visual_studio_code_version: Option<Version>,
753+
client_info: Option<ClientInfo>,
748754

749755
default_config: &'static DefaultConfigData,
750756
/// Config node that obtains its initial value during the server initialization and
@@ -777,7 +783,7 @@ impl fmt::Debug for Config {
777783
.field("caps", &self.caps)
778784
.field("root_path", &self.root_path)
779785
.field("snippets", &self.snippets)
780-
.field("visual_studio_code_version", &self.visual_studio_code_version)
786+
.field("client_info", &self.client_info)
781787
.field("client_config", &self.client_config)
782788
.field("user_config", &self.user_config)
783789
.field("ratoml_file", &self.ratoml_file)
@@ -1335,7 +1341,7 @@ impl Config {
13351341
root_path: AbsPathBuf,
13361342
caps: lsp_types::ClientCapabilities,
13371343
workspace_roots: Vec<AbsPathBuf>,
1338-
visual_studio_code_version: Option<Version>,
1344+
client_info: Option<lsp_types::ClientInfo>,
13391345
) -> Self {
13401346
static DEFAULT_CONFIG_DATA: OnceLock<&'static DefaultConfigData> = OnceLock::new();
13411347

@@ -1346,7 +1352,10 @@ impl Config {
13461352
root_path,
13471353
snippets: Default::default(),
13481354
workspace_roots,
1349-
visual_studio_code_version,
1355+
client_info: client_info.map(|it| ClientInfo {
1356+
name: it.name,
1357+
version: it.version.as_deref().map(Version::parse).and_then(Result::ok),
1358+
}),
13501359
client_config: (FullConfigInput::default(), ConfigErrors(vec![])),
13511360
default_config: DEFAULT_CONFIG_DATA.get_or_init(|| Box::leak(Box::default())),
13521361
source_root_parent_map: Arc::new(FxHashMap::default()),
@@ -1446,9 +1455,11 @@ impl Config {
14461455
limit: self.completion_limit(source_root).to_owned(),
14471456
enable_term_search: self.completion_termSearch_enable(source_root).to_owned(),
14481457
term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
1449-
fields_to_resolve: CompletionFieldsToResolve::from_client_capabilities(
1450-
&client_capability_fields,
1451-
),
1458+
fields_to_resolve: if self.client_is_helix() || self.client_is_neovim() {
1459+
CompletionFieldsToResolve::empty()
1460+
} else {
1461+
CompletionFieldsToResolve::from_client_capabilities(&client_capability_fields)
1462+
},
14521463
}
14531464
}
14541465

@@ -2163,7 +2174,18 @@ impl Config {
21632174
// VSCode is our reference implementation, so we allow ourselves to work around issues by
21642175
// special casing certain versions
21652176
pub fn visual_studio_code_version(&self) -> Option<&Version> {
2166-
self.visual_studio_code_version.as_ref()
2177+
self.client_info
2178+
.as_ref()
2179+
.filter(|it| it.name.starts_with("Visual Studio Code"))
2180+
.and_then(|it| it.version.as_ref())
2181+
}
2182+
2183+
pub fn client_is_helix(&self) -> bool {
2184+
self.client_info.as_ref().map(|it| it.name == "helix").unwrap_or_default()
2185+
}
2186+
2187+
pub fn client_is_neovim(&self) -> bool {
2188+
self.client_info.as_ref().map(|it| it.name == "Neovim").unwrap_or_default()
21672189
}
21682190
}
21692191
// Deserialization definitions

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/capabilities.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
4141
})),
4242
hover_provider: Some(HoverProviderCapability::Simple(true)),
4343
completion_provider: Some(CompletionOptions {
44-
resolve_provider: Some(config.caps().completions_resolve_provider()),
44+
resolve_provider: if config.client_is_helix() || config.client_is_neovim() {
45+
config.completion_item_edit_resolve().then_some(true)
46+
} else {
47+
Some(config.caps().completions_resolve_provider())
48+
},
4549
trigger_characters: Some(vec![
4650
":".to_owned(),
4751
".".to_owned(),

0 commit comments

Comments
 (0)