Skip to content

Commit 695294b

Browse files
committed
ra_db is independent from editor
1 parent 0c88360 commit 695294b

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

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/ra_analysis/src/db.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::{fmt, sync::Arc};
2+
23
use salsa::{self, Database};
3-
use ra_db::{LocationIntener, BaseDatabase};
4+
use ra_db::{LocationIntener, BaseDatabase, FileId};
45

5-
use crate::{
6-
symbol_index,
7-
};
6+
use crate::{symbol_index, LineIndex};
87

98
#[derive(Debug)]
109
pub(crate) struct RootDatabase {
@@ -71,6 +70,19 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas
7170
}
7271
}
7372

73+
salsa::query_group! {
74+
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
75+
fn line_index(file_id: FileId) -> Arc<LineIndex> {
76+
type LineIndexQuery;
77+
}
78+
}
79+
}
80+
81+
fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
82+
let text = db.file_text(file_id);
83+
Arc::new(LineIndex::new(&*text))
84+
}
85+
7486
salsa::database_storage! {
7587
pub(crate) struct RootDatabaseStorage for RootDatabase {
7688
impl ra_db::FilesDatabase {
@@ -84,7 +96,9 @@ salsa::database_storage! {
8496
}
8597
impl ra_db::SyntaxDatabase {
8698
fn source_file() for ra_db::SourceFileQuery;
87-
fn file_lines() for ra_db::FileLinesQuery;
99+
}
100+
impl LineIndexDatabase {
101+
fn line_index() for LineIndexQuery;
88102
}
89103
impl symbol_index::SymbolsDatabase {
90104
fn file_symbols() for symbol_index::FileSymbolsQuery;

crates/ra_analysis/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ use std::{fmt, sync::Arc};
2929

3030
use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
3131
use ra_text_edit::TextEdit;
32+
use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr};
3233
use rayon::prelude::*;
3334
use relative_path::RelativePathBuf;
3435
use rustc_hash::FxHashMap;
3536
use salsa::ParallelDatabase;
3637

37-
use crate::symbol_index::{FileSymbol, SymbolIndex};
38+
use crate::{
39+
symbol_index::{FileSymbol, SymbolIndex},
40+
db::LineIndexDatabase,
41+
};
3842

3943
pub use crate::{
4044
completion::{CompletionItem, CompletionItemKind, InsertText},
@@ -44,10 +48,8 @@ pub use ra_editor::{
4448
Fold, FoldKind, HighlightedRange, Severity, StructureNode,
4549
LineIndex, LineCol, translate_offset_with_edit,
4650
};
47-
4851
pub use ra_db::{
49-
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase,
50-
LocalSyntaxPtr, SourceRootId, SyntaxDatabase,
52+
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
5153
};
5254

5355
#[derive(Default)]
@@ -325,7 +327,7 @@ impl Analysis {
325327
/// Gets the file's `LineIndex`: data structure to convert between absolute
326328
/// offsets and line/column representation.
327329
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
328-
self.db.file_lines(file_id)
330+
self.db.line_index(file_id)
329331
}
330332
/// Selects the next syntactic nodes encopasing the range.
331333
pub fn extend_selection(&self, frange: FileRange) -> TextRange {

crates/ra_db/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ rustc-hash = "1.0"
1111
parking_lot = "0.7.0"
1212
ra_arena = { path = "../ra_arena" }
1313
ra_syntax = { path = "../ra_syntax" }
14-
ra_editor = { path = "../ra_editor" }
1514
test_utils = { path = "../test_utils" }

crates/ra_db/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ mod input;
55
mod loc2id;
66
pub mod mock;
77

8-
use std::sync::Arc;
9-
10-
use ra_editor::LineIndex;
118
use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
129

1310
pub use crate::{
@@ -36,20 +33,13 @@ salsa::query_group! {
3633
fn source_file(file_id: FileId) -> TreePtr<SourceFile> {
3734
type SourceFileQuery;
3835
}
39-
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
40-
type FileLinesQuery;
41-
}
4236
}
4337
}
4438

4539
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr<SourceFile> {
4640
let text = db.file_text(file_id);
4741
SourceFile::parse(&*text)
4842
}
49-
fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
50-
let text = db.file_text(file_id);
51-
Arc::new(LineIndex::new(&*text))
52-
}
5343

5444
#[derive(Clone, Copy, Debug)]
5545
pub struct FilePosition {

crates/ra_hir/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ salsa::database_storage! {
215215
}
216216
impl ra_db::SyntaxDatabase {
217217
fn source_file() for ra_db::SourceFileQuery;
218-
fn file_lines() for ra_db::FileLinesQuery;
219218
}
220219
impl db::HirDatabase {
221220
fn hir_source_file() for db::HirSourceFileQuery;

crates/ra_hir/src/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
10491049
}
10501050

10511051
pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
1052+
db.check_canceled()?;
10521053
let function = Function::new(def_id); // TODO: consts also need inference
10531054
let body = function.body(db)?;
10541055
let scopes = db.fn_scopes(def_id)?;

0 commit comments

Comments
 (0)