Skip to content

Commit 238de1d

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 238de1d

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

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

Lines changed: 7 additions & 5 deletions
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

Lines changed: 28 additions & 6 deletions
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

@@ -1336,6 +1339,7 @@ impl Config {
13361339
}
13371340

13381341
pub fn inlay_hints(&self) -> InlayHintsConfig {
1342+
dbg!("TODO kb");
13391343
let client_capability_fields = self
13401344
.caps
13411345
.text_document
@@ -1667,6 +1671,12 @@ impl Config {
16671671
pub fn typing_autoclose_angle(&self) -> bool {
16681672
self.data.typing_autoClosingAngleBrackets_enable
16691673
}
1674+
1675+
// FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124
1676+
// hence, distinguish it for now.
1677+
pub fn is_visual_studio(&self) -> bool {
1678+
self.is_visual_studio
1679+
}
16701680
}
16711681
// Deserialization definitions
16721682

@@ -2555,8 +2565,12 @@ mod tests {
25552565

25562566
#[test]
25572567
fn proc_macro_srv_null() {
2558-
let mut config =
2559-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2568+
let mut config = Config::new(
2569+
AbsPathBuf::try_from(project_root()).unwrap(),
2570+
Default::default(),
2571+
vec![],
2572+
false,
2573+
);
25602574
config
25612575
.update(serde_json::json!({
25622576
"procMacro_server": null,
@@ -2567,8 +2581,12 @@ mod tests {
25672581

25682582
#[test]
25692583
fn proc_macro_srv_abs() {
2570-
let mut config =
2571-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2584+
let mut config = Config::new(
2585+
AbsPathBuf::try_from(project_root()).unwrap(),
2586+
Default::default(),
2587+
vec![],
2588+
false,
2589+
);
25722590
config
25732591
.update(serde_json::json!({
25742592
"procMacro": {"server": project_root().display().to_string()}
@@ -2579,8 +2597,12 @@ mod tests {
25792597

25802598
#[test]
25812599
fn proc_macro_srv_rel() {
2582-
let mut config =
2583-
Config::new(AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![]);
2600+
let mut config = Config::new(
2601+
AbsPathBuf::try_from(project_root()).unwrap(),
2602+
Default::default(),
2603+
vec![],
2604+
false,
2605+
);
25842606
config
25852607
.update(serde_json::json!({
25862608
"procMacro": {"server": "./server"}

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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)