Remove lower_path from AssistCtx to Semantic

This commit is contained in:
Edwin Cheng 2020-05-01 19:58:47 +08:00
parent bdcf6f5658
commit 44f5e2048c
3 changed files with 10 additions and 8 deletions

View file

@ -1,12 +1,12 @@
//! This module defines `AssistCtx` -- the API surface that is exposed to assists. //! This module defines `AssistCtx` -- the API surface that is exposed to assists.
use hir::Semantics; use hir::Semantics;
use ra_db::{FileRange, Upcast}; use ra_db::FileRange;
use ra_fmt::{leading_indent, reindent}; use ra_fmt::{leading_indent, reindent};
use ra_ide_db::RootDatabase; use ra_ide_db::RootDatabase;
use ra_syntax::{ use ra_syntax::{
algo::{self, find_covering_element, find_node_at_offset}, algo::{self, find_covering_element, find_node_at_offset},
ast, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
TextSize, TokenAtOffset, TokenAtOffset,
}; };
use ra_text_edit::TextEditBuilder; use ra_text_edit::TextEditBuilder;
@ -136,9 +136,6 @@ impl<'a> AssistCtx<'a> {
pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement {
find_covering_element(self.source_file.syntax(), range) find_covering_element(self.source_file.syntax(), range)
} }
pub(crate) fn lower_path(&self, path: ast::Path) -> Option<hir::Path> {
hir::Path::from_src(path, &hir::Hygiene::new(self.db.upcast(), self.frange.file_id.into()))
}
} }
pub(crate) struct AssistGroup<'a> { pub(crate) struct AssistGroup<'a> {

View file

@ -27,7 +27,7 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option<Assist>
return None; return None;
} }
let hir_path = ctx.lower_path(path.clone())?; let hir_path = ctx.sema.lower_path(&path)?;
let segments = collect_hir_path_segments(&hir_path)?; let segments = collect_hir_path_segments(&hir_path)?;
if segments.len() < 2 { if segments.len() < 2 {
return None; return None;

View file

@ -8,7 +8,7 @@ use hir_def::{
resolver::{self, HasResolver, Resolver}, resolver::{self, HasResolver, Resolver},
AsMacroCall, TraitId, AsMacroCall, TraitId,
}; };
use hir_expand::ExpansionInfo; use hir_expand::{hygiene::Hygiene, ExpansionInfo};
use hir_ty::associated_type_shorthand_candidates; use hir_ty::associated_type_shorthand_candidates;
use itertools::Itertools; use itertools::Itertools;
use ra_db::{FileId, FileRange}; use ra_db::{FileId, FileRange};
@ -246,6 +246,11 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.analyze(path.syntax()).resolve_path(self.db, path) self.analyze(path.syntax()).resolve_path(self.db, path)
} }
pub fn lower_path(&self, path: &ast::Path) -> Option<Path> {
let src = self.find_file(path.syntax().clone());
Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into()))
}
pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> {
self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat) self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat)
} }