Go To Definition: Automatically navigate to user code when multiple locations include generated code#80669
Conversation
Modified GetStreamingLocationAsync to automatically navigate to the first non-generated code location when multiple definition locations exist, while still showing all results in the tool window. This improves the user experience when dealing with partial types that have both user code and source-generated code. Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
| var document = sourceSpan.Document; | ||
|
|
||
| // Check if this document is generated code | ||
| var generatedCodeService = document.GetLanguageService<IGeneratedCodeRecognitionService>(); |
There was a problem hiding this comment.
@copilot use the existing IsGeneratedCodeAsync extension. You don't need to directly access this service. You will also not need any sort of null check.
There was a problem hiding this comment.
Updated to use the IsGeneratedCodeAsync extension method and removed the unnecessary service access and null check. Commit: HEAD
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
| ArrayBuilder<(DefinitionItem item, INavigableLocation location)> builder, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| // Look through all definition items to find the first one that comes from a non-generated document |
There was a problem hiding this comment.
@copilot remove all the comments inside this method. they're very redundant.
There was a problem hiding this comment.
Removed all inline comments from the method. Commit: HEAD
| // Check each source span in the definition item | ||
| foreach (var sourceSpan in item.SourceSpans) | ||
| { | ||
| var document = sourceSpan.Document; |
There was a problem hiding this comment.
Inlined the local variable. Commit: HEAD
| { | ||
| // Found a non-generated location, return it | ||
| return location; | ||
| } |
| Assert.Equal(HelloWorldGenerator.GeneratedFolderClassName, await TestServices.Editor.GetSelectedTextAsync(HangMitigatingCancellationToken)); | ||
| } | ||
|
|
||
| [IdeFact] |
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Collections.Immutable; | ||
| using System.Linq; |
There was a problem hiding this comment.
No, it was not needed. SelectAsArray is from PooledObjects, not System.Linq. Removed. Commit: HEAD
…nAsync Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
…dd WorkItem Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Plan: Improve Go To Definition to prefer user code over generated code
GetStreamingLocationAsyncinIStreamingFindReferencesPresenter.csto:IGeneratedCodeRecognitionServiceIsGeneratedCodeAsyncextension methodFixes #77895
Original prompt
Fixes #77895
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.