Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions example_files/example_lint_cfg.README
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// your modifications

{
// if set to 'false', will lint indirectly imported files as well
"direct_only": true,
// linting rules with no arguments are enabled by assigning an empty struct
"sp_brace": {},
// linting rules with arguments are straightforward
Expand Down
1 change: 0 additions & 1 deletion example_files/example_lint_cfg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"direct_only": true,
"sp_brace": {},
"sp_punct": {},
"nsp_funpar": {},
Expand Down
9 changes: 5 additions & 4 deletions src/actions/analysis_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,15 @@ impl IsolatedAnalysisJob {
} else {
self.context.clone()
};
let import_paths = analysis.get_import_names();
self.report.send(TimestampedStorage::make_isolated_result(
self.timestamp,
analysis)).ok();
self.notify.send(ServerToHandle::IsolatedAnalysisDone(
self.path.clone(),
new_context,
analysis.get_import_names()
import_paths
)).ok();
self.report.send(TimestampedStorage::make_isolated_result(
self.timestamp,
analysis)).ok();
},
Err(e) => {
trace!("Failed to create isolated analysis: {}", e);
Expand Down
6 changes: 3 additions & 3 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ pub struct InitActionContext {

// directly opened files
pub direct_opens: Arc<Mutex<HashSet<CanonPath>>>,

pub compilation_info: Arc<Mutex<CompilationInfoStorage>>,

prev_changes: Arc<Mutex<HashMap<PathBuf, i32>>>,
Expand Down Expand Up @@ -534,13 +533,14 @@ impl InitActionContext {
if !self.config.lock().unwrap().linting_enabled {
return;
}
let lint_config = self.lint_config.lock().unwrap().to_owned();
if lint_config.direct_only {
let config = self.config.lock().unwrap().to_owned();
if config.suppress_imports {
let canon_path: CanonPath = file.to_path_buf().into();
if !self.direct_opens.lock().unwrap().contains(&canon_path) {
return;
}
}
let lint_config = self.lint_config.lock().unwrap().to_owned();
debug!("Triggering linting analysis of {:?}", file);
self.lint_analyze(file,
None,
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct Config {
pub analyse_on_save: bool,
pub features: Vec<String>,
pub all_features: bool,
pub suppress_imports: bool,
pub linting_enabled: bool,
pub lint_cfg_path: Option<PathBuf>,
pub no_default_features: bool,
Expand All @@ -119,6 +120,7 @@ impl Default for Config {
analyse_on_save: false,
features: vec![],
all_features: false,
suppress_imports: false,
linting_enabled: true,
lint_cfg_path: None,
no_default_features: false,
Expand Down
15 changes: 3 additions & 12 deletions src/dfa/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ impl ClientInterface {
} else {
self.waiting_for_received_lint.remove(&file);
}

Ok(ServerMessage::Diagnostics(
file, diagnostic_params.diagnostics
.iter().cloned().map(Diagnostic::from)
Expand Down Expand Up @@ -356,17 +355,9 @@ impl ClientInterface {
}{}
// Gather the results
while 'condition: {
if self.waiting_for_received_diag.is_empty()
&& self.waiting_for_received_lint.is_empty() {
if self.has_received_ended_progress {
break 'condition false;
}
debug!("Waiting for progress end");
} else {
debug!("Waiting for outstanding analysises {:?} or lints {:?}",
self.waiting_for_received_diag,
self.waiting_for_received_lint.is_empty());
}
if self.has_received_ended_progress {
break 'condition false;
}
match self.receive() {
ServerMessage::Error(e) => {
trace!("server unexpectedly closed while waiting for analysis");
Expand Down
9 changes: 9 additions & 0 deletions src/dfa/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Args {
files: Vec<PathBuf>,
workspaces: Vec<PathBuf>,
compile_info: Option<PathBuf>,
suppress_imports: Option<bool>,
linting_enabled: Option<bool>,
lint_cfg_path: Option<PathBuf>,
test: bool,
Expand Down Expand Up @@ -72,6 +73,11 @@ fn parse_args() -> Args {
include paths")
.value_parser(clap::value_parser!(PathBuf))
.required(false))
.arg(Arg::new("suppress-imports").short('s').long("suppress-imports")
.action(ArgAction::Set)
.help("Analyses specified files only, without also analyzing files they import")
.value_parser(clap::value_parser!(bool))
.required(false))
.arg(Arg::new("linting-enabled").short('l').long("linting-enabled")
.action(ArgAction::Set)
.help("Turns linting on/off (defaults to true)")
Expand Down Expand Up @@ -99,6 +105,8 @@ fn parse_args() -> Args {
test: args.contains_id("test"),
compile_info: args.get_one::<PathBuf>("compile-info")
.cloned(),
suppress_imports: args.get_one::<bool>("suppress-imports")
.cloned(),
linting_enabled: args.get_one::<bool>("linting-enabled")
.cloned(),
lint_cfg_path: args.get_one::<PathBuf>("lint-cfg-path")
Expand Down Expand Up @@ -134,6 +142,7 @@ fn main_inner() -> Result<(), i32> {
dlsclient.add_workspaces(workspace_rest.cloned().collect()).or(Err(1))?;
let config = Config {
compile_info_path: arg.compile_info.clone(),
suppress_imports: arg.suppress_imports.unwrap_or(false),
linting_enabled,
lint_cfg_path: arg.lint_cfg_path.clone(),
.. Default::default()
Expand Down
2 changes: 0 additions & 2 deletions src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub fn maybe_parse_lint_cfg(path: PathBuf) -> Option<LintCfg> {
#[serde(default)]
#[serde(deny_unknown_fields)]
pub struct LintCfg {
pub direct_only: bool,
#[serde(default)]
pub sp_brace: Option<SpBraceOptions>,
#[serde(default)]
Expand All @@ -72,7 +71,6 @@ pub struct LintCfg {
impl Default for LintCfg {
fn default() -> LintCfg {
LintCfg {
direct_only: true,
sp_brace: Some(SpBraceOptions{}),
sp_punct: Some(SpPunctOptions{}),
nsp_funpar: Some(NspFunparOptions{}),
Expand Down
27 changes: 17 additions & 10 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ impl<O: Output> LsService<O> {
requests) => {
debug!("Received isolated analysis of {:?}", path);
if let ActionContext::Init(ctx) = &mut self.ctx {
let config = ctx.config.lock().unwrap().to_owned();
ctx.update_analysis();
ctx.analysis.lock().unwrap().report_errors(
&path, &self.output);
Expand All @@ -376,17 +377,21 @@ impl<O: Output> LsService<O> {
if let Some(file) = ctx.construct_resolver()
.resolve_with_maybe_context(&file,
context.as_ref()) {
trace!("Analysing imported file {}",
file.to_str().unwrap());
ctx.isolated_analyze(&file,
context.clone(),
&self.output);
if !config.suppress_imports {
trace!("Analysing imported file {}",
file.to_str().unwrap());
ctx.isolated_analyze(&file,
context.clone(),
&self.output);
}
} else {
trace!("Imported file {:?} did not resolve",
file);
}
}
ctx.trigger_device_analysis(&path, &self.output);
if !ctx.config.lock().unwrap().suppress_imports {
ctx.trigger_device_analysis(&path, &self.output);
}
ctx.maybe_trigger_lint_analysis(&path, &self.output);
}
},
Expand All @@ -405,13 +410,15 @@ impl<O: Output> LsService<O> {
ctx.analysis.try_lock().unwrap().report_errors(
&path, &self.output);
}
}, // WIP lint
},
ServerToHandle::AnalysisRequest(importpath, context) => {
if let ActionContext::Init(ctx) = &mut self.ctx {
debug!("Analysing imported file {}",
if !ctx.config.lock().unwrap().to_owned().suppress_imports {
debug!("Analysing imported file {}",
&importpath.to_str().unwrap());
ctx.isolated_analyze(
&importpath, context, &self.output);
ctx.isolated_analyze(
&importpath, context, &self.output);
}
}
}
}
Expand Down
Loading