Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the sourceGeneratedDocumentProvider always lazy #5340

Merged
merged 2 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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