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

Support generated files in referenceProvider #5339

Merged
merged 1 commit into from
Aug 15, 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
22 changes: 19 additions & 3 deletions src/features/referenceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
import AbstractSupport from './abstractProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import {createRequest, toLocation} from '../omnisharp/typeConversion';
import {createRequest, toLocation, toLocationFromUri} from '../omnisharp/typeConversion';
import {ReferenceProvider, Location, TextDocument, CancellationToken, Position} from 'vscode';
import { OmniSharpServer } from '../omnisharp/server';
import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature';
import SourceGeneratedDocumentProvider from './sourceGeneratedDocumentProvider';

export default class OmnisharpReferenceProvider extends AbstractSupport implements ReferenceProvider {

public constructor(server: OmniSharpServer, languageMiddlewareFeature: LanguageMiddlewareFeature, private generatedDocumentProvider: SourceGeneratedDocumentProvider) {
super(server, languageMiddlewareFeature);
}

public async provideReferences(document: TextDocument, position: Position, options: { includeDeclaration: boolean;}, token: CancellationToken): Promise<Location[]> {

let req = createRequest<protocol.FindUsagesRequest>(document, position);
Expand All @@ -20,8 +27,8 @@ export default class OmnisharpReferenceProvider extends AbstractSupport implemen
try {
let res = await serverUtils.findUsages(this._server, req, token);
if (res && Array.isArray(res.QuickFixes)) {
const references = res.QuickFixes.map(toLocation);
const references = res.QuickFixes.map(l => this.mapToLocationWithGeneratedInfoPopulation(l));

// Allow language middlewares to re-map its edits if necessary.
const result = await this._languageMiddlewareFeature.remap("remapLocations", references, token);
return result;
Expand All @@ -31,4 +38,13 @@ export default class OmnisharpReferenceProvider extends AbstractSupport implemen
return [];
}
}

private mapToLocationWithGeneratedInfoPopulation(symbolLocation: protocol.SymbolLocation): Location {
if (symbolLocation.GeneratedFileInfo) {
const uri = this.generatedDocumentProvider.addSourceGeneratedFileWithoutInitialContent(symbolLocation.GeneratedFileInfo, symbolLocation.FileName);
return toLocationFromUri(uri, symbolLocation);
}

return toLocation(symbolLocation);
}
}
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
localDisposables.add(vscode.languages.registerCodeLensProvider(documentSelector, new CodeLensProvider(server, testManager, optionProvider, languageMiddlewareFeature)));
localDisposables.add(vscode.languages.registerDocumentHighlightProvider(documentSelector, new DocumentHighlightProvider(server, languageMiddlewareFeature)));
localDisposables.add(vscode.languages.registerDocumentSymbolProvider(documentSelector, new DocumentSymbolProvider(server, languageMiddlewareFeature)));
localDisposables.add(vscode.languages.registerReferenceProvider(documentSelector, new ReferenceProvider(server, languageMiddlewareFeature)));
localDisposables.add(vscode.languages.registerReferenceProvider(documentSelector, new ReferenceProvider(server, languageMiddlewareFeature, sourceGeneratedDocumentProvider)));
localDisposables.add(vscode.languages.registerHoverProvider(documentSelector, new HoverProvider(server, languageMiddlewareFeature)));
localDisposables.add(vscode.languages.registerRenameProvider(documentSelector, new RenameProvider(server, languageMiddlewareFeature)));
if (options.useFormatting) {
Expand Down
2 changes: 1 addition & 1 deletion src/omnisharp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function getFixAll(server: OmniSharpServer, request: protocol.GetFi
}

export async function findUsages(server: OmniSharpServer, request: protocol.FindUsagesRequest, token: vscode.CancellationToken) {
return server.makeRequest<protocol.QuickFixResponse>(protocol.Requests.FindUsages, request, token);
return server.makeRequest<protocol.FindSymbolsResponse>(protocol.Requests.FindUsages, request, token);
}

export async function formatAfterKeystroke(server: OmniSharpServer, request: protocol.FormatAfterKeystrokeRequest, token: vscode.CancellationToken) {
Expand Down