Skip to content

Commit

Permalink
Cohost Go To Implementation (#10824)
Browse files Browse the repository at this point in the history
Needs dotnet/roslyn#74978
Fixes #10695
Part of #9519

Pretty straightforward. A tiny bit of code moved to be shared with Go To
Def, but that's it.
  • Loading branch information
davidwengier authored Sep 6, 2024
2 parents 459e9d6 + 70f110d commit 49e727b
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 80 deletions.
76 changes: 38 additions & 38 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,82 @@
<Sha>6bcf90f99d13da86c5e9753a6f34b6484673d0a0</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.12.0-2.24419.3">
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.12.0-3.24454.5">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
<Sha>9f86520c46f67d2a8a59af189f8fd87e35c574bb</Sha>
<SourceBuild RepoName="roslyn" ManagedOnly="true" />
</Dependency>
</ProductDependencies>
Expand Down
38 changes: 19 additions & 19 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@
<MicrosoftSourceBuildIntermediatearcadePackageVersion>9.0.0-beta.24453.1</MicrosoftSourceBuildIntermediatearcadePackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>1.0.0-beta.23475.1</MicrosoftDotNetXliffTasksPackageVersion>
<MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>1.0.0-beta.23475.1</MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.12.0-2.24419.3</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.12.0-2.24419.3</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.12.0-2.24419.3</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftSourceBuildIntermediateroslynPackageVersion>4.12.0-2.24419.3</MicrosoftSourceBuildIntermediateroslynPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.12.0-2.24419.3</MicrosoftVisualStudioLanguageServicesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.12.0-3.24454.5</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.12.0-3.24454.5</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.12.0-3.24454.5</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftSourceBuildIntermediateroslynPackageVersion>4.12.0-3.24454.5</MicrosoftSourceBuildIntermediateroslynPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.12.0-3.24454.5</MicrosoftVisualStudioLanguageServicesPackageVersion>
<!--
Exception - Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages are not updated by automation,
but are present in Version.Details.xml for source-build PVP flow. See the comment in Version.Details.xml for more information.
Expand Down
1 change: 1 addition & 0 deletions eng/targets/Services.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<ServiceHubService Include="Microsoft.VisualStudio.Razor.Rename" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteRenameService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.AutoInsert" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteAutoInsertService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.Formatting" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteFormattingService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.GoToImplementation" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteGoToImplementationService+Factory" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ static void AddHandlers(IServiceCollection services, LanguageServerFeatureOption
// Transient because it should only be used once and I'm hoping it doesn't stick around.
services.AddTransient<IOnInitialized>(sp => sp.GetRequiredService<RazorConfigurationEndpoint>());

services.AddHandlerWithCapabilities<ImplementationEndpoint>();

if (!featureOptions.UseRazorCohostServer)
{
services.AddHandlerWithCapabilities<ImplementationEndpoint>();

services.AddSingleton<IRazorComponentDefinitionService, RazorComponentDefinitionService>();
services.AddHandlerWithCapabilities<DefinitionEndpoint>();

Expand Down
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal static class RazorServices
(typeof(IRemoteInlayHintService), null),
(typeof(IRemoteDocumentSymbolService), null),
(typeof(IRemoteRenameService), null),
(typeof(IRemoteGoToImplementationService), null),
];

private const string ComponentName = "Razor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;

Expand Down Expand Up @@ -58,20 +57,7 @@ protected override IRemoteGoToDefinitionService CreateService(in ServiceArgs arg
return NoFurtherHandling;
}

var positionInfo = GetPositionInfo(codeDocument, hostDocumentIndex);

if (positionInfo.LanguageKind == RazorLanguageKind.Html)
{
// Sometimes Html can actually be mapped to C#, like for example component attributes, which map to
// C# properties, even though they appear entirely in a Html context. Since remapping is pretty cheap
// it's easier to just try mapping, and see what happens, rather than checking for specific syntax nodes.
if (DocumentMappingService.TryMapToGeneratedDocumentPosition(codeDocument.GetCSharpDocument(), positionInfo.HostDocumentIndex, out VsPosition? csharpPosition, out _))
{
// We're just gonna pretend this mapped perfectly normally onto C#. Moving this logic to the actual position info
// calculating code is possible, but could have untold effects, so opt-in is better (for now?)
positionInfo = positionInfo with { LanguageKind = RazorLanguageKind.CSharp, Position = csharpPosition };
}
}
var positionInfo = GetPositionInfo(codeDocument, hostDocumentIndex, preferCSharpOverHtml: true);

if (positionInfo.LanguageKind is RazorLanguageKind.Html or RazorLanguageKind.Razor)
{
Expand Down
Loading

0 comments on commit 49e727b

Please sign in to comment.