summaryrefslogtreecommitdiff
path: root/cli/tsc/99_main_compiler.js
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-07-27 07:40:12 +1000
committerGitHub <noreply@github.com>2021-07-27 07:40:12 +1000
commitc6f4e4152992ade2e31a96ba3244afe7b9fc0ab8 (patch)
treeaf5222b1aa4266647995f2c6d6d3c593f9d80300 /cli/tsc/99_main_compiler.js
parent091a26104b9ef7435a1bb36e8fc814196a2cb173 (diff)
refactor(lsp): minor improvements to handling closed documents (#11518)
Ref #10897
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r--cli/tsc/99_main_compiler.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index a2f3af176..f5cfe38dd 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -75,6 +75,9 @@ delete Object.prototype.__proto__;
/** @type {Map<string, ts.SourceFile>} */
const sourceFileCache = new Map();
+ /** @type {string[]=} */
+ let scriptFileNamesCache;
+
/** @type {Map<string, string>} */
const scriptVersionCache = new Map();
@@ -370,7 +373,12 @@ delete Object.prototype.__proto__;
},
getScriptFileNames() {
debug("host.getScriptFileNames()");
- return core.opSync("op_script_names", undefined);
+ // tsc requests the script file names multiple times even though it can't
+ // possibly have changed, so we will memoize it on a per request basis.
+ if (scriptFileNamesCache) {
+ return scriptFileNamesCache;
+ }
+ return scriptFileNamesCache = core.opSync("op_script_names", undefined);
},
getScriptVersion(specifier) {
debug(`host.getScriptVersion("${specifier}")`);
@@ -378,9 +386,8 @@ delete Object.prototype.__proto__;
if (sourceFile) {
return sourceFile.version ?? "1";
}
- // tsc neurotically requests the script version multiple times even though
- // it can't possibly have changed, so we will memoize it on a per request
- // basis.
+ // tsc requests the script version multiple times even though it can't
+ // possibly have changed, so we will memoize it on a per request basis.
if (scriptVersionCache.has(specifier)) {
return scriptVersionCache.get(specifier);
}
@@ -543,6 +550,8 @@ delete Object.prototype.__proto__;
*/
function serverRequest({ id, ...request }) {
debug(`serverRequest()`, { id, ...request });
+ // reset all memoized source files names
+ scriptFileNamesCache = undefined;
// evict all memoized source file versions
scriptVersionCache.clear();
switch (request.method) {