Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22063 from Veykril/push-zyrytxqturpp
Remove `LineIndexDatabase`
Lukas Wirth 5 weeks ago
parent 4a244d4 · parent 587e68b · commit b845801
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ide-assists/src/handlers/bind_unused_param.rs4
-rw-r--r--crates/ide-db/Cargo.toml1
-rw-r--r--crates/ide-db/src/lib.rs25
-rw-r--r--crates/ide-db/src/symbol_index.rs12
-rw-r--r--crates/ide-diagnostics/src/handlers/unlinked_file.rs8
-rw-r--r--crates/ide-diagnostics/src/tests.rs5
-rw-r--r--crates/ide/src/interpret.rs6
-rw-r--r--crates/ide/src/lib.rs5
-rw-r--r--crates/ide/src/view_syntax_tree.rs4
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs11
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs4
-rw-r--r--crates/rust-analyzer/src/cli/lsif.rs10
-rw-r--r--crates/rust-analyzer/src/cli/run_tests.rs4
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs4
-rw-r--r--crates/rust-analyzer/src/cli/unresolved_references.rs4
16 files changed, 53 insertions, 55 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 94e9507c02..88f5c33cb2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1104,7 +1104,6 @@ dependencies = [
"nohash-hasher",
"parser",
"profile",
- "query-group-macro",
"rayon",
"rustc-hash 2.1.1",
"salsa",
diff --git a/crates/ide-assists/src/handlers/bind_unused_param.rs b/crates/ide-assists/src/handlers/bind_unused_param.rs
index 0e85a77822..50e4a367e9 100644
--- a/crates/ide-assists/src/handlers/bind_unused_param.rs
+++ b/crates/ide-assists/src/handlers/bind_unused_param.rs
@@ -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;
diff --git a/crates/ide-db/Cargo.toml b/crates/ide-db/Cargo.toml
index fca06b69d1..2c0919a183 100644
--- a/crates/ide-db/Cargo.toml
+++ b/crates/ide-db/Cargo.toml
@@ -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
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs
index 8d16826e19..99af1c32d8 100644
--- a/crates/ide-db/src/lib.rs
+++ b/crates/ide-db/src/lib.rs
@@ -61,7 +61,7 @@ use std::{fmt, mem::ManuallyDrop};
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 @@ impl RootDatabase {
}
}
-#[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)]
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index 2ad3a51c3d..55acf5abf8 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -400,22 +400,16 @@ impl<'db> SymbolIndex<'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 @@ impl<'db> SymbolIndex<'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.
diff --git a/crates/ide-diagnostics/src/handlers/unlinked_file.rs b/crates/ide-diagnostics/src/handlers/unlinked_file.rs
index d7a0a3b0f5..570319c347 100644
--- a/crates/ide-diagnostics/src/handlers/unlinked_file.rs
+++ b/crates/ide-diagnostics/src/handlers/unlinked_file.rs
@@ -4,11 +4,9 @@ use std::iter;
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
diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs
index 3dc155efe9..fc49542e3c 100644
--- a/crates/ide-diagnostics/src/tests.rs
+++ b/crates/ide-diagnostics/src/tests.rs
@@ -4,9 +4,10 @@ mod overly_long_real_world_cases;
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));
diff --git a/crates/ide/src/interpret.rs b/crates/ide/src/interpret.rs
index 3741822547..994d325ccc 100644
--- a/crates/ide/src/interpret.rs
+++ b/crates/ide/src/interpret.rs
@@ -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:?}"),
}
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 270998cdf7..8a6ef64180 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -64,9 +64,10 @@ use cfg::CfgOptions;
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 @@ impl Analysis {
/// 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.
diff --git a/crates/ide/src/view_syntax_tree.rs b/crates/ide/src/view_syntax_tree.rs
index ecd93e8b28..7732b18082 100644
--- a/crates/ide/src/view_syntax_tree.rs
+++ b/crates/ide/src/view_syntax_tree.rs
@@ -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 @@ use triomphe::Arc;
// | 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 };
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index e56727d39d..bf9a66bf3f 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -26,8 +26,9 @@ use ide::{
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()));
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index efbaad3c49..e50e1c26bb 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -6,7 +6,7 @@ use rustc_hash::FxHashSet;
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 @@ impl flags::Diagnostics {
}
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!(
diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs
index 3950a581fd..4f6de6850a 100644
--- a/crates/rust-analyzer/src/cli/lsif.rs
+++ b/crates/rust-analyzer/src/cli/lsif.rs
@@ -8,7 +8,7 @@ use ide::{
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 @@ impl LsifManager<'_, '_> {
}
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 @@ impl LsifManager<'_, '_> {
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,
};
diff --git a/crates/rust-analyzer/src/cli/run_tests.rs b/crates/rust-analyzer/src/cli/run_tests.rs
index e8c88cadf6..0f7ef84a0e 100644
--- a/crates/rust-analyzer/src/cli/run_tests.rs
+++ b/crates/rust-analyzer/src/cli/run_tests.rs
@@ -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 @@ impl flags::RunTests {
})
.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),
};
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index ef6d4399e6..bca38ed82f 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -7,7 +7,7 @@ use ide::{
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,
}
diff --git a/crates/rust-analyzer/src/cli/unresolved_references.rs b/crates/rust-analyzer/src/cli/unresolved_references.rs
index 2d9b870f4d..f8eacbb670 100644
--- a/crates/rust-analyzer/src/cli/unresolved_references.rs
+++ b/crates/rust-analyzer/src/cli/unresolved_references.rs
@@ -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 @@ impl flags::UnresolvedReferences {
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) {