Cache some LS calls in fourslash (#19517)
* Cache some LS calls in fourslash * Add comment
This commit is contained in:
parent
7dfd6c7e20
commit
7e1e7a711a
1 changed files with 34 additions and 1 deletions
|
@ -314,7 +314,7 @@ namespace FourSlash {
|
||||||
|
|
||||||
const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions);
|
const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions);
|
||||||
this.languageServiceAdapterHost = languageServiceAdapter.getHost();
|
this.languageServiceAdapterHost = languageServiceAdapter.getHost();
|
||||||
this.languageService = languageServiceAdapter.getLanguageService();
|
this.languageService = memoWrap(languageServiceAdapter.getLanguageService(), this); // Wrap the LS to cache some expensive operations certain tests call repeatedly
|
||||||
|
|
||||||
if (startResolveFileRef) {
|
if (startResolveFileRef) {
|
||||||
// Add the entry-point file itself into the languageServiceShimHost
|
// Add the entry-point file itself into the languageServiceShimHost
|
||||||
|
@ -381,6 +381,39 @@ namespace FourSlash {
|
||||||
|
|
||||||
// Open the first file by default
|
// Open the first file by default
|
||||||
this.openFile(0);
|
this.openFile(0);
|
||||||
|
|
||||||
|
function memoWrap(ls: ts.LanguageService, target: TestState): ts.LanguageService {
|
||||||
|
const cacheableMembers: (keyof typeof ls)[] = [
|
||||||
|
"getCompletionsAtPosition",
|
||||||
|
"getCompletionEntryDetails",
|
||||||
|
"getCompletionEntrySymbol",
|
||||||
|
"getQuickInfoAtPosition",
|
||||||
|
"getSignatureHelpItems",
|
||||||
|
"getReferencesAtPosition",
|
||||||
|
"getDocumentHighlights",
|
||||||
|
];
|
||||||
|
const proxy = {} as ts.LanguageService;
|
||||||
|
for (const k in ls) {
|
||||||
|
const key = k as keyof typeof ls;
|
||||||
|
if (cacheableMembers.indexOf(key) === -1) {
|
||||||
|
proxy[key] = (...args: any[]) => (ls[key] as Function)(...args);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const memo = Utils.memoize(
|
||||||
|
(_version: number, _active: string, _caret: number, _selectEnd: number, _marker: string, ...args: any[]) => (ls[key] as Function)(...args),
|
||||||
|
(...args) => args.join("|,|")
|
||||||
|
);
|
||||||
|
proxy[key] = (...args: any[]) => memo(
|
||||||
|
target.languageServiceAdapterHost.getScriptInfo(target.activeFile.fileName).version,
|
||||||
|
target.activeFile.fileName,
|
||||||
|
target.currentCaretPosition,
|
||||||
|
target.selectionEnd,
|
||||||
|
target.lastKnownMarker,
|
||||||
|
...args
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFileContent(fileName: string): string {
|
private getFileContent(fileName: string): string {
|
||||||
|
|
Loading…
Reference in a new issue