Skip to content

Commit 77ec34e

Browse files
333fredJoeRobich
andauthored
Make the sourceGeneratedDocumentProvider always lazy (#5340)
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]>
1 parent 93cb435 commit 77ec34e

File tree

2 files changed

+1
-39
lines changed

2 files changed

+1
-39
lines changed

src/features/definitionProvider.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,7 @@ export default class CSharpDefinitionProvider extends AbstractSupport implements
8787
locations.push(new Location(uri, vscodeRange));
8888
} else if (definition.SourceGeneratedFileInfo) {
8989
// File is source generated
90-
let uri = this.sourceGeneratedDocumentProvider.tryGetExistingSourceGeneratedFile(definition.SourceGeneratedFileInfo);
91-
if (!uri) {
92-
const sourceGeneratedFileResponse = await serverUtils.getSourceGeneratedFile(this._server, definition.SourceGeneratedFileInfo, token);
93-
94-
if (!sourceGeneratedFileResponse || !sourceGeneratedFileResponse.Source || !sourceGeneratedFileResponse.SourceName) {
95-
continue;
96-
}
97-
98-
uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFile(definition.SourceGeneratedFileInfo, sourceGeneratedFileResponse);
99-
}
100-
90+
let uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFileWithoutInitialContent(definition.SourceGeneratedFileInfo, definition.Location.FileName);
10191
locations.push(new Location(uri, toRange3(definition.Location.Range)));
10292
} else {
10393
// if it is a normal source definition, convert the response to a location

src/features/sourceGeneratedDocumentProvider.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,34 +110,6 @@ export default class SourceGeneratedDocumentProvider implements TextDocumentCont
110110
return uri;
111111
}
112112

113-
public addSourceGeneratedFile(fileInfo: SourceGeneratedFileInfo, response: SourceGeneratedFileResponse): Uri {
114-
if (this._documents.has(fileInfo)) {
115-
// Raced with something, return the existing one
116-
return this.tryGetExistingSourceGeneratedFile(fileInfo);
117-
}
118-
119-
const uri = this.getUriForName(response.SourceName);
120-
const uriString = uri.toString();
121-
122-
let triggerUpdate = false;
123-
124-
if (this._uriToDocumentInfo.has(uriString)) {
125-
// Old version of the file in the cache. Remove it, and after it's replaced trigger vscode to update the file.
126-
this._documents.delete(fileInfo);
127-
this._uriToDocumentInfo.delete(uriString);
128-
triggerUpdate = true;
129-
}
130-
131-
this._documents.set(fileInfo, response);
132-
this._uriToDocumentInfo.set(uriString, fileInfo);
133-
134-
if (triggerUpdate) {
135-
this._onDidChangeEmitter.fire(uri);
136-
}
137-
138-
return uri;
139-
}
140-
141113
public async provideTextDocumentContent(uri: Uri, token: CancellationToken): Promise<string> {
142114
const fileInfo = this._uriToDocumentInfo.get(uri.toString());
143115
let response = this._documents.get(fileInfo);

0 commit comments

Comments
 (0)