-
Notifications
You must be signed in to change notification settings - Fork 847
[VS] Partial implementation of Go to definition for external IL symbols #10956
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
Conversation
| (projectInfo, documentInfo) | ||
|
|
||
| let DecompileCSharp (symbolFullTypeName: string, assemblyLocation: string) = | ||
| let logger = new StringBuilder(); |
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.
no semicolon needed
| // Try to decompile; if an exception is thrown the caller will handle it | ||
| let mutable text = decompiler.DecompileTypeAsString(fullTypeName) | ||
|
|
||
| text <- text + "#if false // " + Environment.NewLine |
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.
better without mutable, use let text = text + ...
| let mutable hierarchy = Unchecked.defaultof<_> | ||
| let mutable itemId = Unchecked.defaultof<_> | ||
| let mutable windowFrame = Unchecked.defaultof<_> | ||
| openDocumentService.OpenDocumentViaProject(filePath, ref VSConstants.LOGVIEWID.TextView_guid, &localServiceProvider, &hierarchy, &itemId, &windowFrame) |> ignore |
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.
Can you use output tuples?
let _, localServiceProvider, hierarchy, itemId, windowFrame = openDocumentService.OpenDocumentViaProject(filePath, ref VSConstants.LOGVIEWID.TextView_guid)
| projectContext.DisplayName <- projInfo.Name | ||
| projectContext.AddSourceFile(docInfo.FilePath, sourceCodeKind = SourceCodeKind.Regular) | ||
|
|
||
| projInfo.MetadataReferences |
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.
Just use a for loop
Is there a way to make this happen? We do support navigating to C# symbols in a referenced project, so in theory we might have the tools needed to navigate |
|
|
||
| SourceText.From(text) | ||
|
|
||
| let ShowDocument (filePath, name, serviceProvider: IServiceProvider) = |
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.
style nit: lowercase
|
|
||
| (projectInfo, documentInfo) | ||
|
|
||
| let DecompileCSharp (symbolFullTypeName: string, assemblyLocation: string) = |
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.
style nit: lowercase
| open ICSharpCode.Decompiler.CSharp.Transforms | ||
| open ICSharpCode.Decompiler.TypeSystem | ||
|
|
||
| let GenerateTemporaryCSharpDocument (asmIdentity: AssemblyIdentity, name: string, metadataReferences) = |
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.
style nit: lowercase
| let! location = symbol.Locations |> Seq.tryHead | ||
| return (FSharpGoToDefinitionNavigableItem(project.GetDocument(location.SourceTree), location.SourceSpan), idRange) | ||
| let projectOpt = originDocument.Project.Solution.Projects |> Seq.tryFind (fun p -> p.AssemblyName.Equals(assembly, StringComparison.OrdinalIgnoreCase)) | ||
| if projectOpt.IsSome then |
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.
match?
…ls (dotnet#10956) * Initial commit * Openining document, but incorrect project association * Partial implementation for go-to-def of external symbols * Feedback
|
Looks like you've missed a few piece But at least his is great 👍 |
This is a partial implementation that allows go-to-definition on external IL symbols by generating metadata source files; currently only generating "C#" metadata code.
This is partial, meaning that it doesn't generate a proper metadata-as-source C# file as it is missing formatting and doesn't navigate to the given symbol. We also can't do go-to-def on external "F#" symbols yet.
Roslyn has internal services that could help with the formatting, but there must be additions to F#'s external access in order to take advantage of it.
I thought about re-using Roslyn's whole metadata-as-source implementation by adding a F# external access API, but we really can't use the API as it relies on
ISymbol. See here: http://sourceroslyn.io/#Microsoft.CodeAnalysis.Features/MetadataAsSource/IMetadataAsSourceFileService.cs,25