diff options
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r-- | cli/lsp/diagnostics.rs | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 6ce28f440..9bf45c5ae 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -8,6 +8,7 @@ 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; @@ -301,68 +302,46 @@ fn ts_json_to_diagnostics( .collect() } -// Returns `ConfigSnapshot::root_uri` in the correct format. -fn get_root_specifier( - snapshot: &language_server::StateSnapshot, -) -> Option<ModuleSpecifier> { - let root = snapshot.config.root_uri.as_ref()?; - let root = root.to_file_path().ok()?; - - // FIXME: `root_uri` from `ConfigSnapshot` are without a trailing slash, - // so `Url::join` treats the root as a file, not a directory, and erases the folder name. - // To fix that behaviour we just parsing `root_uri` again. - ModuleSpecifier::from_directory_path(root).ok() -} - // 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_documents( +fn filter_lint_documents( snapshot: &language_server::StateSnapshot, documents: &mut Vec<Document>, ) { - let root_uri = match get_root_specifier(snapshot) { - Some(uri) => uri, - None => return, - }; - - let linter_config = match &snapshot.maybe_lint_config { + let lint_config = match &snapshot.maybe_lint_config { Some(config) => config, None => return, }; - let join_specifiers = |specifiers: &Vec<String>| -> Vec<ModuleSpecifier> { - specifiers - .iter() - .filter_map(|i| root_uri.join(i).ok()) - .collect() - }; - - let ignore_specifiers = join_specifiers(&linter_config.files.exclude); - let include_specifiers = join_specifiers(&linter_config.files.include); - documents.retain(|doc| { - let path = doc.specifier().path(); + 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 ignore_specifiers.iter().any(|i| path.starts_with(i.path())) { + if lint_config + .files + .exclude + .iter() + .any(|i| path.starts_with(i)) + { return false; } // Early return if the include list is empty. - if include_specifiers.is_empty() { + if lint_config.files.include.is_empty() { return true; } - // Ignore files which is not in the include list. - if !include_specifiers + // Ignore files not in the include list. + lint_config + .files + .include .iter() - .any(|i| path.starts_with(i.path())) - { - return false; - } - - true + .any(|i| path.starts_with(i)) }); } @@ -374,7 +353,7 @@ async fn generate_lint_diagnostics( let workspace_settings = snapshot.config.settings.workspace.clone(); let maybe_lint_config = snapshot.maybe_lint_config.clone(); - filter_documents(snapshot, &mut documents); + filter_lint_documents(snapshot, &mut documents); tokio::task::spawn(async move { let mut diagnostics_vec = Vec::new(); |