mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
remove path_ident from CompletionContext
We really shouldn't be looking at the identifier at point. Instead, all filtering and sorting should be implemented at the layer above. This layer should probably be home for auto-import completions as well, but, since that is not yet implemented, let's just stick this into complete_scope.
This commit is contained in:
parent
e01052d1f0
commit
c27a3da5e8
2 changed files with 38 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use ra_text_edit::TextEditBuilder;
|
use ra_text_edit::TextEditBuilder;
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::{SmolStr, ast, AstNode};
|
||||||
use ra_assists::auto_import;
|
use ra_assists::auto_import;
|
||||||
|
|
||||||
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext};
|
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext};
|
||||||
|
@ -9,11 +9,12 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if ctx.is_trivial_path {
|
if ctx.is_trivial_path {
|
||||||
let names = ctx.analyzer.all_names(ctx.db);
|
let names = ctx.analyzer.all_names(ctx.db);
|
||||||
names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
|
names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res));
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(name) = ctx.path_ident.as_ref() {
|
// auto-import
|
||||||
|
// We fetch ident from the original file, because we need to pre-filter auto-imports
|
||||||
|
if ast::NameRef::cast(ctx.token.parent()).is_some() {
|
||||||
let import_resolver = ImportResolver::new();
|
let import_resolver = ImportResolver::new();
|
||||||
let import_names = import_resolver.all_names(&name.to_string());
|
let import_names = import_resolver.all_names(ctx.token.text());
|
||||||
import_names.into_iter().for_each(|(name, path)| {
|
import_names.into_iter().for_each(|(name, path)| {
|
||||||
let edit = {
|
let edit = {
|
||||||
let mut builder = TextEditBuilder::default();
|
let mut builder = TextEditBuilder::default();
|
||||||
|
@ -45,6 +46,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_import_label(name: &str, path: &Vec<SmolStr>) -> String {
|
fn build_import_label(name: &str, path: &Vec<SmolStr>) -> String {
|
||||||
|
|
|
@ -5,10 +5,10 @@ use ra_syntax::{
|
||||||
algo::{find_token_at_offset, find_covering_element, find_node_at_offset},
|
algo::{find_token_at_offset, find_covering_element, find_node_at_offset},
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
};
|
};
|
||||||
|
use hir::source_binder;
|
||||||
use hir::{ source_binder, Name };
|
|
||||||
|
|
||||||
use crate::{db, FilePosition};
|
use crate::{db, FilePosition};
|
||||||
|
|
||||||
/// `CompletionContext` is created early during completion to figure out, where
|
/// `CompletionContext` is created early during completion to figure out, where
|
||||||
/// exactly is the cursor, syntax-wise.
|
/// exactly is the cursor, syntax-wise.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -29,8 +29,6 @@ pub(crate) struct CompletionContext<'a> {
|
||||||
pub(super) is_trivial_path: bool,
|
pub(super) is_trivial_path: bool,
|
||||||
/// If not a trivial path, the prefix (qualifier).
|
/// If not a trivial path, the prefix (qualifier).
|
||||||
pub(super) path_prefix: Option<hir::Path>,
|
pub(super) path_prefix: Option<hir::Path>,
|
||||||
/// If a trivial path, the ident.
|
|
||||||
pub(super) path_ident: Option<Name>,
|
|
||||||
pub(super) after_if: bool,
|
pub(super) after_if: bool,
|
||||||
/// `true` if we are a statement or a last expr in the block.
|
/// `true` if we are a statement or a last expr in the block.
|
||||||
pub(super) can_be_stmt: bool,
|
pub(super) can_be_stmt: bool,
|
||||||
|
@ -65,7 +63,6 @@ impl<'a> CompletionContext<'a> {
|
||||||
is_pat_binding: false,
|
is_pat_binding: false,
|
||||||
is_trivial_path: false,
|
is_trivial_path: false,
|
||||||
path_prefix: None,
|
path_prefix: None,
|
||||||
path_ident: None,
|
|
||||||
after_if: false,
|
after_if: false,
|
||||||
can_be_stmt: false,
|
can_be_stmt: false,
|
||||||
is_new_item: false,
|
is_new_item: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue