From a733f65126451784c8b158d6c6318b556d68ebfc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Jan 2021 16:10:51 +0300 Subject: Allow non-absolute paths to rust source --- crates/rust-analyzer/src/config.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 071fde64d..c135913e2 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -7,7 +7,7 @@ //! configure the server itself, feature flags are passed into analysis, and //! tweak things like automatic insertion of `()` in completions. -use std::{convert::TryFrom, ffi::OsString, iter, path::PathBuf}; +use std::{ffi::OsString, iter, path::PathBuf}; use flycheck::FlycheckConfig; use hir::PrefixKind; @@ -468,11 +468,7 @@ impl Config { self.data.cargo_autoreload } pub fn cargo(&self) -> CargoConfig { - let rustc_source = self.data.rustcSource.clone().and_then(|it| { - AbsPathBuf::try_from(it) - .map_err(|_| log::error!("rustc source directory must be an absolute path")) - .ok() - }); + let rustc_source = self.data.rustcSource.as_ref().map(|it| self.root_path.join(&it)); CargoConfig { no_default_features: self.data.cargo_noDefaultFeatures, -- cgit v1.2.3 From 2870e701630c198bafb346e5a9c91c1d2fc9f092 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Jan 2021 16:18:01 +0300 Subject: Add config option to ignore directories --- crates/rust-analyzer/src/cli/load_cargo.rs | 2 +- crates/rust-analyzer/src/config.rs | 10 ++++++++-- crates/rust-analyzer/src/reload.rs | 16 +++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'crates') 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( vfs.file_id(&path) }); - let project_folders = ProjectFolders::new(&[ws]); + let project_folders = ProjectFolders::new(&[ws], &[]); loader.set_config(vfs::loader::Config { load: project_folders.load, watch: vec![] }); 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! { /// Controls file watching implementation. files_watcher: String = "\"client\"", + /// These directories will be ignored by rust-analyzer. + files_excludeDirs: Vec = "[]", /// Whether to show `Debug` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. @@ -248,7 +250,7 @@ impl LensConfig { #[derive(Debug, Clone)] pub struct FilesConfig { pub watcher: FilesWatcher, - pub exclude: Vec, + pub exclude: Vec, } #[derive(Debug, Clone)] @@ -458,7 +460,7 @@ impl Config { "notify" => FilesWatcher::Notify, "client" | _ => FilesWatcher::Client, }, - exclude: Vec::new(), + exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(), } } pub fn notifications(&self) -> NotificationsConfig { @@ -763,6 +765,10 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json "type": "array", "items": { "type": "string" }, }, + "Vec" => set! { + "type": "array", + "items": { "type": "string" }, + }, "FxHashSet" => set! { "type": "array", "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 { let mut change = Change::new(); - let project_folders = ProjectFolders::new(&workspaces); + let files_config = self.config.files(); + let project_folders = ProjectFolders::new(&workspaces, &files_config.exclude); self.proc_macro_client = match self.config.proc_macro_srv() { None => None, @@ -231,7 +232,7 @@ impl GlobalState { }, }; - let watch = match self.config.files().watcher { + let watch = match files_config.watcher { FilesWatcher::Client => vec![], FilesWatcher::Notify => project_folders.watch, }; @@ -319,7 +320,10 @@ pub(crate) struct ProjectFolders { } impl ProjectFolders { - pub(crate) fn new(workspaces: &[ProjectWorkspace]) -> ProjectFolders { + pub(crate) fn new( + workspaces: &[ProjectWorkspace], + global_excludes: &[AbsPathBuf], + ) -> ProjectFolders { let mut res = ProjectFolders::default(); let mut fsc = FileSetConfig::builder(); let mut local_filesets = vec![]; @@ -333,6 +337,12 @@ impl ProjectFolders { dirs.extensions.push("rs".into()); dirs.include.extend(root.include); dirs.exclude.extend(root.exclude); + for excl in global_excludes { + if dirs.include.iter().any(|incl| incl.starts_with(excl)) { + dirs.exclude.push(excl.clone()); + } + } + vfs::loader::Entry::Directories(dirs) }; -- cgit v1.2.3