mirror of
https://github.com/denoland/deno
synced 2024-08-28 12:29:31 +00:00
perf(lsp): don't keep remote module ast's in memory (#23230)
This commit is contained in:
parent
5dda32088a
commit
7446b0163d
|
@ -792,8 +792,14 @@ fn generate_lint_diagnostics(
|
||||||
let config_data_by_scope = config.tree.data_by_scope();
|
let config_data_by_scope = config.tree.data_by_scope();
|
||||||
let mut diagnostics_vec = Vec::new();
|
let mut diagnostics_vec = Vec::new();
|
||||||
for document in documents {
|
for document in documents {
|
||||||
let settings =
|
let specifier = document.specifier();
|
||||||
config.workspace_settings_for_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 {
|
if !settings.lint {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -803,26 +809,25 @@ fn generate_lint_diagnostics(
|
||||||
}
|
}
|
||||||
// ignore any npm package files
|
// ignore any npm package files
|
||||||
if let Some(npm) = &snapshot.npm {
|
if let Some(npm) = &snapshot.npm {
|
||||||
if npm.node_resolver.in_npm_package(document.specifier()) {
|
if npm.node_resolver.in_npm_package(specifier) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let version = document.maybe_lsp_version();
|
let version = document.maybe_lsp_version();
|
||||||
let (lint_options, lint_rules) = config
|
let (lint_options, lint_rules) = config
|
||||||
.tree
|
.tree
|
||||||
.scope_for_specifier(document.specifier())
|
.scope_for_specifier(specifier)
|
||||||
.and_then(|s| config_data_by_scope.get(s))
|
.and_then(|s| config_data_by_scope.get(s))
|
||||||
.map(|d| (d.lint_options.clone(), d.lint_rules.clone()))
|
.map(|d| (d.lint_options.clone(), d.lint_rules.clone()))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
diagnostics_vec.push(DiagnosticRecord {
|
diagnostics_vec.push(DiagnosticRecord {
|
||||||
specifier: document.specifier().clone(),
|
specifier: specifier.clone(),
|
||||||
versioned: VersionedDiagnostics {
|
versioned: VersionedDiagnostics {
|
||||||
version,
|
version,
|
||||||
diagnostics: generate_document_lint_diagnostics(
|
diagnostics: generate_document_lint_diagnostics(
|
||||||
config,
|
&document,
|
||||||
&lint_options,
|
&lint_options,
|
||||||
lint_rules.rules.clone(),
|
lint_rules.rules.clone(),
|
||||||
&document,
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -831,14 +836,10 @@ fn generate_lint_diagnostics(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_document_lint_diagnostics(
|
fn generate_document_lint_diagnostics(
|
||||||
config: &ConfigSnapshot,
|
document: &Document,
|
||||||
lint_options: &LintOptions,
|
lint_options: &LintOptions,
|
||||||
lint_rules: Vec<&'static dyn LintRule>,
|
lint_rules: Vec<&'static dyn LintRule>,
|
||||||
document: &Document,
|
|
||||||
) -> Vec<lsp::Diagnostic> {
|
) -> Vec<lsp::Diagnostic> {
|
||||||
if !config.specifier_enabled(document.specifier()) {
|
|
||||||
return Vec::new();
|
|
||||||
}
|
|
||||||
if !lint_options.files.matches_specifier(document.specifier()) {
|
if !lint_options.files.matches_specifier(document.specifier()) {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
@ -1753,6 +1754,9 @@ let c: number = "a";
|
||||||
fn get_diagnostics_for_single(
|
fn get_diagnostics_for_single(
|
||||||
diagnostic_vec: DiagnosticVec,
|
diagnostic_vec: DiagnosticVec,
|
||||||
) -> Vec<lsp::Diagnostic> {
|
) -> Vec<lsp::Diagnostic> {
|
||||||
|
if diagnostic_vec.is_empty() {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
assert_eq!(diagnostic_vec.len(), 1);
|
assert_eq!(diagnostic_vec.len(), 1);
|
||||||
diagnostic_vec
|
diagnostic_vec
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -327,7 +327,8 @@ impl Document {
|
||||||
maybe_lsp_version: None,
|
maybe_lsp_version: None,
|
||||||
maybe_module,
|
maybe_module,
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
maybe_parsed_source,
|
maybe_parsed_source: maybe_parsed_source
|
||||||
|
.filter(|_| specifier.scheme() == "file"),
|
||||||
text_info,
|
text_info,
|
||||||
specifier,
|
specifier,
|
||||||
}))
|
}))
|
||||||
|
@ -403,7 +404,8 @@ impl Document {
|
||||||
maybe_headers: maybe_headers.map(ToOwned::to_owned),
|
maybe_headers: maybe_headers.map(ToOwned::to_owned),
|
||||||
maybe_module,
|
maybe_module,
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
maybe_parsed_source,
|
maybe_parsed_source: maybe_parsed_source
|
||||||
|
.filter(|_| specifier.scheme() == "file"),
|
||||||
text_info,
|
text_info,
|
||||||
specifier,
|
specifier,
|
||||||
}))
|
}))
|
||||||
|
@ -474,7 +476,8 @@ impl Document {
|
||||||
line_index,
|
line_index,
|
||||||
maybe_headers: self.0.maybe_headers.clone(),
|
maybe_headers: self.0.maybe_headers.clone(),
|
||||||
maybe_module,
|
maybe_module,
|
||||||
maybe_parsed_source,
|
maybe_parsed_source: maybe_parsed_source
|
||||||
|
.filter(|_| self.0.specifier.scheme() == "file"),
|
||||||
maybe_lsp_version: Some(version),
|
maybe_lsp_version: Some(version),
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
})))
|
})))
|
||||||
|
|
|
@ -98,6 +98,9 @@ impl TestServer {
|
||||||
.documents(DocumentsFilter::AllDiagnosable)
|
.documents(DocumentsFilter::AllDiagnosable)
|
||||||
{
|
{
|
||||||
let specifier = document.specifier();
|
let specifier = document.specifier();
|
||||||
|
if specifier.scheme() != "file" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if !snapshot.config.specifier_enabled_for_test(specifier) {
|
if !snapshot.config.specifier_enabled_for_test(specifier) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue