Skip to content

Commit c9e42fc

Browse files
bors[bot]matklad
andcommitted
468: decouple ra_editor from other stuff r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 1c25bf0 + 695294b commit c9e42fc

File tree

21 files changed

+60
-51
lines changed

21 files changed

+60
-51
lines changed

Cargo.lock

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

crates/ra_analysis/src/call_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use ra_syntax::{
55
AstNode, SyntaxNode, TextUnit, TextRange,
66
SyntaxKind::FN_DEF,
77
ast::{self, ArgListOwner, DocCommentsOwner},
8+
algo::find_node_at_offset,
89
};
9-
use ra_editor::find_node_at_offset;
1010

1111
use crate::{FilePosition, CallInfo, db::RootDatabase};
1212

crates/ra_analysis/src/completion/completion_context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use ra_editor::find_node_at_offset;
21
use ra_text_edit::AtomTextEdit;
32
use ra_syntax::{
43
AstNode, SyntaxNode, SourceFile, TextUnit, TextRange,
54
ast,
6-
algo::{find_leaf_at_offset, find_covering_node},
5+
algo::{find_leaf_at_offset, find_covering_node, find_node_at_offset},
76
SyntaxKind::*,
87
};
98
use hir::source_binder;

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/goto_defenition.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use ra_db::{FileId, Cancelable, SyntaxDatabase};
2-
use ra_syntax::{TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE}};
3-
4-
use ra_editor::find_node_at_offset;
2+
use ra_syntax::{
3+
TextRange, AstNode, ast, SyntaxKind::{NAME, MODULE},
4+
algo::find_node_at_offset,
5+
};
56

67
use crate::{FilePosition, NavigationTarget, db::RootDatabase};
78

crates/ra_analysis/src/hover.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use ra_db::{Cancelable, SyntaxDatabase};
2-
use ra_editor::find_node_at_offset;
32
use ra_syntax::{
43
AstNode, SyntaxNode, TreePtr,
54
ast::{self, NameOwner},
6-
algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}},
5+
algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}},
76
};
87

98
use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};

crates/ra_analysis/src/imp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use hir::{
66
self, Problem, source_binder,
77
};
88
use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
9-
use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity};
9+
use ra_editor::{self, assists, LocalEdit, Severity};
1010
use ra_syntax::{
1111
TextRange, AstNode, SourceFile,
1212
ast::{self, NameOwner},
13+
algo::find_node_at_offset,
1314
SyntaxKind::*,
1415
};
1516

crates/ra_analysis/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,27 @@ 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},
4145
runnables::{Runnable, RunnableKind},
4246
};
43-
pub use ra_editor::{Fold, FoldKind, HighlightedRange, LineIndex, Severity, StructureNode};
44-
47+
pub use ra_editor::{
48+
Fold, FoldKind, HighlightedRange, Severity, StructureNode,
49+
LineIndex, LineCol, translate_offset_with_edit,
50+
};
4551
pub use ra_db::{
46-
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase,
47-
LocalSyntaxPtr, SourceRootId, SyntaxDatabase,
52+
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
4853
};
4954

5055
#[derive(Default)]
@@ -322,7 +327,7 @@ impl Analysis {
322327
/// Gets the file's `LineIndex`: data structure to convert between absolute
323328
/// offsets and line/column representation.
324329
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
325-
self.db.file_lines(file_id)
330+
self.db.line_index(file_id)
326331
}
327332
/// Selects the next syntactic nodes encopasing the range.
328333
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 {

0 commit comments

Comments
 (0)