Skip to content

Commit

Permalink
Add config option to ignore directories
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jan 26, 2021
1 parent a733f65 commit 6619230
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/load_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> = "[]",

/// Whether to show `Debug` action. Only applies when
/// `#rust-analyzer.hoverActions.enable#` is set.
Expand Down Expand Up @@ -248,7 +250,7 @@ impl LensConfig {
#[derive(Debug, Clone)]
pub struct FilesConfig {
pub watcher: FilesWatcher,
pub exclude: Vec<String>,
pub exclude: Vec<AbsPathBuf>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -763,6 +765,10 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"type": "array",
"items": { "type": "string" },
},
"Vec<PathBuf>" => set! {
"type": "array",
"items": { "type": "string" },
},
"FxHashSet<String>" => set! {
"type": "array",
"items": { "type": "string" },
Expand Down
16 changes: 13 additions & 3 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down Expand Up @@ -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![];
Expand All @@ -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)
};

Expand Down
8 changes: 8 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@
"default": "client",
"type": "string"
},
"rust-analyzer.files.excludeDirs": {
"markdownDescription": "These directories will be ignored by rust-analyzer.",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"rust-analyzer.hoverActions.debug": {
"markdownDescription": "Whether to show `Debug` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set.",
"default": true,
Expand Down

0 comments on commit 6619230

Please sign in to comment.