-
Notifications
You must be signed in to change notification settings - Fork 686
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
Fix "go to definition" from metadata within the same metadata file #1772
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,16 @@ export default class DefinitionMetadataDocumentProvider implements TextDocumentC | |
} | ||
|
||
public addMetadataResponse(metadataResponse: MetadataResponse) : Uri { | ||
const uri = this.createUri(metadataResponse); | ||
|
||
const uri = this.createUri(metadataResponse.SourceName); | ||
this._documents.set(uri.toString(), metadataResponse); | ||
|
||
return uri; | ||
} | ||
|
||
public getExistingMetadataResponseUri(sourceName:string) : Uri { | ||
return this.createUri(sourceName); | ||
} | ||
|
||
public register() : void { | ||
this._registration = workspace.registerTextDocumentContentProvider(this.scheme, this); | ||
} | ||
|
@@ -38,9 +41,8 @@ export default class DefinitionMetadataDocumentProvider implements TextDocumentC | |
return this._documents.get(uri.toString()).Source; | ||
} | ||
|
||
private createUri(metadataResponse: MetadataResponse) : Uri { | ||
private createUri(sourceName:string) : Uri { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space after |
||
return Uri.parse(this.scheme + "://" + | ||
metadataResponse.SourceName.replace(/\\/g, "/") | ||
.replace(/(.*)\/(.*)/g, "$1/[metadata] $2")); | ||
sourceName.replace(/\\/g, "/").replace(/(.*)\/(.*)/g, "$1/[metadata] $2")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import AbstractSupport from './abstractProvider'; | ||
import {MetadataRequest, GoToDefinitionRequest, MetadataSource} from '../omnisharp/protocol'; | ||
import * as serverUtils from '../omnisharp/utils'; | ||
import {createRequest, toLocation} from '../omnisharp/typeConvertion'; | ||
import {createRequest, toLocation, toLocationFromUri} from '../omnisharp/typeConvertion'; | ||
import {Uri, TextDocument, Position, Location, CancellationToken, DefinitionProvider} from 'vscode'; | ||
import DefinitionMetadataDocumentProvider from './definitionMetadataDocumentProvider'; | ||
import TelemetryReporter from 'vscode-extension-telemetry'; | ||
|
@@ -29,11 +29,23 @@ export default class CSharpDefinitionProvider extends AbstractSupport implements | |
|
||
return serverUtils.goToDefinition(this._server, req, token).then(gotoDefinitionResponse => { | ||
|
||
// the defintion is in source | ||
if (gotoDefinitionResponse && gotoDefinitionResponse.FileName) { | ||
|
||
// if it is part of an already used metadata file, retrieve its uri instead of going to the physical file | ||
if (gotoDefinitionResponse.FileName.startsWith("$metadata$")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add something to the OmniSharp response to indicate that the result is in metadata, rather than checking the file name. Not a blocking a issue, but I wanted to capture it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes I agree, good point |
||
let uri = this._definitionMetadataDocumentProvider.getExistingMetadataResponseUri(gotoDefinitionResponse.FileName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
return toLocationFromUri(uri, gotoDefinitionResponse); | ||
} | ||
|
||
// if it is a normal source definition, convert the response to a location | ||
return toLocation(gotoDefinitionResponse); | ||
|
||
// the definition is in metadata | ||
} else if (gotoDefinitionResponse.MetadataSource) { | ||
const metadataSource: MetadataSource = gotoDefinitionResponse.MetadataSource; | ||
|
||
// go to metadata endpoint for more information | ||
return serverUtils.getMetadata(this._server, <MetadataRequest> { | ||
Timeout: 5000, | ||
AssemblyName: metadataSource.AssemblyName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,21 @@ import * as vscode from 'vscode'; | |
|
||
export function toLocation(location: protocol.ResourceLocation | protocol.QuickFix): vscode.Location { | ||
const fileName = vscode.Uri.file(location.FileName); | ||
return toLocationFromUri(fileName, location); | ||
} | ||
|
||
export function toLocationFromUri(uri:vscode.Uri, location: protocol.ResourceLocation | protocol.QuickFix): vscode.Location { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space after |
||
const position = new vscode.Position(location.Line - 1, location.Column - 1); | ||
|
||
const endLine = (<protocol.QuickFix>location).EndLine; | ||
const endColumn = (<protocol.QuickFix>location).EndColumn; | ||
|
||
if (endLine !== undefined && endColumn !== undefined) { | ||
const endPosition = new vscode.Position(endLine - 1, endColumn - 1); | ||
return new vscode.Location(fileName, new vscode.Range(position, endPosition)); | ||
return new vscode.Location(uri, new vscode.Range(position, endPosition)); | ||
} | ||
|
||
return new vscode.Location(fileName, position); | ||
return new vscode.Location(uri, position); | ||
} | ||
|
||
export function toRange(rangeLike: { Line: number; Column: number; EndLine: number; EndColumn: number; }): vscode.Range { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space after
: