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

Cohost Document Symbols #10728

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>9ae78a4e6412926d19ba97cfed159bf9de70b538</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.12.0-1.24379.11">
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.12.0-2.24419.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>cf82d399c36008e7936d545cde24141f8d3790fa</Sha>
<Sha>0ec44d9775c80a6861b811d8af637ee36e3315e1</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.24352.2</MicrosoftSourceBuildIntermediatearcadePackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>1.0.0-beta.23475.1</MicrosoftDotNetXliffTasksPackageVersion>
<MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>1.0.0-beta.23475.1</MicrosoftSourceBuildIntermediatexlifftasksPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.12.0-1.24379.11</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.12.0-1.24379.11</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion>
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.12.0-1.24379.11</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftSourceBuildIntermediateroslynPackageVersion>4.12.0-1.24379.11</MicrosoftSourceBuildIntermediateroslynPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.12.0-1.24379.11</MicrosoftVisualStudioLanguageServicesPackageVersion>
<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>
<!--
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 @@ -25,6 +25,7 @@
<ServiceHubService Include="Microsoft.VisualStudio.Razor.SignatureHelp" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteSignatureHelpService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.DocumentHighlight" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteDocumentHighlightService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.InlayHint" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteInlayHintService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.DocumentSymbol" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteDocumentSymbolService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.GoToDefinition" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteGoToDefinitionService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.Razor.Rename" ClassName="Microsoft.CodeAnalysis.Remote.Razor.RemoteRenameService+Factory" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentSymbols;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Text.Tagging;

namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentSymbols;

[RazorLanguageServerEndpoint(Methods.TextDocumentDocumentSymbolName)]
internal class DocumentSymbolEndpoint : IRazorRequestHandler<DocumentSymbolParams, SumType<DocumentSymbol[], SymbolInformation[]>?>, ICapabilitiesProvider
internal class DocumentSymbolEndpoint(
IClientConnection clientConnection,
IDocumentSymbolService documentSymbolService,
LanguageServerFeatureOptions languageServerFeatureOptions) : IRazorRequestHandler<DocumentSymbolParams, SumType<DocumentSymbol[], SymbolInformation[]>?>, ICapabilitiesProvider
{
private readonly IClientConnection _clientConnection;
private readonly IDocumentMappingService _documentMappingService;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;

public DocumentSymbolEndpoint(
IClientConnection clientConnection,
IDocumentMappingService documentMappingService,
LanguageServerFeatureOptions languageServerFeatureOptions)
{
_clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection));
_documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService));
_languageServerFeatureOptions = languageServerFeatureOptions;
}
private readonly IClientConnection _clientConnection = clientConnection;
private readonly IDocumentSymbolService _documentSymbolService = documentSymbolService;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;

public bool MutatesSolutionState => false;

Expand Down Expand Up @@ -76,74 +71,6 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(DocumentSymbolParams req

var codeDocument = await documentContext.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
var csharpDocument = codeDocument.GetCSharpDocument();

if (symbols.TryGetFirst(out var documentSymbols))
{
return RemapDocumentSymbols(csharpDocument, documentSymbols);
}
else if (symbols.TryGetSecond(out var symbolInformations))
{
using var _ = ListPool<SymbolInformation>.GetPooledObject(out var mappedSymbols);

foreach (var symbolInformation in symbolInformations)
{
if (_documentMappingService.TryMapToHostDocumentRange(csharpDocument, symbolInformation.Location.Range, out var newRange))
{
symbolInformation.Location.Range = newRange;
symbolInformation.Location.Uri = documentContext.Uri;
mappedSymbols.Add(symbolInformation);
}
}

return mappedSymbols.ToArray();
}
else
{
Debug.Fail("Unsupported response type");
throw new InvalidOperationException();
}
}

private DocumentSymbol[]? RemapDocumentSymbols(RazorCSharpDocument csharpDocument, DocumentSymbol[]? documentSymbols)
{
if (documentSymbols is null)
{
return null;
}

using var _ = ListPool<DocumentSymbol>.GetPooledObject(out var mappedSymbols);

foreach (var documentSymbol in documentSymbols)
{
if (TryRemapRanges(csharpDocument, documentSymbol))
{
documentSymbol.Children = RemapDocumentSymbols(csharpDocument, documentSymbol.Children);

mappedSymbols.Add(documentSymbol);
}
else if (documentSymbol.Children is [_, ..] &&
RemapDocumentSymbols(csharpDocument, documentSymbol.Children) is [_, ..] mappedChildren)
{
// This range didn't map, but some/all of its children did, so we promote them to this level so we don't
// lose any information.
mappedSymbols.AddRange(mappedChildren);
}
}

return mappedSymbols.ToArray();

bool TryRemapRanges(RazorCSharpDocument csharpDocument, DocumentSymbol documentSymbol)
{
if (_documentMappingService.TryMapToHostDocumentRange(csharpDocument, documentSymbol.Range, out var newRange) &&
_documentMappingService.TryMapToHostDocumentRange(csharpDocument, documentSymbol.SelectionRange, out var newSelectionRange))
{
documentSymbol.Range = newRange;
documentSymbol.SelectionRange = newSelectionRange;

return true;
}

return false;
}
return _documentSymbolService.GetDocumentSymbols(documentContext.Uri, csharpDocument, symbols);
}
}
Loading
Loading