mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Rename Source -> InFile
This commit is contained in:
parent
2702fa1c5d
commit
ccd1b0800a
36 changed files with 189 additions and 189 deletions
|
@ -1,5 +1,5 @@
|
|||
//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
|
||||
use hir::{db::HirDatabase, SourceAnalyzer};
|
||||
use hir::{db::HirDatabase, InFile, SourceAnalyzer};
|
||||
use ra_db::FileRange;
|
||||
use ra_fmt::{leading_indent, reindent};
|
||||
use ra_syntax::{
|
||||
|
@ -117,7 +117,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
|
|||
node: &SyntaxNode,
|
||||
offset: Option<TextUnit>,
|
||||
) -> SourceAnalyzer {
|
||||
SourceAnalyzer::new(self.db, hir::Source::new(self.frange.file_id.into(), node), offset)
|
||||
SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset)
|
||||
}
|
||||
|
||||
pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use format_buf::format;
|
||||
use hir::{db::HirDatabase, FromSource};
|
||||
use hir::{db::HirDatabase, FromSource, InFile};
|
||||
use join_to_string::join;
|
||||
use ra_syntax::{
|
||||
ast::{
|
||||
|
@ -141,7 +141,7 @@ fn find_struct_impl(
|
|||
})?;
|
||||
|
||||
let struct_ty = {
|
||||
let src = hir::Source { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
|
||||
let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
|
||||
hir::Struct::from_source(db, src).unwrap().ty(db)
|
||||
};
|
||||
|
||||
|
@ -152,7 +152,7 @@ fn find_struct_impl(
|
|||
return false;
|
||||
}
|
||||
|
||||
let src = hir::Source { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
|
||||
let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
|
||||
let blk = hir::ImplBlock::from_source(db, src).unwrap();
|
||||
|
||||
let same_ty = blk.target_ty(db) == struct_ty;
|
||||
|
|
|
@ -30,7 +30,7 @@ use crate::{
|
|||
db::{DefDatabase, HirDatabase},
|
||||
ty::display::HirFormatter,
|
||||
ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
|
||||
CallableDef, Either, HirDisplay, Name, Source,
|
||||
CallableDef, Either, HirDisplay, InFile, Name,
|
||||
};
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
|
@ -118,7 +118,7 @@ impl ModuleSource {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_child_node(db: &impl DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource {
|
||||
pub fn from_child_node(db: &impl DefDatabase, child: InFile<&SyntaxNode>) -> ModuleSource {
|
||||
if let Some(m) =
|
||||
child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
|
||||
{
|
||||
|
@ -901,7 +901,7 @@ impl Local {
|
|||
Type { krate, ty: InEnvironment { value: ty, environment } }
|
||||
}
|
||||
|
||||
pub fn source(self, db: &impl HirDatabase) -> Source<Either<ast::BindPat, ast::SelfParam>> {
|
||||
pub fn source(self, db: &impl HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> {
|
||||
let (_body, source_map) = db.body_with_source_map(self.parent.into());
|
||||
let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
|
||||
let root = src.file_syntax(db);
|
||||
|
|
|
@ -9,18 +9,18 @@ use crate::{
|
|||
Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
};
|
||||
|
||||
pub use hir_expand::Source;
|
||||
pub use hir_expand::InFile;
|
||||
|
||||
pub trait HasSource {
|
||||
type Ast;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<Self::Ast>;
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast>;
|
||||
}
|
||||
|
||||
/// NB: Module is !HasSource, because it has two source nodes at the same time:
|
||||
/// definition and declaration.
|
||||
impl Module {
|
||||
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
|
||||
pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> {
|
||||
pub fn definition_source(self, db: &impl DefDatabase) -> InFile<ModuleSource> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
let src = def_map[self.id.local_id].definition_source(db);
|
||||
src.map(|it| match it {
|
||||
|
@ -31,7 +31,7 @@ impl Module {
|
|||
|
||||
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
||||
/// `None` for the crate root.
|
||||
pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
|
||||
pub fn declaration_source(self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> {
|
||||
let def_map = db.crate_def_map(self.id.krate);
|
||||
def_map[self.id.local_id].declaration_source(db)
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ impl Module {
|
|||
|
||||
impl HasSource for StructField {
|
||||
type Ast = FieldSource;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<FieldSource> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<FieldSource> {
|
||||
let var = VariantId::from(self.parent);
|
||||
let src = var.child_source(db);
|
||||
src.map(|it| match it[self.id].clone() {
|
||||
|
@ -50,67 +50,67 @@ impl HasSource for StructField {
|
|||
}
|
||||
impl HasSource for Struct {
|
||||
type Ast = ast::StructDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::StructDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::StructDef> {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Union {
|
||||
type Ast = ast::UnionDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::UnionDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Enum {
|
||||
type Ast = ast::EnumDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::EnumDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for EnumVariant {
|
||||
type Ast = ast::EnumVariant;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::EnumVariant> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumVariant> {
|
||||
self.parent.id.child_source(db).map(|map| map[self.id].clone())
|
||||
}
|
||||
}
|
||||
impl HasSource for Function {
|
||||
type Ast = ast::FnDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::FnDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Const {
|
||||
type Ast = ast::ConstDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::ConstDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Static {
|
||||
type Ast = ast::StaticDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Trait {
|
||||
type Ast = ast::TraitDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::TraitDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for TypeAlias {
|
||||
type Ast = ast::TypeAliasDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::TypeAliasDef> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for MacroDef {
|
||||
type Ast = ast::MacroCall;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::MacroCall> {
|
||||
Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) }
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> {
|
||||
InFile { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) }
|
||||
}
|
||||
}
|
||||
impl HasSource for ImplBlock {
|
||||
type Ast = ast::ImplBlock;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::ImplBlock> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
|
||||
self.id.source(db)
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl HasSource for Import {
|
|||
type Ast = Either<ast::UseTree, ast::ExternCrateItem>;
|
||||
|
||||
/// Returns the syntax of the last path segment corresponding to this import
|
||||
fn source(self, db: &impl DefDatabase) -> Source<Self::Ast> {
|
||||
fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> {
|
||||
let src = self.parent.definition_source(db);
|
||||
let (_, source_map) = db.raw_items_with_source_map(src.file_id);
|
||||
let root = db.parse_or_expand(src.file_id).unwrap();
|
||||
|
|
|
@ -10,46 +10,46 @@ use ra_syntax::{
|
|||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock,
|
||||
Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait,
|
||||
InFile, Local, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait,
|
||||
TypeAlias, Union, VariantDef,
|
||||
};
|
||||
|
||||
pub trait FromSource: Sized {
|
||||
type Ast;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self>;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl FromSource for Struct {
|
||||
type Ast = ast::StructDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Struct { id })
|
||||
}
|
||||
}
|
||||
impl FromSource for Union {
|
||||
type Ast = ast::UnionDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Union { id })
|
||||
}
|
||||
}
|
||||
impl FromSource for Enum {
|
||||
type Ast = ast::EnumDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Enum { id })
|
||||
}
|
||||
}
|
||||
impl FromSource for Trait {
|
||||
type Ast = ast::TraitDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Trait { id })
|
||||
}
|
||||
}
|
||||
impl FromSource for Function {
|
||||
type Ast = ast::FnDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
|
||||
Container::Trait(it) => it.items(db),
|
||||
Container::ImplBlock(it) => it.items(db),
|
||||
|
@ -76,7 +76,7 @@ impl FromSource for Function {
|
|||
|
||||
impl FromSource for Const {
|
||||
type Ast = ast::ConstDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
|
||||
Container::Trait(it) => it.items(db),
|
||||
Container::ImplBlock(it) => it.items(db),
|
||||
|
@ -102,7 +102,7 @@ impl FromSource for Const {
|
|||
}
|
||||
impl FromSource for Static {
|
||||
type Ast = ast::StaticDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
|
||||
Container::Module(it) => it,
|
||||
Container::Trait(_) | Container::ImplBlock(_) => return None,
|
||||
|
@ -120,7 +120,7 @@ impl FromSource for Static {
|
|||
|
||||
impl FromSource for TypeAlias {
|
||||
type Ast = ast::TypeAliasDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
|
||||
Container::Trait(it) => it.items(db),
|
||||
Container::ImplBlock(it) => it.items(db),
|
||||
|
@ -147,11 +147,11 @@ impl FromSource for TypeAlias {
|
|||
|
||||
impl FromSource for MacroDef {
|
||||
type Ast = ast::MacroCall;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let kind = MacroDefKind::Declarative;
|
||||
|
||||
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
||||
let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
|
||||
let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?;
|
||||
let krate = module.krate().crate_id();
|
||||
|
||||
let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value));
|
||||
|
@ -163,7 +163,7 @@ impl FromSource for MacroDef {
|
|||
|
||||
impl FromSource for ImplBlock {
|
||||
type Ast = ast::ImplBlock;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(ImplBlock { id })
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ impl FromSource for ImplBlock {
|
|||
|
||||
impl FromSource for EnumVariant {
|
||||
type Ast = ast::EnumVariant;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let parent_enum = src.value.parent_enum();
|
||||
let src_enum = Source { file_id: src.file_id, value: parent_enum };
|
||||
let src_enum = InFile { file_id: src.file_id, value: parent_enum };
|
||||
let variants = Enum::from_source(db, src_enum)?.variants(db);
|
||||
variants.into_iter().find(|v| same_source(&v.source(db), &src))
|
||||
}
|
||||
|
@ -181,17 +181,17 @@ impl FromSource for EnumVariant {
|
|||
|
||||
impl FromSource for StructField {
|
||||
type Ast = FieldSource;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
|
||||
let variant_def: VariantDef = match src.value {
|
||||
FieldSource::Named(ref field) => {
|
||||
let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?;
|
||||
let src = Source { file_id: src.file_id, value };
|
||||
let src = InFile { file_id: src.file_id, value };
|
||||
let def = Struct::from_source(db, src)?;
|
||||
VariantDef::from(def)
|
||||
}
|
||||
FieldSource::Pos(ref field) => {
|
||||
let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?;
|
||||
let src = Source { file_id: src.file_id, value };
|
||||
let src = InFile { file_id: src.file_id, value };
|
||||
let def = EnumVariant::from_source(db, src)?;
|
||||
VariantDef::from(def)
|
||||
}
|
||||
|
@ -206,14 +206,14 @@ impl FromSource for StructField {
|
|||
}
|
||||
|
||||
impl Local {
|
||||
pub fn from_source(db: &impl HirDatabase, src: Source<ast::BindPat>) -> Option<Self> {
|
||||
pub fn from_source(db: &impl HirDatabase, src: InFile<ast::BindPat>) -> Option<Self> {
|
||||
let file_id = src.file_id;
|
||||
let parent: DefWithBody = src.value.syntax().ancestors().find_map(|it| {
|
||||
let res = match_ast! {
|
||||
match it {
|
||||
ast::ConstDef(value) => { Const::from_source(db, Source { value, file_id})?.into() },
|
||||
ast::StaticDef(value) => { Static::from_source(db, Source { value, file_id})?.into() },
|
||||
ast::FnDef(value) => { Function::from_source(db, Source { value, file_id})?.into() },
|
||||
ast::ConstDef(value) => { Const::from_source(db, InFile { value, file_id})?.into() },
|
||||
ast::StaticDef(value) => { Static::from_source(db, InFile { value, file_id})?.into() },
|
||||
ast::FnDef(value) => { Function::from_source(db, InFile { value, file_id})?.into() },
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
|
@ -227,16 +227,16 @@ impl Local {
|
|||
}
|
||||
|
||||
impl Module {
|
||||
pub fn from_declaration(db: &impl DefDatabase, src: Source<ast::Module>) -> Option<Self> {
|
||||
pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
|
||||
let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
|
||||
|
||||
let parent_module = match parent_declaration {
|
||||
Some(parent_declaration) => {
|
||||
let src_parent = Source { file_id: src.file_id, value: parent_declaration };
|
||||
let src_parent = InFile { file_id: src.file_id, value: parent_declaration };
|
||||
Module::from_declaration(db, src_parent)
|
||||
}
|
||||
_ => {
|
||||
let src_parent = Source {
|
||||
let src_parent = InFile {
|
||||
file_id: src.file_id,
|
||||
value: ModuleSource::new(db, Some(src.file_id.original_file(db)), None),
|
||||
};
|
||||
|
@ -248,13 +248,13 @@ impl Module {
|
|||
parent_module.child(db, &child_name.as_name())
|
||||
}
|
||||
|
||||
pub fn from_definition(db: &impl DefDatabase, src: Source<ModuleSource>) -> Option<Self> {
|
||||
pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> {
|
||||
match src.value {
|
||||
ModuleSource::Module(ref module) => {
|
||||
assert!(!module.has_semi());
|
||||
return Module::from_declaration(
|
||||
db,
|
||||
Source { file_id: src.file_id, value: module.clone() },
|
||||
InFile { file_id: src.file_id, value: module.clone() },
|
||||
);
|
||||
}
|
||||
ModuleSource::SourceFile(_) => (),
|
||||
|
@ -271,13 +271,13 @@ impl Module {
|
|||
}
|
||||
}
|
||||
|
||||
fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: Source<N>) -> Option<DEF>
|
||||
fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: InFile<N>) -> Option<DEF>
|
||||
where
|
||||
N: AstNode,
|
||||
DEF: AstItemDef<N>,
|
||||
{
|
||||
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
||||
let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
|
||||
let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?;
|
||||
let ctx = LocationCtx::new(db, module.id, src.file_id);
|
||||
let items = db.ast_id_map(src.file_id);
|
||||
let item_id = items.ast_id(&src.value);
|
||||
|
@ -291,7 +291,7 @@ enum Container {
|
|||
}
|
||||
|
||||
impl Container {
|
||||
fn find(db: &impl DefDatabase, src: Source<&SyntaxNode>) -> Option<Container> {
|
||||
fn find(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<Container> {
|
||||
// FIXME: this doesn't try to handle nested declarations
|
||||
for container in src.value.ancestors() {
|
||||
let res = match_ast! {
|
||||
|
@ -322,6 +322,6 @@ impl Container {
|
|||
/// In general, we do not guarantee that we have exactly one instance of a
|
||||
/// syntax tree for each file. We probably should add such guarantee, but, for
|
||||
/// the time being, we will use identity-less AstPtr comparison.
|
||||
fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool {
|
||||
fn same_source<N: AstNode>(s1: &InFile<N>, s2: &InFile<N>) -> bool {
|
||||
s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new)
|
||||
}
|
||||
|
|
|
@ -63,5 +63,5 @@ pub use hir_def::{
|
|||
type_ref::Mutability,
|
||||
};
|
||||
pub use hir_expand::{
|
||||
either::Either, name::Name, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Source,
|
||||
either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ use hir_def::{
|
|||
AssocItemId, DefWithBodyId,
|
||||
};
|
||||
use hir_expand::{
|
||||
hygiene::Hygiene, name::AsName, AstId, HirFileId, MacroCallId, MacroFileKind, Source,
|
||||
hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroFileKind,
|
||||
};
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
|
@ -37,7 +37,7 @@ use crate::{
|
|||
GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
|
||||
};
|
||||
|
||||
fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
|
||||
fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
|
||||
match_ast! {
|
||||
match (node.value) {
|
||||
ast::Module(it) => {
|
||||
|
@ -71,7 +71,7 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -
|
|||
|
||||
fn def_with_body_from_child_node(
|
||||
db: &impl HirDatabase,
|
||||
child: Source<&SyntaxNode>,
|
||||
child: InFile<&SyntaxNode>,
|
||||
) -> Option<DefWithBody> {
|
||||
child.value.ancestors().find_map(|node| {
|
||||
match_ast! {
|
||||
|
@ -141,8 +141,8 @@ impl Expansion {
|
|||
pub fn map_token_down(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
token: Source<&SyntaxToken>,
|
||||
) -> Option<Source<SyntaxToken>> {
|
||||
token: InFile<&SyntaxToken>,
|
||||
) -> Option<InFile<SyntaxToken>> {
|
||||
let exp_info = self.file_id().expansion_info(db)?;
|
||||
exp_info.map_token_down(token)
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ impl Expansion {
|
|||
impl SourceAnalyzer {
|
||||
pub fn new(
|
||||
db: &impl HirDatabase,
|
||||
node: Source<&SyntaxNode>,
|
||||
node: InFile<&SyntaxNode>,
|
||||
offset: Option<TextUnit>,
|
||||
) -> SourceAnalyzer {
|
||||
let def_with_body = def_with_body_from_child_node(db, node);
|
||||
|
@ -192,12 +192,12 @@ impl SourceAnalyzer {
|
|||
}
|
||||
|
||||
fn expr_id(&self, expr: &ast::Expr) -> Option<ExprId> {
|
||||
let src = Source { file_id: self.file_id, value: expr };
|
||||
let src = InFile { file_id: self.file_id, value: expr };
|
||||
self.body_source_map.as_ref()?.node_expr(src)
|
||||
}
|
||||
|
||||
fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> {
|
||||
let src = Source { file_id: self.file_id, value: pat };
|
||||
let src = InFile { file_id: self.file_id, value: pat };
|
||||
self.body_source_map.as_ref()?.node_pat(src)
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ impl SourceAnalyzer {
|
|||
pub fn resolve_macro_call(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
macro_call: Source<&ast::MacroCall>,
|
||||
macro_call: InFile<&ast::MacroCall>,
|
||||
) -> Option<MacroDef> {
|
||||
let hygiene = Hygiene::new(db, macro_call.file_id);
|
||||
let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?;
|
||||
|
@ -318,7 +318,7 @@ impl SourceAnalyzer {
|
|||
let name = name_ref.as_name();
|
||||
let source_map = self.body_source_map.as_ref()?;
|
||||
let scopes = self.scopes.as_ref()?;
|
||||
let scope = scope_for(scopes, source_map, Source::new(self.file_id, name_ref.syntax()))?;
|
||||
let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?;
|
||||
let entry = scopes.resolve_name_in_scope(scope, &name)?;
|
||||
Some(ScopeEntryWithSyntax {
|
||||
name: entry.name().clone(),
|
||||
|
@ -446,7 +446,7 @@ impl SourceAnalyzer {
|
|||
pub fn expand(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
macro_call: Source<&ast::MacroCall>,
|
||||
macro_call: InFile<&ast::MacroCall>,
|
||||
) -> Option<Expansion> {
|
||||
let def = self.resolve_macro_call(db, macro_call)?.id;
|
||||
let ast_id = AstId::new(
|
||||
|
@ -463,19 +463,19 @@ impl SourceAnalyzer {
|
|||
fn scope_for(
|
||||
scopes: &ExprScopes,
|
||||
source_map: &BodySourceMap,
|
||||
node: Source<&SyntaxNode>,
|
||||
node: InFile<&SyntaxNode>,
|
||||
) -> Option<ScopeId> {
|
||||
node.value
|
||||
.ancestors()
|
||||
.filter_map(ast::Expr::cast)
|
||||
.filter_map(|it| source_map.node_expr(Source::new(node.file_id, &it)))
|
||||
.filter_map(|it| source_map.node_expr(InFile::new(node.file_id, &it)))
|
||||
.find_map(|it| scopes.scope_for(it))
|
||||
}
|
||||
|
||||
fn scope_for_offset(
|
||||
scopes: &ExprScopes,
|
||||
source_map: &BodySourceMap,
|
||||
offset: Source<TextUnit>,
|
||||
offset: InFile<TextUnit>,
|
||||
) -> Option<ScopeId> {
|
||||
scopes
|
||||
.scope_by_expr()
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||
use hir_expand::{
|
||||
either::Either,
|
||||
name::{AsName, Name},
|
||||
Source,
|
||||
InFile,
|
||||
};
|
||||
use ra_arena::{map::ArenaMap, Arena};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
@ -88,7 +88,7 @@ impl EnumData {
|
|||
impl HasChildSource for EnumId {
|
||||
type ChildId = LocalEnumVariantId;
|
||||
type Value = ast::EnumVariant;
|
||||
fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
let src = self.source(db);
|
||||
let mut trace = Trace::new_for_map();
|
||||
lower_enum(&mut trace, &src.value);
|
||||
|
@ -145,7 +145,7 @@ impl HasChildSource for VariantId {
|
|||
type ChildId = LocalStructFieldId;
|
||||
type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
|
||||
|
||||
fn child_source(&self, db: &impl DefDatabase) -> Source<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
|
||||
let src = match self {
|
||||
VariantId::EnumVariantId(it) => {
|
||||
// I don't really like the fact that we call into parent source
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{ops, sync::Arc};
|
||||
|
||||
use hir_expand::{either::Either, hygiene::Hygiene, AstId, Source};
|
||||
use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile};
|
||||
use mbe::ast_to_token_tree;
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode, AttrsOwner},
|
||||
|
@ -68,7 +68,7 @@ impl Attrs {
|
|||
}
|
||||
}
|
||||
|
||||
fn from_attrs_owner(db: &impl DefDatabase, owner: Source<&dyn AttrsOwner>) -> Attrs {
|
||||
fn from_attrs_owner(db: &impl DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
|
||||
let hygiene = Hygiene::new(db, owner.file_id);
|
||||
Attrs::new(owner.value, &hygiene)
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ where
|
|||
N: ast::AttrsOwner,
|
||||
D: DefDatabase,
|
||||
{
|
||||
let src = Source::new(src.file_id(), src.to_node(db));
|
||||
let src = InFile::new(src.file_id(), src.to_node(db));
|
||||
Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub mod scope;
|
|||
use std::{ops::Index, sync::Arc};
|
||||
|
||||
use hir_expand::{
|
||||
either::Either, hygiene::Hygiene, AstId, HirFileId, MacroDefId, MacroFileKind, Source,
|
||||
either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind,
|
||||
};
|
||||
use ra_arena::{map::ArenaMap, Arena};
|
||||
use ra_syntax::{ast, AstNode, AstPtr};
|
||||
|
@ -73,8 +73,8 @@ impl Expander {
|
|||
std::mem::forget(mark);
|
||||
}
|
||||
|
||||
fn to_source<T>(&self, value: T) -> Source<T> {
|
||||
Source { file_id: self.current_file_id, value }
|
||||
fn to_source<T>(&self, value: T) -> InFile<T> {
|
||||
InFile { file_id: self.current_file_id, value }
|
||||
}
|
||||
|
||||
fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
|
||||
|
@ -115,10 +115,10 @@ pub struct Body {
|
|||
}
|
||||
|
||||
pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
|
||||
pub type ExprSource = Source<ExprPtr>;
|
||||
pub type ExprSource = InFile<ExprPtr>;
|
||||
|
||||
pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
|
||||
pub type PatSource = Source<PatPtr>;
|
||||
pub type PatSource = InFile<PatPtr>;
|
||||
|
||||
/// An item body together with the mapping from syntax nodes to HIR expression
|
||||
/// IDs. This is needed to go from e.g. a position in a file to the HIR
|
||||
|
@ -205,7 +205,7 @@ impl BodySourceMap {
|
|||
self.expr_map_back.get(expr).copied()
|
||||
}
|
||||
|
||||
pub fn node_expr(&self, node: Source<&ast::Expr>) -> Option<ExprId> {
|
||||
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
||||
let src = node.map(|it| Either::A(AstPtr::new(it)));
|
||||
self.expr_map.get(&src).cloned()
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ impl BodySourceMap {
|
|||
self.pat_map_back.get(pat).copied()
|
||||
}
|
||||
|
||||
pub fn node_pat(&self, node: Source<&ast::Pat>) -> Option<PatId> {
|
||||
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
||||
let src = node.map(|it| Either::A(AstPtr::new(it)));
|
||||
self.pat_map.get(&src).cloned()
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hir_expand::{name::AsName, Source};
|
||||
use hir_expand::{name::AsName, InFile};
|
||||
use ra_db::{fixture::WithFixture, FileId, SourceDatabase};
|
||||
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||
use test_utils::{assert_eq_text, covers, extract_offset};
|
||||
|
@ -211,7 +211,7 @@ mod tests {
|
|||
let (_body, source_map) = db.body_with_source_map(function.into());
|
||||
|
||||
let expr_id = source_map
|
||||
.node_expr(Source { file_id: file_id.into(), value: &marker.into() })
|
||||
.node_expr(InFile { file_id: file_id.into(), value: &marker.into() })
|
||||
.unwrap();
|
||||
let scope = scopes.scope_for(expr_id);
|
||||
|
||||
|
@ -318,7 +318,7 @@ mod tests {
|
|||
let expr_scope = {
|
||||
let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap();
|
||||
let expr_id =
|
||||
source_map.node_expr(Source { file_id: file_id.into(), value: &expr_ast }).unwrap();
|
||||
source_map.node_expr(InFile { file_id: file_id.into(), value: &expr_ast }).unwrap();
|
||||
scopes.scope_for(expr_id).unwrap()
|
||||
};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use hir_expand::diagnostics::Diagnostic;
|
|||
use ra_db::RelativePathBuf;
|
||||
use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
|
||||
|
||||
use hir_expand::{HirFileId, Source};
|
||||
use hir_expand::{HirFileId, InFile};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UnresolvedModule {
|
||||
|
@ -19,8 +19,8 @@ impl Diagnostic for UnresolvedModule {
|
|||
fn message(&self) -> String {
|
||||
"unresolved module".to_string()
|
||||
}
|
||||
fn source(&self) -> Source<SyntaxNodePtr> {
|
||||
Source { file_id: self.file, value: self.decl.into() }
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.decl.into() }
|
||||
}
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
|
|
|
@ -36,7 +36,7 @@ mod marks;
|
|||
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source};
|
||||
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
|
||||
use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
|
||||
use ra_db::{impl_intern_key, salsa, CrateId};
|
||||
use ra_syntax::{ast, AstNode};
|
||||
|
@ -105,10 +105,10 @@ pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
|
|||
let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
|
||||
Self::intern(ctx.db, loc)
|
||||
}
|
||||
fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source<N> {
|
||||
fn source(self, db: &(impl AstDatabase + InternDatabase)) -> InFile<N> {
|
||||
let loc = self.lookup_intern(db);
|
||||
let value = loc.ast_id.to_node(db);
|
||||
Source { file_id: loc.ast_id.file_id(), value }
|
||||
InFile { file_id: loc.ast_id.file_id(), value }
|
||||
}
|
||||
fn module(self, db: &impl InternDatabase) -> ModuleId {
|
||||
let loc = self.lookup_intern(db);
|
||||
|
@ -517,42 +517,42 @@ impl HasModule for StaticLoc {
|
|||
|
||||
pub trait HasSource {
|
||||
type Value;
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>;
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
|
||||
}
|
||||
|
||||
impl HasSource for FunctionLoc {
|
||||
type Value = ast::FnDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::FnDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::FnDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
InFile::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for TypeAliasLoc {
|
||||
type Value = ast::TypeAliasDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::TypeAliasDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::TypeAliasDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
InFile::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for ConstLoc {
|
||||
type Value = ast::ConstDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::ConstDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::ConstDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
InFile::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSource for StaticLoc {
|
||||
type Value = ast::StaticDef;
|
||||
|
||||
fn source(&self, db: &impl db::DefDatabase) -> Source<ast::StaticDef> {
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<ast::StaticDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
Source::new(self.ast_id.file_id(), node)
|
||||
InFile::new(self.ast_id.file_id(), node)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,5 +562,5 @@ pub trait HasChildSource {
|
|||
fn child_source(
|
||||
&self,
|
||||
db: &impl db::DefDatabase,
|
||||
) -> Source<ArenaMap<Self::ChildId, Self::Value>>;
|
||||
) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ mod tests;
|
|||
use std::sync::Arc;
|
||||
|
||||
use hir_expand::{
|
||||
ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, MacroDefId,
|
||||
Source,
|
||||
ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile,
|
||||
MacroDefId,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use ra_arena::Arena;
|
||||
|
@ -261,21 +261,21 @@ impl ModuleData {
|
|||
pub fn definition_source(
|
||||
&self,
|
||||
db: &impl DefDatabase,
|
||||
) -> Source<Either<ast::SourceFile, ast::Module>> {
|
||||
) -> InFile<Either<ast::SourceFile, ast::Module>> {
|
||||
if let Some(file_id) = self.definition {
|
||||
let sf = db.parse(file_id).tree();
|
||||
return Source::new(file_id.into(), Either::A(sf));
|
||||
return InFile::new(file_id.into(), Either::A(sf));
|
||||
}
|
||||
let decl = self.declaration.unwrap();
|
||||
Source::new(decl.file_id(), Either::B(decl.to_node(db)))
|
||||
InFile::new(decl.file_id(), Either::B(decl.to_node(db)))
|
||||
}
|
||||
|
||||
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
||||
/// `None` for the crate root.
|
||||
pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
|
||||
pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> {
|
||||
let decl = self.declaration?;
|
||||
let value = decl.to_node(db);
|
||||
Some(Source { file_id: decl.file_id(), value })
|
||||
Some(InFile { file_id: decl.file_id(), value })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ use ra_syntax::{
|
|||
use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, LocalImportId,
|
||||
Source,
|
||||
attr::Attrs, db::DefDatabase, path::Path, trace::Trace, FileAstId, HirFileId, InFile,
|
||||
LocalImportId,
|
||||
};
|
||||
|
||||
/// `RawItems` is a set of top-level items in a file (except for impls).
|
||||
|
@ -313,7 +313,7 @@ impl RawItemsCollector {
|
|||
|
||||
let mut buf = Vec::new();
|
||||
Path::expand_use_item(
|
||||
Source { value: use_item, file_id: self.file_id },
|
||||
InFile { value: use_item, file_id: self.file_id },
|
||||
&self.hygiene,
|
||||
|path, use_tree, is_glob, alias| {
|
||||
let import_data = ImportData {
|
||||
|
|
|
@ -13,7 +13,7 @@ use ra_syntax::{
|
|||
AstNode,
|
||||
};
|
||||
|
||||
use crate::{type_ref::TypeRef, Source};
|
||||
use crate::{type_ref::TypeRef, InFile};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Path {
|
||||
|
@ -67,7 +67,7 @@ pub enum PathKind {
|
|||
impl Path {
|
||||
/// Calls `cb` with all paths, represented by this use item.
|
||||
pub(crate) fn expand_use_item(
|
||||
item_src: Source<ast::UseItem>,
|
||||
item_src: InFile<ast::UseItem>,
|
||||
hygiene: &Hygiene,
|
||||
mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
|
||||
) {
|
||||
|
|
|
@ -18,11 +18,11 @@ use std::{any::Any, fmt};
|
|||
|
||||
use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange};
|
||||
|
||||
use crate::{db::AstDatabase, Source};
|
||||
use crate::{db::AstDatabase, InFile};
|
||||
|
||||
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
|
||||
fn message(&self) -> String;
|
||||
fn source(&self) -> Source<SyntaxNodePtr>;
|
||||
fn source(&self) -> InFile<SyntaxNodePtr>;
|
||||
fn highlight_range(&self) -> TextRange {
|
||||
self.source().value.range()
|
||||
}
|
||||
|
|
|
@ -90,9 +90,9 @@ impl HirFileId {
|
|||
let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
|
||||
|
||||
Some(ExpansionInfo {
|
||||
expanded: Source::new(self, parse.syntax_node()),
|
||||
arg: Source::new(loc.ast_id.file_id, arg_tt),
|
||||
def: Source::new(loc.ast_id.file_id, def_tt),
|
||||
expanded: InFile::new(self, parse.syntax_node()),
|
||||
arg: InFile::new(loc.ast_id.file_id, arg_tt),
|
||||
def: InFile::new(loc.ast_id.file_id, def_tt),
|
||||
macro_arg,
|
||||
macro_def,
|
||||
exp_map,
|
||||
|
@ -167,9 +167,9 @@ impl MacroCallId {
|
|||
/// ExpansionInfo mainly describes how to map text range between src and expanded macro
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ExpansionInfo {
|
||||
expanded: Source<SyntaxNode>,
|
||||
arg: Source<ast::TokenTree>,
|
||||
def: Source<ast::TokenTree>,
|
||||
expanded: InFile<SyntaxNode>,
|
||||
arg: InFile<ast::TokenTree>,
|
||||
def: InFile<ast::TokenTree>,
|
||||
|
||||
macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>,
|
||||
macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
|
||||
|
@ -177,7 +177,7 @@ pub struct ExpansionInfo {
|
|||
}
|
||||
|
||||
impl ExpansionInfo {
|
||||
pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> {
|
||||
pub fn map_token_down(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
|
||||
assert_eq!(token.file_id, self.arg.file_id);
|
||||
let range =
|
||||
token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?;
|
||||
|
@ -191,7 +191,7 @@ impl ExpansionInfo {
|
|||
Some(self.expanded.with_value(token))
|
||||
}
|
||||
|
||||
pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> {
|
||||
pub fn map_token_up(&self, token: InFile<&SyntaxToken>) -> Option<InFile<SyntaxToken>> {
|
||||
let token_id = self.exp_map.token_by_range(token.value.text_range())?;
|
||||
|
||||
let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
|
||||
|
@ -254,33 +254,33 @@ impl<N: AstNode> AstId<N> {
|
|||
}
|
||||
}
|
||||
|
||||
/// `Source<T>` stores a value of `T` inside a particular file/syntax tree.
|
||||
/// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
|
||||
///
|
||||
/// Typical usages are:
|
||||
///
|
||||
/// * `Source<SyntaxNode>` -- syntax node in a file
|
||||
/// * `Source<ast::FnDef>` -- ast node in a file
|
||||
/// * `Source<TextUnit>` -- offset in a file
|
||||
/// * `InFile<SyntaxNode>` -- syntax node in a file
|
||||
/// * `InFile<ast::FnDef>` -- ast node in a file
|
||||
/// * `InFile<TextUnit>` -- offset in a file
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
pub struct Source<T> {
|
||||
pub struct InFile<T> {
|
||||
pub file_id: HirFileId,
|
||||
pub value: T,
|
||||
}
|
||||
|
||||
impl<T> Source<T> {
|
||||
pub fn new(file_id: HirFileId, value: T) -> Source<T> {
|
||||
Source { file_id, value }
|
||||
impl<T> InFile<T> {
|
||||
pub fn new(file_id: HirFileId, value: T) -> InFile<T> {
|
||||
InFile { file_id, value }
|
||||
}
|
||||
|
||||
// Similarly, naming here is stupid...
|
||||
pub fn with_value<U>(&self, value: U) -> Source<U> {
|
||||
Source::new(self.file_id, value)
|
||||
pub fn with_value<U>(&self, value: U) -> InFile<U> {
|
||||
InFile::new(self.file_id, value)
|
||||
}
|
||||
|
||||
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
|
||||
Source::new(self.file_id, f(self.value))
|
||||
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> InFile<U> {
|
||||
InFile::new(self.file_id, f(self.value))
|
||||
}
|
||||
pub fn as_ref(&self) -> Source<&T> {
|
||||
pub fn as_ref(&self) -> InFile<&T> {
|
||||
self.with_value(&self.value)
|
||||
}
|
||||
pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::any::Any;
|
||||
|
||||
use hir_expand::{db::AstDatabase, name::Name, HirFileId, Source};
|
||||
use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
|
||||
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
|
||||
|
||||
pub use hir_def::diagnostics::UnresolvedModule;
|
||||
|
@ -19,8 +19,8 @@ impl Diagnostic for NoSuchField {
|
|||
"no such field".to_string()
|
||||
}
|
||||
|
||||
fn source(&self) -> Source<SyntaxNodePtr> {
|
||||
Source { file_id: self.file, value: self.field.into() }
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.field.into() }
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
|
@ -44,8 +44,8 @@ impl Diagnostic for MissingFields {
|
|||
}
|
||||
message
|
||||
}
|
||||
fn source(&self) -> Source<SyntaxNodePtr> {
|
||||
Source { file_id: self.file, value: self.field_list.into() }
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.field_list.into() }
|
||||
}
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
|
@ -72,8 +72,8 @@ impl Diagnostic for MissingOkInTailExpr {
|
|||
fn message(&self) -> String {
|
||||
"wrap return expression in Ok".to_string()
|
||||
}
|
||||
fn source(&self) -> Source<SyntaxNodePtr> {
|
||||
Source { file_id: self.file, value: self.expr.into() }
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
InFile { file_id: self.file, value: self.expr.into() }
|
||||
}
|
||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||
self
|
||||
|
|
|
@ -8,7 +8,7 @@ use hir_def::{
|
|||
body::BodySourceMap, db::DefDatabase, nameres::CrateDefMap, AssocItemId, DefWithBodyId,
|
||||
LocalModuleId, Lookup, ModuleDefId,
|
||||
};
|
||||
use hir_expand::Source;
|
||||
use hir_expand::InFile;
|
||||
use insta::assert_snapshot;
|
||||
use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase};
|
||||
use ra_syntax::{
|
||||
|
@ -4680,7 +4680,7 @@ fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
|
|||
for decl in crate_def_map[module.local_id].scope.declarations() {
|
||||
if let ModuleDefId::FunctionId(func) = decl {
|
||||
let (_body, source_map) = db.body_with_source_map(func.into());
|
||||
if let Some(expr_id) = source_map.node_expr(Source::new(pos.file_id.into(), &expr)) {
|
||||
if let Some(expr_id) = source_map.node_expr(InFile::new(pos.file_id.into(), &expr)) {
|
||||
let infer = db.infer(func.into());
|
||||
let ty = &infer[expr_id];
|
||||
return ty.display(db).to_string();
|
||||
|
|
|
@ -18,7 +18,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
|
|||
// Find the calling expression and it's NameRef
|
||||
let calling_node = FnCallNode::with_node(&syntax, position.offset)?;
|
||||
let name_ref = calling_node.name_ref()?;
|
||||
let name_ref = hir::Source::new(position.file_id.into(), name_ref.syntax());
|
||||
let name_ref = hir::InFile::new(position.file_id.into(), name_ref.syntax());
|
||||
|
||||
let analyzer = hir::SourceAnalyzer::new(db, name_ref, None);
|
||||
let (mut call_info, has_self) = match &calling_node {
|
||||
|
|
|
@ -54,13 +54,13 @@ impl<'a> CompletionContext<'a> {
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
hir::InFile { file_id: position.file_id.into(), value: src },
|
||||
);
|
||||
let token =
|
||||
original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?;
|
||||
let analyzer = hir::SourceAnalyzer::new(
|
||||
db,
|
||||
hir::Source::new(position.file_id.into(), &token.parent()),
|
||||
hir::InFile::new(position.file_id.into(), &token.parent()),
|
||||
Some(position.offset),
|
||||
);
|
||||
let mut ctx = CompletionContext {
|
||||
|
|
|
@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
|||
});
|
||||
let source_file = db.parse(file_id).tree();
|
||||
let src =
|
||||
hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) };
|
||||
hir::InFile { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) };
|
||||
if let Some(m) = hir::Module::from_definition(db, src) {
|
||||
m.diagnostics(db, &mut sink);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source};
|
||||
use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource};
|
||||
use ra_db::{FileId, SourceDatabase};
|
||||
use ra_syntax::{
|
||||
ast::{self, DocCommentsOwner, NameOwner},
|
||||
|
@ -141,7 +141,7 @@ impl NavigationTarget {
|
|||
/// Allows `NavigationTarget` to be created from a `NameOwner`
|
||||
pub(crate) fn from_named(
|
||||
db: &RootDatabase,
|
||||
node: Source<&dyn ast::NameOwner>,
|
||||
node: InFile<&dyn ast::NameOwner>,
|
||||
docs: Option<String>,
|
||||
description: Option<String>,
|
||||
) -> NavigationTarget {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
//! Utilities to work with files, produced by macros.
|
||||
use std::iter::successors;
|
||||
|
||||
use hir::Source;
|
||||
use hir::InFile;
|
||||
use ra_db::FileId;
|
||||
use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxToken};
|
||||
|
||||
use crate::{db::RootDatabase, FileRange};
|
||||
|
||||
pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> FileRange {
|
||||
pub(crate) fn original_range(db: &RootDatabase, node: InFile<&SyntaxNode>) -> FileRange {
|
||||
let expansion = match node.file_id.expansion_info(db) {
|
||||
None => {
|
||||
return FileRange {
|
||||
|
@ -44,8 +44,8 @@ pub(crate) fn descend_into_macros(
|
|||
db: &RootDatabase,
|
||||
file_id: FileId,
|
||||
token: SyntaxToken,
|
||||
) -> Source<SyntaxToken> {
|
||||
let src = Source::new(file_id.into(), token);
|
||||
) -> InFile<SyntaxToken> {
|
||||
let src = InFile::new(file_id.into(), token);
|
||||
|
||||
successors(Some(src), |token| {
|
||||
let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
|
||||
|
|
|
@ -22,7 +22,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?;
|
||||
let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?;
|
||||
|
||||
let source = hir::Source::new(position.file_id.into(), mac.syntax());
|
||||
let source = hir::InFile::new(position.file_id.into(), mac.syntax());
|
||||
let expanded = expand_macro_recur(db, source, source.with_value(&mac))?;
|
||||
|
||||
// FIXME:
|
||||
|
@ -34,8 +34,8 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
|
||||
fn expand_macro_recur(
|
||||
db: &RootDatabase,
|
||||
source: hir::Source<&SyntaxNode>,
|
||||
macro_call: hir::Source<&ast::MacroCall>,
|
||||
source: hir::InFile<&SyntaxNode>,
|
||||
macro_call: hir::InFile<&ast::MacroCall>,
|
||||
) -> Option<SyntaxNode> {
|
||||
let analyzer = hir::SourceAnalyzer::new(db, source, None);
|
||||
let expansion = analyzer.expand(db, macro_call)?;
|
||||
|
@ -46,7 +46,7 @@ fn expand_macro_recur(
|
|||
let mut replaces = FxHashMap::default();
|
||||
|
||||
for child in children.into_iter() {
|
||||
let node = hir::Source::new(macro_file_id, &child);
|
||||
let node = hir::InFile::new(macro_file_id, &child);
|
||||
if let Some(new_node) = expand_macro_recur(db, source, node) {
|
||||
// Replace the whole node if it is root
|
||||
// `replace_descendants` will not replace the parent node
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir::{db::AstDatabase, Source};
|
||||
use hir::{db::AstDatabase, InFile};
|
||||
use ra_syntax::{
|
||||
ast::{self, DocCommentsOwner},
|
||||
match_ast, AstNode, SyntaxNode,
|
||||
|
@ -58,7 +58,7 @@ impl ReferenceResult {
|
|||
|
||||
pub(crate) fn reference_definition(
|
||||
db: &RootDatabase,
|
||||
name_ref: Source<&ast::NameRef>,
|
||||
name_ref: InFile<&ast::NameRef>,
|
||||
) -> ReferenceResult {
|
||||
use self::ReferenceResult::*;
|
||||
|
||||
|
@ -94,7 +94,7 @@ pub(crate) fn reference_definition(
|
|||
|
||||
pub(crate) fn name_definition(
|
||||
db: &RootDatabase,
|
||||
name: Source<&ast::Name>,
|
||||
name: InFile<&ast::Name>,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let parent = name.value.syntax().parent()?;
|
||||
|
||||
|
@ -115,7 +115,7 @@ pub(crate) fn name_definition(
|
|||
None
|
||||
}
|
||||
|
||||
fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> {
|
||||
fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option<NavigationTarget> {
|
||||
match_ast! {
|
||||
match (node.value) {
|
||||
ast::StructDef(it) => {
|
||||
|
|
|
@ -227,7 +227,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
|
|||
.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, hir::Source::new(frange.file_id.into(), &node), None);
|
||||
hir::SourceAnalyzer::new(db, hir::InFile::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
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn goto_implementation(
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
hir::InFile { file_id: position.file_id.into(), value: src },
|
||||
)?;
|
||||
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) {
|
||||
|
@ -42,15 +42,15 @@ fn impls_for_def(
|
|||
) -> Option<Vec<NavigationTarget>> {
|
||||
let ty = match node {
|
||||
ast::NominalDef::StructDef(def) => {
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: def.clone() };
|
||||
let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
|
||||
hir::Struct::from_source(db, src)?.ty(db)
|
||||
}
|
||||
ast::NominalDef::EnumDef(def) => {
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: def.clone() };
|
||||
let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
|
||||
hir::Enum::from_source(db, src)?.ty(db)
|
||||
}
|
||||
ast::NominalDef::UnionDef(def) => {
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: def.clone() };
|
||||
let src = hir::InFile { file_id: position.file_id.into(), value: def.clone() };
|
||||
hir::Union::from_source(db, src)?.ty(db)
|
||||
}
|
||||
};
|
||||
|
@ -73,7 +73,7 @@ fn impls_for_trait(
|
|||
node: &ast::TraitDef,
|
||||
module: hir::Module,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: node.clone() };
|
||||
let src = hir::InFile { file_id: position.file_id.into(), value: node.clone() };
|
||||
let tr = hir::Trait::from_source(db, src)?;
|
||||
|
||||
let krate = module.krate();
|
||||
|
|
|
@ -38,7 +38,7 @@ fn get_inlay_hints(
|
|||
node: &SyntaxNode,
|
||||
max_inlay_hint_length: Option<usize>,
|
||||
) -> Option<Vec<InlayHint>> {
|
||||
let analyzer = SourceAnalyzer::new(db, hir::Source::new(file_id.into(), node), None);
|
||||
let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None);
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::LetStmt(it) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = match hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
hir::InFile { file_id: position.file_id.into(), value: src },
|
||||
) {
|
||||
None => return Vec::new(),
|
||||
Some(it) => it,
|
||||
|
@ -23,7 +23,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
|||
pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
|
||||
let src = hir::ModuleSource::from_file_id(db, file_id);
|
||||
let module =
|
||||
match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src })
|
||||
match hir::Module::from_definition(db, hir::InFile { file_id: file_id.into(), value: src })
|
||||
{
|
||||
Some(it) => it,
|
||||
None => return Vec::new(),
|
||||
|
|
|
@ -14,7 +14,7 @@ mod name_definition;
|
|||
mod rename;
|
||||
mod search_scope;
|
||||
|
||||
use hir::Source;
|
||||
use hir::InFile;
|
||||
use once_cell::unsync::Lazy;
|
||||
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
||||
use ra_prof::profile;
|
||||
|
@ -107,12 +107,12 @@ fn find_name<'a>(
|
|||
position: FilePosition,
|
||||
) -> Option<RangeInfo<(String, NameDefinition)>> {
|
||||
if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
|
||||
let def = classify_name(db, Source::new(position.file_id.into(), &name))?;
|
||||
let def = classify_name(db, InFile::new(position.file_id.into(), &name))?;
|
||||
let range = name.syntax().text_range();
|
||||
return Some(RangeInfo::new(range, (name.text().to_string(), def)));
|
||||
}
|
||||
let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
|
||||
let def = classify_name_ref(db, Source::new(position.file_id.into(), &name_ref))?;
|
||||
let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?;
|
||||
let range = name_ref.syntax().text_range();
|
||||
Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ fn process_definition(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if let Some(d) = classify_name_ref(db, Source::new(file_id.into(), &name_ref)) {
|
||||
if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) {
|
||||
if d == def {
|
||||
refs.push(FileRange { file_id, range });
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Functions that are used to classify an element from its definition or reference.
|
||||
|
||||
use hir::{FromSource, Module, ModuleSource, PathResolution, Source, SourceAnalyzer};
|
||||
use hir::{FromSource, InFile, Module, ModuleSource, PathResolution, SourceAnalyzer};
|
||||
use ra_prof::profile;
|
||||
use ra_syntax::{ast, match_ast, AstNode};
|
||||
use test_utils::tested_by;
|
||||
|
@ -11,7 +11,7 @@ use super::{
|
|||
};
|
||||
use crate::db::RootDatabase;
|
||||
|
||||
pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> {
|
||||
pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option<NameDefinition> {
|
||||
let _p = profile("classify_name");
|
||||
let parent = name.value.syntax().parent()?;
|
||||
|
||||
|
@ -117,7 +117,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
|||
|
||||
pub(crate) fn classify_name_ref(
|
||||
db: &RootDatabase,
|
||||
name_ref: Source<&ast::NameRef>,
|
||||
name_ref: InFile<&ast::NameRef>,
|
||||
) -> Option<NameDefinition> {
|
||||
let _p = profile("classify_name_ref");
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ fn rename_mod(
|
|||
) -> Option<SourceChange> {
|
||||
let mut source_file_edits = Vec::new();
|
||||
let mut file_system_edits = Vec::new();
|
||||
let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() };
|
||||
let module_src = hir::InFile { file_id: position.file_id.into(), value: ast_module.clone() };
|
||||
if let Some(module) = hir::Module::from_declaration(db, module_src) {
|
||||
let src = module.definition_source(db);
|
||||
let file_id = src.file_id.original_file(db);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir::Source;
|
||||
use hir::InFile;
|
||||
use itertools::Itertools;
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_syntax::{
|
||||
|
@ -66,8 +66,8 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti
|
|||
return None;
|
||||
}
|
||||
let range = module.syntax().text_range();
|
||||
let src = hir::ModuleSource::from_child_node(db, Source::new(file_id.into(), &module.syntax()));
|
||||
let module = hir::Module::from_definition(db, Source::new(file_id.into(), src))?;
|
||||
let src = hir::ModuleSource::from_child_node(db, InFile::new(file_id.into(), &module.syntax()));
|
||||
let module = hir::Module::from_definition(db, InFile::new(file_id.into(), src))?;
|
||||
|
||||
let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::");
|
||||
Some(Runnable { range, kind: RunnableKind::TestMod { path } })
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use hir::{Name, Source};
|
||||
use hir::{InFile, Name};
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_prof::profile;
|
||||
use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T};
|
||||
|
@ -81,7 +81,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
|||
|
||||
let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
|
||||
let name_kind =
|
||||
classify_name_ref(db, Source::new(file_id.into(), &name_ref)).map(|d| d.kind);
|
||||
classify_name_ref(db, InFile::new(file_id.into(), &name_ref)).map(|d| d.kind);
|
||||
|
||||
if let Some(Local(local)) = &name_kind {
|
||||
if let Some(name) = local.name(db) {
|
||||
|
@ -95,7 +95,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
|||
NAME => {
|
||||
let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
|
||||
let name_kind =
|
||||
classify_name(db, Source::new(file_id.into(), &name)).map(|d| d.kind);
|
||||
classify_name(db, InFile::new(file_id.into(), &name)).map(|d| d.kind);
|
||||
|
||||
if let Some(Local(local)) = &name_kind {
|
||||
if let Some(name) = local.name(db) {
|
||||
|
|
Loading…
Reference in a new issue