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