@@ -46,6 +46,20 @@ fn find_nu_scripts_in_folder(folder_uri: &Uri) -> Result<nu_glob::Paths> {
4646 nu_glob:: glob ( & pattern, Uninterruptible ) . into_diagnostic ( )
4747}
4848
49+ /// HACK: when current file is imported (use keyword) by others in the workspace,
50+ /// it will get parsed a second time via `parse_module_block`, so that its definitions'
51+ /// ids are renewed, making it harder to track the references.
52+ /// The fake path stops that with `ParseError::ModuleNotFound`,
53+ /// which seems benign for tasks like references/renaming.
54+ ///
55+ /// FIXME: cross-file shadowing can still cause false-positive/false-negative cases
56+ fn pseudo_path ( ) -> Result < PathBuf > {
57+ let mut path = std:: env:: current_dir ( ) . into_diagnostic ( ) ?;
58+ path. push ( "non-existing-dir" ) ;
59+ path. push ( "non-existing-file" ) ;
60+ Ok ( path)
61+ }
62+
4963impl LanguageServer {
5064 /// Get initial workspace folders from initialization response
5165 pub ( crate ) fn initialize_workspace_folders (
@@ -138,7 +152,8 @@ impl LanguageServer {
138152 ) -> Option < Vec < Location > > {
139153 self . occurrences = BTreeMap :: new ( ) ;
140154 let path_uri = params. text_document_position . text_document . uri . to_owned ( ) ;
141- let mut engine_state = self . new_engine_state ( None ) ;
155+ let mut engine_state = self . new_engine_state ( Some ( & path_to_uri ( pseudo_path ( ) . ok ( ) ?) ) ) ;
156+
142157 let ( _, id, span, _) = self
143158 . parse_and_find (
144159 & mut engine_state,
@@ -199,7 +214,7 @@ impl LanguageServer {
199214 self . occurrences = BTreeMap :: new ( ) ;
200215
201216 let path_uri = params. text_document . uri . to_owned ( ) ;
202- let mut engine_state = self . new_engine_state ( None ) ;
217+ let mut engine_state = self . new_engine_state ( Some ( & path_to_uri ( pseudo_path ( ) ? ) ) ) ;
203218
204219 let ( working_set, id, span, file_offset) =
205220 self . parse_and_find ( & mut engine_state, & path_uri, params. position ) ?;
0 commit comments