Skip to content

Commit f818294

Browse files
authored
fix(lsp): don't panic on unresolved dts import hover (#34112)
Fixes #33723 - Return no hover when a dependency hover in a `.d.ts` file has neither code nor type resolution. - Add an LSP regression test for hovering an unresolved bare import in `types.d.ts`. Co-authored-by: lunadogbot <lunadogbot@users.noreply.github.com>
1 parent 99be4f5 commit f818294

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

cli/lsp/language_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ impl Inner {
19221922
self
19231923
.resolution_to_hover_text(&dep.maybe_type, module.scope.as_deref()),
19241924
),
1925-
(true, true, _) => unreachable!("{}", json!(params)),
1925+
(true, true, _) => return Ok(None),
19261926
};
19271927
let value = if let Some(docs) = self.module_registry.get_hover(dep).await
19281928
{

tests/integration/lsp_tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,33 @@ fn lsp_hover_dependency() {
27902790
client.shutdown();
27912791
}
27922792

2793+
#[test(timeout = 300)]
2794+
fn lsp_hover_unresolved_dependency_in_dts() {
2795+
let context = TestContextBuilder::new().use_temp_cwd().build();
2796+
let mut client = context.new_lsp_command().build();
2797+
client.initialize_default();
2798+
client.did_open(json!({
2799+
"textDocument": {
2800+
"uri": "file:///a/types.d.ts",
2801+
"languageId": "typescript",
2802+
"version": 1,
2803+
"text": "import UI5Element from 'unresolved-bare-specifier';\n",
2804+
}
2805+
}));
2806+
2807+
let res = client.write_request(
2808+
"textDocument/hover",
2809+
json!({
2810+
"textDocument": {
2811+
"uri": "file:///a/types.d.ts",
2812+
},
2813+
"position": { "line": 0, "character": 29 }
2814+
}),
2815+
);
2816+
assert_eq!(res, json!(null));
2817+
client.shutdown();
2818+
}
2819+
27932820
// This tests for a regression covered by denoland/deno#12753 where the lsp was
27942821
// unable to resolve dependencies when there was an invalid syntax in the module
27952822
#[test(timeout = 300)]

0 commit comments

Comments
 (0)