From deea8f52d9803bb8a93d5dbd935970a20f07a51e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 13:34:28 +0200 Subject: [PATCH] allow to exclude certain files and directories --- crates/ra_lsp_server/src/config.rs | 11 +++++++++-- crates/ra_lsp_server/src/main_loop.rs | 8 +++++++- crates/ra_lsp_server/src/world.rs | 24 +++++++++++++----------- docs/user/README.md | 3 +++ editors/code/package.json | 5 +++++ editors/code/src/config.ts | 4 ++++ editors/code/src/server.ts | 3 ++- 7 files changed, 43 insertions(+), 15 deletions(-) diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index a16cc292e5..6dcdc695a7 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Deserializer}; /// Client provided initialization options -#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "camelCase", default)] pub struct ServerConfig { /// Whether the client supports our custom highlighting publishing decorations. @@ -18,12 +18,19 @@ pub struct ServerConfig { #[serde(deserialize_with = "nullable_bool_true")] pub show_workspace_loaded: bool, + pub exclude_globs: Vec, + pub lru_capacity: Option, } impl Default for ServerConfig { fn default() -> ServerConfig { - ServerConfig { publish_decorations: false, show_workspace_loaded: true, lru_capacity: None } + ServerConfig { + publish_decorations: false, + show_workspace_loaded: true, + exclude_globs: Vec::new(), + lru_capacity: None, + } } } diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 8ab5018288..9d540a87e6 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -56,6 +56,7 @@ pub fn main_loop( msg_receiver: &Receiver, msg_sender: &Sender, ) -> Result<()> { + log::debug!("server_config: {:?}", config); // FIXME: support dynamic workspace loading. let workspaces = { let ws_worker = workspace_loader(); @@ -77,11 +78,16 @@ pub fn main_loop( } loaded_workspaces }; - + let globs = config + .exclude_globs + .iter() + .map(|glob| ra_vfs_glob::Glob::new(glob)) + .collect::, _>>()?; let mut state = WorldState::new( ws_roots, workspaces, config.lru_capacity, + &globs, Options { publish_decorations: config.publish_decorations, show_workspace_loaded: config.show_workspace_loaded, diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index a8aafe5cb6..9990ef62e1 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -10,7 +10,7 @@ use ra_ide_api::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, }; use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; -use ra_vfs_glob::RustPackageFilterBuilder; +use ra_vfs_glob::{Glob, RustPackageFilterBuilder}; use relative_path::RelativePathBuf; use crate::{ @@ -56,25 +56,27 @@ impl WorldState { folder_roots: Vec, workspaces: Vec, lru_capacity: Option, + exclude_globs: &[Glob], options: Options, ) -> WorldState { let mut change = AnalysisChange::new(); let mut roots = Vec::new(); roots.extend(folder_roots.iter().map(|path| { - RootEntry::new( - path.clone(), - RustPackageFilterBuilder::default().set_member(true).into_vfs_filter(), - ) + let mut filter = RustPackageFilterBuilder::default().set_member(true); + for glob in exclude_globs.iter() { + filter = filter.exclude(glob.clone()); + } + RootEntry::new(path.clone(), filter.into_vfs_filter()) })); for ws in workspaces.iter() { roots.extend(ws.to_roots().into_iter().map(|pkg_root| { - RootEntry::new( - pkg_root.path().clone(), - RustPackageFilterBuilder::default() - .set_member(pkg_root.is_member()) - .into_vfs_filter(), - ) + let mut filter = + RustPackageFilterBuilder::default().set_member(pkg_root.is_member()); + for glob in exclude_globs.iter() { + filter = filter.exclude(glob.clone()); + } + RootEntry::new(pkg_root.path().clone(), filter.into_vfs_filter()) })); } diff --git a/docs/user/README.md b/docs/user/README.md index a5e17f6041..7990d1d31b 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -71,6 +71,9 @@ See https://github.com/microsoft/vscode/issues/72308[microsoft/vscode#72308] for * `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable * `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo watch` for live error highlighting (note, this **does not** use rust-analyzer) +* `rust-analyzer.excludeGlobs`: a list of glob-patterns for exclusion (see globset [docs](https://docs.rs/globset) for syntax). + Note: glob patterns are applied to all Cargo packages and a rooted at a package root. + This is not very intuitive and a limitation of a current implementation. * `rust-analyzer.cargo-watch.check-arguments`: cargo-watch check arguments. (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` ) * `rust-analyzer.trace.server`: enables internal logging diff --git a/editors/code/package.json b/editors/code/package.json index 808dc5dc1b..48ab886bf8 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -197,6 +197,11 @@ ], "description": "Whether to run `cargo watch` on startup" }, + "rust-analyzer.excludeGlobs": { + "type": "array", + "default": "[]", + "description": "Paths to exclude from analysis" + }, "rust-analyzer.cargo-watch.arguments": { "type": "string", "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 4d58a1a936..4df6b50ef7 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -22,6 +22,7 @@ export class Config { public showWorkspaceLoadedNotification = true; public lruCapacity: null | number = null; public displayInlayHints = true; + public excludeGlobs = []; public cargoWatchOptions: CargoWatchOptions = { enableOnStartup: 'ask', trace: 'off', @@ -128,5 +129,8 @@ export class Config { if (config.has('displayInlayHints')) { this.displayInlayHints = config.get('displayInlayHints') as boolean; } + if (config.has('excludeGlobs')) { + this.excludeGlobs = config.get('excludeGlobs') || []; + } } } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 7029142fdc..2b4c25c284 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -36,7 +36,8 @@ export class Server { publishDecorations: true, showWorkspaceLoaded: Server.config.showWorkspaceLoadedNotification, - lruCapacity: Server.config.lruCapacity + lruCapacity: Server.config.lruCapacity, + excludeGlobs: Server.config.excludeGlobs }, traceOutputChannel };