Skip to content

Commit b845801

Browse files
authored
Merge pull request #22063 from Veykril/push-zyrytxqturpp
Remove `LineIndexDatabase`
2 parents 4a244d4 + 587e68b commit b845801

16 files changed

Lines changed: 53 additions & 55 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide-assists/src/handlers/bind_unused_param.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::assist_context::{AssistContext, Assists};
2-
use ide_db::{LineIndexDatabase, assists::AssistId, defs::Definition};
2+
use ide_db::{assists::AssistId, defs::Definition, line_index};
33
use syntax::{
44
AstNode,
55
ast::{self, HasName, edit::AstNodeEdit},
@@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
4343
format!("Bind as `let _ = {name};`"),
4444
param.syntax().text_range(),
4545
|builder| {
46-
let line_index = ctx.db().line_index(ctx.vfs_file_id());
46+
let line_index = line_index(ctx.db(), ctx.vfs_file_id());
4747

4848
let indent = func.indent_level();
4949
let text_indent = indent + 1;

crates/ide-db/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ arrayvec.workspace = true
2525
memchr = "2.7.5"
2626
salsa.workspace = true
2727
salsa-macros.workspace = true
28-
query-group.workspace = true
2928
triomphe.workspace = true
3029
nohash-hasher.workspace = true
3130
bitflags.workspace = true

crates/ide-db/src/lib.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use std::{fmt, mem::ManuallyDrop};
6161

6262
use base_db::{
6363
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, Nonce, SourceDatabase,
64-
SourceRoot, SourceRootId, SourceRootInput, query_group, set_all_crates_with_durability,
64+
SourceRoot, SourceRootId, SourceRootInput, set_all_crates_with_durability,
6565
};
6666
use hir::{
6767
FilePositionWrapper, FileRangeWrapper,
@@ -252,15 +252,20 @@ impl RootDatabase {
252252
}
253253
}
254254

255-
#[query_group::query_group]
256-
pub trait LineIndexDatabase: base_db::SourceDatabase {
257-
#[salsa::invoke_interned(line_index)]
258-
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
259-
}
260-
261-
fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
262-
let text = db.file_text(file_id).text(db);
263-
Arc::new(LineIndex::new(text))
255+
pub fn line_index(db: &dyn SourceDatabase, file_id: FileId) -> &Arc<LineIndex> {
256+
#[salsa::interned]
257+
pub struct InternedFileId {
258+
id: FileId,
259+
}
260+
#[salsa::tracked(returns(ref))]
261+
fn line_index<'db>(
262+
db: &'db dyn SourceDatabase,
263+
file_id: InternedFileId<'db>,
264+
) -> Arc<LineIndex> {
265+
let text = db.file_text(file_id.id(db)).text(db);
266+
Arc::new(LineIndex::new(text))
267+
}
268+
line_index(db, InternedFileId::new(db, file_id))
264269
}
265270

266271
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]

crates/ide-db/src/symbol_index.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,22 +400,16 @@ impl<'db> SymbolIndex<'db> {
400400
/// The symbol index for a given module. These modules should only be in source roots that
401401
/// are inside local_roots.
402402
pub fn module_symbols(db: &dyn HirDatabase, module: Module) -> &SymbolIndex<'_> {
403-
// FIXME:
404-
#[salsa::interned]
405-
struct InternedModuleId {
406-
id: hir::ModuleId,
407-
}
408-
409403
#[salsa::tracked(returns(ref))]
410404
fn module_symbols<'db>(
411405
db: &'db dyn HirDatabase,
412-
module: InternedModuleId<'db>,
406+
module: hir::ModuleId,
413407
) -> SymbolIndex<'db> {
414408
let _p = tracing::info_span!("module_symbols").entered();
415409

