aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/Cargo.toml2
-rw-r--r--crates/ra_analysis/src/lib.rs18
-rw-r--r--crates/ra_analysis/tests/tests.rs13
-rw-r--r--crates/ra_lsp_server/src/server_world.rs9
4 files changed, 24 insertions, 18 deletions
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml
index 5d7915fa5..ff56a3c34 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.2" 14salsa = "0.6.1"
15rustc-hash = "1.0" 15rustc-hash = "1.0"
16 16
17[dev-dependencies] 17[dev-dependencies]
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 703938cf9..af7894cd0 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -15,9 +15,9 @@ mod completion;
15use std::{ 15use std::{
16 fmt, 16 fmt,
17 sync::Arc, 17 sync::Arc,
18 collections::BTreeMap,
19}; 18};
20 19
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::{RelativePath, RelativePathBuf};
23use rayon::prelude::*; 23use rayon::prelude::*;
@@ -55,9 +55,21 @@ pub struct FileId(pub u32);
55#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 55#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub struct CrateId(pub u32); 56pub struct CrateId(pub u32);
57 57
58#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] 58#[derive(Debug, Clone, Default, PartialEq, Eq)]
59pub struct CrateGraph { 59pub struct CrateGraph {
60 pub crate_roots: BTreeMap<CrateId, FileId>, 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 }
61} 73}
62 74
63pub trait FileResolver: fmt::Debug + Send + Sync + 'static { 75pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs
index 198d6a263..806e1fb34 100644
--- a/crates/ra_analysis/tests/tests.rs
+++ b/crates/ra_analysis/tests/tests.rs
@@ -7,7 +7,6 @@ extern crate test_utils;
7 7
8use std::{ 8use std::{
9 sync::Arc, 9 sync::Arc,
10 collections::BTreeMap,
11}; 10};
12 11
13use ra_syntax::TextRange; 12use ra_syntax::TextRange;
@@ -130,19 +129,17 @@ fn test_resolve_crate_root() {
130 let snap = host.analysis(); 129 let snap = host.analysis();
131 assert!(snap.crate_for(FileId(2)).unwrap().is_empty()); 130 assert!(snap.crate_for(FileId(2)).unwrap().is_empty());
132 131
133 let crate_graph = CrateGraph { 132 let crate_graph = {
134 crate_roots: { 133 let mut g = CrateGraph::new();
135 let mut m = BTreeMap::default(); 134 g.add_crate_root(FileId(1));
136 m.insert(CrateId(1), FileId(1)); 135 g
137 m
138 },
139 }; 136 };
140 let mut change = AnalysisChange::new(); 137 let mut change = AnalysisChange::new();
141 change.set_crate_graph(crate_graph); 138 change.set_crate_graph(crate_graph);
142 host.apply_change(change); 139 host.apply_change(change);
143 let snap = host.analysis(); 140 let snap = host.analysis();
144 141
145 assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(1)],); 142 assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(0)],);
146} 143}
147 144
148#[test] 145#[test]
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index 555de66ff..25986e230 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -2,11 +2,10 @@ use std::{
2 fs, 2 fs,
3 path::{Path, PathBuf}, 3 path::{Path, PathBuf},
4 sync::Arc, 4 sync::Arc,
5 collections::BTreeMap,
6}; 5};
7 6
8use languageserver_types::Url; 7use languageserver_types::Url;
9use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, CrateId, FileId, FileResolver, LibraryData}; 8use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, FileId, FileResolver, LibraryData};
10use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
11 10
12use crate::{ 11use crate::{
@@ -149,7 +148,7 @@ impl ServerWorldState {
149 Ok(file_id) 148 Ok(file_id)
150 } 149 }
151 pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { 150 pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {
152 let mut crate_roots = BTreeMap::default(); 151 let mut crate_graph = CrateGraph::new();
153 ws.iter() 152 ws.iter()
154 .flat_map(|ws| { 153 .flat_map(|ws| {
155 ws.packages() 154 ws.packages()
@@ -158,11 +157,9 @@ impl ServerWorldState {
158 }) 157 })
159 .for_each(|root| { 158 .for_each(|root| {
160 if let Some(file_id) = self.path_map.get_id(root) { 159 if let Some(file_id) = self.path_map.get_id(root) {
161 let crate_id = CrateId(crate_roots.len() as u32); 160 crate_graph.add_crate_root(file_id);
162 crate_roots.insert(crate_id, file_id);
163 } 161 }
164 }); 162 });
165 let crate_graph = CrateGraph { crate_roots };
166 self.workspaces = Arc::new(ws); 163 self.workspaces = Arc::new(ws);
167 let mut change = AnalysisChange::new(); 164 let mut change = AnalysisChange::new();
168 change.set_crate_graph(crate_graph); 165 change.set_crate_graph(crate_graph);