mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-23 19:43:23 +00:00
ra_db is independent from editor
This commit is contained in:
parent
0c88360eb4
commit
695294bbb9
7 changed files with 28 additions and 24 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -679,7 +679,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_arena 0.1.0",
|
||||
"ra_editor 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use std::{fmt, sync::Arc};
|
||||
use salsa::{self, Database};
|
||||
use ra_db::{LocationIntener, BaseDatabase};
|
||||
|
||||
use crate::{
|
||||
symbol_index,
|
||||
};
|
||||
use salsa::{self, Database};
|
||||
use ra_db::{LocationIntener, BaseDatabase, FileId};
|
||||
|
||||
use crate::{symbol_index, LineIndex};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct RootDatabase {
|
||||
|
@ -71,6 +70,19 @@ impl AsRef<LocationIntener<hir::MacroCallLoc, hir::MacroCallId>> for RootDatabas
|
|||
}
|
||||
}
|
||||
|
||||
salsa::query_group! {
|
||||
pub(crate) trait LineIndexDatabase: ra_db::FilesDatabase + BaseDatabase {
|
||||
fn line_index(file_id: FileId) -> Arc<LineIndex> {
|
||||
type LineIndexQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
|
||||
salsa::database_storage! {
|
||||
pub(crate) struct RootDatabaseStorage for RootDatabase {
|
||||
impl ra_db::FilesDatabase {
|
||||
|
@ -84,7 +96,9 @@ salsa::database_storage! {
|
|||
}
|
||||
impl ra_db::SyntaxDatabase {
|
||||
fn source_file() for ra_db::SourceFileQuery;
|
||||
fn file_lines() for ra_db::FileLinesQuery;
|
||||
}
|
||||
impl LineIndexDatabase {
|
||||
fn line_index() for LineIndexQuery;
|
||||
}
|
||||
impl symbol_index::SymbolsDatabase {
|
||||
fn file_symbols() for symbol_index::FileSymbolsQuery;
|
||||
|
|
|
@ -29,12 +29,16 @@ use std::{fmt, sync::Arc};
|
|||
|
||||
use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
|
||||
use ra_text_edit::TextEdit;
|
||||
use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr};
|
||||
use rayon::prelude::*;
|
||||
use relative_path::RelativePathBuf;
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa::ParallelDatabase;
|
||||
|
||||
use crate::symbol_index::{FileSymbol, SymbolIndex};
|
||||
use crate::{
|
||||
symbol_index::{FileSymbol, SymbolIndex},
|
||||
db::LineIndexDatabase,
|
||||
};
|
||||
|
||||
pub use crate::{
|
||||
completion::{CompletionItem, CompletionItemKind, InsertText},
|
||||
|
@ -44,10 +48,8 @@ pub use ra_editor::{
|
|||
Fold, FoldKind, HighlightedRange, Severity, StructureNode,
|
||||
LineIndex, LineCol, translate_offset_with_edit,
|
||||
};
|
||||
|
||||
pub use ra_db::{
|
||||
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, FilesDatabase,
|
||||
LocalSyntaxPtr, SourceRootId, SyntaxDatabase,
|
||||
Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -325,7 +327,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) -> Arc<LineIndex> {
|
||||
self.db.file_lines(file_id)
|
||||
self.db.line_index(file_id)
|
||||
}
|
||||
/// Selects the next syntactic nodes encopasing the range.
|
||||
pub fn extend_selection(&self, frange: FileRange) -> TextRange {
|
||||
|
|
|
@ -11,5 +11,4 @@ rustc-hash = "1.0"
|
|||
parking_lot = "0.7.0"
|
||||
ra_arena = { path = "../ra_arena" }
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_editor = { path = "../ra_editor" }
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
|
|
@ -5,9 +5,6 @@ mod input;
|
|||
mod loc2id;
|
||||
pub mod mock;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_editor::LineIndex;
|
||||
use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
|
||||
|
||||
pub use crate::{
|
||||
|
@ -36,9 +33,6 @@ salsa::query_group! {
|
|||
fn source_file(file_id: FileId) -> TreePtr<SourceFile> {
|
||||
type SourceFileQuery;
|
||||
}
|
||||
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
|
||||
type FileLinesQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,10 +40,6 @@ fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr<SourceFile>
|
|||
let text = db.file_text(file_id);
|
||||
SourceFile::parse(&*text)
|
||||
}
|
||||
fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FilePosition {
|
||||
|
|
|
@ -215,7 +215,6 @@ salsa::database_storage! {
|
|||
}
|
||||
impl ra_db::SyntaxDatabase {
|
||||
fn source_file() for ra_db::SourceFileQuery;
|
||||
fn file_lines() for ra_db::FileLinesQuery;
|
||||
}
|
||||
impl db::HirDatabase {
|
||||
fn hir_source_file() for db::HirSourceFileQuery;
|
||||
|
|
|
@ -1049,6 +1049,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}
|
||||
|
||||
pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
|
||||
db.check_canceled()?;
|
||||
let function = Function::new(def_id); // TODO: consts also need inference
|
||||
let body = function.body(db)?;
|
||||
let scopes = db.fn_scopes(def_id)?;
|
||||
|
|
Loading…
Reference in a new issue