Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use module name as line after which we'll insert auto-import #6025

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tooling/lsp/src/requests/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
macros_api::{ModuleDefId, NodeInterner},
node_interner::ReferenceId,
parser::{Item, ItemKind, ParsedSubModule},
token::CustomAtrribute,

Check warning on line 27 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Atrribute)
ParsedModule, StructType, Type,
};
use sort_text::underscore_sort_text;
Expand All @@ -34,7 +34,7 @@
use super::process_request;

mod auto_import;
mod builtins;

Check warning on line 37 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (builtins)
mod completion_items;
mod kinds;
mod sort_text;
Expand Down Expand Up @@ -219,7 +219,7 @@
let mut idents: Vec<Ident> = Vec::new();

// Find in which ident we are in, and in which part of it
// (it could be that we are completting in the middle of an ident)

Check warning on line 222 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (completting)
for segment in &path.segments {
let ident = &segment.ident;

Expand Down Expand Up @@ -882,7 +882,7 @@
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;

Expand All @@ -897,7 +897,9 @@
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;
}

Expand Down Expand Up @@ -1329,7 +1331,7 @@
false
}

fn visit_custom_attribute(&mut self, attribute: &CustomAtrribute, target: AttributeTarget) {

Check warning on line 1334 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Atrribute)
if self.byte_index != attribute.contents_span.end() as usize {
return;
}
Expand All @@ -1346,8 +1348,8 @@
///
/// For example:
///
/// // "merk" and "ro" match "merkle" and "root" and are in order

Check warning on line 1351 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (merk)
/// name_matches("compute_merkle_root", "merk_ro") == true

Check warning on line 1352 in tooling/lsp/src/requests/completion.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (merk)
///
/// // "ro" matches "root", but "merkle" comes before it, so no match
/// name_matches("compute_merkle_root", "ro_mer") == false
Expand Down
5 changes: 3 additions & 2 deletions tooling/lsp/src/requests/completion/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@
#[test]
async fn test_use_first_segment() {
let src = r#"
mod foobaz {}

Check warning on line 135 in tooling/lsp/src/requests/completion/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (foobaz)
mod foobar {}
use foob>|<

Check warning on line 137 in tooling/lsp/src/requests/completion/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (foob)
"#;

assert_completion(
src,
vec![module_completion_item("foobaz"), module_completion_item("foobar")],

Check warning on line 142 in tooling/lsp/src/requests/completion/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (foobaz)
)
.await;
}
Expand Down Expand Up @@ -302,7 +302,7 @@
mod bar {
mod something {}

use super::foob>|<

Check warning on line 305 in tooling/lsp/src/requests/completion/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (foob)
}
"#;

Expand Down Expand Up @@ -1395,6 +1395,7 @@
#[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() {}
Expand Down Expand Up @@ -1422,8 +1423,8 @@
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(),
}])
Expand Down
Loading