Skip to content

Commit

Permalink
Make the sourceGeneratedDocumentProvider always lazy (#5340)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Joey Robichaud <[email protected]>
  • Loading branch information
333fred and JoeRobich authored Aug 20, 2022
1 parent 93cb435 commit 77ec34e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
12 changes: 1 addition & 11 deletions src/features/definitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 0 additions & 28 deletions src/features/sourceGeneratedDocumentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const fileInfo = this._uriToDocumentInfo.get(uri.toString());
let response = this._documents.get(fileInfo);
Expand Down

0 comments on commit 77ec34e

Please sign in to comment.