summaryrefslogtreecommitdiff
path: root/cli/lsp/tsc.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-05-16 22:12:25 +0100
committerGitHub <noreply@github.com>2024-05-16 22:12:25 +0100
commitf8956eb763159f325d5cb0d4c4281d2e640e2e71 (patch)
tree740ee2ddd33a48c96be30ddf04e99265606d073d /cli/lsp/tsc.rs
parent7893ab9f0bb406081723ce80829d3ad6303da162 (diff)
fix(lsp): respect types dependencies for tsc roots (#23825)
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r--cli/lsp/tsc.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 6999b40ef..b41a8fb19 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -67,6 +67,7 @@ use regex::Captures;
use regex::Regex;
use serde_repr::Deserialize_repr;
use serde_repr::Serialize_repr;
+use std::borrow::Cow;
use std::cell::RefCell;
use std::cmp;
use std::collections::HashMap;
@@ -4261,12 +4262,12 @@ fn op_script_names(state: &mut OpState) -> Vec<String> {
// ensure this is first so it resolves the node types first
let specifier = "asset:///node_types.d.ts";
result.push(specifier.to_string());
- seen.insert(specifier);
+ seen.insert(Cow::Borrowed(specifier));
}
// inject these next because they're global
for specifier in state.state_snapshot.resolver.graph_import_specifiers() {
- if seen.insert(specifier.as_str()) {
+ if seen.insert(Cow::Borrowed(specifier.as_str())) {
result.push(specifier.to_string());
}
}
@@ -4278,10 +4279,27 @@ fn op_script_names(state: &mut OpState) -> Vec<String> {
.documents(DocumentsFilter::AllDiagnosable);
for doc in &docs {
let specifier = doc.specifier();
- if seen.insert(specifier.as_str())
- && (doc.is_open() || specifier.scheme() == "file")
+ let is_open = doc.is_open();
+ if seen.insert(Cow::Borrowed(specifier.as_str()))
+ && (is_open || specifier.scheme() == "file")
{
- result.push(specifier.to_string());
+ let types_specifier = (|| {
+ let documents = &state.state_snapshot.documents;
+ let types = doc.maybe_types_dependency().maybe_specifier()?;
+ let (types, _) = documents.resolve_dependency(types, specifier)?;
+ let types_doc = documents.get(&types)?;
+ Some(types_doc.specifier().clone())
+ })();
+ // If there is a types dep, use that as the root instead. But if the doc
+ // is open, include both as roots.
+ if let Some(types_specifier) = &types_specifier {
+ if seen.insert(Cow::Owned(types_specifier.to_string())) {
+ result.push(types_specifier.to_string());
+ }
+ }
+ if types_specifier.is_none() || is_open {
+ result.push(specifier.to_string());
+ }
}
}