mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Move input to top-level
This commit is contained in:
parent
5ef3fda5e1
commit
d190019571
9 changed files with 67 additions and 62 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -608,7 +608,7 @@ dependencies = [
|
||||||
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"test_utils 0.1.0",
|
"test_utils 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -834,7 +834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "salsa"
|
name = "salsa"
|
||||||
version = "0.6.1"
|
version = "0.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1350,7 +1350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||||
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
||||||
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
||||||
"checksum salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fc085b9e4a2cf422e798387d0dc1091c6dae97411b2b177755950db9a26dace"
|
"checksum salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fe802c02c7b0074b0b4794442d73e3c7d071967300a98bb0f5dfc25e9f1ef"
|
||||||
"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c"
|
"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c"
|
||||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||||
|
|
|
@ -11,7 +11,7 @@ rayon = "1.0.2"
|
||||||
fst = "0.3.1"
|
fst = "0.3.1"
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_editor = { path = "../ra_editor" }
|
ra_editor = { path = "../ra_editor" }
|
||||||
salsa = "0.6.1"
|
salsa = "0.6.2"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -6,7 +6,8 @@ use ra_syntax::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
FileId, Cancelable,
|
FileId, Cancelable,
|
||||||
db::{self, SyntaxDatabase, input::FilesDatabase},
|
input::FilesDatabase,
|
||||||
|
db::{self, SyntaxDatabase},
|
||||||
descriptors::module::{ModulesDatabase, ModuleTree, ModuleId},
|
descriptors::module::{ModulesDatabase, ModuleTree, ModuleId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
pub(crate) mod input;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
@ -51,13 +49,13 @@ impl Clone for RootDatabase {
|
||||||
|
|
||||||
salsa::database_storage! {
|
salsa::database_storage! {
|
||||||
pub(crate) struct RootDatabaseStorage for RootDatabase {
|
pub(crate) struct RootDatabaseStorage for RootDatabase {
|
||||||
impl input::FilesDatabase {
|
impl crate::input::FilesDatabase {
|
||||||
fn file_text() for input::FileTextQuery;
|
fn file_text() for crate::input::FileTextQuery;
|
||||||
fn file_source_root() for input::FileSourceRootQuery;
|
fn file_source_root() for crate::input::FileSourceRootQuery;
|
||||||
fn source_root() for input::SourceRootQuery;
|
fn source_root() for crate::input::SourceRootQuery;
|
||||||
fn libraries() for input::LibrarieseQuery;
|
fn libraries() for crate::input::LibrarieseQuery;
|
||||||
fn library_symbols() for input::LibrarySymbolsQuery;
|
fn library_symbols() for crate::input::LibrarySymbolsQuery;
|
||||||
fn crate_graph() for input::CrateGraphQuery;
|
fn crate_graph() for crate::input::CrateGraphQuery;
|
||||||
}
|
}
|
||||||
impl SyntaxDatabase {
|
impl SyntaxDatabase {
|
||||||
fn file_syntax() for FileSyntaxQuery;
|
fn file_syntax() for FileSyntaxQuery;
|
||||||
|
@ -72,7 +70,7 @@ salsa::database_storage! {
|
||||||
}
|
}
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
pub(crate) trait SyntaxDatabase: input::FilesDatabase {
|
pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
|
||||||
fn file_syntax(file_id: FileId) -> File {
|
fn file_syntax(file_id: FileId) -> File {
|
||||||
type FileSyntaxQuery;
|
type FileSyntaxQuery;
|
||||||
}
|
}
|
|
@ -8,8 +8,8 @@ use ra_syntax::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
FileId, Cancelable, FileResolverImp,
|
FileId, Cancelable, FileResolverImp, db,
|
||||||
db::{self, input::{SourceRoot, SourceRootId}},
|
input::{SourceRoot, SourceRootId},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|
|
@ -7,7 +7,8 @@ use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
FileId, Cancelable,
|
FileId, Cancelable,
|
||||||
db::{SyntaxDatabase, input::SourceRootId},
|
db::SyntaxDatabase,
|
||||||
|
input::SourceRootId,
|
||||||
};
|
};
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
|
|
|
@ -18,8 +18,9 @@ use crate::{
|
||||||
AnalysisChange,
|
AnalysisChange,
|
||||||
db::{
|
db::{
|
||||||
self, SyntaxDatabase,
|
self, SyntaxDatabase,
|
||||||
input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE}
|
|
||||||
},
|
},
|
||||||
|
input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE},
|
||||||
descriptors::module::{ModulesDatabase, ModuleTree, Problem},
|
descriptors::module::{ModulesDatabase, ModuleTree, Problem},
|
||||||
descriptors::{FnDescriptor},
|
descriptors::{FnDescriptor},
|
||||||
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
|
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
|
||||||
|
@ -102,7 +103,7 @@ impl AnalysisHostImpl {
|
||||||
|
|
||||||
for (file_id, text) in change.files_changed {
|
for (file_id, text) in change.files_changed {
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileTextQuery)
|
.query(crate::input::FileTextQuery)
|
||||||
.set(file_id, Arc::new(text))
|
.set(file_id, Arc::new(text))
|
||||||
}
|
}
|
||||||
if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
|
if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
|
||||||
|
@ -111,22 +112,22 @@ impl AnalysisHostImpl {
|
||||||
let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
|
let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
|
||||||
for (file_id, text) in change.files_added {
|
for (file_id, text) in change.files_added {
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileTextQuery)
|
.query(crate::input::FileTextQuery)
|
||||||
.set(file_id, Arc::new(text));
|
.set(file_id, Arc::new(text));
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileSourceRootQuery)
|
.query(crate::input::FileSourceRootQuery)
|
||||||
.set(file_id, db::input::WORKSPACE);
|
.set(file_id, crate::input::WORKSPACE);
|
||||||
source_root.files.insert(file_id);
|
source_root.files.insert(file_id);
|
||||||
}
|
}
|
||||||
for file_id in change.files_removed {
|
for file_id in change.files_removed {
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileTextQuery)
|
.query(crate::input::FileTextQuery)
|
||||||
.set(file_id, Arc::new(String::new()));
|
.set(file_id, Arc::new(String::new()));
|
||||||
source_root.files.remove(&file_id);
|
source_root.files.remove(&file_id);
|
||||||
}
|
}
|
||||||
source_root.file_resolver = file_resolver;
|
source_root.file_resolver = file_resolver;
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::SourceRootQuery)
|
.query(crate::input::SourceRootQuery)
|
||||||
.set(WORKSPACE, Arc::new(source_root))
|
.set(WORKSPACE, Arc::new(source_root))
|
||||||
}
|
}
|
||||||
if !change.libraries_added.is_empty() {
|
if !change.libraries_added.is_empty() {
|
||||||
|
@ -138,10 +139,10 @@ impl AnalysisHostImpl {
|
||||||
for (file_id, text) in library.files {
|
for (file_id, text) in library.files {
|
||||||
files.insert(file_id);
|
files.insert(file_id);
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileSourceRootQuery)
|
.query(crate::input::FileSourceRootQuery)
|
||||||
.set_constant(file_id, source_root_id);
|
.set_constant(file_id, source_root_id);
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::FileTextQuery)
|
.query(crate::input::FileTextQuery)
|
||||||
.set_constant(file_id, Arc::new(text));
|
.set_constant(file_id, Arc::new(text));
|
||||||
}
|
}
|
||||||
let source_root = SourceRoot {
|
let source_root = SourceRoot {
|
||||||
|
@ -149,18 +150,18 @@ impl AnalysisHostImpl {
|
||||||
file_resolver: library.file_resolver,
|
file_resolver: library.file_resolver,
|
||||||
};
|
};
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::SourceRootQuery)
|
.query(crate::input::SourceRootQuery)
|
||||||
.set(source_root_id, Arc::new(source_root));
|
.set(source_root_id, Arc::new(source_root));
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::LibrarySymbolsQuery)
|
.query(crate::input::LibrarySymbolsQuery)
|
||||||
.set(source_root_id, Arc::new(library.symbol_index));
|
.set(source_root_id, Arc::new(library.symbol_index));
|
||||||
}
|
}
|
||||||
self.db
|
self.db
|
||||||
.query(db::input::LibrarieseQuery)
|
.query(crate::input::LibrarieseQuery)
|
||||||
.set((), Arc::new(libraries));
|
.set((), Arc::new(libraries));
|
||||||
}
|
}
|
||||||
if let Some(crate_graph) = change.crate_graph {
|
if let Some(crate_graph) = change.crate_graph {
|
||||||
self.db.query(db::input::CrateGraphQuery)
|
self.db.query(crate::input::CrateGraphQuery)
|
||||||
.set((), Arc::new(crate_graph))
|
.set((), Arc::new(crate_graph))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,42 @@
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
fmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use salsa;
|
use salsa;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use relative_path::RelativePath;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use crate::{FileId, FileResolverImp, CrateGraph, symbol_index::SymbolIndex};
|
use crate::{symbol_index::SymbolIndex, FileResolverImp};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct FileId(pub u32);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct CrateId(pub u32);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||||
|
pub struct CrateGraph {
|
||||||
|
pub(crate) crate_roots: FxHashMap<CrateId, FileId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CrateGraph {
|
||||||
|
pub fn new() -> CrateGraph {
|
||||||
|
CrateGraph::default()
|
||||||
|
}
|
||||||
|
pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
|
||||||
|
let crate_id = CrateId(self.crate_roots.len() as u32);
|
||||||
|
let prev = self.crate_roots.insert(crate_id, file_id);
|
||||||
|
assert!(prev.is_none());
|
||||||
|
crate_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
|
||||||
|
fn file_stem(&self, file_id: FileId) -> String;
|
||||||
|
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
|
||||||
|
}
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
pub(crate) trait FilesDatabase: salsa::Database {
|
pub(crate) trait FilesDatabase: salsa::Database {
|
|
@ -6,6 +6,7 @@ extern crate relative_path;
|
||||||
extern crate rustc_hash;
|
extern crate rustc_hash;
|
||||||
extern crate salsa;
|
extern crate salsa;
|
||||||
|
|
||||||
|
mod input;
|
||||||
mod db;
|
mod db;
|
||||||
mod descriptors;
|
mod descriptors;
|
||||||
mod imp;
|
mod imp;
|
||||||
|
@ -17,9 +18,8 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
|
use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::RelativePathBuf;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -29,6 +29,7 @@ use crate::{
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
descriptors::FnDescriptor,
|
descriptors::FnDescriptor,
|
||||||
|
input::{FileId, FileResolver, CrateGraph, CrateId}
|
||||||
};
|
};
|
||||||
pub use ra_editor::{
|
pub use ra_editor::{
|
||||||
CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable,
|
CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable,
|
||||||
|
@ -49,34 +50,6 @@ impl std::fmt::Display for Canceled {
|
||||||
impl std::error::Error for Canceled {
|
impl std::error::Error for Canceled {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct FileId(pub u32);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct CrateId(pub u32);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
||||||
pub struct CrateGraph {
|
|
||||||
crate_roots: FxHashMap<CrateId, FileId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CrateGraph {
|
|
||||||
pub fn new() -> CrateGraph {
|
|
||||||
CrateGraph::default()
|
|
||||||
}
|
|
||||||
pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
|
|
||||||
let crate_id = CrateId(self.crate_roots.len() as u32);
|
|
||||||
let prev = self.crate_roots.insert(crate_id, file_id);
|
|
||||||
assert!(prev.is_none());
|
|
||||||
crate_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
|
|
||||||
fn file_stem(&self, file_id: FileId) -> String;
|
|
||||||
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AnalysisChange {
|
pub struct AnalysisChange {
|
||||||
files_added: Vec<(FileId, String)>,
|
files_added: Vec<(FileId, String)>,
|
||||||
|
|
Loading…
Reference in a new issue