diff --git a/example_files/example_lint_cfg.README b/example_files/example_lint_cfg.README index 2289e2b..b7f64e1 100644 --- a/example_files/example_lint_cfg.README +++ b/example_files/example_lint_cfg.README @@ -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 diff --git a/example_files/example_lint_cfg.json b/example_files/example_lint_cfg.json index cfb5fee..f92abc9 100644 --- a/example_files/example_lint_cfg.json +++ b/example_files/example_lint_cfg.json @@ -1,5 +1,4 @@ { - "direct_only": true, "sp_brace": {}, "sp_punct": {}, "nsp_funpar": {}, diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index 23716b5..e70944b 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -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); diff --git a/src/actions/mod.rs b/src/actions/mod.rs index d6a4a27..ad27aa8 100644 --- a/src/actions/mod.rs +++ b/src/actions/mod.rs @@ -177,7 +177,6 @@ pub struct InitActionContext { // directly opened files pub direct_opens: Arc>>, - pub compilation_info: Arc>, prev_changes: Arc>>, @@ -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, diff --git a/src/config.rs b/src/config.rs index a82377a..7d30547 100644 --- a/src/config.rs +++ b/src/config.rs @@ -104,6 +104,7 @@ pub struct Config { pub analyse_on_save: bool, pub features: Vec, pub all_features: bool, + pub suppress_imports: bool, pub linting_enabled: bool, pub lint_cfg_path: Option, pub no_default_features: bool, @@ -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, diff --git a/src/dfa/client.rs b/src/dfa/client.rs index 7b8f8ce..06eb448 100644 --- a/src/dfa/client.rs +++ b/src/dfa/client.rs @@ -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) @@ -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"); diff --git a/src/dfa/main.rs b/src/dfa/main.rs index 3b83849..91ba473 100644 --- a/src/dfa/main.rs +++ b/src/dfa/main.rs @@ -33,6 +33,7 @@ struct Args { files: Vec, workspaces: Vec, compile_info: Option, + suppress_imports: Option, linting_enabled: Option, lint_cfg_path: Option, test: bool, @@ -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)") @@ -99,6 +105,8 @@ fn parse_args() -> Args { test: args.contains_id("test"), compile_info: args.get_one::("compile-info") .cloned(), + suppress_imports: args.get_one::("suppress-imports") + .cloned(), linting_enabled: args.get_one::("linting-enabled") .cloned(), lint_cfg_path: args.get_one::("lint-cfg-path") @@ -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() diff --git a/src/lint/mod.rs b/src/lint/mod.rs index 5d1ef7d..6b1fa2c 100644 --- a/src/lint/mod.rs +++ b/src/lint/mod.rs @@ -52,7 +52,6 @@ pub fn maybe_parse_lint_cfg(path: PathBuf) -> Option { #[serde(default)] #[serde(deny_unknown_fields)] pub struct LintCfg { - pub direct_only: bool, #[serde(default)] pub sp_brace: Option, #[serde(default)] @@ -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{}), diff --git a/src/server/mod.rs b/src/server/mod.rs index 3a06023..5e8e728 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -366,6 +366,7 @@ impl LsService { 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); @@ -376,17 +377,21 @@ impl LsService { 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); } }, @@ -405,13 +410,15 @@ impl LsService { 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); + } } } }