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

Fix "go to definition" from metadata within the same metadata file #1772

Merged

Conversation

filipw
Copy link
Contributor

@filipw filipw commented Oct 2, 2017

At the moment we have a nice story of going from source -> metadata and from metadata -> other metadata.
However, when trying to go from metadata as source file to the same metadata as source file, we get an error.

Albeit not a huge issue, it can be a little annoying. An example is below.

Given the following metadata as source file (shortened for brevity), where we position the caret at $$:

namespace System.Text
{
    //
    // Summary:
    //     Represents a character encoding.To browse the .NET Framework source code for
    //     this type, see the Reference Source.
    public abstract class Encoding
    {
        //
        // Summary:
        //     Gets an encoding for the UTF-7 format.
        //
        // Returns:
        //     An encoding for the UTF-7 format.
        public static Encodin$$g UTF7 { get; }
     }
}

When I invoke "go to definition" on $$, I should be taken back to Encoding definition within the same metadata file. Instead I get:

screenshot 2017-10-02 20 47 03

This PR fixes this.

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just minor nits.

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after :

this._documents.set(uri.toString(), metadataResponse);

return uri;
}

public getExistingMetadataResponseUri(sourceName:string) : Uri {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after :

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$")) {
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree, good point

return toLocationFromUri(fileName, location);
}

export function toLocationFromUri(uri:vscode.Uri, location: protocol.ResourceLocation | protocol.QuickFix): vscode.Location {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after :


// 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$")) {
let uri = this._definitionMetadataDocumentProvider.getExistingMetadataResponseUri(gotoDefinitionResponse.FileName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const rather than let

@DustinCampbell
Copy link
Member

Looks good! Anything else?

@filipw
Copy link
Contributor Author

filipw commented Oct 2, 2017

Looks good! Anything else?

No, I think this can go as is. We will do something smarter in Omnisharp in the future and then we can tweak this code to be a bit cleaner. ✨

@DustinCampbell
Copy link
Member

Sounds great.

@DustinCampbell DustinCampbell merged commit 25e8854 into dotnet:master Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants