Skip to content

Commit 6c2e0d7

Browse files
fix(lsp): handle navigation result errors (#10701)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 3438a3d commit 6c2e0d7

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

.changeset/spotty-swans-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#10694](https://github.com/biomejs/biome/issues/10694). The Biome Language Server no longer prints an error when the user hovers a variable imported from node_modules.

crates/biome_lsp/src/handlers/navigation.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ pub(crate) fn goto_definition(
5151
path: path.clone(),
5252
cursor_range,
5353
enabled,
54-
})?;
54+
});
55+
// The feature might not have access to all files per design e.g. node_modules dependencies.
56+
// This will return a `Result`, but we shouldn't bubble it as an error to the user.
57+
let Ok(result) = result else {
58+
return Ok(None);
59+
};
5560

5661
match result {
5762
Some(definition) => {

crates/biome_lsp/src/server_goto.tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,4 +742,38 @@ async fn goto_definition_css_cross_file_multiple_definitions() -> Result<()> {
742742
Ok(())
743743
}
744744

745+
#[tokio::test]
746+
async fn goto_definition_node_modules_import_does_not_error() -> Result<()> {
747+
// Regression test for https://github.com/biomejs/biome/issues/10694.
748+
//
749+
// Line 0: `import { helper } from 'external-pkg';`
750+
// 0123456789 → `helper` starts at char 9
751+
let (res, _fs) = goto_definition_cross_file(CrossFileTestParams {
752+
name: "goto_definition_node_modules_import_does_not_error",
753+
config: r#"{ "linter": { "enabled": true } }"#,
754+
files: vec![
755+
(
756+
"node_modules/external-pkg/index.js",
757+
"export function helper() {}\n",
758+
),
759+
(
760+
"main.js",
761+
"import { helper } from 'external-pkg';\nhelper();\n",
762+
),
763+
],
764+
open_file: "main.js",
765+
language_id: "javascript",
766+
source: "import { helper } from 'external-pkg';\nhelper();\n",
767+
cursor: pos(0, 9),
768+
})
769+
.await?;
770+
771+
assert!(
772+
res.is_none(),
773+
"go-to definition on a node_modules import should resolve to None, not error"
774+
);
775+
776+
Ok(())
777+
}
778+
745779
// #endregion

0 commit comments

Comments
 (0)