1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

perf(lsp): don't keep remote module ast's in memory (#23230)

This commit is contained in:
Nayeem Rahman 2024-04-04 23:39:17 +01:00 committed by GitHub
parent 5dda32088a
commit 7446b0163d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 15 deletions

View file

@ -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<lsp::Diagnostic> {
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<lsp::Diagnostic> {
if diagnostic_vec.is_empty() {
return vec![];
}
assert_eq!(diagnostic_vec.len(), 1);
diagnostic_vec
.into_iter()

View file

@ -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),
})))

View file

@ -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;
}