Skip to content

Commit b8d99cc

Browse files
committed
fix(lsp): hack solution for workspace-wide PWD
1 parent 6e04433 commit b8d99cc

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

crates/nu-lsp/src/workspace.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,17 @@ impl LanguageServer {
138138
) -> Option<Vec<Location>> {
139139
self.occurrences = BTreeMap::new();
140140
let path_uri = params.text_document_position.text_document.uri.to_owned();
141-
let mut engine_state = self.new_engine_state(None);
141+
142+
// HACK: when current file is imported (use keyword) by others in the workspace,
143+
// it will get parsed a second time via `parse_module_block`, so that its definitions'
144+
// ids are renewed, making it harder to track the references.
145+
// The fake Uri stops that with `ParseError::ModuleNotFound`,
146+
// which seems benign for tasks like this.
147+
// FIXME: cross-file shadowing can still cause false-positive/false-negative cases
148+
let mut engine_state = self.new_engine_state(Some(&path_to_uri(
149+
"/non-exisiting-directory/non-existing-file",
150+
)));
151+
142152
let (_, id, span, _) = self
143153
.parse_and_find(
144154
&mut engine_state,
@@ -199,7 +209,16 @@ impl LanguageServer {
199209
self.occurrences = BTreeMap::new();
200210

201211
let path_uri = params.text_document.uri.to_owned();
202-
let mut engine_state = self.new_engine_state(None);
212+
213+
// HACK: when current file is imported (use keyword) by others in the workspace,
214+
// it will get parsed a second time via `parse_module_block`, so that its definitions'
215+
// ids are renewed, making it harder to track the references.
216+
// The fake Uri stops that with `ParseError::ModuleNotFound`,
217+
// which seems benign for tasks like this.
218+
// FIXME: cross-file shadowing can still cause false-positive/false-negative cases
219+
let mut engine_state = self.new_engine_state(Some(&path_to_uri(
220+
"/non-exisiting-directory/non-existing-file",
221+
)));
203222

204223
let (working_set, id, span, file_offset) =
205224
self.parse_and_find(&mut engine_state, &path_uri, params.position)?;

0 commit comments

Comments
 (0)