mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Remove import source map
This commit is contained in:
		
							parent
							
								
									ec56f59ac1
								
							
						
					
					
						commit
						02f79e37ca
					
				@ -4,8 +4,8 @@ pub use hir_def::db::{
 | 
			
		||||
    BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery,
 | 
			
		||||
    DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery,
 | 
			
		||||
    FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
 | 
			
		||||
    LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery,
 | 
			
		||||
    StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery,
 | 
			
		||||
    LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery,
 | 
			
		||||
    TraitDataQuery, TypeAliasDataQuery,
 | 
			
		||||
};
 | 
			
		||||
pub use hir_expand::db::{
 | 
			
		||||
    AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,7 @@ use crate::{
 | 
			
		||||
    docs::Documentation,
 | 
			
		||||
    generics::GenericParams,
 | 
			
		||||
    lang_item::{LangItemTarget, LangItems},
 | 
			
		||||
    nameres::{
 | 
			
		||||
        raw::{ImportSourceMap, RawItems},
 | 
			
		||||
        CrateDefMap,
 | 
			
		||||
    },
 | 
			
		||||
    nameres::{raw::RawItems, CrateDefMap},
 | 
			
		||||
    AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
 | 
			
		||||
    GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
 | 
			
		||||
    TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
 | 
			
		||||
@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase {
 | 
			
		||||
 | 
			
		||||
#[salsa::query_group(DefDatabaseStorage)]
 | 
			
		||||
pub trait DefDatabase: InternDatabase + AstDatabase {
 | 
			
		||||
    #[salsa::invoke(RawItems::raw_items_with_source_map_query)]
 | 
			
		||||
    fn raw_items_with_source_map(
 | 
			
		||||
        &self,
 | 
			
		||||
        file_id: HirFileId,
 | 
			
		||||
    ) -> (Arc<RawItems>, Arc<ImportSourceMap>);
 | 
			
		||||
 | 
			
		||||
    #[salsa::invoke(RawItems::raw_items_query)]
 | 
			
		||||
    fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,23 +7,21 @@
 | 
			
		||||
 | 
			
		||||
use std::{ops::Index, sync::Arc};
 | 
			
		||||
 | 
			
		||||
use either::Either;
 | 
			
		||||
use hir_expand::{
 | 
			
		||||
    ast_id_map::AstIdMap,
 | 
			
		||||
    db::AstDatabase,
 | 
			
		||||
    hygiene::Hygiene,
 | 
			
		||||
    name::{AsName, Name},
 | 
			
		||||
};
 | 
			
		||||
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
 | 
			
		||||
use ra_arena::{impl_arena_id, Arena, RawId};
 | 
			
		||||
use ra_syntax::{
 | 
			
		||||
    ast::{self, AttrsOwner, NameOwner},
 | 
			
		||||
    AstNode, AstPtr,
 | 
			
		||||
    AstNode,
 | 
			
		||||
};
 | 
			
		||||
use test_utils::tested_by;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile,
 | 
			
		||||
    LocalImportId,
 | 
			
		||||
    attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile, LocalImportId,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// `RawItems` is a set of top-level items in a file (except for impls).
 | 
			
		||||
@ -41,29 +39,14 @@ pub struct RawItems {
 | 
			
		||||
    items: Vec<RawItem>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Default, PartialEq, Eq)]
 | 
			
		||||
pub struct ImportSourceMap {
 | 
			
		||||
    map: ArenaMap<LocalImportId, ImportSourcePtr>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>;
 | 
			
		||||
 | 
			
		||||
impl RawItems {
 | 
			
		||||
    pub(crate) fn raw_items_query(
 | 
			
		||||
        db: &(impl DefDatabase + AstDatabase),
 | 
			
		||||
        file_id: HirFileId,
 | 
			
		||||
    ) -> Arc<RawItems> {
 | 
			
		||||
        db.raw_items_with_source_map(file_id).0
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub(crate) fn raw_items_with_source_map_query(
 | 
			
		||||
        db: &(impl DefDatabase + AstDatabase),
 | 
			
		||||
        file_id: HirFileId,
 | 
			
		||||
    ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
 | 
			
		||||
        let mut collector = RawItemsCollector {
 | 
			
		||||
            raw_items: RawItems::default(),
 | 
			
		||||
            source_ast_id_map: db.ast_id_map(file_id),
 | 
			
		||||
            imports: Trace::new(),
 | 
			
		||||
            file_id,
 | 
			
		||||
            hygiene: Hygiene::new(db, file_id),
 | 
			
		||||
        };
 | 
			
		||||
@ -74,11 +57,8 @@ impl RawItems {
 | 
			
		||||
                collector.process_module(None, item_list);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        let mut raw_items = collector.raw_items;
 | 
			
		||||
        let (arena, map) = collector.imports.into_arena_and_map();
 | 
			
		||||
        raw_items.imports = arena;
 | 
			
		||||
        let source_map = ImportSourceMap { map };
 | 
			
		||||
        (Arc::new(raw_items), Arc::new(source_map))
 | 
			
		||||
        let raw_items = collector.raw_items;
 | 
			
		||||
        Arc::new(raw_items)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub(super) fn items(&self) -> &[RawItem] {
 | 
			
		||||
@ -217,7 +197,6 @@ pub(super) struct ImplData {
 | 
			
		||||
 | 
			
		||||
struct RawItemsCollector {
 | 
			
		||||
    raw_items: RawItems,
 | 
			
		||||
    imports: Trace<LocalImportId, ImportData, ImportSourcePtr>,
 | 
			
		||||
    source_ast_id_map: Arc<AstIdMap>,
 | 
			
		||||
    file_id: HirFileId,
 | 
			
		||||
    hygiene: Hygiene,
 | 
			
		||||
@ -324,7 +303,7 @@ impl RawItemsCollector {
 | 
			
		||||
        ModPath::expand_use_item(
 | 
			
		||||
            InFile { value: use_item, file_id: self.file_id },
 | 
			
		||||
            &self.hygiene,
 | 
			
		||||
            |path, use_tree, is_glob, alias| {
 | 
			
		||||
            |path, _use_tree, is_glob, alias| {
 | 
			
		||||
                let import_data = ImportData {
 | 
			
		||||
                    path,
 | 
			
		||||
                    alias,
 | 
			
		||||
@ -333,11 +312,11 @@ impl RawItemsCollector {
 | 
			
		||||
                    is_extern_crate: false,
 | 
			
		||||
                    is_macro_use: false,
 | 
			
		||||
                };
 | 
			
		||||
                buf.push((import_data, Either::Left(AstPtr::new(use_tree))));
 | 
			
		||||
                buf.push(import_data);
 | 
			
		||||
            },
 | 
			
		||||
        );
 | 
			
		||||
        for (import_data, ptr) in buf {
 | 
			
		||||
            self.push_import(current_module, attrs.clone(), import_data, ptr);
 | 
			
		||||
        for import_data in buf {
 | 
			
		||||
            self.push_import(current_module, attrs.clone(), import_data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -360,12 +339,7 @@ impl RawItemsCollector {
 | 
			
		||||
                is_extern_crate: true,
 | 
			
		||||
                is_macro_use,
 | 
			
		||||
            };
 | 
			
		||||
            self.push_import(
 | 
			
		||||
                current_module,
 | 
			
		||||
                attrs,
 | 
			
		||||
                import_data,
 | 
			
		||||
                Either::Right(AstPtr::new(&extern_crate)),
 | 
			
		||||
            );
 | 
			
		||||
            self.push_import(current_module, attrs, import_data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -396,14 +370,8 @@ impl RawItemsCollector {
 | 
			
		||||
        self.push_item(current_module, attrs, RawItemKind::Impl(imp))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn push_import(
 | 
			
		||||
        &mut self,
 | 
			
		||||
        current_module: Option<Module>,
 | 
			
		||||
        attrs: Attrs,
 | 
			
		||||
        data: ImportData,
 | 
			
		||||
        source: ImportSourcePtr,
 | 
			
		||||
    ) {
 | 
			
		||||
        let import = self.imports.alloc(|| source, || data);
 | 
			
		||||
    fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) {
 | 
			
		||||
        let import = self.raw_items.imports.alloc(data);
 | 
			
		||||
        self.push_item(current_module, attrs, RawItemKind::Import(import))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -18,10 +18,6 @@ pub(crate) struct Trace<ID: ArenaId, T, V> {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
 | 
			
		||||
    pub(crate) fn new() -> Trace<ID, T, V> {
 | 
			
		||||
        Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub(crate) fn new_for_arena() -> Trace<ID, T, V> {
 | 
			
		||||
        Trace { arena: Some(Arena::default()), map: None, len: 0 }
 | 
			
		||||
    }
 | 
			
		||||
@ -52,8 +48,4 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> {
 | 
			
		||||
    pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> {
 | 
			
		||||
        self.map.take().unwrap()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub(crate) fn into_arena_and_map(mut self) -> (Arena<ID, T>, ArenaMap<ID, V>) {
 | 
			
		||||
        (self.arena.take().unwrap(), self.map.take().unwrap())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -270,7 +270,6 @@ impl RootDatabase {
 | 
			
		||||
 | 
			
		||||
        self.query(hir::db::AstIdMapQuery).sweep(sweep);
 | 
			
		||||
 | 
			
		||||
        self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep);
 | 
			
		||||
        self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep);
 | 
			
		||||
 | 
			
		||||
        self.query(hir::db::ExprScopesQuery).sweep(sweep);
 | 
			
		||||
@ -309,7 +308,6 @@ impl RootDatabase {
 | 
			
		||||
            hir::db::StructDataQuery
 | 
			
		||||
            hir::db::EnumDataQuery
 | 
			
		||||
            hir::db::TraitDataQuery
 | 
			
		||||
            hir::db::RawItemsWithSourceMapQuery
 | 
			
		||||
            hir::db::RawItemsQuery
 | 
			
		||||
            hir::db::CrateDefMapQuery
 | 
			
		||||
            hir::db::GenericParamsQuery
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user