diff options
author | Aleksey Kladov <[email protected]> | 2021-01-26 13:18:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-26 13:45:54 +0000 |
commit | 2870e701630c198bafb346e5a9c91c1d2fc9f092 (patch) | |
tree | cf85185c893a344bbfe29e48fcf856b630a06ec5 /crates | |
parent | a733f65126451784c8b158d6c6318b556d68ebfc (diff) |
Add config option to ignore directories
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 16 |
3 files changed, 22 insertions, 6 deletions
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 16ccab781..dbab4f5f4 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -46,7 +46,7 @@ pub fn load_cargo( | |||
46 | vfs.file_id(&path) | 46 | vfs.file_id(&path) |
47 | }); | 47 | }); |
48 | 48 | ||
49 | let project_folders = ProjectFolders::new(&[ws]); | 49 | let project_folders = ProjectFolders::new(&[ws], &[]); |
50 | loader.set_config(vfs::loader::Config { load: project_folders.load, watch: vec![] }); | 50 | loader.set_config(vfs::loader::Config { load: project_folders.load, watch: vec![] }); |
51 | 51 | ||
52 | log::debug!("crate graph: {:?}", crate_graph); | 52 | log::debug!("crate graph: {:?}", crate_graph); |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index c135913e2..37487b6ac 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -105,6 +105,8 @@ config_data! { | |||
105 | 105 | ||
106 | /// Controls file watching implementation. | 106 | /// Controls file watching implementation. |
107 | files_watcher: String = "\"client\"", | 107 | files_watcher: String = "\"client\"", |
108 | /// These directories will be ignored by rust-analyzer. | ||
109 | files_excludeDirs: Vec<PathBuf> = "[]", | ||
108 | 110 | ||
109 | /// Whether to show `Debug` action. Only applies when | 111 | /// Whether to show `Debug` action. Only applies when |
110 | /// `#rust-analyzer.hoverActions.enable#` is set. | 112 | /// `#rust-analyzer.hoverActions.enable#` is set. |
@@ -248,7 +250,7 @@ impl LensConfig { | |||
248 | #[derive(Debug, Clone)] | 250 | #[derive(Debug, Clone)] |
249 | pub struct FilesConfig { | 251 | pub struct FilesConfig { |
250 | pub watcher: FilesWatcher, | 252 | pub watcher: FilesWatcher, |
251 | pub exclude: Vec<String>, | 253 | pub exclude: Vec<AbsPathBuf>, |
252 | } | 254 | } |
253 | 255 | ||
254 | #[derive(Debug, Clone)] | 256 | #[derive(Debug, Clone)] |
@@ -458,7 +460,7 @@ impl Config { | |||
458 | "notify" => FilesWatcher::Notify, | 460 | "notify" => FilesWatcher::Notify, |
459 | "client" | _ => FilesWatcher::Client, | 461 | "client" | _ => FilesWatcher::Client, |
460 | }, | 462 | }, |
461 | exclude: Vec::new(), | 463 | exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(), |
462 | } | 464 | } |
463 | } | 465 | } |
464 | pub fn notifications(&self) -> NotificationsConfig { | 466 | pub fn notifications(&self) -> NotificationsConfig { |
@@ -763,6 +765,10 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json | |||
763 | "type": "array", | 765 | "type": "array", |
764 | "items": { "type": "string" }, | 766 | "items": { "type": "string" }, |
765 | }, | 767 | }, |
768 | "Vec<PathBuf>" => set! { | ||
769 | "type": "array", | ||
770 | "items": { "type": "string" }, | ||
771 | }, | ||
766 | "FxHashSet<String>" => set! { | 772 | "FxHashSet<String>" => set! { |
767 | "type": "array", | 773 | "type": "array", |
768 | "items": { "type": "string" }, | 774 | "items": { "type": "string" }, |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index dabfb4241..0507186dc 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -214,7 +214,8 @@ impl GlobalState { | |||
214 | 214 | ||
215 | let mut change = Change::new(); | 215 | let mut change = Change::new(); |
216 | 216 | ||
217 | let project_folders = ProjectFolders::new(&workspaces); | 217 | let files_config = self.config.files(); |
218 | let project_folders = ProjectFolders::new(&workspaces, &files_config.exclude); | ||
218 | 219 | ||
219 | self.proc_macro_client = match self.config.proc_macro_srv() { | 220 | self.proc_macro_client = match self.config.proc_macro_srv() { |
220 | None => None, | 221 | None => None, |
@@ -231,7 +232,7 @@ impl GlobalState { | |||
231 | }, | 232 | }, |
232 | }; | 233 | }; |
233 | 234 | ||
234 | let watch = match self.config.files().watcher { | 235 | let watch = match files_config.watcher { |
235 | FilesWatcher::Client => vec![], | 236 | FilesWatcher::Client => vec![], |
236 | FilesWatcher::Notify => project_folders.watch, | 237 | FilesWatcher::Notify => project_folders.watch, |
237 | }; | 238 | }; |
@@ -319,7 +320,10 @@ pub(crate) struct ProjectFolders { | |||
319 | } | 320 | } |
320 | 321 | ||
321 | impl ProjectFolders { | 322 | impl ProjectFolders { |
322 | pub(crate) fn new(workspaces: &[ProjectWorkspace]) -> ProjectFolders { | 323 | pub(crate) fn new( |
324 | workspaces: &[ProjectWorkspace], | ||
325 | global_excludes: &[AbsPathBuf], | ||
326 | ) -> ProjectFolders { | ||
323 | let mut res = ProjectFolders::default(); | 327 | let mut res = ProjectFolders::default(); |
324 | let mut fsc = FileSetConfig::builder(); | 328 | let mut fsc = FileSetConfig::builder(); |
325 | let mut local_filesets = vec![]; | 329 | let mut local_filesets = vec![]; |
@@ -333,6 +337,12 @@ impl ProjectFolders { | |||
333 | dirs.extensions.push("rs".into()); | 337 | dirs.extensions.push("rs".into()); |
334 | dirs.include.extend(root.include); | 338 | dirs.include.extend(root.include); |
335 | dirs.exclude.extend(root.exclude); | 339 | dirs.exclude.extend(root.exclude); |
340 | for excl in global_excludes { | ||
341 | if dirs.include.iter().any(|incl| incl.starts_with(excl)) { | ||
342 | dirs.exclude.push(excl.clone()); | ||
343 | } | ||
344 | } | ||
345 | |||
336 | vfs::loader::Entry::Directories(dirs) | 346 | vfs::loader::Entry::Directories(dirs) |
337 | }; | 347 | }; |
338 | 348 | ||