diff options
-rw-r--r-- | crates/project_model/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/project_model/src/project_json.rs | 21 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 13 | ||||
-rw-r--r-- | docs/dev/syntax.md | 2 | ||||
-rw-r--r-- | docs/user/manual.adoc | 5 |
5 files changed, 35 insertions, 14 deletions
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs index 288c39e49..258f60e28 100644 --- a/crates/project_model/src/lib.rs +++ b/crates/project_model/src/lib.rs | |||
@@ -308,7 +308,13 @@ impl ProjectWorkspace { | |||
308 | .crates() | 308 | .crates() |
309 | .filter_map(|(crate_id, krate)| { | 309 | .filter_map(|(crate_id, krate)| { |
310 | let file_path = &krate.root_module; | 310 | let file_path = &krate.root_module; |
311 | let file_id = load(&file_path)?; | 311 | let file_id = match load(&file_path) { |
312 | Some(id) => id, | ||
313 | None => { | ||
314 | log::error!("failed to load crate root {}", file_path.display()); | ||
315 | return None; | ||
316 | } | ||
317 | }; | ||
312 | 318 | ||
313 | let env = krate.env.clone().into_iter().collect(); | 319 | let env = krate.env.clone().into_iter().collect(); |
314 | let proc_macro = krate | 320 | let proc_macro = krate |
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 545f254aa..a6895ecdd 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs | |||
@@ -13,7 +13,7 @@ use crate::cfg_flag::CfgFlag; | |||
13 | #[derive(Clone, Debug, Eq, PartialEq)] | 13 | #[derive(Clone, Debug, Eq, PartialEq)] |
14 | pub struct ProjectJson { | 14 | pub struct ProjectJson { |
15 | pub(crate) sysroot_src: Option<AbsPathBuf>, | 15 | pub(crate) sysroot_src: Option<AbsPathBuf>, |
16 | project_root: Option<AbsPathBuf>, | 16 | project_root: AbsPathBuf, |
17 | crates: Vec<Crate>, | 17 | crates: Vec<Crate>, |
18 | } | 18 | } |
19 | 19 | ||
@@ -34,10 +34,17 @@ pub struct Crate { | |||
34 | } | 34 | } |
35 | 35 | ||
36 | impl ProjectJson { | 36 | impl ProjectJson { |
37 | /// Create a new ProjectJson instance. | ||
38 | /// | ||
39 | /// # Arguments | ||
40 | /// | ||
41 | /// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`) | ||
42 | /// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via | ||
43 | /// configuration. | ||
37 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { | 44 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { |
38 | ProjectJson { | 45 | ProjectJson { |
39 | sysroot_src: data.sysroot_src.map(|it| base.join(it)), | 46 | sysroot_src: data.sysroot_src.map(|it| base.join(it)), |
40 | project_root: base.parent().map(AbsPath::to_path_buf), | 47 | project_root: base.to_path_buf(), |
41 | crates: data | 48 | crates: data |
42 | .crates | 49 | .crates |
43 | .into_iter() | 50 | .into_iter() |
@@ -85,17 +92,17 @@ impl ProjectJson { | |||
85 | .collect::<Vec<_>>(), | 92 | .collect::<Vec<_>>(), |
86 | } | 93 | } |
87 | } | 94 | } |
95 | /// Returns the number of crates in the project. | ||
88 | pub fn n_crates(&self) -> usize { | 96 | pub fn n_crates(&self) -> usize { |
89 | self.crates.len() | 97 | self.crates.len() |
90 | } | 98 | } |
99 | /// Returns an iterator over the crates in the project. | ||
91 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { | 100 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { |
92 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) | 101 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) |
93 | } | 102 | } |
94 | pub fn path(&self) -> Option<&AbsPath> { | 103 | /// Returns the path to the project's root folder. |
95 | match &self.project_root { | 104 | pub fn path(&self) -> &AbsPath { |
96 | Some(p) => Some(p.as_path()), | 105 | &self.project_root |
97 | None => None, | ||
98 | } | ||
99 | } | 106 | } |
100 | } | 107 | } |
101 | 108 | ||
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index b819618cb..b070087a4 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -201,11 +201,14 @@ impl GlobalState { | |||
201 | let mut crate_graph = CrateGraph::default(); | 201 | let mut crate_graph = CrateGraph::default(); |
202 | let vfs = &mut self.vfs.write().0; | 202 | let vfs = &mut self.vfs.write().0; |
203 | let loader = &mut self.loader; | 203 | let loader = &mut self.loader; |
204 | let mem_docs = &self.mem_docs; | ||
204 | let mut load = |path: &AbsPath| { | 205 | let mut load = |path: &AbsPath| { |
205 | let contents = loader.handle.load_sync(path); | 206 | let vfs_path = vfs::VfsPath::from(path.to_path_buf()); |
206 | let path = vfs::VfsPath::from(path.to_path_buf()); | 207 | if !mem_docs.contains_key(&vfs_path) { |
207 | vfs.set_file_contents(path.clone(), contents); | 208 | let contents = loader.handle.load_sync(path); |
208 | vfs.file_id(&path) | 209 | vfs.set_file_contents(vfs_path.clone(), contents); |
210 | } | ||
211 | vfs.file_id(&vfs_path) | ||
209 | }; | 212 | }; |
210 | for ws in workspaces.iter() { | 213 | for ws in workspaces.iter() { |
211 | crate_graph.extend(ws.to_crate_graph( | 214 | crate_graph.extend(ws.to_crate_graph( |
@@ -249,7 +252,7 @@ impl GlobalState { | |||
249 | // Enable flychecks for json projects if a custom flycheck command was supplied | 252 | // Enable flychecks for json projects if a custom flycheck command was supplied |
250 | // in the workspace configuration. | 253 | // in the workspace configuration. |
251 | match config { | 254 | match config { |
252 | FlycheckConfig::CustomCommand { .. } => project.path(), | 255 | FlycheckConfig::CustomCommand { .. } => Some(project.path()), |
253 | _ => None, | 256 | _ => None, |
254 | } | 257 | } |
255 | } | 258 | } |
diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md index c08062ef4..2eb08b7ca 100644 --- a/docs/dev/syntax.md +++ b/docs/dev/syntax.md | |||
@@ -72,7 +72,7 @@ Points of note: | |||
72 | * Trivia and non-trivia tokens are not distinguished on the type level. | 72 | * Trivia and non-trivia tokens are not distinguished on the type level. |
73 | * Each token carries its full text. | 73 | * Each token carries its full text. |
74 | * The original text can be recovered by concatenating the texts of all tokens in order. | 74 | * The original text can be recovered by concatenating the texts of all tokens in order. |
75 | * Accessing a child of particular type (for example, parameter list of a function) generally involves linerary traversing the children, looking for a specific `kind`. | 75 | * Accessing a child of particular type (for example, parameter list of a function) generally involves linearly traversing the children, looking for a specific `kind`. |
76 | * Modifying the tree is roughly `O(depth)`. | 76 | * Modifying the tree is roughly `O(depth)`. |
77 | We don't make special efforts to guarantee that the depth is not linear, but, in practice, syntax trees are branchy and shallow. | 77 | We don't make special efforts to guarantee that the depth is not linear, but, in practice, syntax trees are branchy and shallow. |
78 | * If mandatory (grammar wise) node is missing from the input, it's just missing from the tree. | 78 | * If mandatory (grammar wise) node is missing from the input, it's just missing from the tree. |
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index b15c9ee7f..d3e6b23ae 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -44,6 +44,11 @@ https://github.com/rust-analyzer/rust-analyzer/tree/master/editors/code[in tree] | |||
44 | 44 | ||
45 | You can install the latest release of the plugin from | 45 | You can install the latest release of the plugin from |
46 | https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer[the marketplace]. | 46 | https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer[the marketplace]. |
47 | |||
48 | Note that the plugin may cause conflicts with the | ||
49 | https://marketplace.visualstudio.com/items?itemName=rust-lang.rust[official Rust plugin]. It is | ||
50 | recommended to disable the Rust plugin when using the rust-analyzer extension. | ||
51 | |||
47 | By default, the plugin will prompt you to download the matching version of the server as well: | 52 | By default, the plugin will prompt you to download the matching version of the server as well: |
48 | 53 | ||
49 | image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[] | 54 | image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[] |