From 891919f1562d8db228f4ff7abda04f1ab81c1e78 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Sat, 13 Aug 2022 15:31:31 -0700 Subject: [PATCH] Make the sourceGeneratedDocumentProvider always lazy GoToDefinition might not immediately go to the document definition for any given location if there are multiple locations (common for source generated symbols), so we shouldn't immediately resolve the generated document during handling of the GoToDefintion response. Instead, only retrieve the file content when the user actually tries to display the file. --- src/features/definitionProvider.ts | 12 +------- .../sourceGeneratedDocumentProvider.ts | 28 ------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/features/definitionProvider.ts b/src/features/definitionProvider.ts index 1d8e84256..3982995fb 100644 --- a/src/features/definitionProvider.ts +++ b/src/features/definitionProvider.ts @@ -87,17 +87,7 @@ export default class CSharpDefinitionProvider extends AbstractSupport implements locations.push(new Location(uri, vscodeRange)); } else if (definition.SourceGeneratedFileInfo) { // File is source generated - let uri = this.sourceGeneratedDocumentProvider.tryGetExistingSourceGeneratedFile(definition.SourceGeneratedFileInfo); - if (!uri) { - const sourceGeneratedFileResponse = await serverUtils.getSourceGeneratedFile(this._server, definition.SourceGeneratedFileInfo, token); - - if (!sourceGeneratedFileResponse || !sourceGeneratedFileResponse.Source || !sourceGeneratedFileResponse.SourceName) { - continue; - } - - uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFile(definition.SourceGeneratedFileInfo, sourceGeneratedFileResponse); - } - + let uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFileWithoutInitialContent(definition.SourceGeneratedFileInfo, definition.Location.FileName); locations.push(new Location(uri, toRange3(definition.Location.Range))); } else { // if it is a normal source definition, convert the response to a location diff --git a/src/features/sourceGeneratedDocumentProvider.ts b/src/features/sourceGeneratedDocumentProvider.ts index e5e187940..52d77f1db 100644 --- a/src/features/sourceGeneratedDocumentProvider.ts +++ b/src/features/sourceGeneratedDocumentProvider.ts @@ -110,34 +110,6 @@ export default class SourceGeneratedDocumentProvider implements TextDocumentCont return uri; } - public addSourceGeneratedFile(fileInfo: SourceGeneratedFileInfo, response: SourceGeneratedFileResponse): Uri { - if (this._documents.has(fileInfo)) { - // Raced with something, return the existing one - return this.tryGetExistingSourceGeneratedFile(fileInfo); - } - - const uri = this.getUriForName(response.SourceName); - const uriString = uri.toString(); - - let triggerUpdate = false; - - if (this._uriToDocumentInfo.has(uriString)) { - // Old version of the file in the cache. Remove it, and after it's replaced trigger vscode to update the file. - this._documents.delete(fileInfo); - this._uriToDocumentInfo.delete(uriString); - triggerUpdate = true; - } - - this._documents.set(fileInfo, response); - this._uriToDocumentInfo.set(uriString, fileInfo); - - if (triggerUpdate) { - this._onDidChangeEmitter.fire(uri); - } - - return uri; - } - public async provideTextDocumentContent(uri: Uri, token: CancellationToken): Promise { const fileInfo = this._uriToDocumentInfo.get(uri.toString()); let response = this._documents.get(fileInfo);