-
Notifications
You must be signed in to change notification settings - Fork 229
Cohost Go To Implementation #10824
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
Merged
davidwengier
merged 6 commits into
dotnet:main
from
davidwengier:CohostGoToImplementation
Sep 6, 2024
Merged
Cohost Go To Implementation #10824
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7cd940
Cohost go to implementation
davidwengier 84c2983
Whitespace
davidwengier 6e12161
Bump to real Roslyn version
davidwengier 054f9ee
Merge remote-tracking branch 'upstream/main' into CohostGoToImplement…
davidwengier f7681c2
Fix build
davidwengier 70f110d
Fix test
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...or/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/IRemoteGoToImplementationService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.ExternalAccess.Razor; | ||
| using RoslynLocation = Roslyn.LanguageServer.Protocol.Location; | ||
| using RoslynPosition = Roslyn.LanguageServer.Protocol.Position; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Razor.Remote; | ||
|
|
||
| internal interface IRemoteGoToImplementationService : IRemoteJsonService | ||
| { | ||
| ValueTask<RemoteResponse<RoslynLocation[]?>> GetImplementationAsync( | ||
| JsonSerializableRazorPinnedSolutionInfoWrapper solutionInfo, | ||
| JsonSerializableDocumentId razorDocumentId, | ||
| RoslynPosition position, | ||
| CancellationToken cancellationToken); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...Microsoft.CodeAnalysis.Remote.Razor/GoToImplementation/RemoteGoToImplementationService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Razor.Language; | ||
| using Microsoft.AspNetCore.Razor.PooledObjects; | ||
| using Microsoft.CodeAnalysis.ExternalAccess.Razor; | ||
| using Microsoft.CodeAnalysis.Razor.DocumentMapping; | ||
| using Microsoft.CodeAnalysis.Razor.Protocol; | ||
| using Microsoft.CodeAnalysis.Razor.Remote; | ||
| using Microsoft.CodeAnalysis.Remote.Razor.DocumentMapping; | ||
| using Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem; | ||
| using Microsoft.CodeAnalysis.Text; | ||
| using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
| using Roslyn.LanguageServer.Protocol; | ||
| using static Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<Roslyn.LanguageServer.Protocol.Location[]?>; | ||
| using ExternalHandlers = Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers; | ||
| using RoslynLocation = Roslyn.LanguageServer.Protocol.Location; | ||
| using RoslynPosition = Roslyn.LanguageServer.Protocol.Position; | ||
| using VsPosition = Microsoft.VisualStudio.LanguageServer.Protocol.Position; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Remote.Razor; | ||
|
|
||
| internal sealed class RemoteGoToImplementationService(in ServiceArgs args) : RazorDocumentServiceBase(in args), IRemoteGoToImplementationService | ||
| { | ||
| internal sealed class Factory : FactoryBase<IRemoteGoToImplementationService> | ||
| { | ||
| protected override IRemoteGoToImplementationService CreateService(in ServiceArgs args) | ||
| => new RemoteGoToImplementationService(in args); | ||
| } | ||
|
|
||
| protected override IDocumentPositionInfoStrategy DocumentPositionInfoStrategy => PreferAttributeNameDocumentPositionInfoStrategy.Instance; | ||
|
|
||
| public ValueTask<RemoteResponse<RoslynLocation[]?>> GetImplementationAsync( | ||
| JsonSerializableRazorPinnedSolutionInfoWrapper solutionInfo, | ||
| JsonSerializableDocumentId documentId, | ||
| RoslynPosition position, | ||
| CancellationToken cancellationToken) | ||
| => RunServiceAsync( | ||
| solutionInfo, | ||
| documentId, | ||
| context => GetImplementationAsync(context, position, cancellationToken), | ||
| cancellationToken); | ||
|
|
||
| private async ValueTask<RemoteResponse<RoslynLocation[]?>> GetImplementationAsync( | ||
| RemoteDocumentContext context, | ||
| RoslynPosition position, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var codeDocument = await context.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (!codeDocument.Source.Text.TryGetAbsoluteIndex(position, out var hostDocumentIndex)) | ||
| { | ||
| return NoFurtherHandling; | ||
| } | ||
|
|
||
| var positionInfo = GetPositionInfo(codeDocument, hostDocumentIndex, preferCSharpOverHtml: true); | ||
|
|
||
| if (positionInfo.LanguageKind is RazorLanguageKind.Razor) | ||
| { | ||
| return NoFurtherHandling; | ||
| } | ||
|
|
||
| if (positionInfo.LanguageKind is RazorLanguageKind.Html) | ||
| { | ||
| return CallHtml; | ||
| } | ||
|
|
||
| if (!DocumentMappingService.TryMapToGeneratedDocumentPosition(codeDocument.GetCSharpDocument(), positionInfo.HostDocumentIndex, out var mappedPosition, out _)) | ||
| { | ||
| // If we can't map to the generated C# file, we're done. | ||
| return NoFurtherHandling; | ||
| } | ||
|
|
||
| // Finally, call into C#. | ||
| var generatedDocument = await context.Snapshot.GetGeneratedDocumentAsync().ConfigureAwait(false); | ||
|
|
||
| var locations = await ExternalHandlers.GoToImplementation | ||
| .FindImplementationsAsync( | ||
| generatedDocument, | ||
| mappedPosition, | ||
| supportsVisualStudioExtensions: true, | ||
| cancellationToken) | ||
| .ConfigureAwait(false); | ||
|
|
||
| if (locations is null and not []) | ||
| { | ||
| // C# didn't return anything, so we're done. | ||
| return NoFurtherHandling; | ||
| } | ||
|
|
||
| // Map the C# locations back to the Razor file. | ||
| using var mappedLocations = new PooledArrayBuilder<RoslynLocation>(locations.Length); | ||
|
|
||
| foreach (var location in locations) | ||
| { | ||
| var (uri, range) = location; | ||
|
|
||
| var (mappedDocumentUri, mappedRange) = await DocumentMappingService | ||
| .MapToHostDocumentUriAndRangeAsync(context.Snapshot, uri, range.ToLinePositionSpan(), cancellationToken) | ||
| .ConfigureAwait(false); | ||
|
|
||
| var mappedLocation = RoslynLspFactory.CreateLocation(mappedDocumentUri, mappedRange); | ||
|
|
||
| mappedLocations.Add(mappedLocation); | ||
| } | ||
|
|
||
| return Results(mappedLocations.ToArray()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.