mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Merge pull request #22063 from Veykril/push-zyrytxqturpp
Remove `LineIndexDatabase`
This commit is contained in:
@@ -1104,7 +1104,6 @@ dependencies = [
|
||||
"nohash-hasher",
|
||||
"parser",
|
||||
"profile",
|
||||
"query-group-macro",
|
||||
"rayon",
|
||||
"rustc-hash 2.1.1",
|
||||
"salsa",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::assist_context::{AssistContext, Assists};
|
||||
use ide_db::{LineIndexDatabase, assists::AssistId, defs::Definition};
|
||||
use ide_db::{assists::AssistId, defs::Definition, line_index};
|
||||
use syntax::{
|
||||
AstNode,
|
||||
ast::{self, HasName, edit::AstNodeEdit},
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
|
||||
format!("Bind as `let _ = {name};`"),
|
||||
param.syntax().text_range(),
|
||||
|builder| {
|
||||
let line_index = ctx.db().line_index(ctx.vfs_file_id());
|
||||
let line_index = line_index(ctx.db(), ctx.vfs_file_id());
|
||||
|
||||
let indent = func.indent_level();
|
||||
let text_indent = indent + 1;
|
||||
|
||||
@@ -25,7 +25,6 @@ arrayvec.workspace = true
|
||||
memchr = "2.7.5"
|
||||
salsa.workspace = true
|
||||
salsa-macros.workspace = true
|
||||
query-group.workspace = true
|
||||
triomphe.workspace = true
|
||||
nohash-hasher.workspace = true
|
||||
bitflags.workspace = true
|
||||
|
||||
@@ -61,7 +61,7 @@ pub mod syntax_helpers {
|
||||
|
||||
use base_db::{
|
||||
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, Nonce, SourceDatabase,
|
||||
SourceRoot, SourceRootId, SourceRootInput, query_group, set_all_crates_with_durability,
|
||||
SourceRoot, SourceRootId, SourceRootInput, set_all_crates_with_durability,
|
||||
};
|
||||
use hir::{
|
||||
FilePositionWrapper, FileRangeWrapper,
|
||||
@@ -252,15 +252,20 @@ pub fn update_lru_capacities(&mut self, _lru_capacities: &FxHashMap<Box<str>, u1
|
||||
}
|
||||
}
|
||||
|
||||
#[query_group::query_group]
|
||||
pub trait LineIndexDatabase: base_db::SourceDatabase {
|
||||
#[salsa::invoke_interned(line_index)]
|
||||
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
|
||||
}
|
||||
|
||||
fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id).text(db);
|
||||
Arc::new(LineIndex::new(text))
|
||||
pub fn line_index(db: &dyn SourceDatabase, file_id: FileId) -> &Arc<LineIndex> {
|
||||
#[salsa::interned]
|
||||
pub struct InternedFileId {
|
||||
id: FileId,
|
||||
}
|
||||
#[salsa::tracked(returns(ref))]
|
||||
fn line_index<'db>(
|
||||
db: &'db dyn SourceDatabase,
|
||||
file_id: InternedFileId<'db>,
|
||||
) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id.id(db)).text(db);
|
||||
Arc::new(LineIndex::new(text))
|
||||
}
|
||||
line_index(db, InternedFileId::new(db, file_id))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
|
||||
@@ -400,22 +400,16 @@ fn library_symbols<'db>(
|
||||
/// The symbol index for a given module. These modules should only be in source roots that
|
||||
/// are inside local_roots.
|
||||
pub fn module_symbols(db: &dyn HirDatabase, module: Module) -> &SymbolIndex<'_> {
|
||||
// FIXME:
|
||||
#[salsa::interned]
|
||||
struct InternedModuleId {
|
||||
id: hir::ModuleId,
|
||||
}
|
||||
|
||||
#[salsa::tracked(returns(ref))]
|
||||
fn module_symbols<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
module: InternedModuleId<'db>,
|
||||
module: hir::ModuleId,
|
||||
) -> SymbolIndex<'db> {
|
||||
let _p = tracing::info_span!("module_symbols").entered();
|
||||
|
||||
// We call this without attaching because this runs in parallel, so we need to attach here.
|
||||
hir::attach_db(db, || {
|
||||
let module: Module = module.id(db).into();
|
||||
let module: Module = module.into();
|
||||
SymbolIndex::new(SymbolCollector::new_module(
|
||||
db,
|
||||
module,
|
||||
@@ -424,7 +418,7 @@ fn module_symbols<'db>(
|
||||
})
|
||||
}
|
||||
|
||||
module_symbols(db, InternedModuleId::new(db, hir::ModuleId::from(module)))
|
||||
module_symbols(db, hir::ModuleId::from(module))
|
||||
}
|
||||
|
||||
/// The symbol index for all extern prelude crates.
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
use hir::crate_def_map;
|
||||
use hir::{InFile, ModuleSource};
|
||||
use ide_db::base_db;
|
||||
use ide_db::text_edit::TextEdit;
|
||||
use ide_db::{
|
||||
FileId, FileRange, LineIndexDatabase, base_db::SourceDatabase, source_change::SourceChange,
|
||||
};
|
||||
use ide_db::{FileId, FileRange, base_db::SourceDatabase, source_change::SourceChange};
|
||||
use ide_db::{base_db, line_index};
|
||||
use paths::Utf8Component;
|
||||
use syntax::{
|
||||
AstNode, TextRange,
|
||||
@@ -26,7 +24,7 @@ pub(crate) fn unlinked_file(
|
||||
acc: &mut Vec<Diagnostic>,
|
||||
file_id: FileId,
|
||||
) {
|
||||
let mut range = TextRange::up_to(ctx.sema.db.line_index(file_id).len());
|
||||
let mut range = TextRange::up_to(line_index(ctx.sema.db, file_id).len());
|
||||
let fixes = fixes(ctx, file_id, range);
|
||||
// FIXME: This is a hack for the vscode extension to notice whether there is an autofix or not before having to resolve diagnostics.
|
||||
// This is to prevent project linking popups from appearing when there is an autofix. https://github.com/rust-lang/rust-analyzer/issues/14523
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
use hir::setup_tracing;
|
||||
use ide_db::{
|
||||
LineIndexDatabase, RootDatabase,
|
||||
RootDatabase,
|
||||
assists::{AssistResolveStrategy, ExprFillDefaultMode},
|
||||
base_db::SourceDatabase,
|
||||
line_index,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use stdx::trim_indent;
|
||||
@@ -242,7 +243,7 @@ pub(crate) fn check_diagnostics_with_config(
|
||||
.into_group_map();
|
||||
for file_id in files {
|
||||
let file_id = file_id.file_id(&db);
|
||||
let line_index = db.line_index(file_id);
|
||||
let line_index = line_index(&db, file_id);
|
||||
|
||||
let mut actual = annotations.remove(&file_id).unwrap_or_default();
|
||||
let mut expected = extract_annotations(db.file_text(file_id).text(&db));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use hir::{ConstEvalError, DefWithBody, DisplayTarget, Semantics};
|
||||
use ide_db::{FilePosition, LineIndexDatabase, RootDatabase, base_db::SourceDatabase};
|
||||
use ide_db::{FilePosition, RootDatabase, base_db::SourceDatabase, line_index};
|
||||
use std::time::{Duration, Instant};
|
||||
use stdx::format_to;
|
||||
use syntax::{AstNode, TextRange, algo::ancestors_at_offset, ast};
|
||||
@@ -40,7 +40,7 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option<(Dura
|
||||
|
||||
let path = source_root.path_for_file(&file_id).map(|x| x.to_string());
|
||||
let path = path.as_deref().unwrap_or("<unknown file>");
|
||||
match db.line_index(file_id).try_line_col(text_range.start()) {
|
||||
match line_index(db, file_id).try_line_col(text_range.start()) {
|
||||
Some(line_col) => format!("file://{path}:{}:{}", line_col.line + 1, line_col.col),
|
||||
None => format!("file://{path} range {text_range:?}"),
|
||||
}
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn render_const_eval_error(
|
||||
let source_root = db.source_root(source_root).source_root(db);
|
||||
let path = source_root.path_for_file(&file_id).map(|x| x.to_string());
|
||||
let path = path.as_deref().unwrap_or("<unknown file>");
|
||||
match db.line_index(file_id).try_line_col(text_range.start()) {
|
||||
match line_index(db, file_id).try_line_col(text_range.start()) {
|
||||
Some(line_col) => format!("file://{path}:{}:{}", line_col.line + 1, line_col.col),
|
||||
None => format!("file://{path} range {text_range:?}"),
|
||||
}
|
||||
|
||||
@@ -64,9 +64,10 @@
|
||||
use fetch_crates::CrateInfo;
|
||||
use hir::{ChangeWithProcMacros, EditionedFileId, crate_def_map, sym};
|
||||
use ide_db::base_db::relevant_crates;
|
||||
use ide_db::line_index;
|
||||
use ide_db::ra_fixture::RaFixtureAnalysis;
|
||||
use ide_db::{
|
||||
FxHashMap, FxIndexSet, LineIndexDatabase,
|
||||
FxHashMap, FxIndexSet,
|
||||
base_db::{
|
||||
CrateOrigin, CrateWorkspaceData, Env, FileSet, SourceDatabase, VfsPath,
|
||||
salsa::{Cancelled, Database},
|
||||
@@ -358,7 +359,7 @@ pub fn is_library_file(&self, file_id: FileId) -> Cancellable<bool> {
|
||||
/// Gets the file's `LineIndex`: data structure to convert between absolute
|
||||
/// offsets and line/column representation.
|
||||
pub fn file_line_index(&self, file_id: FileId) -> Cancellable<Arc<LineIndex>> {
|
||||
self.with_db(|db| db.line_index(file_id))
|
||||
self.with_db(|db| line_index(db, file_id).clone())
|
||||
}
|
||||
|
||||
/// Selects the next syntactic nodes encompassing the range.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use hir::Semantics;
|
||||
use ide_db::{
|
||||
FileId, LineIndexDatabase, RootDatabase,
|
||||
FileId, RootDatabase, line_index,
|
||||
line_index::{LineCol, LineIndex},
|
||||
};
|
||||
use span::{TextRange, TextSize};
|
||||
@@ -20,7 +20,7 @@
|
||||
// | VS Code | **Rust Syntax Tree** |
|
||||
pub(crate) fn view_syntax_tree(db: &RootDatabase, file_id: FileId) -> String {
|
||||
let sema = Semantics::new(db);
|
||||
let line_index = db.line_index(file_id);
|
||||
let line_index = line_index(db, file_id).clone();
|
||||
let parse = sema.parse_guess_edition(file_id);
|
||||
|
||||
let ctx = SyntaxTreeCtx { line_index, in_string: None };
|
||||
|
||||
@@ -26,8 +26,9 @@
|
||||
InlayHintsConfig, LineCol, RaFixtureConfig, RootDatabase,
|
||||
};
|
||||
use ide_db::{
|
||||
EditionedFileId, LineIndexDatabase, SnippetCap,
|
||||
EditionedFileId, SnippetCap,
|
||||
base_db::{SourceDatabase, salsa::Database},
|
||||
line_index,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace};
|
||||
@@ -1487,7 +1488,7 @@ fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id:
|
||||
let node = src.map(|e| e.to_node(&root).syntax().clone());
|
||||
let original_range = node.as_ref().original_file_range_rooted(db);
|
||||
let path = vfs.file_path(original_range.file_id.file_id(db));
|
||||
let line_index = db.line_index(original_range.file_id.file_id(db));
|
||||
let line_index = line_index(db, original_range.file_id.file_id(db));
|
||||
let text_range = original_range.range;
|
||||
let (start, end) =
|
||||
(line_index.line_col(text_range.start()), line_index.line_col(text_range.end()));
|
||||
@@ -1503,7 +1504,7 @@ fn location_csv_pat(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, pat_id: Pa
|
||||
let node = src.map(|e| e.to_node(&root).syntax().clone());
|
||||
let original_range = node.as_ref().original_file_range_rooted(db);
|
||||
let path = vfs.file_path(original_range.file_id.file_id(db));
|
||||
let line_index = db.line_index(original_range.file_id.file_id(db));
|
||||
let line_index = line_index(db, original_range.file_id.file_id(db));
|
||||
let text_range = original_range.range;
|
||||
let (start, end) =
|
||||
(line_index.line_col(text_range.start()), line_index.line_col(text_range.end()));
|
||||
@@ -1522,7 +1523,7 @@ fn expr_syntax_range<'a>(
|
||||
let node = src.map(|e| e.to_node(&root).syntax().clone());
|
||||
let original_range = node.as_ref().original_file_range_rooted(db);
|
||||
let path = vfs.file_path(original_range.file_id.file_id(db));
|
||||
let line_index = db.line_index(original_range.file_id.file_id(db));
|
||||
let line_index = line_index(db, original_range.file_id.file_id(db));
|
||||
let text_range = original_range.range;
|
||||
let (start, end) =
|
||||
(line_index.line_col(text_range.start()), line_index.line_col(text_range.end()));
|
||||
@@ -1543,7 +1544,7 @@ fn pat_syntax_range<'a>(
|
||||
let node = src.map(|e| e.to_node(&root).syntax().clone());
|
||||
let original_range = node.as_ref().original_file_range_rooted(db);
|
||||
let path = vfs.file_path(original_range.file_id.file_id(db));
|
||||
let line_index = db.line_index(original_range.file_id.file_id(db));
|
||||
let line_index = line_index(db, original_range.file_id.file_id(db));
|
||||
let text_range = original_range.range;
|
||||
let (start, end) =
|
||||
(line_index.line_col(text_range.start()), line_index.line_col(text_range.end()));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use hir::{Crate, Module, db::HirDatabase, sym};
|
||||
use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity};
|
||||
use ide_db::{LineIndexDatabase, base_db::SourceDatabase};
|
||||
use ide_db::{base_db::SourceDatabase, line_index};
|
||||
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace_at};
|
||||
|
||||
use crate::cli::{flags, progress_report::ProgressReport};
|
||||
@@ -99,7 +99,7 @@ fn run_(self) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
let Diagnostic { code, message, range, severity, .. } = diagnostic;
|
||||
let line_index = db.line_index(range.file_id);
|
||||
let line_index = line_index(db, range.file_id);
|
||||
let start = line_index.line_col(range.range.start());
|
||||
let end = line_index.line_col(range.range.end());
|
||||
bar.println(format!(
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
RootDatabase, StaticIndex, StaticIndexedFile, TokenId, TokenStaticData,
|
||||
VendoredLibrariesConfig,
|
||||
};
|
||||
use ide_db::{LineIndexDatabase, line_index::WideEncoding};
|
||||
use ide_db::{line_index, line_index::WideEncoding};
|
||||
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace};
|
||||
use lsp_types::lsif;
|
||||
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
|
||||
@@ -120,9 +120,9 @@ fn get_range_id(&mut self, id: FileRange) -> Id {
|
||||
}
|
||||
let file_id = id.file_id;
|
||||
let doc_id = self.get_file_id(file_id);
|
||||
let line_index = self.db.line_index(file_id);
|
||||
let line_index = line_index(self.db, file_id);
|
||||
let line_index = LineIndex {
|
||||
index: line_index,
|
||||
index: line_index.clone(),
|
||||
encoding: PositionEncoding::Wide(WideEncoding::Utf16),
|
||||
endings: LineEndings::Unix,
|
||||
};
|
||||
@@ -241,9 +241,9 @@ fn add_file(&mut self, file: StaticIndexedFile) {
|
||||
let StaticIndexedFile { file_id, tokens, folds, .. } = file;
|
||||
let doc_id = self.get_file_id(file_id);
|
||||
let text = self.analysis.file_text(file_id).unwrap();
|
||||
let line_index = self.db.line_index(file_id);
|
||||
let line_index = line_index(self.db, file_id);
|
||||
let line_index = LineIndex {
|
||||
index: line_index,
|
||||
index: line_index.clone(),
|
||||
encoding: PositionEncoding::Wide(WideEncoding::Utf16),
|
||||
endings: LineEndings::Unix,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use hir::{Crate, Module};
|
||||
use hir_ty::db::HirDatabase;
|
||||
use ide_db::{LineIndexDatabase, base_db::SourceDatabase};
|
||||
use ide_db::{base_db::SourceDatabase, line_index};
|
||||
use profile::StopWatch;
|
||||
use project_model::{CargoConfig, RustLibSource};
|
||||
use syntax::TextRange;
|
||||
@@ -38,7 +38,7 @@ pub fn run(self) -> Result<()> {
|
||||
})
|
||||
.filter(|x| x.is_test(db));
|
||||
let span_formatter = |file_id, text_range: TextRange| {
|
||||
let line_col = match db.line_index(file_id).try_line_col(text_range.start()) {
|
||||
let line_col = match line_index(db, file_id).try_line_col(text_range.start()) {
|
||||
None => " (unknown line col)".to_owned(),
|
||||
Some(x) => format!("#{}:{}", x.line + 1, x.col),
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
RootDatabase, StaticIndex, StaticIndexedFile, SymbolInformationKind, TextRange, TokenId,
|
||||
TokenStaticData, VendoredLibrariesConfig,
|
||||
};
|
||||
use ide_db::LineIndexDatabase;
|
||||
use ide_db::line_index;
|
||||
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace_at};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use scip::types::{self as scip_types, SymbolInformation};
|
||||
@@ -348,7 +348,7 @@ fn get_relative_filepath(
|
||||
|
||||
fn get_line_index(db: &RootDatabase, file_id: FileId) -> LineIndex {
|
||||
LineIndex {
|
||||
index: db.line_index(file_id),
|
||||
index: line_index(db, file_id).clone(),
|
||||
encoding: PositionEncoding::Utf8,
|
||||
endings: LineEndings::Unix,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Reports references in code that the IDE layer cannot resolve.
|
||||
use hir::{AnyDiagnostic, Crate, Module, Semantics, db::HirDatabase, sym};
|
||||
use ide::{AnalysisHost, RootDatabase, TextRange};
|
||||
use ide_db::{FxHashSet, LineIndexDatabase as _, base_db::SourceDatabase, defs::NameRefClass};
|
||||
use ide_db::{FxHashSet, base_db::SourceDatabase, defs::NameRefClass, line_index};
|
||||
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace_at};
|
||||
use parser::SyntaxKind;
|
||||
use syntax::{AstNode, WalkEvent, ast};
|
||||
@@ -75,7 +75,7 @@ fn run_(self) -> anyhow::Result<()> {
|
||||
let file_path = vfs.file_path(file_id);
|
||||
eprintln!("processing crate: {crate_name}, module: {file_path}",);
|
||||
|
||||
let line_index = db.line_index(file_id);
|
||||
let line_index = line_index(db, file_id);
|
||||
let file_text = db.file_text(file_id);
|
||||
|
||||
for range in find_unresolved_references(db, &sema, file_id, &module) {
|
||||
|
||||
Reference in New Issue
Block a user