aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--crates/ra_analysis/Cargo.toml2
-rw-r--r--crates/ra_analysis/src/completion.rs3
-rw-r--r--crates/ra_analysis/src/db.rs (renamed from crates/ra_analysis/src/db/mod.rs)18
-rw-r--r--crates/ra_analysis/src/descriptors/module/imp.rs4
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs3
-rw-r--r--crates/ra_analysis/src/imp.rs27
-rw-r--r--crates/ra_analysis/src/input.rs (renamed from crates/ra_analysis/src/db/input.rs)33
-rw-r--r--crates/ra_analysis/src/lib.rs33
9 files changed, 67 insertions, 62 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 982463f0b..ea4275e63 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -608,7 +608,7 @@ dependencies = [
608 "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 608 "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
609 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 609 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
610 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 610 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
611 "salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 611 "salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
612 "test_utils 0.1.0", 612 "test_utils 0.1.0",
613] 613]
614 614
@@ -834,7 +834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
834 834
835[[package]] 835[[package]]
836name = "salsa" 836name = "salsa"
837version = "0.6.1" 837version = "0.6.2"
838source = "registry+https://github.com/rust-lang/crates.io-index" 838source = "registry+https://github.com/rust-lang/crates.io-index"
839dependencies = [ 839dependencies = [
840 "derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", 840 "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"
1350"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 1350"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
1351"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" 1351"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
1352"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 1352"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
1353"checksum salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fc085b9e4a2cf422e798387d0dc1091c6dae97411b2b177755950db9a26dace" 1353"checksum salsa 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fe802c02c7b0074b0b4794442d73e3c7d071967300a98bb0f5dfc25e9f1ef"
1354"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c" 1354"checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c"
1355"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 1355"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
1356"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1356"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml
index ff56a3c34..5d7915fa5 100644
--- a/crates/ra_analysis/Cargo.toml
+++ b/crates/ra_analysis/Cargo.toml
@@ -11,7 +11,7 @@ rayon = "1.0.2"
11fst = "0.3.1" 11fst = "0.3.1"
12ra_syntax = { path = "../ra_syntax" } 12ra_syntax = { path = "../ra_syntax" }
13ra_editor = { path = "../ra_editor" } 13ra_editor = { path = "../ra_editor" }
14salsa = "0.6.1" 14salsa = "0.6.2"
15rustc-hash = "1.0" 15rustc-hash = "1.0"
16 16
17[dev-dependencies] 17[dev-dependencies]
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index 04bb82c18..0a2f99575 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -6,7 +6,8 @@ use ra_syntax::{
6 6
7use crate::{ 7use crate::{
8 FileId, Cancelable, 8 FileId, Cancelable,
9 db::{self, SyntaxDatabase, input::FilesDatabase}, 9 input::FilesDatabase,
10 db::{self, SyntaxDatabase},
10 descriptors::module::{ModulesDatabase, ModuleTree, ModuleId}, 11 descriptors::module::{ModulesDatabase, ModuleTree, ModuleId},
11}; 12};
12 13
diff --git a/crates/ra_analysis/src/db/mod.rs b/crates/ra_analysis/src/db.rs
index 1a9023697..3ca14af79 100644
--- a/crates/ra_analysis/src/db/mod.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -1,5 +1,3 @@
1pub(crate) mod input;
2
3use std::{ 1use std::{
4 sync::Arc, 2 sync::Arc,
5}; 3};
@@ -51,13 +49,13 @@ impl Clone for RootDatabase {
51 49
52salsa::database_storage! { 50salsa::database_storage! {
53 pub(crate) struct RootDatabaseStorage for RootDatabase { 51 pub(crate) struct RootDatabaseStorage for RootDatabase {
54 impl input::FilesDatabase { 52 impl crate::input::FilesDatabase {
55 fn file_text() for input::FileTextQuery; 53 fn file_text() for crate::input::FileTextQuery;
56 fn file_source_root() for input::FileSourceRootQuery; 54 fn file_source_root() for crate::input::FileSourceRootQuery;
57 fn source_root() for input::SourceRootQuery; 55 fn source_root() for crate::input::SourceRootQuery;
58 fn libraries() for input::LibrarieseQuery; 56 fn libraries() for crate::input::LibrarieseQuery;
59 fn library_symbols() for input::LibrarySymbolsQuery; 57 fn library_symbols() for crate::input::LibrarySymbolsQuery;
60 fn crate_graph() for input::CrateGraphQuery; 58 fn crate_graph() for crate::input::CrateGraphQuery;
61 } 59 }
62 impl SyntaxDatabase { 60 impl SyntaxDatabase {
63 fn file_syntax() for FileSyntaxQuery; 61 fn file_syntax() for FileSyntaxQuery;
@@ -72,7 +70,7 @@ salsa::database_storage! {
72} 70}
73 71
74salsa::query_group! { 72salsa::query_group! {
75 pub(crate) trait SyntaxDatabase: input::FilesDatabase { 73 pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
76 fn file_syntax(file_id: FileId) -> File { 74 fn file_syntax(file_id: FileId) -> File {
77 type FileSyntaxQuery; 75 type FileSyntaxQuery;
78 } 76 }
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs
index 6a408dc89..aecf6e29a 100644
--- a/crates/ra_analysis/src/descriptors/module/imp.rs
+++ b/crates/ra_analysis/src/descriptors/module/imp.rs
@@ -8,8 +8,8 @@ use ra_syntax::{
8}; 8};
9 9
10use crate::{ 10use crate::{
11 FileId, Cancelable, FileResolverImp, 11 FileId, Cancelable, FileResolverImp, db,
12 db::{self, input::{SourceRoot, SourceRootId}}, 12 input::{SourceRoot, SourceRootId},
13}; 13};
14 14
15use super::{ 15use super::{
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs
index 98024cc15..8968c4afd 100644
--- a/crates/ra_analysis/src/descriptors/module/mod.rs
+++ b/crates/ra_analysis/src/descriptors/module/mod.rs
@@ -7,7 +7,8 @@ use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode};
7 7
8use crate::{ 8use crate::{
9 FileId, Cancelable, 9 FileId, Cancelable,
10 db::{SyntaxDatabase, input::SourceRootId}, 10 db::SyntaxDatabase,
11 input::SourceRootId,
11}; 12};
12 13
13salsa::query_group! { 14salsa::query_group! {
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index b24b5cfdc..69f5ed330 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -18,8 +18,9 @@ use crate::{
18 AnalysisChange, 18 AnalysisChange,
19 db::{ 19 db::{
20 self, SyntaxDatabase, 20 self, SyntaxDatabase,
21 input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE} 21
22 }, 22 },
23 input::{SourceRootId, FilesDatabase, SourceRoot, WORKSPACE},
23 descriptors::module::{ModulesDatabase, ModuleTree, Problem}, 24 descriptors::module::{ModulesDatabase, ModuleTree, Problem},
24 descriptors::{FnDescriptor}, 25 descriptors::{FnDescriptor},
25 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position, 26 CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
@@ -102,7 +103,7 @@ impl AnalysisHostImpl {
102 103
103 for (file_id, text) in change.files_changed { 104 for (file_id, text) in change.files_changed {
104 self.db 105 self.db
105 .query(db::input::FileTextQuery) 106 .query(crate::input::FileTextQuery)
106 .set(file_id, Arc::new(text)) 107 .set(file_id, Arc::new(text))
107 } 108 }
108 if !(change.files_added.is_empty() && change.files_removed.is_empty()) { 109 if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
@@ -111,22 +112,22 @@ impl AnalysisHostImpl {
111 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); 112 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
112 for (file_id, text) in change.files_added { 113 for (file_id, text) in change.files_added {
113 self.db 114 self.db
114 .query(db::input::FileTextQuery) 115 .query(crate::input::FileTextQuery)
115 .set(file_id, Arc::new(text)); 116 .set(file_id, Arc::new(text));
116 self.db 117 self.db
117 .query(db::input::FileSourceRootQuery) 118 .query(crate::input::FileSourceRootQuery)
118 .set(file_id, db::input::WORKSPACE); 119 .set(file_id, crate::input::WORKSPACE);
119 source_root.files.insert(file_id); 120 source_root.files.insert(file_id);
120 } 121 }
121 for file_id in change.files_removed { 122 for file_id in change.files_removed {
122 self.db 123 self.db
123 .query(db::input::FileTextQuery) 124 .query(crate::input::FileTextQuery)
124 .set(file_id, Arc::new(String::new())); 125 .set(file_id, Arc::new(String::new()));
125 source_root.files.remove(&file_id); 126 source_root.files.remove(&file_id);
126 } 127 }
127 source_root.file_resolver = file_resolver; 128 source_root.file_resolver = file_resolver;
128 self.db 129 self.db
129 .query(db::input::SourceRootQuery) 130 .query(crate::input::SourceRootQuery)
130 .set(WORKSPACE, Arc::new(source_root)) 131 .set(WORKSPACE, Arc::new(source_root))
131 } 132 }
132 if !change.libraries_added.is_empty() { 133 if !change.libraries_added.is_empty() {
@@ -138,10 +139,10 @@ impl AnalysisHostImpl {
138 for (file_id, text) in library.files { 139 for (file_id, text) in library.files {
139 files.insert(file_id); 140 files.insert(file_id);
140 self.db 141 self.db
141 .query(db::input::FileSourceRootQuery) 142 .query(crate::input::FileSourceRootQuery)
142 .set_constant(file_id, source_root_id); 143 .set_constant(file_id, source_root_id);
143 self.db 144 self.db
144 .query(db::input::FileTextQuery) 145 .query(crate::input::FileTextQuery)
145 .set_constant(file_id, Arc::new(text)); 146 .set_constant(file_id, Arc::new(text));
146 } 147 }
147 let source_root = SourceRoot { 148 let source_root = SourceRoot {
@@ -149,18 +150,18 @@ impl AnalysisHostImpl {
149 file_resolver: library.file_resolver, 150 file_resolver: library.file_resolver,
150 }; 151 };
151 self.db 152 self.db
152 .query(db::input::SourceRootQuery) 153 .query(crate::input::SourceRootQuery)
153 .set(source_root_id, Arc::new(source_root)); 154 .set(source_root_id, Arc::new(source_root));
154 self.db 155 self.db
155 .query(db::input::LibrarySymbolsQuery) 156 .query(crate::input::LibrarySymbolsQuery)
156 .set(source_root_id, Arc::new(library.symbol_index)); 157 .set(source_root_id, Arc::new(library.symbol_index));
157 } 158 }
158 self.db 159 self.db
159 .query(db::input::LibrarieseQuery) 160 .query(crate::input::LibrarieseQuery)
160 .set((), Arc::new(libraries)); 161 .set((), Arc::new(libraries));
161 } 162 }
162 if let Some(crate_graph) = change.crate_graph { 163 if let Some(crate_graph) = change.crate_graph {
163 self.db.query(db::input::CrateGraphQuery) 164 self.db.query(crate::input::CrateGraphQuery)
164 .set((), Arc::new(crate_graph)) 165 .set((), Arc::new(crate_graph))
165 } 166 }
166 } 167 }
diff --git a/crates/ra_analysis/src/db/input.rs b/crates/ra_analysis/src/input.rs
index 9baf7474c..e64fad40c 100644
--- a/crates/ra_analysis/src/db/input.rs
+++ b/crates/ra_analysis/src/input.rs
@@ -1,11 +1,42 @@
1use std::{ 1use std::{
2 sync::Arc, 2 sync::Arc,
3 fmt,
3}; 4};
4 5
5use salsa; 6use salsa;
6use rustc_hash::FxHashSet; 7use rustc_hash::FxHashSet;
8use relative_path::RelativePath;
9use rustc_hash::FxHashMap;
7 10
8use crate::{FileId, FileResolverImp, CrateGraph, symbol_index::SymbolIndex}; 11use crate::{symbol_index::SymbolIndex, FileResolverImp};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct FileId(pub u32);
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct CrateId(pub u32);
18
19#[derive(Debug, Clone, Default, PartialEq, Eq)]
20pub struct CrateGraph {
21 pub(crate) crate_roots: FxHashMap<CrateId, FileId>,
22}
23
24impl CrateGraph {
25 pub fn new() -> CrateGraph {
26 CrateGraph::default()
27 }
28 pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
29 let crate_id = CrateId(self.crate_roots.len() as u32);
30 let prev = self.crate_roots.insert(crate_id, file_id);
31 assert!(prev.is_none());
32 crate_id
33 }
34}
35
36pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
37 fn file_stem(&self, file_id: FileId) -> String;
38 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
39}
9 40
10salsa::query_group! { 41salsa::query_group! {
11 pub(crate) trait FilesDatabase: salsa::Database { 42 pub(crate) trait FilesDatabase: salsa::Database {
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index af7894cd0..a67cac21e 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -6,6 +6,7 @@ extern crate relative_path;
6extern crate rustc_hash; 6extern crate rustc_hash;
7extern crate salsa; 7extern crate salsa;
8 8
9mod input;
9mod db; 10mod db;
10mod descriptors; 11mod descriptors;
11mod imp; 12mod imp;
@@ -17,9 +18,8 @@ use std::{
17 sync::Arc, 18 sync::Arc,
18}; 19};
19 20
20use rustc_hash::FxHashMap;
21use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; 21use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
22use relative_path::{RelativePath, RelativePathBuf}; 22use relative_path::RelativePathBuf;
23use rayon::prelude::*; 23use rayon::prelude::*;
24 24
25use crate::{ 25use crate::{
@@ -29,6 +29,7 @@ use crate::{
29 29
30pub use crate::{ 30pub use crate::{
31 descriptors::FnDescriptor, 31 descriptors::FnDescriptor,
32 input::{FileId, FileResolver, CrateGraph, CrateId}
32}; 33};
33pub use ra_editor::{ 34pub use ra_editor::{
34 CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, 35 CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable,
@@ -49,34 +50,6 @@ impl std::fmt::Display for Canceled {
49impl std::error::Error for Canceled { 50impl std::error::Error for Canceled {
50} 51}
51 52
52#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
53pub struct FileId(pub u32);
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub struct CrateId(pub u32);
57
58#[derive(Debug, Clone, Default, PartialEq, Eq)]
59pub struct CrateGraph {
60 crate_roots: FxHashMap<CrateId, FileId>,
61}
62
63impl CrateGraph {
64 pub fn new() -> CrateGraph {
65 CrateGraph::default()
66 }
67 pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{
68 let crate_id = CrateId(self.crate_roots.len() as u32);
69 let prev = self.crate_roots.insert(crate_id, file_id);
70 assert!(prev.is_none());
71 crate_id
72 }
73}
74
75pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
76 fn file_stem(&self, file_id: FileId) -> String;
77 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
78}
79
80#[derive(Default)] 53#[derive(Default)]
81pub struct AnalysisChange { 54pub struct AnalysisChange {
82 files_added: Vec<(FileId, String)>, 55 files_added: Vec<(FileId, String)>,