summaryrefslogtreecommitdiff
path: root/cli/tsc/99_main_compiler.js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-07-22 15:06:08 +0100
committerGitHub <noreply@github.com>2024-07-22 15:06:08 +0100
commit5a696551b78e0122b7d3e35eafc1b97aa6c119ed (patch)
treee7e2b9fe6e8665f87a580ef26079346b970c8f21 /cli/tsc/99_main_compiler.js
parent95847f4e9443ad8c8e0504c9fdd1d7f8eb4e588f (diff)
fix(lsp): scope attribution for asset documents (#24663)
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r--cli/tsc/99_main_compiler.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index 4fba5449f..75c6f8117 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -169,6 +169,10 @@ delete Object.prototype.__proto__;
const isCjsCache = new SpecifierIsCjsCache();
+ // Maps asset specifiers to the first scope that the asset was loaded into.
+ /** @type {Map<string, string | null>} */
+ const assetScopes = new Map();
+
/** @type {number | null} */
let projectVersionCache = null;
@@ -837,6 +841,9 @@ delete Object.prototype.__proto__;
}
const sourceFile = sourceFileCache.get(specifier);
if (sourceFile) {
+ if (!assetScopes.has(specifier)) {
+ assetScopes.set(specifier, lastRequestScope);
+ }
// This case only occurs for assets.
return ts.ScriptSnapshot.fromString(sourceFile.text);
}
@@ -1210,6 +1217,7 @@ delete Object.prototype.__proto__;
const newConfigsByScope = maybeChange[2];
if (newConfigsByScope) {
isNodeSourceFileCache.clear();
+ assetScopes.clear();
/** @type { typeof languageServiceEntries.byScope } */
const newByScope = new Map();
for (const [scope, config] of newConfigsByScope) {
@@ -1247,6 +1255,12 @@ delete Object.prototype.__proto__;
}
}
+ // For requests pertaining to an asset document, we make it so that the
+ // passed scope is just its own specifier. We map it to an actual scope here
+ // based on the first scope that the asset was loaded into.
+ if (scope?.startsWith(ASSETS_URL_PREFIX)) {
+ scope = assetScopes.get(scope) ?? null;
+ }
lastRequestMethod = method;
lastRequestScope = scope;
const ls = (scope ? languageServiceEntries.byScope.get(scope)?.ls : null) ??