Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit f7744ff

Browse files
committed
rls: Introduce crate_blacklist config allowing for custom blacklists
This in turns removes the old `use_crate_blacklist` setting. To not use the blacklist, one can specify `[]` as the config value.
1 parent 7f5629e commit f7744ff

File tree

7 files changed

+88
-36
lines changed

7 files changed

+88
-36
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test = false
2121
path = "rls/src/main.rs"
2222

2323
[dependencies]
24-
rls-analysis = "0.17.0"
24+
rls-analysis = "0.18.0"
2525
rls-blacklist = "0.1.3"
2626
rls-data = "0.19"
2727
# FIXME: Release rls-rustc 0.6.0 to crates.io

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ Currently we accept the following options:
115115
* `all_targets` (`bool`, defaults to `true`) checks the project as if you were
116116
running `cargo check --all-targets`. I.e., check all targets and integration
117117
tests too
118-
* `use_crate_blacklist` (`bool`, defaults to `true`) if disabled, also indexes
119-
data from the [blacklisted](https://github.com/nrc/rls-blacklist/blob/master/src/lib.rs) crates
118+
* `crate_blacklist` (`[String]`, defaults to [this list](https://github.com/rust-dev-tools/rls-blacklist/blob/master/src/lib.rs))
119+
allows to specify which crates should be skipped by the RLS.
120+
By default skips libraries that are of considerable size but which the user
121+
often may not be directly interested in, thus reducing the build latency.
120122
* `build_on_save` (`bool`, defaults to `false`) toggles whether the RLS should
121123
perform continuous analysis or only after a file is saved
122124
* `features` (`[String]`, defaults to empty) list of Cargo features to enable

rls/src/actions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl InitActionContext {
335335
related_information_support: self.client_capabilities.related_information_support,
336336
shown_cargo_error: self.shown_cargo_error.clone(),
337337
active_build_count: self.active_build_count.clone(),
338-
use_black_list: config.use_crate_blacklist,
338+
crate_blacklist: config.crate_blacklist.as_ref().clone(),
339339
notifier: Box::new(BuildDiagnosticsNotifier::new(out.clone())),
340340
blocked_threads: vec![],
341341
_token: token,

rls/src/actions/post_build.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::actions::diagnostics::{parse_diagnostics, Diagnostic, ParsedDiagnosti
1616
use crate::actions::progress::DiagnosticsNotifier;
1717
use crate::build::{BuildResult, Crate};
1818
use crate::concurrency::JobToken;
19+
use crate::config::CrateBlacklist;
1920
use crate::lsp_data::{PublishDiagnosticsParams, Range};
2021

2122
use failure;
@@ -35,7 +36,7 @@ pub struct PostBuildHandler {
3536
pub file_to_crates: Arc<Mutex<HashMap<PathBuf, HashSet<Crate>>>>,
3637
pub project_path: PathBuf,
3738
pub show_warnings: bool,
38-
pub use_black_list: bool,
39+
pub crate_blacklist: CrateBlacklist,
3940
pub related_information_support: bool,
4041
pub shown_cargo_error: Arc<AtomicBool>,
4142
pub active_build_count: Arc<AtomicUsize>,
@@ -172,28 +173,15 @@ impl PostBuildHandler {
172173
}
173174

174175
fn reload_analysis_from_disk(&self, cwd: &Path) {
175-
if self.use_black_list {
176-
self.analysis
177-
.reload_with_blacklist(&self.project_path, cwd, &rls_blacklist::CRATE_BLACKLIST)
178-
.unwrap();
179-
} else {
180-
self.analysis.reload(&self.project_path, cwd).unwrap();
181-
}
176+
self.analysis
177+
.reload_with_blacklist(&self.project_path, cwd, &self.crate_blacklist.0[..])
178+
.unwrap();
182179
}
183180

184181
fn reload_analysis_from_memory(&self, cwd: &Path, analysis: Vec<Analysis>) {
185-
if self.use_black_list {
186-
self.analysis
187-
.reload_from_analysis(
188-
analysis,
189-
&self.project_path,
190-
cwd,
191-
&rls_blacklist::CRATE_BLACKLIST,
192-
)
193-
.unwrap();
194-
} else {
195-
self.analysis.reload_from_analysis(analysis, &self.project_path, cwd, &[]).unwrap();
196-
}
182+
self.analysis
183+
.reload_from_analysis(analysis, &self.project_path, cwd, &self.crate_blacklist.0[..])
184+
.unwrap();
197185
}
198186

199187
fn finalize(mut self) {

rls/src/build/cargo.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,23 @@ impl Executor for RlsExecutor {
498498
cmd.get_envs(),
499499
);
500500

501-
if rls_blacklist::CRATE_BLACKLIST.contains(&&*crate_name) {
501+
let (crate_blacklist, full_docs) = {
502+
let config = self.config.lock().unwrap();
503+
(config.crate_blacklist.clone(), *config.full_docs.clone().as_ref())
504+
};
505+
if crate_blacklist.as_ref().0.contains(&crate_name) {
502506
// By running the original command (rather than using our shim), we
503507
// avoid producing save-analysis data.
504508
trace!("crate is blacklisted");
505509
return cargo_cmd.exec();
506510
}
507511
// Only include public symbols in externally compiled deps data
508-
let mut save_config = rls_data::config::Config::default();
509-
save_config.pub_only = true;
510-
save_config.reachable_only = true;
511-
save_config.full_docs =
512-
self.config.lock().map(|config| *config.full_docs.as_ref()).unwrap();
513-
let save_config = serde_json::to_string(&save_config)?;
512+
let save_config = serde_json::to_string(&rls_data::config::Config {
513+
pub_only: true,
514+
reachable_only: true,
515+
full_docs,
516+
..Default::default()
517+
})?;
514518
cmd.env("RUST_SAVE_ANALYSIS_CONFIG", &OsString::from(save_config));
515519

516520
return cmd.exec();

rls/src/config.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::io::sink;
88
use std::marker::PhantomData;
99
use std::path::{Path, PathBuf};
1010
use std::str::FromStr;
11+
use std::sync::Arc;
1112

1213
use cargo::core::{Shell, Workspace};
1314
use cargo::util::{homedir, important_paths, Config as CargoConfig};
@@ -135,7 +136,9 @@ pub struct Config {
135136
/// `true` to build the project only when a file got saved and not on file change.
136137
/// Default: `false`.
137138
pub build_on_save: bool,
138-
pub use_crate_blacklist: bool,
139+
/// Blacklist of crates for RLS to skip. By default omits `winapi`, Unicode
140+
/// table crates, `serde`, `libc`, `glium` and other.
141+
pub crate_blacklist: Inferrable<CrateBlacklist>,
139142
/// The Cargo target directory. If set, overrides the default one.
140143
pub target_dir: Inferrable<Option<PathBuf>>,
141144
pub features: Vec<String>,
@@ -185,7 +188,7 @@ impl Default for Config {
185188
show_warnings: true,
186189
clear_env_rust_log: true,
187190
build_on_save: false,
188-
use_crate_blacklist: true,
191+
crate_blacklist: Inferrable::Inferred(CrateBlacklist::default()),
189192
target_dir: Inferrable::Inferred(None),
190193
features: vec![],
191194
all_features: false,
@@ -432,10 +435,65 @@ impl Default for FmtConfig {
432435
}
433436
}
434437

438+
#[derive(Clone, Debug, PartialEq)]
439+
/// List of crates for which IDE analysis should not be generated
440+
pub struct CrateBlacklist(pub Arc<[String]>);
441+
442+
impl<'de> Deserialize<'de> for CrateBlacklist {
443+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
444+
where
445+
D: Deserializer<'de>,
446+
{
447+
let boxed = <Box<[String]> as serde::Deserialize>::deserialize(deserializer)?;
448+
Ok(CrateBlacklist(boxed.into()))
449+
}
450+
}
451+
452+
impl Default for CrateBlacklist {
453+
fn default() -> Self {
454+
CrateBlacklist(
455+
[
456+
"cocoa",
457+
"gleam",
458+
"glium",
459+
"idna",
460+
"libc",
461+
"openssl",
462+
"rustc_serialize",
463+
"serde",
464+
"serde_json",
465+
"typenum",
466+
"unicode_normalization",
467+
"unicode_segmentation",
468+
"winapi",
469+
]
470+
.iter()
471+
.map(ToString::to_string)
472+
.collect::<Vec<_>>()
473+
.into(),
474+
)
475+
}
476+
}
477+
435478
#[test]
436479
fn clippy_preference_from_str() {
437480
assert_eq!(ClippyPreference::from_str("Optin"), Ok(ClippyPreference::OptIn));
438481
assert_eq!(ClippyPreference::from_str("OFF"), Ok(ClippyPreference::Off));
439482
assert_eq!(ClippyPreference::from_str("opt-in"), Ok(ClippyPreference::OptIn));
440483
assert_eq!(ClippyPreference::from_str("on"), Ok(ClippyPreference::On));
441484
}
485+
486+
#[test]
487+
fn blacklist_default() {
488+
let value = serde_json::json!({});
489+
let config = Config::try_deserialize(&value, &mut Default::default(), &mut vec![]).unwrap();
490+
assert_eq!(config.crate_blacklist.as_ref(), &CrateBlacklist::default());
491+
let value = serde_json::json!({"crate_blacklist": []});
492+
493+
let config = Config::try_deserialize(&value, &mut Default::default(), &mut vec![]).unwrap();
494+
assert_eq!(&*config.crate_blacklist.as_ref().0, &[] as &[String]);
495+
496+
let value = serde_json::json!({"crate_blacklist": ["serde"]});
497+
let config = Config::try_deserialize(&value, &mut Default::default(), &mut vec![]).unwrap();
498+
assert_eq!(&*config.crate_blacklist.as_ref().0, &["serde".to_string()]);
499+
}

0 commit comments

Comments
 (0)