allow to exclude certain files and directories

This commit is contained in:
Aleksey Kladov 2019-08-06 13:34:28 +02:00
parent 058c2daba1
commit deea8f52d9
7 changed files with 43 additions and 15 deletions

View file

@ -1,7 +1,7 @@
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
/// Client provided initialization options /// Client provided initialization options
#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)] #[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase", default)] #[serde(rename_all = "camelCase", default)]
pub struct ServerConfig { pub struct ServerConfig {
/// Whether the client supports our custom highlighting publishing decorations. /// Whether the client supports our custom highlighting publishing decorations.
@ -18,12 +18,19 @@ pub struct ServerConfig {
#[serde(deserialize_with = "nullable_bool_true")] #[serde(deserialize_with = "nullable_bool_true")]
pub show_workspace_loaded: bool, pub show_workspace_loaded: bool,
pub exclude_globs: Vec<String>,
pub lru_capacity: Option<usize>, pub lru_capacity: Option<usize>,
} }
impl Default for ServerConfig { impl Default for ServerConfig {
fn default() -> 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,
}
} }
} }

View file

@ -56,6 +56,7 @@ pub fn main_loop(
msg_receiver: &Receiver<RawMessage>, msg_receiver: &Receiver<RawMessage>,
msg_sender: &Sender<RawMessage>, msg_sender: &Sender<RawMessage>,
) -> Result<()> { ) -> Result<()> {
log::debug!("server_config: {:?}", config);
// FIXME: support dynamic workspace loading. // FIXME: support dynamic workspace loading.
let workspaces = { let workspaces = {
let ws_worker = workspace_loader(); let ws_worker = workspace_loader();
@ -77,11 +78,16 @@ pub fn main_loop(
} }
loaded_workspaces loaded_workspaces
}; };
let globs = config
.exclude_globs
.iter()
.map(|glob| ra_vfs_glob::Glob::new(glob))
.collect::<std::result::Result<Vec<_>, _>>()?;
let mut state = WorldState::new( let mut state = WorldState::new(
ws_roots, ws_roots,
workspaces, workspaces,
config.lru_capacity, config.lru_capacity,
&globs,
Options { Options {
publish_decorations: config.publish_decorations, publish_decorations: config.publish_decorations,
show_workspace_loaded: config.show_workspace_loaded, show_workspace_loaded: config.show_workspace_loaded,

View file

@ -10,7 +10,7 @@ use ra_ide_api::{
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
}; };
use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot};
use ra_vfs_glob::RustPackageFilterBuilder; use ra_vfs_glob::{Glob, RustPackageFilterBuilder};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use crate::{ use crate::{
@ -56,25 +56,27 @@ impl WorldState {
folder_roots: Vec<PathBuf>, folder_roots: Vec<PathBuf>,
workspaces: Vec<ProjectWorkspace>, workspaces: Vec<ProjectWorkspace>,
lru_capacity: Option<usize>, lru_capacity: Option<usize>,
exclude_globs: &[Glob],
options: Options, options: Options,
) -> WorldState { ) -> WorldState {
let mut change = AnalysisChange::new(); let mut change = AnalysisChange::new();
let mut roots = Vec::new(); let mut roots = Vec::new();
roots.extend(folder_roots.iter().map(|path| { roots.extend(folder_roots.iter().map(|path| {
RootEntry::new( let mut filter = RustPackageFilterBuilder::default().set_member(true);
path.clone(), for glob in exclude_globs.iter() {
RustPackageFilterBuilder::default().set_member(true).into_vfs_filter(), filter = filter.exclude(glob.clone());
) }
RootEntry::new(path.clone(), filter.into_vfs_filter())
})); }));
for ws in workspaces.iter() { for ws in workspaces.iter() {
roots.extend(ws.to_roots().into_iter().map(|pkg_root| { roots.extend(ws.to_roots().into_iter().map(|pkg_root| {
RootEntry::new( let mut filter =
pkg_root.path().clone(), RustPackageFilterBuilder::default().set_member(pkg_root.is_member());
RustPackageFilterBuilder::default() for glob in exclude_globs.iter() {
.set_member(pkg_root.is_member()) filter = filter.exclude(glob.clone());
.into_vfs_filter(), }
) RootEntry::new(pkg_root.path().clone(), filter.into_vfs_filter())
})); }));
} }

View file

@ -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.raLspServerPath`: path to `ra_lsp_server` executable
* `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo * `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo
watch` for live error highlighting (note, this **does not** use rust-analyzer) 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. * `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""` ) (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` )
* `rust-analyzer.trace.server`: enables internal logging * `rust-analyzer.trace.server`: enables internal logging

View file

@ -197,6 +197,11 @@
], ],
"description": "Whether to run `cargo watch` on startup" "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": { "rust-analyzer.cargo-watch.arguments": {
"type": "string", "type": "string",
"description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",

View file

@ -22,6 +22,7 @@ export class Config {
public showWorkspaceLoadedNotification = true; public showWorkspaceLoadedNotification = true;
public lruCapacity: null | number = null; public lruCapacity: null | number = null;
public displayInlayHints = true; public displayInlayHints = true;
public excludeGlobs = [];
public cargoWatchOptions: CargoWatchOptions = { public cargoWatchOptions: CargoWatchOptions = {
enableOnStartup: 'ask', enableOnStartup: 'ask',
trace: 'off', trace: 'off',
@ -128,5 +129,8 @@ export class Config {
if (config.has('displayInlayHints')) { if (config.has('displayInlayHints')) {
this.displayInlayHints = config.get('displayInlayHints') as boolean; this.displayInlayHints = config.get('displayInlayHints') as boolean;
} }
if (config.has('excludeGlobs')) {
this.excludeGlobs = config.get('excludeGlobs') || [];
}
} }
} }

View file

@ -36,7 +36,8 @@ export class Server {
publishDecorations: true, publishDecorations: true,
showWorkspaceLoaded: showWorkspaceLoaded:
Server.config.showWorkspaceLoadedNotification, Server.config.showWorkspaceLoadedNotification,
lruCapacity: Server.config.lruCapacity lruCapacity: Server.config.lruCapacity,
excludeGlobs: Server.config.excludeGlobs
}, },
traceOutputChannel traceOutputChannel
}; };