416410
// We call this without attaching because this runs in parallel, so we need to attach here.
417411
hir::attach_db(db, || {
418-
let module: Module = module.id(db).into();
412+
let module: Module = module.into();
419413
SymbolIndex::new(SymbolCollector::new_module(
420414
db,
421415
module,
@@ -424,7 +418,7 @@ impl<'db> SymbolIndex<'db> {
424418
})
425419
}
426420

427-
module_symbols(db, InternedModuleId::new(db, hir::ModuleId::from(module)))
421+
module_symbols(db, hir::ModuleId::from(module))
428422
}
429423

430424
/// The symbol index for all extern prelude crates.

crates/ide-diagnostics/src/handlers/unlinked_file.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ use std::iter;
44

55
use hir::crate_def_map;
66
use hir::{InFile, ModuleSource};
7-
use ide_db::base_db;
87
use ide_db::text_edit::TextEdit;
9-
use ide_db::{
10-
FileId, FileRange, LineIndexDatabase, base_db::SourceDatabase, source_change::SourceChange,
11-
};
8+
use ide_db::{FileId, FileRange, base_db::SourceDatabase, source_change::SourceChange};
9+
use ide_db::{base_db, line_index};
1210
use paths::Utf8Component;
1311
use syntax::{
1412
AstNode, TextRange,
@@ -26,7 +24,7 @@ pub(crate) fn unlinked_file(
2624
acc: &mut Vec<Diagnostic>,
2725
file_id: FileId,
2826
) {
29-
let mut range = TextRange::up_to(ctx.sema.db.line_index(file_id).len());
27+
let mut range = TextRange::up_to(line_index(ctx.sema.db, file_id).len());
3028
let fixes = fixes(ctx, file_id, range);
3129
// FIXME: This is a hack for the vscode extension to notice whether there is an autofix or not before having to resolve diagnostics.
3230
// This is to prevent project linking popups from appearing when there is an autofix. https://github.com/rust-lang/rust-analyzer/issues/14523

crates/ide-diagnostics/src/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ mod overly_long_real_world_cases;
44

55
use hir::setup_tracing;
66
use ide_db::{
7-
LineIndexDatabase, RootDatabase,
7+
RootDatabase,
88
assists::{AssistResolveStrategy, ExprFillDefaultMode},
99
base_db::SourceDatabase,
10+
line_index,
1011
};
1112
use itertools::Itertools;
1213
use stdx::trim_indent;
@@ -242,7 +243,7 @@ pub(crate) fn check_diagnostics_with_config(
242243
.into_group_map();
243244
for file_id in files {
244245
let file_id = file_id.file_id(&db);
245-
let line_index = db.line_index(file_id);
246+
let line_index = line_index(&db, file_id);
246247

247248
let mut actual = annotations.remove(&file_id).unwrap_or_default();
248249
let mut expected = extract_annotations(db.file_text(file_id).text(&db));

crates/ide/src/interpret.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hir::{ConstEvalError, DefWithBody, DisplayTarget, Semantics};
2-
use ide_db::{FilePosition, LineIndexDatabase, RootDatabase, base_db::SourceDatabase};
2+
use ide_db::{FilePosition, RootDatabase, base_db::SourceDatabase, line_index};
33
use std::time::{Duration, Instant};
44
use stdx::format_to;
55
use syntax::{AstNode, TextRange, algo::ancestors_at_offset, ast};
@@ -40,7 +40,7 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option<(Dura
4040

4141
let path = source_root.path_for_file(&file_id).map(|x| x.to_string());
4242
let path = path.as_deref().unwrap_or("<unknown file>");
43-
match db.line_index(file_id).try_line_col(text_range.start()) {
43+
match line_index(db, file_id).try_line_col(text_range.start()) {
4444
Some(line_col) => format!("file://{path}:{}:{}", line_col.line + 1, line_col.col),
4545
None => format!("file://{path} range {text_range:?}"),
4646
}
@@ -68,7 +68,7 @@ pub(crate) fn render_const_eval_error(
6868
let source_root = db.source_root(source_root).source_root(db);
6969
let path = source_root.path_for_file(&file_id).map(|x| x.to_string());
7070
let path = path.as_deref().unwrap_or("<unknown file>");
71-
match db.line_index(file_id).try_line_col(text_range.start()) {
71+
match line_index(db, file_id).try_line_col(text_range.start()) {
7272
Some(line_col) => format!("file://{path}:{}:{}", line_col.line + 1, line_col.col),
7373
None => format!("file://{path} range {text_range:?}"),
7474
}

crates/ide/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ use cfg::CfgOptions;
6464
use fetch_crates::CrateInfo;
6565
use hir::{ChangeWithProcMacros, EditionedFileId, crate_def_map, sym};
6666
use ide_db::base_db::relevant_crates;
67+
use ide_db::line_index;
6768
use ide_db::ra_fixture::RaFixtureAnalysis;
6869
use ide_db::{
69-
FxHashMap, FxIndexSet, LineIndexDatabase,
70+
FxHashMap, FxIndexSet,
7071
base_db::{
7172
CrateOrigin, CrateWorkspaceData, Env, FileSet, SourceDatabase, VfsPath,
7273
salsa::{Cancelled, Database},
@@ -358,7 +359,7 @@ impl Analysis {
358359
/// Gets the file's `LineIndex`: data structure to convert between absolute
359360
/// offsets and line/column representation.
360361
pub fn file_line_index(&self, file_id: FileId) -> Cancellable<Arc<LineIndex>> {
361-
self.with_db(|db| db.line_index(file_id))
362+
self.with_db(|db| line_index(db, file_id).clone())
362363
}
363364

364365
/// Selects the next syntactic nodes encompassing the range.

crates/ide/src/view_syntax_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::Semantics;
22
use ide_db::{
3-
FileId, LineIndexDatabase, RootDatabase,
3+
FileId, RootDatabase, line_index,
44
line_index::{LineCol, LineIndex},
55
};
66
use span::{TextRange, TextSize};
@@ -20,7 +20,7 @@ use triomphe::Arc;
2020
// | VS Code | **Rust Syntax Tree** |
2121
pub(crate) fn view_syntax_tree(db: &RootDatabase, file_id: FileId) -> String {
2222
let sema = Semantics::new(db);
23-
let line_index = db.line_index(file_id);
23+
let line_index = line_index(db, file_id).clone();
2424
let parse = sema.parse_guess_edition(file_id);
2525

2626
let ctx = SyntaxTreeCtx { line_index, in_string: None };

0 commit comments

Comments
 (0)