mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
refactor(lsp): memoize script versions per tsc request (#10601)
This commit is contained in:
parent
afaac64737
commit
3318c495f6
1 changed files with 15 additions and 3 deletions
|
@ -72,6 +72,9 @@ delete Object.prototype.__proto__;
|
||||||
/** @type {Map<string, ts.SourceFile>} */
|
/** @type {Map<string, ts.SourceFile>} */
|
||||||
const sourceFileCache = new Map();
|
const sourceFileCache = new Map();
|
||||||
|
|
||||||
|
/** @type {Map<string, string>} */
|
||||||
|
const scriptVersionCache = new Map();
|
||||||
|
|
||||||
/** @param {ts.DiagnosticRelatedInformation} diagnostic */
|
/** @param {ts.DiagnosticRelatedInformation} diagnostic */
|
||||||
function fromRelatedInformation({
|
function fromRelatedInformation({
|
||||||
start,
|
start,
|
||||||
|
@ -368,7 +371,15 @@ delete Object.prototype.__proto__;
|
||||||
if (sourceFile) {
|
if (sourceFile) {
|
||||||
return sourceFile.version ?? "1";
|
return sourceFile.version ?? "1";
|
||||||
}
|
}
|
||||||
return core.opSync("op_script_version", { specifier });
|
// 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.
|
||||||
|
if (scriptVersionCache.has(specifier)) {
|
||||||
|
return scriptVersionCache.get(specifier);
|
||||||
|
}
|
||||||
|
const scriptVersion = core.opSync("op_script_version", { specifier });
|
||||||
|
scriptVersionCache.set(specifier, scriptVersion);
|
||||||
|
return scriptVersion;
|
||||||
},
|
},
|
||||||
getScriptSnapshot(specifier) {
|
getScriptSnapshot(specifier) {
|
||||||
debug(`host.getScriptSnapshot("${specifier}")`);
|
debug(`host.getScriptSnapshot("${specifier}")`);
|
||||||
|
@ -386,8 +397,7 @@ delete Object.prototype.__proto__;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/** @type {string | undefined} */
|
const version = host.getScriptVersion(specifier);
|
||||||
const version = core.opSync("op_script_version", { specifier });
|
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
return new ScriptSnapshot(specifier, version);
|
return new ScriptSnapshot(specifier, version);
|
||||||
}
|
}
|
||||||
|
@ -526,6 +536,8 @@ delete Object.prototype.__proto__;
|
||||||
*/
|
*/
|
||||||
function serverRequest({ id, ...request }) {
|
function serverRequest({ id, ...request }) {
|
||||||
debug(`serverRequest()`, { id, ...request });
|
debug(`serverRequest()`, { id, ...request });
|
||||||
|
// evict all memoized source file versions
|
||||||
|
scriptVersionCache.clear();
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case "configure": {
|
case "configure": {
|
||||||
const { options, errors } = ts
|
const { options, errors } = ts
|
||||||
|
|
Loading…
Reference in a new issue