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 go to definition from metadata #1620

Merged
merged 2 commits into from
Jul 7, 2017
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
6 changes: 3 additions & 3 deletions src/features/definitionMetadataDocumentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { workspace, Uri, TextDocument, Disposable, TextDocumentContentProvider}
import { MetadataResponse } from '../omnisharp/protocol';

export default class DefinitionMetadataDocumentProvider implements TextDocumentContentProvider, Disposable {
private _scheme = "omnisharp-metadata";
readonly scheme = "omnisharp-metadata";
private _registration : Disposable;
private _documents: Map<string, MetadataResponse>;
private _documentClosedSubscription: Disposable;
Expand Down Expand Up @@ -31,15 +31,15 @@ export default class DefinitionMetadataDocumentProvider implements TextDocumentC
}

public register() : void {
this._registration = workspace.registerTextDocumentContentProvider(this._scheme, this);
this._registration = workspace.registerTextDocumentContentProvider(this.scheme, this);
}

public provideTextDocumentContent(uri : Uri) : string {
return this._documents.get(uri.toString()).Source;
}

private createUri(metadataResponse: MetadataResponse) : Uri {
return Uri.parse(this._scheme + "://" +
return Uri.parse(this.scheme + "://" +
metadataResponse.SourceName.replace(/\\/g, "/")
.replace(/(.*)\/(.*)/g, "$1/[metadata] $2"));
}
Expand Down
4 changes: 3 additions & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe
definitionMetadataDocumentProvider.register();
localDisposables.push(definitionMetadataDocumentProvider);

localDisposables.push(vscode.languages.registerDefinitionProvider(documentSelector, new DefinitionProvider(server, definitionMetadataDocumentProvider)));
const definitionProvider = new DefinitionProvider(server, definitionMetadataDocumentProvider);
localDisposables.push(vscode.languages.registerDefinitionProvider(documentSelector, definitionProvider));
localDisposables.push(vscode.languages.registerDefinitionProvider({ scheme: definitionMetadataDocumentProvider.scheme }, definitionProvider));
localDisposables.push(vscode.languages.registerImplementationProvider(documentSelector, new ImplementationProvider(server)));
localDisposables.push(vscode.languages.registerCodeLensProvider(documentSelector, new CodeLensProvider(server)));
localDisposables.push(vscode.languages.registerDocumentHighlightProvider(documentSelector, new DocumentHighlightProvider(server)));
Expand Down
8 changes: 7 additions & 1 deletion src/omnisharp/typeConvertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ export function createRequest<T extends protocol.Request>(document: vscode.TextD
Column = where.start.character + 1;
}

// for metadata sources, we need to remove the [metadata] from the filename, and prepend the $metadata$ authority
// this is expected by the Omnisharp server to support metadata-to-metadata navigation
let fileName = document.uri.scheme === "omnisharp-metadata" ?
`${document.uri.authority}${document.fileName.replace("[metadata] ", "")}` :
document.fileName;

let request: protocol.Request = {
FileName: document.fileName,
FileName: fileName,
Buffer: includeBuffer ? document.getText() : undefined,
Line,
Column
Expand Down