mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
perf(lsp): fix redundant serialization of sources (#21435)
This commit is contained in:
parent
f29075ae4c
commit
0f990d9d92
1 changed files with 23 additions and 27 deletions
|
@ -555,9 +555,13 @@ delete Object.prototype.__proto__;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; }} */
|
/** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; }} */
|
||||||
const { data, scriptKind, version } = ops.op_load(
|
const fileInfo = ops.op_load(
|
||||||
{ specifier },
|
{ specifier },
|
||||||
);
|
);
|
||||||
|
if (!fileInfo) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const { data, scriptKind, version } = fileInfo;
|
||||||
assert(
|
assert(
|
||||||
data != null,
|
data != null,
|
||||||
`"data" is unexpectedly null for "${specifier}".`,
|
`"data" is unexpectedly null for "${specifier}".`,
|
||||||
|
@ -713,10 +717,6 @@ delete Object.prototype.__proto__;
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
debug(`host.getScriptVersion("${specifier}")`);
|
debug(`host.getScriptVersion("${specifier}")`);
|
||||||
}
|
}
|
||||||
const sourceFile = sourceFileCache.get(specifier);
|
|
||||||
if (sourceFile) {
|
|
||||||
return sourceFile.version ?? "1";
|
|
||||||
}
|
|
||||||
// tsc requests the script version multiple times even though it can't
|
// 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.
|
// possibly have changed, so we will memoize it on a per request basis.
|
||||||
if (scriptVersionCache.has(specifier)) {
|
if (scriptVersionCache.has(specifier)) {
|
||||||
|
@ -730,30 +730,26 @@ delete Object.prototype.__proto__;
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
debug(`host.getScriptSnapshot("${specifier}")`);
|
debug(`host.getScriptSnapshot("${specifier}")`);
|
||||||
}
|
}
|
||||||
const sourceFile = sourceFileCache.get(specifier);
|
let sourceFile = sourceFileCache.get(specifier);
|
||||||
|
if (
|
||||||
|
!specifier.startsWith(ASSETS_URL_PREFIX) &&
|
||||||
|
sourceFile?.version != this.getScriptVersion(specifier)
|
||||||
|
) {
|
||||||
|
sourceFileCache.delete(specifier);
|
||||||
|
sourceFile = undefined;
|
||||||
|
}
|
||||||
|
if (!sourceFile) {
|
||||||
|
sourceFile = this.getSourceFile(
|
||||||
|
specifier,
|
||||||
|
specifier.endsWith(".json")
|
||||||
|
? ts.ScriptTarget.JSON
|
||||||
|
: ts.ScriptTarget.ESNext,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (sourceFile) {
|
if (sourceFile) {
|
||||||
return {
|
return ts.ScriptSnapshot.fromString(sourceFile.text);
|
||||||
getText(start, end) {
|
|
||||||
return sourceFile.text.substring(start, end);
|
|
||||||
},
|
|
||||||
getLength() {
|
|
||||||
return sourceFile.text.length;
|
|
||||||
},
|
|
||||||
getChangeRange() {
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileInfo = ops.op_load(
|
|
||||||
{ specifier },
|
|
||||||
);
|
|
||||||
if (fileInfo) {
|
|
||||||
scriptVersionCache.set(specifier, fileInfo.version);
|
|
||||||
return ts.ScriptSnapshot.fromString(fileInfo.data);
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue