From 3c346c8ea6aa888475c19d512ddd4c247c00b1ea Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Mon, 8 Apr 2024 19:45:20 +0100 Subject: [PATCH] perf(lsp): don't pass remote modules as tsc roots (#23259) --- cli/lsp/documents.rs | 7 +++++++ cli/lsp/tsc.rs | 4 +++- cli/tsc/99_main_compiler.js | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index fceb3fb4b8..6a4832eae3 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -1146,6 +1146,13 @@ impl Documents { } } + pub fn is_open(&self, specifier: &ModuleSpecifier) -> bool { + let Some(specifier) = self.resolve_specifier(specifier) else { + return false; + }; + self.open_docs.contains_key(&specifier) + } + /// Return a collection of documents that are contained in the document store /// based on the provided filter. pub fn documents(&self, filter: DocumentsFilter) -> Vec> { diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 9c27f3f217..923a0d4435 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -4064,7 +4064,9 @@ fn op_script_names(state: &mut OpState) -> Vec { if seen.insert(specifier.as_str()) { if let Some(specifier) = documents.resolve_specifier(specifier) { // only include dependencies we know to exist otherwise typescript will error - if documents.exists(&specifier) { + if documents.exists(&specifier) + && (specifier.scheme() == "file" || documents.is_open(&specifier)) + { result.push(specifier.to_string()); } } diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index bfac52ccea..3408b0f07d 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -550,7 +550,7 @@ delete Object.prototype.__proto__; ts.toPath( fileName, this.getCurrentDirectory(), - this.getCanonicalFileName(fileName), + this.getCanonicalFileName.bind(this), ); }, // @ts-ignore Undocumented method.