diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index ac1f522d75..b5f079b049 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -792,8 +792,14 @@ fn generate_lint_diagnostics( let config_data_by_scope = config.tree.data_by_scope(); let mut diagnostics_vec = Vec::new(); for document in documents { - let settings = - config.workspace_settings_for_specifier(document.specifier()); + let specifier = document.specifier(); + if specifier.scheme() != "file" { + continue; + } + if !config.specifier_enabled(specifier) { + continue; + } + let settings = config.workspace_settings_for_specifier(specifier); if !settings.lint { continue; } @@ -803,26 +809,25 @@ fn generate_lint_diagnostics( } // ignore any npm package files if let Some(npm) = &snapshot.npm { - if npm.node_resolver.in_npm_package(document.specifier()) { + if npm.node_resolver.in_npm_package(specifier) { continue; } } let version = document.maybe_lsp_version(); let (lint_options, lint_rules) = config .tree - .scope_for_specifier(document.specifier()) + .scope_for_specifier(specifier) .and_then(|s| config_data_by_scope.get(s)) .map(|d| (d.lint_options.clone(), d.lint_rules.clone())) .unwrap_or_default(); diagnostics_vec.push(DiagnosticRecord { - specifier: document.specifier().clone(), + specifier: specifier.clone(), versioned: VersionedDiagnostics { version, diagnostics: generate_document_lint_diagnostics( - config, + &document, &lint_options, lint_rules.rules.clone(), - &document, ), }, }); @@ -831,14 +836,10 @@ fn generate_lint_diagnostics( } fn generate_document_lint_diagnostics( - config: &ConfigSnapshot, + document: &Document, lint_options: &LintOptions, lint_rules: Vec<&'static dyn LintRule>, - document: &Document, ) -> Vec { - if !config.specifier_enabled(document.specifier()) { - return Vec::new(); - } if !lint_options.files.matches_specifier(document.specifier()) { return Vec::new(); } @@ -1753,6 +1754,9 @@ let c: number = "a"; fn get_diagnostics_for_single( diagnostic_vec: DiagnosticVec, ) -> Vec { + if diagnostic_vec.is_empty() { + return vec![]; + } assert_eq!(diagnostic_vec.len(), 1); diagnostic_vec .into_iter() diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 0e9b6c3c30..7641529385 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -327,7 +327,8 @@ impl Document { maybe_lsp_version: None, maybe_module, maybe_navigation_tree: Mutex::new(None), - maybe_parsed_source, + maybe_parsed_source: maybe_parsed_source + .filter(|_| specifier.scheme() == "file"), text_info, specifier, })) @@ -403,7 +404,8 @@ impl Document { maybe_headers: maybe_headers.map(ToOwned::to_owned), maybe_module, maybe_navigation_tree: Mutex::new(None), - maybe_parsed_source, + maybe_parsed_source: maybe_parsed_source + .filter(|_| specifier.scheme() == "file"), text_info, specifier, })) @@ -474,7 +476,8 @@ impl Document { line_index, maybe_headers: self.0.maybe_headers.clone(), maybe_module, - maybe_parsed_source, + maybe_parsed_source: maybe_parsed_source + .filter(|_| self.0.specifier.scheme() == "file"), maybe_lsp_version: Some(version), maybe_navigation_tree: Mutex::new(None), }))) diff --git a/cli/lsp/testing/server.rs b/cli/lsp/testing/server.rs index 1049c4dc2b..bdf2380786 100644 --- a/cli/lsp/testing/server.rs +++ b/cli/lsp/testing/server.rs @@ -98,6 +98,9 @@ impl TestServer { .documents(DocumentsFilter::AllDiagnosable) { let specifier = document.specifier(); + if specifier.scheme() != "file" { + continue; + } if !snapshot.config.specifier_enabled_for_test(specifier) { continue; }