diff --git a/tooling/lsp/src/requests/completion.rs b/tooling/lsp/src/requests/completion.rs index de5c36bc59f..d07ad826094 100644 --- a/tooling/lsp/src/requests/completion.rs +++ b/tooling/lsp/src/requests/completion.rs @@ -882,7 +882,7 @@ impl<'a> Visitor for NodeFinder<'a> { false } - fn visit_parsed_submodule(&mut self, parsed_sub_module: &ParsedSubModule, span: Span) -> bool { + fn visit_parsed_submodule(&mut self, parsed_sub_module: &ParsedSubModule, _span: Span) -> bool { // Switch `self.module_id` to the submodule let previous_module_id = self.module_id; @@ -897,7 +897,9 @@ impl<'a> Visitor for NodeFinder<'a> { let old_auto_import_line = self.auto_import_line; self.nesting += 1; - if let Some(lsp_location) = to_lsp_location(self.files, self.file, span) { + if let Some(lsp_location) = + to_lsp_location(self.files, self.file, parsed_sub_module.name.span()) + { self.auto_import_line = (lsp_location.range.start.line + 1) as usize; } diff --git a/tooling/lsp/src/requests/completion/tests.rs b/tooling/lsp/src/requests/completion/tests.rs index 7e11e0d9d52..6809e24e645 100644 --- a/tooling/lsp/src/requests/completion/tests.rs +++ b/tooling/lsp/src/requests/completion/tests.rs @@ -1395,6 +1395,7 @@ mod completion_tests { #[test] async fn test_auto_imports_when_in_nested_module_and_item_is_further_nested() { let src = r#" + #[something] mod foo { mod bar { pub fn hello_world() {} @@ -1422,8 +1423,8 @@ mod completion_tests { item.additional_text_edits, Some(vec![TextEdit { range: Range { - start: Position { line: 2, character: 4 }, - end: Position { line: 2, character: 4 }, + start: Position { line: 3, character: 4 }, + end: Position { line: 3, character: 4 }, }, new_text: "use bar::hello_world;\n\n ".to_string(), }])