mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
migrate ra_hir to the new rowan
This commit is contained in:
parent
7e02aa0eff
commit
e2b28f5bb8
22 changed files with 206 additions and 210 deletions
|
@ -4,10 +4,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||||
use ra_syntax::{
|
use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
|
||||||
ast::{self, NameOwner, StructKind, TypeAscriptionOwner},
|
|
||||||
TreeArc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
type_ref::TypeRef, AsName, AstDatabase, Crate, DefDatabase, Enum, EnumVariant, FieldSource,
|
type_ref::TypeRef, AsName, AstDatabase, Crate, DefDatabase, Enum, EnumVariant, FieldSource,
|
||||||
|
@ -59,11 +56,11 @@ impl StructData {
|
||||||
struct_: Struct,
|
struct_: Struct,
|
||||||
) -> Arc<StructData> {
|
) -> Arc<StructData> {
|
||||||
let src = struct_.source(db);
|
let src = struct_.source(db);
|
||||||
Arc::new(StructData::new(&*src.ast))
|
Arc::new(StructData::new(&src.ast))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant> {
|
fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = ast::EnumVariant> {
|
||||||
enum_def.variant_list().into_iter().flat_map(|it| it.variants())
|
enum_def.variant_list().into_iter().flat_map(|it| it.variants())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +68,9 @@ impl EnumVariant {
|
||||||
pub(crate) fn source_impl(
|
pub(crate) fn source_impl(
|
||||||
self,
|
self,
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
) -> Source<TreeArc<ast::EnumVariant>> {
|
) -> Source<ast::EnumVariant> {
|
||||||
let src = self.parent.source(db);
|
let src = self.parent.source(db);
|
||||||
let ast = variants(&*src.ast)
|
let ast = variants(&src.ast)
|
||||||
.zip(db.enum_data(self.parent).variants.iter())
|
.zip(db.enum_data(self.parent).variants.iter())
|
||||||
.find(|(_syntax, (id, _))| *id == self.id)
|
.find(|(_syntax, (id, _))| *id == self.id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -96,7 +93,7 @@ impl EnumData {
|
||||||
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
|
||||||
let src = e.source(db);
|
let src = e.source(db);
|
||||||
let name = src.ast.name().map(|n| n.as_name());
|
let name = src.ast.name().map(|n| n.as_name());
|
||||||
let variants = variants(&*src.ast)
|
let variants = variants(&src.ast)
|
||||||
.map(|var| EnumVariantData {
|
.map(|var| EnumVariantData {
|
||||||
name: var.name().map(|it| it.as_name()),
|
name: var.name().map(|it| it.as_name()),
|
||||||
variant_data: Arc::new(VariantData::new(var.kind())),
|
variant_data: Arc::new(VariantData::new(var.kind())),
|
||||||
|
|
|
@ -4,10 +4,7 @@ pub(crate) mod docs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_db::{CrateId, Edition, FileId, SourceRootId};
|
use ra_db::{CrateId, Edition, FileId, SourceRootId};
|
||||||
use ra_syntax::{
|
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||||
ast::{self, NameOwner, TypeAscriptionOwner},
|
|
||||||
TreeArc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::{EnumVariantId, StructFieldId, VariantDef},
|
adt::{EnumVariantId, StructFieldId, VariantDef},
|
||||||
|
@ -155,8 +152,8 @@ impl_froms!(
|
||||||
);
|
);
|
||||||
|
|
||||||
pub enum ModuleSource {
|
pub enum ModuleSource {
|
||||||
SourceFile(TreeArc<ast::SourceFile>),
|
SourceFile(ast::SourceFile),
|
||||||
Module(TreeArc<ast::Module>),
|
Module(ast::Module),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleSource {
|
impl ModuleSource {
|
||||||
|
@ -199,7 +196,7 @@ impl Module {
|
||||||
self,
|
self,
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
import: ImportId,
|
import: ImportId,
|
||||||
) -> Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>> {
|
) -> Either<ast::UseTree, ast::ExternCrateItem> {
|
||||||
let src = self.definition_source(db);
|
let src = self.definition_source(db);
|
||||||
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
|
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
|
||||||
source_map.get(&src.ast, import)
|
source_map.get(&src.ast, import)
|
||||||
|
@ -321,8 +318,8 @@ pub struct StructField {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FieldSource {
|
pub enum FieldSource {
|
||||||
Named(TreeArc<ast::NamedFieldDef>),
|
Named(ast::NamedFieldDef),
|
||||||
Pos(TreeArc<ast::PosFieldDef>),
|
Pos(ast::PosFieldDef),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StructField {
|
impl StructField {
|
||||||
|
@ -736,7 +733,7 @@ impl ConstData {
|
||||||
konst: Const,
|
konst: Const,
|
||||||
) -> Arc<ConstData> {
|
) -> Arc<ConstData> {
|
||||||
let node = konst.source(db).ast;
|
let node = konst.source(db).ast;
|
||||||
const_data_for(&*node)
|
const_data_for(&node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn static_data_query(
|
pub(crate) fn static_data_query(
|
||||||
|
@ -744,7 +741,7 @@ impl ConstData {
|
||||||
konst: Static,
|
konst: Static,
|
||||||
) -> Arc<ConstData> {
|
) -> Arc<ConstData> {
|
||||||
let node = konst.source(db).ast;
|
let node = konst.source(db).ast;
|
||||||
const_data_for(&*node)
|
const_data_for(&node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,21 +71,21 @@ pub(crate) fn documentation_query(
|
||||||
def: DocDef,
|
def: DocDef,
|
||||||
) -> Option<Documentation> {
|
) -> Option<Documentation> {
|
||||||
match def {
|
match def {
|
||||||
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
|
DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.ast),
|
||||||
DocDef::StructField(it) => match it.source(db).ast {
|
DocDef::StructField(it) => match it.source(db).ast {
|
||||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
FieldSource::Named(named) => docs_from_ast(&named),
|
||||||
FieldSource::Pos(..) => None,
|
FieldSource::Pos(..) => None,
|
||||||
},
|
},
|
||||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Struct(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Enum(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Static(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Static(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Const(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Function(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Union(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Union(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::Trait(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).ast),
|
||||||
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).ast),
|
DocDef::MacroDef(it) => docs_from_ast(&it.source(db).ast),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ra_syntax::{ast, TreeArc};
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function,
|
ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function,
|
||||||
|
@ -34,7 +34,7 @@ impl Module {
|
||||||
pub fn declaration_source(
|
pub fn declaration_source(
|
||||||
self,
|
self,
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
) -> Option<Source<TreeArc<ast::Module>>> {
|
) -> Option<Source<ast::Module>> {
|
||||||
let def_map = db.crate_def_map(self.krate);
|
let def_map = db.crate_def_map(self.krate);
|
||||||
let decl = def_map[self.module_id].declaration?;
|
let decl = def_map[self.module_id].declaration?;
|
||||||
let ast = decl.to_node(db);
|
let ast = decl.to_node(db);
|
||||||
|
@ -49,62 +49,62 @@ impl HasSource for StructField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Struct {
|
impl HasSource for Struct {
|
||||||
type Ast = TreeArc<ast::StructDef>;
|
type Ast = ast::StructDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StructDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Union {
|
impl HasSource for Union {
|
||||||
type Ast = TreeArc<ast::StructDef>;
|
type Ast = ast::StructDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StructDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Enum {
|
impl HasSource for Enum {
|
||||||
type Ast = TreeArc<ast::EnumDef>;
|
type Ast = ast::EnumDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for EnumVariant {
|
impl HasSource for EnumVariant {
|
||||||
type Ast = TreeArc<ast::EnumVariant>;
|
type Ast = ast::EnumVariant;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumVariant>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> {
|
||||||
self.source_impl(db)
|
self.source_impl(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Function {
|
impl HasSource for Function {
|
||||||
type Ast = TreeArc<ast::FnDef>;
|
type Ast = ast::FnDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::FnDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Const {
|
impl HasSource for Const {
|
||||||
type Ast = TreeArc<ast::ConstDef>;
|
type Ast = ast::ConstDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ConstDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Static {
|
impl HasSource for Static {
|
||||||
type Ast = TreeArc<ast::StaticDef>;
|
type Ast = ast::StaticDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::StaticDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for Trait {
|
impl HasSource for Trait {
|
||||||
type Ast = TreeArc<ast::TraitDef>;
|
type Ast = ast::TraitDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TraitDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for TypeAlias {
|
impl HasSource for TypeAlias {
|
||||||
type Ast = TreeArc<ast::TypeAliasDef>;
|
type Ast = ast::TypeAliasDef;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TypeAliasDef>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TypeAliasDef> {
|
||||||
self.id.source(db)
|
self.id.source(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl HasSource for MacroDef {
|
impl HasSource for MacroDef {
|
||||||
type Ast = TreeArc<ast::MacroCall>;
|
type Ast = ast::MacroCall;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> {
|
||||||
Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
|
Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use ra_db::{salsa, SourceDatabase};
|
use ra_db::{salsa, SourceDatabase};
|
||||||
use ra_syntax::{ast, Parse, SmolStr, SyntaxNode, TreeArc};
|
use ra_syntax::{ast, Parse, SmolStr, SyntaxNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::{EnumData, StructData},
|
adt::{EnumData, StructData},
|
||||||
|
@ -62,11 +62,11 @@ pub trait AstDatabase: InternDatabase {
|
||||||
|
|
||||||
#[salsa::transparent]
|
#[salsa::transparent]
|
||||||
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
|
#[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
|
||||||
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
|
fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> SyntaxNode;
|
||||||
|
|
||||||
#[salsa::transparent]
|
#[salsa::transparent]
|
||||||
#[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
|
#[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
|
||||||
fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
|
fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::ids::HirFileId::parse_macro_query)]
|
#[salsa::invoke(crate::ids::HirFileId::parse_macro_query)]
|
||||||
fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<Parse<SyntaxNode>>;
|
fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<Parse<SyntaxNode>>;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{any::Any, fmt};
|
use std::{any::Any, fmt};
|
||||||
|
|
||||||
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc};
|
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange};
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
|
|
||||||
use crate::{HirDatabase, HirFileId, Name};
|
use crate::{HirDatabase, HirFileId, Name};
|
||||||
|
@ -33,9 +33,9 @@ pub trait AstDiagnostic {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl dyn Diagnostic {
|
impl dyn Diagnostic {
|
||||||
pub fn syntax_node(&self, db: &impl HirDatabase) -> TreeArc<SyntaxNode> {
|
pub fn syntax_node(&self, db: &impl HirDatabase) -> SyntaxNode {
|
||||||
let node = db.parse_or_expand(self.file()).unwrap();
|
let node = db.parse_or_expand(self.file()).unwrap();
|
||||||
self.syntax_node_ptr().to_node(&*node).to_owned()
|
self.syntax_node_ptr().to_node(&node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
|
pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
|
||||||
|
@ -143,11 +143,11 @@ impl Diagnostic for MissingFields {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AstDiagnostic for MissingFields {
|
impl AstDiagnostic for MissingFields {
|
||||||
type AST = TreeArc<ast::NamedFieldList>;
|
type AST = ast::NamedFieldList;
|
||||||
|
|
||||||
fn ast(&self, db: &impl HirDatabase) -> Self::AST {
|
fn ast(&self, db: &impl HirDatabase) -> Self::AST {
|
||||||
let root = db.parse_or_expand(self.file()).unwrap();
|
let root = db.parse_or_expand(self.file()).unwrap();
|
||||||
let node = self.syntax_node_ptr().to_node(&*root);
|
let node = self.syntax_node_ptr().to_node(&root);
|
||||||
ast::NamedFieldList::cast(&node).unwrap().to_owned()
|
ast::NamedFieldList::cast(node).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,7 +550,7 @@ where
|
||||||
self.exprs.alloc(block)
|
self.exprs.alloc(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId {
|
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
|
||||||
let syntax_ptr = SyntaxNodePtr::new(expr.syntax());
|
let syntax_ptr = SyntaxNodePtr::new(expr.syntax());
|
||||||
match expr.kind() {
|
match expr.kind() {
|
||||||
ast::ExprKind::IfExpr(e) => {
|
ast::ExprKind::IfExpr(e) => {
|
||||||
|
@ -565,7 +565,8 @@ where
|
||||||
.map(|b| match b {
|
.map(|b| match b {
|
||||||
ast::ElseBranch::Block(it) => self.collect_block(it),
|
ast::ElseBranch::Block(it) => self.collect_block(it),
|
||||||
ast::ElseBranch::IfExpr(elif) => {
|
ast::ElseBranch::IfExpr(elif) => {
|
||||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
let expr: ast::Expr =
|
||||||
|
ast::Expr::cast(elif.syntax().clone()).unwrap();
|
||||||
self.collect_expr(expr)
|
self.collect_expr(expr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -582,7 +583,7 @@ where
|
||||||
let else_branch = e.else_branch().map(|b| match b {
|
let else_branch = e.else_branch().map(|b| match b {
|
||||||
ast::ElseBranch::Block(it) => self.collect_block(it),
|
ast::ElseBranch::Block(it) => self.collect_block(it),
|
||||||
ast::ElseBranch::IfExpr(elif) => {
|
ast::ElseBranch::IfExpr(elif) => {
|
||||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
let expr: ast::Expr = ast::Expr::cast(elif.syntax().clone()).unwrap();
|
||||||
self.collect_expr(expr)
|
self.collect_expr(expr)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -689,7 +690,7 @@ where
|
||||||
let struct_lit = if let Some(nfl) = e.named_field_list() {
|
let struct_lit = if let Some(nfl) = e.named_field_list() {
|
||||||
let fields = nfl
|
let fields = nfl
|
||||||
.fields()
|
.fields()
|
||||||
.inspect(|field| field_ptrs.push(AstPtr::new(*field)))
|
.inspect(|field| field_ptrs.push(AstPtr::new(field)))
|
||||||
.map(|field| StructLitField {
|
.map(|field| StructLitField {
|
||||||
name: field
|
name: field
|
||||||
.name_ref()
|
.name_ref()
|
||||||
|
@ -699,7 +700,7 @@ where
|
||||||
self.collect_expr(e)
|
self.collect_expr(e)
|
||||||
} else if let Some(nr) = field.name_ref() {
|
} else if let Some(nr) = field.name_ref() {
|
||||||
// field shorthand
|
// field shorthand
|
||||||
let id = self.exprs.alloc(Expr::Path(Path::from_name_ref(nr)));
|
let id = self.exprs.alloc(Expr::Path(Path::from_name_ref(&nr)));
|
||||||
self.source_map
|
self.source_map
|
||||||
.expr_map
|
.expr_map
|
||||||
.insert(SyntaxNodePtr::new(nr.syntax()), id);
|
.insert(SyntaxNodePtr::new(nr.syntax()), id);
|
||||||
|
@ -837,7 +838,7 @@ where
|
||||||
let ast_id = self
|
let ast_id = self
|
||||||
.db
|
.db
|
||||||
.ast_id_map(self.current_file_id)
|
.ast_id_map(self.current_file_id)
|
||||||
.ast_id(e)
|
.ast_id(&e)
|
||||||
.with_file_id(self.current_file_id);
|
.with_file_id(self.current_file_id);
|
||||||
|
|
||||||
if let Some(path) = e.path().and_then(Path::from_ast) {
|
if let Some(path) = e.path().and_then(Path::from_ast) {
|
||||||
|
@ -845,11 +846,11 @@ where
|
||||||
let call_id = MacroCallLoc { def: def.id, ast_id }.id(self.db);
|
let call_id = MacroCallLoc { def: def.id, ast_id }.id(self.db);
|
||||||
let file_id = call_id.as_file(MacroFileKind::Expr);
|
let file_id = call_id.as_file(MacroFileKind::Expr);
|
||||||
if let Some(node) = self.db.parse_or_expand(file_id) {
|
if let Some(node) = self.db.parse_or_expand(file_id) {
|
||||||
if let Some(expr) = ast::Expr::cast(&*node) {
|
if let Some(expr) = ast::Expr::cast(node) {
|
||||||
log::debug!("macro expansion {}", expr.syntax().debug_dump());
|
log::debug!("macro expansion {}", expr.syntax().debug_dump());
|
||||||
let old_file_id =
|
let old_file_id =
|
||||||
std::mem::replace(&mut self.current_file_id, file_id);
|
std::mem::replace(&mut self.current_file_id, file_id);
|
||||||
let id = self.collect_expr(&expr);
|
let id = self.collect_expr(expr);
|
||||||
self.current_file_id = old_file_id;
|
self.current_file_id = old_file_id;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -863,7 +864,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_expr_opt(&mut self, expr: Option<&ast::Expr>) -> ExprId {
|
fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId {
|
||||||
if let Some(expr) = expr {
|
if let Some(expr) = expr {
|
||||||
self.collect_expr(expr)
|
self.collect_expr(expr)
|
||||||
} else {
|
} else {
|
||||||
|
@ -871,7 +872,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_block(&mut self, block: &ast::Block) -> ExprId {
|
fn collect_block(&mut self, block: ast::Block) -> ExprId {
|
||||||
let statements = block
|
let statements = block
|
||||||
.statements()
|
.statements()
|
||||||
.map(|s| match s.kind() {
|
.map(|s| match s.kind() {
|
||||||
|
@ -890,7 +891,7 @@ where
|
||||||
self.alloc_expr(Expr::Block { statements, tail }, SyntaxNodePtr::new(block.syntax()))
|
self.alloc_expr(Expr::Block { statements, tail }, SyntaxNodePtr::new(block.syntax()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_block_opt(&mut self, block: Option<&ast::Block>) -> ExprId {
|
fn collect_block_opt(&mut self, block: Option<ast::Block>) -> ExprId {
|
||||||
if let Some(block) = block {
|
if let Some(block) = block {
|
||||||
self.collect_block(block)
|
self.collect_block(block)
|
||||||
} else {
|
} else {
|
||||||
|
@ -898,7 +899,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_pat(&mut self, pat: &ast::Pat) -> PatId {
|
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
|
||||||
let pattern = match pat.kind() {
|
let pattern = match pat.kind() {
|
||||||
ast::PatKind::BindPat(bp) => {
|
ast::PatKind::BindPat(bp) => {
|
||||||
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
|
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
|
||||||
|
@ -932,7 +933,8 @@ where
|
||||||
let mut fields: Vec<_> = field_pat_list
|
let mut fields: Vec<_> = field_pat_list
|
||||||
.bind_pats()
|
.bind_pats()
|
||||||
.filter_map(|bind_pat| {
|
.filter_map(|bind_pat| {
|
||||||
let ast_pat = ast::Pat::cast(bind_pat.syntax()).expect("bind pat is a pat");
|
let ast_pat =
|
||||||
|
ast::Pat::cast(bind_pat.syntax().clone()).expect("bind pat is a pat");
|
||||||
let pat = self.collect_pat(ast_pat);
|
let pat = self.collect_pat(ast_pat);
|
||||||
let name = bind_pat.name()?.as_name();
|
let name = bind_pat.name()?.as_name();
|
||||||
Some(FieldPat { name, pat })
|
Some(FieldPat { name, pat })
|
||||||
|
@ -953,11 +955,11 @@ where
|
||||||
ast::PatKind::LiteralPat(_) => Pat::Missing,
|
ast::PatKind::LiteralPat(_) => Pat::Missing,
|
||||||
ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing,
|
ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing,
|
||||||
};
|
};
|
||||||
let ptr = AstPtr::new(pat);
|
let ptr = AstPtr::new(&pat);
|
||||||
self.alloc_pat(pattern, Either::A(ptr))
|
self.alloc_pat(pattern, Either::A(ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_pat_opt(&mut self, pat: Option<&ast::Pat>) -> PatId {
|
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
|
||||||
if let Some(pat) = pat {
|
if let Some(pat) = pat {
|
||||||
self.collect_pat(pat)
|
self.collect_pat(pat)
|
||||||
} else {
|
} else {
|
||||||
|
@ -965,20 +967,20 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_const_body(&mut self, node: &ast::ConstDef) {
|
fn collect_const_body(&mut self, node: ast::ConstDef) {
|
||||||
let body = self.collect_expr_opt(node.body());
|
let body = self.collect_expr_opt(node.body());
|
||||||
self.body_expr = Some(body);
|
self.body_expr = Some(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_static_body(&mut self, node: &ast::StaticDef) {
|
fn collect_static_body(&mut self, node: ast::StaticDef) {
|
||||||
let body = self.collect_expr_opt(node.body());
|
let body = self.collect_expr_opt(node.body());
|
||||||
self.body_expr = Some(body);
|
self.body_expr = Some(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_fn_body(&mut self, node: &ast::FnDef) {
|
fn collect_fn_body(&mut self, node: ast::FnDef) {
|
||||||
if let Some(param_list) = node.param_list() {
|
if let Some(param_list) = node.param_list() {
|
||||||
if let Some(self_param) = param_list.self_param() {
|
if let Some(self_param) = param_list.self_param() {
|
||||||
let ptr = AstPtr::new(self_param);
|
let ptr = AstPtr::new(&self_param);
|
||||||
let param_pat = self.alloc_pat(
|
let param_pat = self.alloc_pat(
|
||||||
Pat::Bind {
|
Pat::Bind {
|
||||||
name: SELF_PARAM,
|
name: SELF_PARAM,
|
||||||
|
@ -1027,17 +1029,17 @@ pub(crate) fn body_with_source_map_query(
|
||||||
DefWithBody::Const(ref c) => {
|
DefWithBody::Const(ref c) => {
|
||||||
let src = c.source(db);
|
let src = c.source(db);
|
||||||
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
||||||
collector.collect_const_body(&src.ast)
|
collector.collect_const_body(src.ast)
|
||||||
}
|
}
|
||||||
DefWithBody::Function(ref f) => {
|
DefWithBody::Function(ref f) => {
|
||||||
let src = f.source(db);
|
let src = f.source(db);
|
||||||
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
||||||
collector.collect_fn_body(&src.ast)
|
collector.collect_fn_body(src.ast)
|
||||||
}
|
}
|
||||||
DefWithBody::Static(ref s) => {
|
DefWithBody::Static(ref s) => {
|
||||||
let src = s.source(db);
|
let src = s.source(db);
|
||||||
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
|
||||||
collector.collect_static_body(&src.ast)
|
collector.collect_static_body(src.ast)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ mod tests {
|
||||||
|
|
||||||
let (db, _source_root, file_id) = MockDatabase::with_single_file(&code);
|
let (db, _source_root, file_id) = MockDatabase::with_single_file(&code);
|
||||||
let file = db.parse(file_id).ok().unwrap();
|
let file = db.parse(file_id).ok().unwrap();
|
||||||
let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
||||||
let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None);
|
let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None);
|
||||||
|
|
||||||
let scopes = analyzer.scopes();
|
let scopes = analyzer.scopes();
|
||||||
|
@ -290,10 +290,10 @@ mod tests {
|
||||||
let file = db.parse(file_id).ok().unwrap();
|
let file = db.parse(file_id).ok().unwrap();
|
||||||
let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
|
let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
|
||||||
.expect("failed to find a name at the target offset");
|
.expect("failed to find a name at the target offset");
|
||||||
let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||||
let analyzer = SourceAnalyzer::new(&db, file_id, name_ref.syntax(), None);
|
let analyzer = SourceAnalyzer::new(&db, file_id, name_ref.syntax(), None);
|
||||||
|
|
||||||
let local_name_entry = analyzer.resolve_local_name(name_ref).unwrap();
|
let local_name_entry = analyzer.resolve_local_name(&name_ref).unwrap();
|
||||||
let local_name =
|
let local_name =
|
||||||
local_name_entry.ptr().either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
|
local_name_entry.ptr().either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
|
||||||
assert_eq!(local_name.range(), expected_name.syntax().range());
|
assert_eq!(local_name.range(), expected_name.syntax().range());
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
.and_then(StructLit::cast)
|
.and_then(StructLit::cast)
|
||||||
.and_then(|lit| lit.named_field_list())
|
.and_then(|lit| lit.named_field_list())
|
||||||
{
|
{
|
||||||
let field_list_ptr = AstPtr::new(field_list_node);
|
let field_list_ptr = AstPtr::new(&field_list_node);
|
||||||
self.sink.push(MissingFields {
|
self.sink.push(MissingFields {
|
||||||
file: file_id,
|
file: file_id,
|
||||||
field_list: field_list_ptr,
|
field_list: field_list_ptr,
|
||||||
|
|
|
@ -76,17 +76,17 @@ impl GenericParams {
|
||||||
generics.parent_params = parent.map(|p| db.generic_params(p));
|
generics.parent_params = parent.map(|p| db.generic_params(p));
|
||||||
let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
|
let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
|
||||||
match def {
|
match def {
|
||||||
GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::Union(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Union(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::Enum(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::Trait(it) => {
|
GenericDef::Trait(it) => {
|
||||||
// traits get the Self type as an implicit first type parameter
|
// traits get the Self type as an implicit first type parameter
|
||||||
generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
|
generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
|
||||||
generics.fill(&*it.source(db).ast, start + 1);
|
generics.fill(&it.source(db).ast, start + 1);
|
||||||
}
|
}
|
||||||
GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).ast, start),
|
GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start),
|
||||||
GenericDef::EnumVariant(_) => {}
|
GenericDef::EnumVariant(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +102,9 @@ impl GenericParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_params(&mut self, params: &ast::TypeParamList, start: u32) {
|
fn fill_params(&mut self, params: ast::TypeParamList, start: u32) {
|
||||||
for (idx, type_param) in params.type_params().enumerate() {
|
for (idx, type_param) in params.type_params().enumerate() {
|
||||||
let name = type_param.name().map(AsName::as_name).unwrap_or_else(Name::missing);
|
let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
|
||||||
let default = type_param.default_type().and_then(|t| t.path()).and_then(Path::from_ast);
|
let default = type_param.default_type().and_then(|t| t.path()).and_then(Path::from_ast);
|
||||||
|
|
||||||
let param = GenericParam { idx: idx as u32 + start, name: name.clone(), default };
|
let param = GenericParam { idx: idx as u32 + start, name: name.clone(), default };
|
||||||
|
@ -121,7 +121,7 @@ impl GenericParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_where_predicates(&mut self, where_clause: &ast::WhereClause) {
|
fn fill_where_predicates(&mut self, where_clause: ast::WhereClause) {
|
||||||
for pred in where_clause.predicates() {
|
for pred in where_clause.predicates() {
|
||||||
let type_ref = match pred.type_ref() {
|
let type_ref = match pred.type_ref() {
|
||||||
Some(type_ref) => type_ref,
|
Some(type_ref) => type_ref,
|
||||||
|
@ -134,7 +134,7 @@ impl GenericParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_where_predicate_from_bound(&mut self, bound: &ast::TypeBound, type_ref: TypeRef) {
|
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
|
||||||
let path = bound
|
let path = bound
|
||||||
.type_ref()
|
.type_ref()
|
||||||
.and_then(|tr| match tr.kind() {
|
.and_then(|tr| match tr.kind() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
use mbe::MacroRules;
|
use mbe::MacroRules;
|
||||||
use ra_db::{salsa, FileId};
|
use ra_db::{salsa, FileId};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{ast, AstNode, Parse, SyntaxNode, TreeArc};
|
use ra_syntax::{ast, AstNode, Parse, SyntaxNode};
|
||||||
|
|
||||||
use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source};
|
use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source};
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ impl HirFileId {
|
||||||
pub(crate) fn parse_or_expand_query(
|
pub(crate) fn parse_or_expand_query(
|
||||||
db: &impl AstDatabase,
|
db: &impl AstDatabase,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
) -> Option<TreeArc<SyntaxNode>> {
|
) -> Option<SyntaxNode> {
|
||||||
match file_id.0 {
|
match file_id.0 {
|
||||||
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()),
|
HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
||||||
HirFileIdRepr::Macro(macro_file) => {
|
HirFileIdRepr::Macro(macro_file) => {
|
||||||
db.parse_macro(macro_file).map(|it| it.tree().to_owned())
|
db.parse_macro(macro_file).map(|it| it.syntax_node())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>);
|
||||||
pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
||||||
let macro_call = id.0.to_node(db);
|
let macro_call = id.0.to_node(db);
|
||||||
let arg = macro_call.token_tree()?;
|
let arg = macro_call.token_tree()?;
|
||||||
let (tt, _) = mbe::ast_to_token_tree(arg).or_else(|| {
|
let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| {
|
||||||
log::warn!("fail on macro_def to token tree: {:#?}", arg);
|
log::warn!("fail on macro_def to token tree: {:#?}", arg);
|
||||||
None
|
None
|
||||||
})?;
|
})?;
|
||||||
|
@ -138,7 +138,7 @@ pub(crate) fn macro_arg_query(db: &impl AstDatabase, id: MacroCallId) -> Option<
|
||||||
let loc = id.loc(db);
|
let loc = id.loc(db);
|
||||||
let macro_call = loc.ast_id.to_node(db);
|
let macro_call = loc.ast_id.to_node(db);
|
||||||
let arg = macro_call.token_tree()?;
|
let arg = macro_call.token_tree()?;
|
||||||
let (tt, _) = mbe::ast_to_token_tree(arg)?;
|
let (tt, _) = mbe::ast_to_token_tree(&arg)?;
|
||||||
Some(Arc::new(tt))
|
Some(Arc::new(tt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
||||||
let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
|
let loc = ItemLoc { module: ctx.module, ast_id: ast_id.with_file_id(ctx.file_id) };
|
||||||
Self::intern(ctx.db, loc)
|
Self::intern(ctx.db, loc)
|
||||||
}
|
}
|
||||||
fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<TreeArc<N>> {
|
fn source(self, db: &(impl AstDatabase + DefDatabase)) -> Source<N> {
|
||||||
let loc = self.lookup_intern(db);
|
let loc = self.lookup_intern(db);
|
||||||
let ast = loc.ast_id.to_node(db);
|
let ast = loc.ast_id.to_node(db);
|
||||||
Source { file_id: loc.ast_id.file_id(), ast }
|
Source { file_id: loc.ast_id.file_id(), ast }
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||||
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
AstPtr, SourceFile, TreeArc,
|
AstPtr, SourceFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -28,9 +28,9 @@ impl ImplSourceMap {
|
||||||
self.map.insert(impl_id, AstPtr::new(impl_block))
|
self.map.insert(impl_id, AstPtr::new(impl_block))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> TreeArc<ast::ImplBlock> {
|
pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> ast::ImplBlock {
|
||||||
let file = match source {
|
let file = match source {
|
||||||
ModuleSource::SourceFile(file) => &*file,
|
ModuleSource::SourceFile(file) => file.clone(),
|
||||||
ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
|
ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ pub struct ImplBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasSource for ImplBlock {
|
impl HasSource for ImplBlock {
|
||||||
type Ast = TreeArc<ast::ImplBlock>;
|
type Ast = ast::ImplBlock;
|
||||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ImplBlock>> {
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ImplBlock> {
|
||||||
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
let source_map = db.impls_in_module_with_source_map(self.module).1;
|
||||||
let src = self.module.definition_source(db);
|
let src = self.module.definition_source(db);
|
||||||
Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) }
|
Source { file_id: src.file_id, ast: source_map.get(&src.ast, self.impl_id) }
|
||||||
|
@ -132,9 +132,9 @@ impl ImplData {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| match item_node.kind() {
|
.map(|item_node| match item_node.kind() {
|
||||||
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
|
@ -202,20 +202,20 @@ impl ModuleImplBlocks {
|
||||||
|
|
||||||
let src = m.module.definition_source(db);
|
let src = m.module.definition_source(db);
|
||||||
let node = match &src.ast {
|
let node = match &src.ast {
|
||||||
ModuleSource::SourceFile(node) => node.syntax(),
|
ModuleSource::SourceFile(node) => node.syntax().clone(),
|
||||||
ModuleSource::Module(node) => {
|
ModuleSource::Module(node) => {
|
||||||
node.item_list().expect("inline module should have item list").syntax()
|
node.item_list().expect("inline module should have item list").syntax().clone()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
|
for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
|
||||||
let impl_block = ImplData::from_ast(db, src.file_id, m.module, impl_block_ast);
|
let impl_block = ImplData::from_ast(db, src.file_id, m.module, &impl_block_ast);
|
||||||
let id = m.impls.alloc(impl_block);
|
let id = m.impls.alloc(impl_block);
|
||||||
for &impl_item in &m.impls[id].items {
|
for &impl_item in &m.impls[id].items {
|
||||||
m.impls_by_def.insert(impl_item, id);
|
m.impls_by_def.insert(impl_item, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
source_map.insert(id, impl_block_ast);
|
source_map.insert(id, &impl_block_ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
m
|
m
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_syntax::{ast::AttrsOwner, SmolStr, TreeArc};
|
use ra_syntax::{ast::AttrsOwner, SmolStr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AstDatabase, Crate, DefDatabase, Enum, Function, HasSource, HirDatabase, ImplBlock, Module,
|
AstDatabase, Crate, DefDatabase, Enum, Function, HasSource, HirDatabase, ImplBlock, Module,
|
||||||
|
@ -95,7 +95,7 @@ impl LangItems {
|
||||||
// Look for impl targets
|
// Look for impl targets
|
||||||
for impl_block in module.impl_blocks(db) {
|
for impl_block in module.impl_blocks(db) {
|
||||||
let src = impl_block.source(db);
|
let src = impl_block.source(db);
|
||||||
if let Some(lang_item_name) = lang_item_name(&*src.ast) {
|
if let Some(lang_item_name) = lang_item_name(&src.ast) {
|
||||||
self.items
|
self.items
|
||||||
.entry(lang_item_name)
|
.entry(lang_item_name)
|
||||||
.or_insert_with(|| LangItemTarget::ImplBlock(impl_block));
|
.or_insert_with(|| LangItemTarget::ImplBlock(impl_block));
|
||||||
|
@ -137,11 +137,11 @@ impl LangItems {
|
||||||
item: T,
|
item: T,
|
||||||
constructor: fn(T) -> LangItemTarget,
|
constructor: fn(T) -> LangItemTarget,
|
||||||
) where
|
) where
|
||||||
T: Copy + HasSource<Ast = TreeArc<N>>,
|
T: Copy + HasSource<Ast = N>,
|
||||||
N: AttrsOwner,
|
N: AttrsOwner,
|
||||||
{
|
{
|
||||||
let node = item.source(db).ast;
|
let node = item.source(db).ast;
|
||||||
if let Some(lang_item_name) = lang_item_name(&*node) {
|
if let Some(lang_item_name) = lang_item_name(&node) {
|
||||||
self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
|
self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl AsName for ast::Name {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsName for ast::FieldKind<'a> {
|
impl AsName for ast::FieldKind {
|
||||||
fn as_name(&self) -> Name {
|
fn as_name(&self) -> Name {
|
||||||
match self {
|
match self {
|
||||||
ast::FieldKind::Name(nr) => nr.as_name(),
|
ast::FieldKind::Name(nr) => nr.as_name(),
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{ops::Index, sync::Arc};
|
||||||
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, AttrsOwner, NameOwner},
|
ast::{self, AttrsOwner, NameOwner},
|
||||||
AstNode, AstPtr, SmolStr, SourceFile, TreeArc,
|
AstNode, AstPtr, SmolStr, SourceFile,
|
||||||
};
|
};
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ pub struct ImportSourceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
|
type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
|
||||||
type ImportSource = Either<TreeArc<ast::UseTree>, TreeArc<ast::ExternCrateItem>>;
|
type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>;
|
||||||
|
|
||||||
impl ImportSourcePtr {
|
impl ImportSourcePtr {
|
||||||
fn to_node(self, file: &SourceFile) -> ImportSource {
|
fn to_node(self, file: &SourceFile) -> ImportSource {
|
||||||
|
@ -50,11 +50,11 @@ impl ImportSourceMap {
|
||||||
|
|
||||||
pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource {
|
pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource {
|
||||||
let file = match source {
|
let file = match source {
|
||||||
ModuleSource::SourceFile(file) => &*file,
|
ModuleSource::SourceFile(file) => file.clone(),
|
||||||
ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
|
ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.map[import].to_node(file)
|
self.map[import].to_node(&file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ impl RawItems {
|
||||||
source_map: ImportSourceMap::default(),
|
source_map: ImportSourceMap::default(),
|
||||||
};
|
};
|
||||||
if let Some(node) = db.parse_or_expand(file_id) {
|
if let Some(node) = db.parse_or_expand(file_id) {
|
||||||
if let Some(source_file) = ast::SourceFile::cast(&node) {
|
if let Some(source_file) = ast::SourceFile::cast(node) {
|
||||||
collector.process_module(None, &*source_file);
|
collector.process_module(None, source_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Arc::new(collector.raw_items), Arc::new(collector.source_map))
|
(Arc::new(collector.raw_items), Arc::new(collector.source_map))
|
||||||
|
@ -188,7 +188,7 @@ struct RawItemsCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawItemsCollector {
|
impl RawItemsCollector {
|
||||||
fn process_module(&mut self, current_module: Option<Module>, body: &impl ast::ModuleItemOwner) {
|
fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) {
|
||||||
for item_or_macro in body.items_with_macros() {
|
for item_or_macro in body.items_with_macros() {
|
||||||
match item_or_macro {
|
match item_or_macro {
|
||||||
ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m),
|
ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m),
|
||||||
|
@ -197,7 +197,7 @@ impl RawItemsCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_item(&mut self, current_module: Option<Module>, item: &ast::ModuleItem) {
|
fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
|
||||||
let (kind, name) = match item.kind() {
|
let (kind, name) = match item.kind() {
|
||||||
ast::ModuleItemKind::Module(module) => {
|
ast::ModuleItemKind::Module(module) => {
|
||||||
self.add_module(current_module, module);
|
self.add_module(current_module, module);
|
||||||
|
@ -216,7 +216,7 @@ impl RawItemsCollector {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::StructDef(it) => {
|
ast::ModuleItemKind::StructDef(it) => {
|
||||||
let id = self.source_ast_id_map.ast_id(it);
|
let id = self.source_ast_id_map.ast_id(&it);
|
||||||
let name = it.name();
|
let name = it.name();
|
||||||
if it.is_union() {
|
if it.is_union() {
|
||||||
(DefKind::Union(id), name)
|
(DefKind::Union(id), name)
|
||||||
|
@ -225,22 +225,22 @@ impl RawItemsCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::EnumDef(it) => {
|
ast::ModuleItemKind::EnumDef(it) => {
|
||||||
(DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::FnDef(it) => {
|
ast::ModuleItemKind::FnDef(it) => {
|
||||||
(DefKind::Function(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::TraitDef(it) => {
|
ast::ModuleItemKind::TraitDef(it) => {
|
||||||
(DefKind::Trait(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::TypeAliasDef(it) => {
|
ast::ModuleItemKind::TypeAliasDef(it) => {
|
||||||
(DefKind::TypeAlias(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::ConstDef(it) => {
|
ast::ModuleItemKind::ConstDef(it) => {
|
||||||
(DefKind::Const(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::StaticDef(it) => {
|
ast::ModuleItemKind::StaticDef(it) => {
|
||||||
(DefKind::Static(self.source_ast_id_map.ast_id(it)), it.name())
|
(DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
|
@ -250,14 +250,14 @@ impl RawItemsCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_module(&mut self, current_module: Option<Module>, module: &ast::Module) {
|
fn add_module(&mut self, current_module: Option<Module>, module: ast::Module) {
|
||||||
let name = match module.name() {
|
let name = match module.name() {
|
||||||
Some(it) => it.as_name(),
|
Some(it) => it.as_name(),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let attr_path = extract_mod_path_attribute(module);
|
let attr_path = extract_mod_path_attribute(&module);
|
||||||
let ast_id = self.source_ast_id_map.ast_id(module);
|
let ast_id = self.source_ast_id_map.ast_id(&module);
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
let item =
|
let item =
|
||||||
self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path });
|
self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path });
|
||||||
|
@ -278,10 +278,10 @@ impl RawItemsCollector {
|
||||||
tested_by!(name_res_works_for_broken_modules);
|
tested_by!(name_res_works_for_broken_modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_use_item(&mut self, current_module: Option<Module>, use_item: &ast::UseItem) {
|
fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) {
|
||||||
let is_prelude = use_item.has_atom_attr("prelude_import");
|
let is_prelude = use_item.has_atom_attr("prelude_import");
|
||||||
|
|
||||||
Path::expand_use_item(use_item, |path, use_tree, is_glob, alias| {
|
Path::expand_use_item(&use_item, |path, use_tree, is_glob, alias| {
|
||||||
let import_data =
|
let import_data =
|
||||||
ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false };
|
ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false };
|
||||||
self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree)));
|
self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree)));
|
||||||
|
@ -291,11 +291,11 @@ impl RawItemsCollector {
|
||||||
fn add_extern_crate_item(
|
fn add_extern_crate_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
current_module: Option<Module>,
|
current_module: Option<Module>,
|
||||||
extern_crate: &ast::ExternCrateItem,
|
extern_crate: ast::ExternCrateItem,
|
||||||
) {
|
) {
|
||||||
if let Some(name_ref) = extern_crate.name_ref() {
|
if let Some(name_ref) = extern_crate.name_ref() {
|
||||||
let path = Path::from_name_ref(name_ref);
|
let path = Path::from_name_ref(&name_ref);
|
||||||
let alias = extern_crate.alias().and_then(|a| a.name()).map(AsName::as_name);
|
let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
|
||||||
let import_data = ImportData {
|
let import_data = ImportData {
|
||||||
path,
|
path,
|
||||||
alias,
|
alias,
|
||||||
|
@ -303,18 +303,18 @@ impl RawItemsCollector {
|
||||||
is_prelude: false,
|
is_prelude: false,
|
||||||
is_extern_crate: true,
|
is_extern_crate: true,
|
||||||
};
|
};
|
||||||
self.push_import(current_module, import_data, Either::B(AstPtr::new(extern_crate)));
|
self.push_import(current_module, import_data, Either::B(AstPtr::new(&extern_crate)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_macro(&mut self, current_module: Option<Module>, m: &ast::MacroCall) {
|
fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) {
|
||||||
let path = match m.path().and_then(Path::from_ast) {
|
let path = match m.path().and_then(Path::from_ast) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let name = m.name().map(|it| it.as_name());
|
let name = m.name().map(|it| it.as_name());
|
||||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
let ast_id = self.source_ast_id_map.ast_id(&m);
|
||||||
let export = m.has_atom_attr("macro_export");
|
let export = m.has_atom_attr("macro_export");
|
||||||
let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export });
|
let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export });
|
||||||
self.push_item(current_module, RawItem::Macro(m));
|
self.push_item(current_module, RawItem::Macro(m));
|
||||||
|
|
|
@ -47,9 +47,9 @@ pub enum PathKind {
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
/// Calls `cb` with all paths, represented by this use item.
|
/// Calls `cb` with all paths, represented by this use item.
|
||||||
pub fn expand_use_item<'a>(
|
pub fn expand_use_item(
|
||||||
item: &'a ast::UseItem,
|
item: &ast::UseItem,
|
||||||
mut cb: impl FnMut(Path, &'a ast::UseTree, bool, Option<Name>),
|
mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
|
||||||
) {
|
) {
|
||||||
if let Some(tree) = item.use_tree() {
|
if let Some(tree) = item.use_tree() {
|
||||||
expand_use_tree(None, tree, &mut cb);
|
expand_use_tree(None, tree, &mut cb);
|
||||||
|
@ -57,7 +57,7 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts an `ast::Path` to `Path`. Works with use trees.
|
/// Converts an `ast::Path` to `Path`. Works with use trees.
|
||||||
pub fn from_ast(mut path: &ast::Path) -> Option<Path> {
|
pub fn from_ast(mut path: ast::Path) -> Option<Path> {
|
||||||
let mut kind = PathKind::Plain;
|
let mut kind = PathKind::Plain;
|
||||||
let mut segments = Vec::new();
|
let mut segments = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
|
@ -87,7 +87,7 @@ impl Path {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path = match qualifier(path) {
|
path = match qualifier(&path) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => break,
|
None => break,
|
||||||
};
|
};
|
||||||
|
@ -95,7 +95,7 @@ impl Path {
|
||||||
segments.reverse();
|
segments.reverse();
|
||||||
return Some(Path { kind, segments });
|
return Some(Path { kind, segments });
|
||||||
|
|
||||||
fn qualifier(path: &ast::Path) -> Option<&ast::Path> {
|
fn qualifier(path: &ast::Path) -> Option<ast::Path> {
|
||||||
if let Some(q) = path.qualifier() {
|
if let Some(q) = path.qualifier() {
|
||||||
return Some(q);
|
return Some(q);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenericArgs {
|
impl GenericArgs {
|
||||||
pub(crate) fn from_ast(node: &ast::TypeArgList) -> Option<GenericArgs> {
|
pub(crate) fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> {
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
for type_arg in node.type_args() {
|
for type_arg in node.type_args() {
|
||||||
let type_ref = TypeRef::from_ast_opt(type_arg.type_ref());
|
let type_ref = TypeRef::from_ast_opt(type_arg.type_ref());
|
||||||
|
@ -160,10 +160,10 @@ impl From<Name> for Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_use_tree<'a>(
|
fn expand_use_tree(
|
||||||
prefix: Option<Path>,
|
prefix: Option<Path>,
|
||||||
tree: &'a ast::UseTree,
|
tree: ast::UseTree,
|
||||||
cb: &mut impl FnMut(Path, &'a ast::UseTree, bool, Option<Name>),
|
cb: &mut impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
|
||||||
) {
|
) {
|
||||||
if let Some(use_tree_list) = tree.use_tree_list() {
|
if let Some(use_tree_list) = tree.use_tree_list() {
|
||||||
let prefix = match tree.path() {
|
let prefix = match tree.path() {
|
||||||
|
@ -188,7 +188,7 @@ fn expand_use_tree<'a>(
|
||||||
if let Some(segment) = ast_path.segment() {
|
if let Some(segment) = ast_path.segment() {
|
||||||
if segment.kind() == Some(ast::PathSegmentKind::SelfKw) {
|
if segment.kind() == Some(ast::PathSegmentKind::SelfKw) {
|
||||||
if let Some(prefix) = prefix {
|
if let Some(prefix) = prefix {
|
||||||
cb(prefix, tree, false, alias);
|
cb(prefix, &tree, false, alias);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ fn expand_use_tree<'a>(
|
||||||
}
|
}
|
||||||
if let Some(path) = convert_path(prefix, ast_path) {
|
if let Some(path) = convert_path(prefix, ast_path) {
|
||||||
let is_glob = tree.has_star();
|
let is_glob = tree.has_star();
|
||||||
cb(path, tree, is_glob, alias)
|
cb(path, &tree, is_glob, alias)
|
||||||
}
|
}
|
||||||
// FIXME: report errors somewhere
|
// FIXME: report errors somewhere
|
||||||
// We get here if we do
|
// We get here if we do
|
||||||
|
@ -204,7 +204,7 @@ fn expand_use_tree<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_path(prefix: Option<Path>, path: &ast::Path) -> Option<Path> {
|
fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> {
|
||||||
let prefix =
|
let prefix =
|
||||||
if let Some(qual) = path.qualifier() { Some(convert_path(prefix, qual)?) } else { prefix };
|
if let Some(qual) = path.qualifier() { Some(convert_path(prefix, qual)?) } else { prefix };
|
||||||
let segment = path.segment()?;
|
let segment = path.segment()?;
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub fn module_from_file_id(db: &impl HirDatabase, file_id: FileId) -> Option<Mod
|
||||||
pub fn module_from_declaration(
|
pub fn module_from_declaration(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
decl: &ast::Module,
|
decl: ast::Module,
|
||||||
) -> Option<Module> {
|
) -> Option<Module> {
|
||||||
let parent_module = module_from_file_id(db, file_id);
|
let parent_module = module_from_file_id(db, file_id);
|
||||||
let child_name = decl.name();
|
let child_name = decl.name();
|
||||||
|
@ -50,8 +50,8 @@ pub fn module_from_declaration(
|
||||||
/// Locates the module by position in the source code.
|
/// Locates the module by position in the source code.
|
||||||
pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> {
|
pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Module> {
|
||||||
let parse = db.parse(position.file_id);
|
let parse = db.parse(position.file_id);
|
||||||
match find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) {
|
match &find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) {
|
||||||
Some(m) if !m.has_semi() => module_from_inline(db, position.file_id, m),
|
Some(m) if !m.has_semi() => module_from_inline(db, position.file_id, m.clone()),
|
||||||
_ => module_from_file_id(db, position.file_id),
|
_ => module_from_file_id(db, position.file_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,12 @@ pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Op
|
||||||
fn module_from_inline(
|
fn module_from_inline(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
module: &ast::Module,
|
module: ast::Module,
|
||||||
) -> Option<Module> {
|
) -> Option<Module> {
|
||||||
assert!(!module.has_semi());
|
assert!(!module.has_semi());
|
||||||
let file_id = file_id.into();
|
let file_id = file_id.into();
|
||||||
let ast_id_map = db.ast_id_map(file_id);
|
let ast_id_map = db.ast_id_map(file_id);
|
||||||
let item_id = ast_id_map.ast_id(module).with_file_id(file_id);
|
let item_id = ast_id_map.ast_id(&module).with_file_id(file_id);
|
||||||
module_from_source(db, file_id, Some(item_id))
|
module_from_source(db, file_id, Some(item_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,16 +127,16 @@ fn try_get_resolver_for_node(
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
) -> Option<Resolver> {
|
) -> Option<Resolver> {
|
||||||
if let Some(module) = ast::Module::cast(node) {
|
if let Some(module) = ast::Module::cast(node.clone()) {
|
||||||
Some(module_from_declaration(db, file_id, module)?.resolver(db))
|
Some(module_from_declaration(db, file_id, module)?.resolver(db))
|
||||||
} else if let Some(_) = ast::SourceFile::cast(node) {
|
} else if let Some(_) = ast::SourceFile::cast(node.clone()) {
|
||||||
Some(module_from_source(db, file_id.into(), None)?.resolver(db))
|
Some(module_from_source(db, file_id.into(), None)?.resolver(db))
|
||||||
} else if let Some(s) = ast::StructDef::cast(node) {
|
} else if let Some(s) = ast::StructDef::cast(node.clone()) {
|
||||||
let module = module_from_child_node(db, file_id, s.syntax())?;
|
let module = module_from_child_node(db, file_id, s.syntax())?;
|
||||||
Some(struct_from_module(db, module, s).resolver(db))
|
Some(struct_from_module(db, module, &s).resolver(db))
|
||||||
} else if let Some(e) = ast::EnumDef::cast(node) {
|
} else if let Some(e) = ast::EnumDef::cast(node.clone()) {
|
||||||
let module = module_from_child_node(db, file_id, e.syntax())?;
|
let module = module_from_child_node(db, file_id, e.syntax())?;
|
||||||
Some(enum_from_module(db, module, e).resolver(db))
|
Some(enum_from_module(db, module, &e).resolver(db))
|
||||||
} else if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
|
} else if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
|
||||||
Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db))
|
Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db))
|
||||||
} else {
|
} else {
|
||||||
|
@ -153,14 +153,14 @@ fn def_with_body_from_child_node(
|
||||||
let module = module_from_child_node(db, file_id, node)?;
|
let module = module_from_child_node(db, file_id, node)?;
|
||||||
let ctx = LocationCtx::new(db, module, file_id.into());
|
let ctx = LocationCtx::new(db, module, file_id.into());
|
||||||
node.ancestors().find_map(|node| {
|
node.ancestors().find_map(|node| {
|
||||||
if let Some(def) = ast::FnDef::cast(node) {
|
if let Some(def) = ast::FnDef::cast(node.clone()) {
|
||||||
return Some(Function { id: ctx.to_def(def) }.into());
|
return Some(Function { id: ctx.to_def(&def) }.into());
|
||||||
}
|
}
|
||||||
if let Some(def) = ast::ConstDef::cast(node) {
|
if let Some(def) = ast::ConstDef::cast(node.clone()) {
|
||||||
return Some(Const { id: ctx.to_def(def) }.into());
|
return Some(Const { id: ctx.to_def(&def) }.into());
|
||||||
}
|
}
|
||||||
if let Some(def) = ast::StaticDef::cast(node) {
|
if let Some(def) = ast::StaticDef::cast(node.clone()) {
|
||||||
return Some(Static { id: ctx.to_def(def) }.into());
|
return Some(Static { id: ctx.to_def(&def) }.into());
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
|
@ -237,7 +237,7 @@ impl SourceAnalyzer {
|
||||||
SourceAnalyzer {
|
SourceAnalyzer {
|
||||||
resolver: node
|
resolver: node
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.find_map(|node| try_get_resolver_for_node(db, file_id, node))
|
.find_map(|node| try_get_resolver_for_node(db, file_id, &node))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
body_source_map: None,
|
body_source_map: None,
|
||||||
infer: None,
|
infer: None,
|
||||||
|
@ -257,17 +257,17 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
|
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
|
||||||
let expr_id = self.body_source_map.as_ref()?.node_expr(call.into())?;
|
let expr_id = self.body_source_map.as_ref()?.node_expr(&call.clone().into())?;
|
||||||
self.infer.as_ref()?.method_resolution(expr_id)
|
self.infer.as_ref()?.method_resolution(expr_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<crate::StructField> {
|
pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<crate::StructField> {
|
||||||
let expr_id = self.body_source_map.as_ref()?.node_expr(field.into())?;
|
let expr_id = self.body_source_map.as_ref()?.node_expr(&field.clone().into())?;
|
||||||
self.infer.as_ref()?.field_resolution(expr_id)
|
self.infer.as_ref()?.field_resolution(expr_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_variant(&self, struct_lit: &ast::StructLit) -> Option<crate::VariantDef> {
|
pub fn resolve_variant(&self, struct_lit: &ast::StructLit) -> Option<crate::VariantDef> {
|
||||||
let expr_id = self.body_source_map.as_ref()?.node_expr(struct_lit.into())?;
|
let expr_id = self.body_source_map.as_ref()?.node_expr(&struct_lit.clone().into())?;
|
||||||
self.infer.as_ref()?.variant_resolution(expr_id)
|
self.infer.as_ref()?.variant_resolution(expr_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,18 +290,18 @@ impl SourceAnalyzer {
|
||||||
|
|
||||||
pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option<PathResolution> {
|
pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option<PathResolution> {
|
||||||
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
|
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
|
||||||
let expr_id = self.body_source_map.as_ref()?.node_expr(path_expr.into())?;
|
let expr_id = self.body_source_map.as_ref()?.node_expr(&path_expr.into())?;
|
||||||
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
|
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
|
||||||
return Some(PathResolution::AssocItem(assoc));
|
return Some(PathResolution::AssocItem(assoc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
|
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
|
||||||
let pat_id = self.body_source_map.as_ref()?.node_pat(path_pat.into())?;
|
let pat_id = self.body_source_map.as_ref()?.node_pat(&path_pat.into())?;
|
||||||
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
|
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
|
||||||
return Some(PathResolution::AssocItem(assoc));
|
return Some(PathResolution::AssocItem(assoc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hir_path = crate::Path::from_ast(path)?;
|
let hir_path = crate::Path::from_ast(path.clone())?;
|
||||||
let res = self.resolver.resolve_path_without_assoc_items(db, &hir_path);
|
let res = self.resolver.resolve_path_without_assoc_items(db, &hir_path);
|
||||||
let res = res.clone().take_types().or_else(|| res.take_values())?;
|
let res = res.clone().take_types().or_else(|| res.take_values())?;
|
||||||
let res = match res {
|
let res = match res {
|
||||||
|
@ -343,12 +343,12 @@ impl SourceAnalyzer {
|
||||||
// FIXME: at least, this should work with any DefWithBody, but ideally
|
// FIXME: at least, this should work with any DefWithBody, but ideally
|
||||||
// this should be hir-based altogether
|
// this should be hir-based altogether
|
||||||
let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
|
let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
|
||||||
let ptr = Either::A(AstPtr::new(pat.into()));
|
let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone())));
|
||||||
fn_def
|
fn_def
|
||||||
.syntax()
|
.syntax()
|
||||||
.descendants()
|
.descendants()
|
||||||
.filter_map(ast::NameRef::cast)
|
.filter_map(ast::NameRef::cast)
|
||||||
.filter(|name_ref| match self.resolve_local_name(*name_ref) {
|
.filter(|name_ref| match self.resolve_local_name(&name_ref) {
|
||||||
None => false,
|
None => false,
|
||||||
Some(entry) => entry.ptr() == ptr,
|
Some(entry) => entry.ptr() == ptr,
|
||||||
})
|
})
|
||||||
|
@ -411,7 +411,7 @@ fn scope_for(
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
) -> Option<ScopeId> {
|
) -> Option<ScopeId> {
|
||||||
node.ancestors()
|
node.ancestors()
|
||||||
.map(SyntaxNodePtr::new)
|
.map(|it| SyntaxNodePtr::new(&it))
|
||||||
.filter_map(|ptr| source_map.syntax_expr(ptr))
|
.filter_map(|ptr| source_map.syntax_expr(ptr))
|
||||||
.find_map(|it| scopes.scope_for(it))
|
.find_map(|it| scopes.scope_for(it))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||||
use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr, TreeArc};
|
use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr};
|
||||||
|
|
||||||
use crate::{AstDatabase, HirFileId};
|
use crate::{AstDatabase, HirFileId};
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ impl<N: AstNode> AstId<N> {
|
||||||
self.file_id
|
self.file_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_node(&self, db: &impl AstDatabase) -> TreeArc<N> {
|
pub(crate) fn to_node(&self, db: &impl AstDatabase) -> N {
|
||||||
let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw);
|
let syntax_node = db.ast_id_to_node(self.file_id, self.file_ast_id.raw);
|
||||||
N::cast(&syntax_node).unwrap().to_owned()
|
N::cast(syntax_node).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ pub struct AstIdMap {
|
||||||
impl AstIdMap {
|
impl AstIdMap {
|
||||||
pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
pub(crate) fn ast_id_map_query(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||||
let map = if let Some(node) = db.parse_or_expand(file_id) {
|
let map = if let Some(node) = db.parse_or_expand(file_id) {
|
||||||
AstIdMap::from_source(&*node)
|
AstIdMap::from_source(&node)
|
||||||
} else {
|
} else {
|
||||||
AstIdMap::default()
|
AstIdMap::default()
|
||||||
};
|
};
|
||||||
|
@ -104,9 +104,9 @@ impl AstIdMap {
|
||||||
db: &impl AstDatabase,
|
db: &impl AstDatabase,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
ast_id: ErasedFileAstId,
|
ast_id: ErasedFileAstId,
|
||||||
) -> TreeArc<SyntaxNode> {
|
) -> SyntaxNode {
|
||||||
let node = db.parse_or_expand(file_id).unwrap();
|
let node = db.parse_or_expand(file_id).unwrap();
|
||||||
db.ast_id_map(file_id).arena[ast_id].to_node(&*node).to_owned()
|
db.ast_id_map(file_id).arena[ast_id].to_node(&node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
|
pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> FileAstId<N> {
|
||||||
|
@ -131,7 +131,7 @@ impl AstIdMap {
|
||||||
// change parent's id. This means that, say, adding a new function to a
|
// change parent's id. This means that, say, adding a new function to a
|
||||||
// trait does not change ids of top-level items, which helps caching.
|
// trait does not change ids of top-level items, which helps caching.
|
||||||
bfs(node, |it| {
|
bfs(node, |it| {
|
||||||
if let Some(module_item) = ast::ModuleItem::cast(it) {
|
if let Some(module_item) = ast::ModuleItem::cast(it.clone()) {
|
||||||
res.alloc(module_item.syntax());
|
res.alloc(module_item.syntax());
|
||||||
} else if let Some(macro_call) = ast::MacroCall::cast(it) {
|
} else if let Some(macro_call) = ast::MacroCall::cast(it) {
|
||||||
res.alloc(macro_call.syntax());
|
res.alloc(macro_call.syntax());
|
||||||
|
@ -146,8 +146,8 @@ impl AstIdMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Walks the subtree in bfs order, calling `f` for each node.
|
/// Walks the subtree in bfs order, calling `f` for each node.
|
||||||
fn bfs(node: &SyntaxNode, mut f: impl FnMut(&SyntaxNode)) {
|
fn bfs(node: &SyntaxNode, mut f: impl FnMut(SyntaxNode)) {
|
||||||
let mut curr_layer = vec![node];
|
let mut curr_layer = vec![node.clone()];
|
||||||
let mut next_layer = vec![];
|
let mut next_layer = vec![];
|
||||||
while !curr_layer.is_empty() {
|
while !curr_layer.is_empty() {
|
||||||
curr_layer.drain(..).for_each(|node| {
|
curr_layer.drain(..).for_each(|node| {
|
||||||
|
|
|
@ -31,9 +31,9 @@ impl TraitData {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| match item_node.kind() {
|
.map(|item_node| match item_node.kind() {
|
||||||
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(it) }.into(),
|
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3086,7 +3086,7 @@ fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
||||||
let file = db.parse(pos.file_id).ok().unwrap();
|
let file = db.parse(pos.file_id).ok().unwrap();
|
||||||
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
||||||
let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
|
let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
|
||||||
let ty = analyzer.type_of(db, expr).unwrap();
|
let ty = analyzer.type_of(db, &expr).unwrap();
|
||||||
ty.display(db).to_string()
|
ty.display(db).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3126,7 +3126,7 @@ fn infer(content: &str) -> String {
|
||||||
types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
|
types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
|
||||||
for (syntax_ptr, ty) in &types {
|
for (syntax_ptr, ty) in &types {
|
||||||
let node = syntax_ptr.to_node(source_file.syntax());
|
let node = syntax_ptr.to_node(source_file.syntax());
|
||||||
let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) {
|
let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) {
|
||||||
(self_param.self_kw_token().range(), "self".to_string())
|
(self_param.self_kw_token().range(), "self".to_string())
|
||||||
} else {
|
} else {
|
||||||
(syntax_ptr.range(), node.text().to_string().replace("\n", " "))
|
(syntax_ptr.range(), node.text().to_string().replace("\n", " "))
|
||||||
|
@ -3137,7 +3137,7 @@ fn infer(content: &str) -> String {
|
||||||
|
|
||||||
for node in source_file.syntax().descendants() {
|
for node in source_file.syntax().descendants() {
|
||||||
if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
|
if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF {
|
||||||
let analyzer = SourceAnalyzer::new(&db, file_id, node, None);
|
let analyzer = SourceAnalyzer::new(&db, file_id, &node, None);
|
||||||
infer_def(analyzer.inference_result(), analyzer.body_source_map());
|
infer_def(analyzer.inference_result(), analyzer.body_source_map());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3179,7 +3179,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
let node =
|
let node =
|
||||||
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
SourceAnalyzer::new(&db, pos.file_id, node, None);
|
SourceAnalyzer::new(&db, pos.file_id, &node, None);
|
||||||
});
|
});
|
||||||
assert!(format!("{:?}", events).contains("infer"))
|
assert!(format!("{:?}", events).contains("infer"))
|
||||||
}
|
}
|
||||||
|
@ -3200,7 +3200,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
let node =
|
let node =
|
||||||
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
SourceAnalyzer::new(&db, pos.file_id, node, None);
|
SourceAnalyzer::new(&db, pos.file_id, &node, None);
|
||||||
});
|
});
|
||||||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub enum TypeRef {
|
||||||
|
|
||||||
impl TypeRef {
|
impl TypeRef {
|
||||||
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
|
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
|
||||||
pub(crate) fn from_ast(node: &ast::TypeRef) -> Self {
|
pub(crate) fn from_ast(node: ast::TypeRef) -> Self {
|
||||||
use ra_syntax::ast::TypeRefKind::*;
|
use ra_syntax::ast::TypeRefKind::*;
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
||||||
|
@ -95,7 +95,7 @@ impl TypeRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_ast_opt(node: Option<&ast::TypeRef>) -> Self {
|
pub(crate) fn from_ast_opt(node: Option<ast::TypeRef>) -> Self {
|
||||||
if let Some(node) = node {
|
if let Some(node) = node {
|
||||||
TypeRef::from_ast(node)
|
TypeRef::from_ast(node)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl<T> Parse<T> {
|
||||||
Parse { green, errors: Arc::new(errors), _ty: PhantomData }
|
Parse { green, errors: Arc::new(errors), _ty: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syntax_node(&self) -> SyntaxNode {
|
pub fn syntax_node(&self) -> SyntaxNode {
|
||||||
SyntaxNode::new(self.green.clone())
|
SyntaxNode::new(self.green.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue