mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
allow to exclude certain files and directories
This commit is contained in:
parent
058c2daba1
commit
deea8f52d9
7 changed files with 43 additions and 15 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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())
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue