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};
/// 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<String>,
pub lru_capacity: Option<usize>,
}
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,
}
}
}

View file

@ -56,6 +56,7 @@ pub fn main_loop(
msg_receiver: &Receiver<RawMessage>,
msg_sender: &Sender<RawMessage>,
) -> 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::<std::result::Result<Vec<_>, _>>()?;
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,

View file

@ -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<PathBuf>,
workspaces: Vec<ProjectWorkspace>,
lru_capacity: Option<usize>,
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())
}));
}

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.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

View file

@ -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\"\"` )",

View file

@ -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') || [];
}
}
}

View file

@ -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
};