2271: Force passing Source when creating a SourceAnalyzer r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-11-15 23:12:59 +00:00 committed by GitHub
commit d9d99369b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 54 deletions

View file

@ -19,7 +19,11 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
let calling_node = FnCallNode::with_node(&syntax, position.offset)?;
let name_ref = calling_node.name_ref()?;
let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None);
let analyzer = hir::SourceAnalyzer::new(
db,
hir::Source::new(position.file_id.into(), name_ref.syntax()),
None,
);
let (mut call_info, has_self) = match &calling_node {
FnCallNode::CallExpr(expr) => {
//FIXME: apply subst

View file

@ -58,8 +58,11 @@ impl<'a> CompletionContext<'a> {
);
let token =
original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?;
let analyzer =
hir::SourceAnalyzer::new(db, position.file_id, &token.parent(), Some(position.offset));
let analyzer = hir::SourceAnalyzer::new(
db,
hir::Source::new(position.file_id.into(), &token.parent()),
Some(position.offset),
);
let mut ctx = CompletionContext {
db,
analyzer,

View file

@ -18,7 +18,8 @@ pub(crate) fn goto_type_definition(
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())
})?;
let analyzer = hir::SourceAnalyzer::new(db, position.file_id, &node, None);
let analyzer =
hir::SourceAnalyzer::new(db, hir::Source::new(position.file_id.into(), &node), None);
let ty: hir::Ty = if let Some(ty) =
ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))

View file

@ -230,7 +230,8 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
.ancestors()
.take_while(|it| it.text_range() == leaf_node.text_range())
.find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?;
let analyzer = hir::SourceAnalyzer::new(db, frange.file_id, &node, None);
let analyzer =
hir::SourceAnalyzer::new(db, hir::Source::new(frange.file_id.into(), &node), None);
let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
{
ty

View file

@ -32,6 +32,7 @@ fn get_inlay_hints(
file_id: FileId,
node: &SyntaxNode,
) -> Option<Vec<InlayHint>> {
let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None);
match_ast! {
match node {
ast::LetStmt(it) => {
@ -39,11 +40,9 @@ fn get_inlay_hints(
return None;
}
let pat = it.pat()?;
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
Some(get_pat_type_hints(db, &analyzer, pat, false))
},
ast::LambdaExpr(it) => {
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
it.param_list().map(|param_list| {
param_list
.params()
@ -56,21 +55,17 @@ fn get_inlay_hints(
},
ast::ForExpr(it) => {
let pat = it.pat()?;
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
Some(get_pat_type_hints(db, &analyzer, pat, false))
},
ast::IfExpr(it) => {
let pat = it.condition()?.pat()?;
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
Some(get_pat_type_hints(db, &analyzer, pat, true))
},
ast::WhileExpr(it) => {
let pat = it.condition()?.pat()?;
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
Some(get_pat_type_hints(db, &analyzer, pat, true))
},
ast::MatchArmList(it) => {
let analyzer = SourceAnalyzer::new(db, file_id, it.syntax(), None);
Some(
it
.arms()

View file

@ -129,7 +129,8 @@ pub(crate) fn classify_name_ref(
let _p = profile("classify_name_ref");
let parent = name_ref.syntax().parent()?;
let analyzer = SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
let analyzer =
SourceAnalyzer::new(db, hir::Source::new(file_id.into(), name_ref.syntax()), None);
if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
tested_by!(goto_definition_works_for_methods);