mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Merge #2270
2270: Reduce some duplication r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
ad10c4b8e2
@ -1,6 +1,5 @@
|
||||
//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
|
||||
|
||||
use hir::db::HirDatabase;
|
||||
use hir::{db::HirDatabase, SourceAnalyzer};
|
||||
use ra_db::FileRange;
|
||||
use ra_fmt::{leading_indent, reindent};
|
||||
use ra_syntax::{
|
||||
@ -113,6 +112,13 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
|
||||
pub(crate) fn covering_element(&self) -> SyntaxElement {
|
||||
find_covering_element(self.source_file.syntax(), self.frange.range)
|
||||
}
|
||||
pub(crate) fn source_analyzer(
|
||||
&self,
|
||||
node: &SyntaxNode,
|
||||
offset: Option<TextUnit>,
|
||||
) -> SourceAnalyzer {
|
||||
SourceAnalyzer::new(self.db, self.frange.file_id, node, offset)
|
||||
}
|
||||
|
||||
pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement {
|
||||
find_covering_element(self.source_file.syntax(), range)
|
||||
|
@ -40,7 +40,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
|
||||
}
|
||||
// Infer type
|
||||
let db = ctx.db;
|
||||
let analyzer = hir::SourceAnalyzer::new(db, ctx.frange.file_id, stmt.syntax(), None);
|
||||
let analyzer = ctx.source_analyzer(stmt.syntax(), None);
|
||||
let ty = analyzer.type_of(db, &expr)?;
|
||||
// Assist not applicable if the type is unknown
|
||||
if is_unknown(&ty) {
|
||||
|
@ -100,8 +100,7 @@ fn add_missing_impl_members_inner(
|
||||
let impl_item_list = impl_node.item_list()?;
|
||||
|
||||
let trait_def = {
|
||||
let file_id = ctx.frange.file_id;
|
||||
let analyzer = hir::SourceAnalyzer::new(ctx.db, file_id, impl_node.syntax(), None);
|
||||
let analyzer = ctx.source_analyzer(impl_node.syntax(), None);
|
||||
|
||||
resolve_target_trait_def(ctx.db, &analyzer, &impl_node)?
|
||||
};
|
||||
|
@ -47,8 +47,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist
|
||||
|
||||
let expr = match_expr.expr()?;
|
||||
let enum_def = {
|
||||
let file_id = ctx.frange.file_id;
|
||||
let analyzer = hir::SourceAnalyzer::new(ctx.db, file_id, expr.syntax(), None);
|
||||
let analyzer = ctx.source_analyzer(expr.syntax(), None);
|
||||
resolve_enum_def(ctx.db, &analyzer, &expr)?
|
||||
};
|
||||
let variant_list = enum_def.variant_list()?;
|
||||
|
@ -45,7 +45,7 @@ pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option<
|
||||
} else {
|
||||
let_stmt.syntax().text_range()
|
||||
};
|
||||
let analyzer = hir::SourceAnalyzer::new(ctx.db, ctx.frange.file_id, bind_pat.syntax(), None);
|
||||
let analyzer = ctx.source_analyzer(bind_pat.syntax(), None);
|
||||
let refs = analyzer.find_all_refs(&bind_pat);
|
||||
|
||||
let mut wrap_in_parens = vec![true; refs.len()];
|
||||
|
@ -125,12 +125,12 @@ pub struct ModuleData {
|
||||
pub impls: Vec<ImplId>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Declarations {
|
||||
fns: FxHashMap<FileAstId<ast::FnDef>, FunctionId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct ModuleScope {
|
||||
items: FxHashMap<Name, Resolution>,
|
||||
/// Macros visable in current module in legacy textual scope
|
||||
|
Loading…
Reference in New Issue
Block a user