Skip to content

Commit 1841192

Browse files
Do not resolve inlayHint.textEdit for VSCode client
VSCode behaves strangely, allowing to navigate into label location, but not allowing to apply hint's text edit, after hint is resolved. See microsoft/vscode#193124 for details. For now, stub hint resolution for VSCode specifically.
1 parent 22b18b9 commit 1841192

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ fn run_server() -> anyhow::Result<()> {
190190
}
191191
};
192192

193+
let mut is_visual_studio = false;
194+
if let Some(client_info) = client_info {
195+
tracing::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default());
196+
is_visual_studio = client_info.name == "Visual Studio Code";
197+
}
198+
193199
let workspace_roots = workspace_folders
194200
.map(|workspaces| {
195201
workspaces
@@ -201,7 +207,7 @@ fn run_server() -> anyhow::Result<()> {
201207
})
202208
.filter(|workspaces| !workspaces.is_empty())
203209
.unwrap_or_else(|| vec![root_path.clone()]);
204-
let mut config = Config::new(root_path, capabilities, workspace_roots);
210+
let mut config = Config::new(root_path, capabilities, workspace_roots, is_visual_studio);
205211
if let Some(json) = initialization_options {
206212
if let Err(e) = config.update(json) {
207213
use lsp_types::{
@@ -231,10 +237,6 @@ fn run_server() -> anyhow::Result<()> {
231237

232238
connection.initialize_finish(initialize_id, initialize_result)?;
233239

234-
if let Some(client_info) = client_info {
235-
tracing::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default());
236-
}
237-
238240
if !config.has_linked_projects() && config.detached_files().is_empty() {
239241
config.rediscover_workspaces();
240242
}

crates/rust-analyzer/src/config.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ pub struct Config {
565565
data: ConfigData,
566566
detached_files: Vec<AbsPathBuf>,
567567
snippets: Vec<Snippet>,
568+
is_visual_studio: bool,
568569
}
569570

570571
type ParallelCachePrimingNumThreads = u8;
@@ -760,6 +761,7 @@ impl Config {
760761
root_path: AbsPathBuf,
761762
caps: ClientCapabilities,
762763
workspace_roots: Vec<AbsPathBuf>,
764+
is_visual_studio: bool,
763765
) -> Self {
764766
Config {
765767
caps,
@@ -769,6 +771,7 @@ impl Config {
769771
root_path,
770772
snippets: Default::default(),
771773
workspace_roots,
774+
is_visual_studio,
772775
}
773776
}
774777

@@ -1667,6 +1670,12 @@ impl Config {
16671670
pub fn typing_autoclose_angle(&self) -> bool {
16681671
self.data.typing_autoClosingAngleBrackets_enable
16691672
}
1673+
1674+
// FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124
1675+
// hence, distinguish it for now.
1676+
pub fn is_visual_studio(&self) -> bool {
1677+
self.is_visual_studio
1678+
}
16701679
}
16711680
// Deserialization definitions
16721681

@@ -2555,8 +2564,12 @@ mod tests {
25552564

25562565
#[test]
25572566
fn proc_macro_srv_null() {
2558-
let mut config =
2559-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2567+
let mut config = Config::new(
2568+
AbsPathBuf::try_from(project_root()).unwrap(),
2569+
Default::default(),
2570+
vec![],
2571+
false,
2572+
);
25602573
config
25612574
.update(serde_json::json!({
25622575
"procMacro_server": null,
@@ -2567,8 +2580,12 @@ mod tests {
25672580

25682581
#[test]
25692582
fn proc_macro_srv_abs() {
2570-
let mut config =
2571-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2583+
let mut config = Config::new(
2584+
AbsPathBuf::try_from(project_root()).unwrap(),
2585+
Default::default(),
2586+
vec![],
2587+
false,
2588+
);
25722589
config
25732590
.update(serde_json::json!({
25742591
"procMacro": {"server": project_root().display().to_string()}
@@ -2579,8 +2596,12 @@ mod tests {
25792596

25802597
#[test]
25812598
fn proc_macro_srv_rel() {
2582-
let mut config =
2583-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2599+
let mut config = Config::new(
2600+
AbsPathBuf::try_from(project_root()).unwrap(),
2601+
Default::default(),
2602+
vec![],
2603+
false,
2604+
);
25842605
config
25852606
.update(serde_json::json!({
25862607
"procMacro": {"server": "./server"}

crates/rust-analyzer/src/diagnostics/to_proto.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,12 @@ mod tests {
538538
let (sender, _) = crossbeam_channel::unbounded();
539539
let state = GlobalState::new(
540540
sender,
541-
Config::new(workspace_root.to_path_buf(), ClientCapabilities::default(), Vec::new()),
541+
Config::new(
542+
workspace_root.to_path_buf(),
543+
ClientCapabilities::default(),
544+
Vec::new(),
545+
false,
546+
),
542547
);
543548
let snap = state.snapshot();
544549
let mut actual = map_rust_diagnostic_to_lsp(&config, &diagnostic, workspace_root, &snap);

crates/rust-analyzer/src/lsp/to_proto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,11 @@ pub(crate) fn inlay_hint(
443443
file_id: FileId,
444444
inlay_hint: InlayHint,
445445
) -> Cancellable<lsp_types::InlayHint> {
446+
let is_visual_studio = snap.config.is_visual_studio();
446447
let needs_resolve = inlay_hint.needs_resolve;
447448
let (label, tooltip, mut something_to_resolve) =
448449
inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?;
449-
let text_edits = if needs_resolve && fields_to_resolve.resolve_text_edits {
450+
let text_edits = if !is_visual_studio && needs_resolve && fields_to_resolve.resolve_text_edits {
450451
something_to_resolve |= inlay_hint.text_edit.is_some();
451452
None
452453
} else {

crates/rust-analyzer/tests/slow-tests/support.rs

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl Project<'_> {
150150
..Default::default()
151151
},
152152
roots,
153+
false,
153154
);
154155
config.update(self.config).expect("invalid config");
155156
config.rediscover_workspaces();

0 commit comments

Comments
 (0)