diff options
Diffstat (limited to 'cli/lsp/diagnostics.rs')
| -rw-r--r-- | cli/lsp/diagnostics.rs | 91 |
1 files changed, 27 insertions, 64 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 8a0d50ef1..c20307bb3 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -2,13 +2,11 @@ use super::analysis; use super::documents; -use super::documents::Document; use super::documents::Documents; use super::language_server; use super::tsc; use crate::diagnostics; -use crate::fs_util::specifier_to_file_path; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; @@ -302,59 +300,14 @@ fn ts_json_to_diagnostics( .collect() } -// Filters documents according to the `include` and the `exclude` lists (from `StateSnapshot::maybe_lint_config`). -// If a document is in the `exclude` list - then it be removed. -// If the `include` list is not empty, and a document is not in - then it be removed too. -fn filter_lint_documents( - snapshot: &language_server::StateSnapshot, - documents: &mut Vec<Document>, -) { - let lint_config = match &snapshot.maybe_lint_config { - Some(config) => config, - None => return, - }; - - documents.retain(|doc| { - let path = if let Ok(file_path) = specifier_to_file_path(doc.specifier()) { - file_path - } else { - return false; - }; - - // Skip files which is in the exclude list. - if lint_config - .files - .exclude - .iter() - .any(|i| path.starts_with(i)) - { - return false; - } - - // Early return if the include list is empty. - if lint_config.files.include.is_empty() { - return true; - } - - // Ignore files not in the include list. - lint_config - .files - .include - .iter() - .any(|i| path.starts_with(i)) - }); -} - async fn generate_lint_diagnostics( snapshot: &language_server::StateSnapshot, collection: Arc<Mutex<DiagnosticCollection>>, ) -> Result<DiagnosticVec, AnyError> { - let mut documents = snapshot.documents.documents(true, true); + let documents = snapshot.documents.documents(true, true); let workspace_settings = snapshot.config.settings.workspace.clone(); let maybe_lint_config = snapshot.maybe_lint_config.clone(); - filter_lint_documents(snapshot, &mut documents); - tokio::task::spawn(async move { let mut diagnostics_vec = Vec::new(); if workspace_settings.lint { @@ -365,25 +318,35 @@ async fn generate_lint_diagnostics( .await .get_version(document.specifier(), &DiagnosticSource::DenoLint); if version != current_version { - let diagnostics = match document.maybe_parsed_source() { - Some(Ok(parsed_source)) => { - if let Ok(references) = analysis::get_lint_references( - &parsed_source, - maybe_lint_config.as_ref(), - ) { - references - .into_iter() - .map(|r| r.to_diagnostic()) - .collect::<Vec<_>>() - } else { + let is_allowed = match &maybe_lint_config { + Some(lint_config) => { + lint_config.files.matches_specifier(document.specifier()) + } + None => true, + }; + let diagnostics = if is_allowed { + match document.maybe_parsed_source() { + Some(Ok(parsed_source)) => { + if let Ok(references) = analysis::get_lint_references( + &parsed_source, + maybe_lint_config.as_ref(), + ) { + references + .into_iter() + .map(|r| r.to_diagnostic()) + .collect::<Vec<_>>() + } else { + Vec::new() + } + } + Some(Err(_)) => Vec::new(), + None => { + error!("Missing file contents for: {}", document.specifier()); Vec::new() } } - Some(Err(_)) => Vec::new(), - None => { - error!("Missing file contents for: {}", document.specifier()); - Vec::new() - } + } else { + Vec::new() }; diagnostics_vec.push(( document.specifier().clone(), |
