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

Use Roslyn LSP library instead of Visual Studio #10682

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
95c37af
Rename VsLsp files to just Lsp
davidwengier Jul 30, 2024
a9ab067
Remote RoslynLsp files
davidwengier Jul 30, 2024
b0dcedb
Rename VsLsp* and RoslynLsp* to just Lsp*
davidwengier Jul 30, 2024
27c038c
Change all Range aliases to LspRange aliases
davidwengier Jul 30, 2024
4c649b2
Reference Roslyn protocol library, and deal with the extern alias bits
davidwengier Jul 30, 2024
eb3565c
Remove unused usings
davidwengier Jul 30, 2024
9792de5
More Range -> LspRange
davidwengier Jul 30, 2024
8d45e98
Introduce extern alias where necessary to reference Roslyn types
davidwengier Jul 30, 2024
bbb5adb
Move Lsp helpers into the right namespace
davidwengier Jul 30, 2024
e4537e0
Adjust namespaces and factory method names
davidwengier Jul 30, 2024
6067779
Adjust visibility on a couple of things
davidwengier Jul 30, 2024
be5f735
Fix issues with ContainedLanguage being dependent on VS types
davidwengier Jul 30, 2024
a21fd27
Roslyn types are immutable
davidwengier Jul 30, 2024
8725bba
Cohost signature help now only has to return a single type
davidwengier Jul 30, 2024
bd720ba
Project file tweaks
davidwengier Jul 30, 2024
7caf726
PR feedback
davidwengier Jul 31, 2024
ccd76da
Use extension method as extension method
davidwengier Jul 31, 2024
f505e9c
Move test code back to the test where it belongs
davidwengier Jul 31, 2024
1d5a102
Merge remote-tracking branch 'upstream/main' into LspTypes
davidwengier Jul 31, 2024
e572122
Fixes after merge
davidwengier Jul 31, 2024
4ca0fbe
Merge remote-tracking branch 'upstream/main' into LspTypes
davidwengier Aug 14, 2024
ef3b749
Merge remote-tracking branch 'upstream/main' into LspTypes
davidwengier Sep 17, 2024
dd43a04
Fixes after merge
davidwengier Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="$(MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="$(MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="$(MicrosoftCodeAnalysisExternalAccessRazorPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.LanguageServer.Protocol" Version="$(MicrosoftCodeAnalysisExternalAccessRazorPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="$(MicrosoftCodeAnalysisExternalAccessRazorPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="$(MicrosoftCodeAnalysisRemoteServiceHubPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Test.Utilities" Version="$(MicrosoftCodeAnalysisTestUtilitiesPackageVersion)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable disable

using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand All @@ -31,9 +29,9 @@ public class RazorCodeActionsBenchmark : RazorLanguageServerBenchmarkBase
private CodeActionEndpoint? CodeActionEndpoint { get; set; }
private IDocumentSnapshot? DocumentSnapshot { get; set; }
private SourceText? DocumentText { get; set; }
private Range? RazorCodeActionRange { get; set; }
private Range? CSharpCodeActionRange { get; set; }
private Range? HtmlCodeActionRange { get; set; }
private LspRange? RazorCodeActionRange { get; set; }
private LspRange? CSharpCodeActionRange { get; set; }
private LspRange? HtmlCodeActionRange { get; set; }
private RazorRequestContext RazorRequestContext { get; set; }

public enum FileTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
using Microsoft.CodeAnalysis.Razor.Protocol.Diagnostics;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand Down Expand Up @@ -117,27 +115,27 @@ private IDocumentMappingService BuildRazorDocumentMappingService()
{
var razorDocumentMappingService = new Mock<IDocumentMappingService>(MockBehavior.Strict);

Range? hostDocumentRange;
LspRange? hostDocumentRange;
razorDocumentMappingService.Setup(
r => r.TryMapToHostDocumentRange(
It.IsAny<IRazorGeneratedDocument>(),
InRange,
It.IsAny<MappingBehavior>(),
out hostDocumentRange))
.Returns((IRazorGeneratedDocument generatedDocument, Range range, MappingBehavior mappingBehavior, out Range? actualOutRange) =>
.Returns((IRazorGeneratedDocument generatedDocument, LspRange range, MappingBehavior mappingBehavior, out LspRange? actualOutRange) =>
{
actualOutRange = OutRange;
return true;
});

Range? hostDocumentRange2;
LspRange? hostDocumentRange2;
razorDocumentMappingService.Setup(
r => r.TryMapToHostDocumentRange(
It.IsAny<IRazorGeneratedDocument>(),
It.IsNotIn(InRange),
It.IsAny<MappingBehavior>(),
out hostDocumentRange2))
.Returns((IRazorGeneratedDocument generatedDocument, Range range, MappingBehavior mappingBehavior, out Range? actualOutRange) =>
.Returns((IRazorGeneratedDocument generatedDocument, LspRange range, MappingBehavior mappingBehavior, out LspRange? actualOutRange) =>
{
actualOutRange = null;
return false;
Expand Down Expand Up @@ -205,8 +203,8 @@ public Task<TResponse> SendRequestAsync<TParams, TResponse>(string method, TPara
}
}

private Range InRange { get; set; } = VsLspFactory.CreateSingleLineRange(line: 85, character: 8, length: 8);
private Range OutRange { get; set; } = VsLspFactory.CreateSingleLineRange(line: 6, character: 8, length: 8);
private LspRange InRange { get; set; } = LspFactory.CreateSingleLineRange(line: 85, character: 8, length: 8);
private LspRange OutRange { get; set; } = LspFactory.CreateSingleLineRange(line: 6, character: 8, length: 8);

private Diagnostic[] GetDiagnostics(int n) => Enumerable.Range(1, n).Select(_ => new Diagnostic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand All @@ -33,7 +31,7 @@ public class RazorSemanticTokensBenchmark : RazorLanguageServerBenchmarkBase

private DocumentContext DocumentContext { get; set; }

private Range Range { get; set; }
private LspRange Range { get; set; }

private string PagesDirectory { get; set; }

Expand Down Expand Up @@ -62,7 +60,7 @@ public async Task InitializeRazorSemanticAsync()
DocumentContext = new DocumentContext(documentUri, documentSnapshot, projectContext: null);

var text = await DocumentContext.GetSourceTextAsync(CancellationToken.None).ConfigureAwait(false);
Range = VsLspFactory.CreateRange(
Range = LspFactory.CreateRange(
start: (0, 0),
end: (text.Lines.Count - 1, text.Lines[^1].Span.Length - 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand All @@ -36,7 +34,7 @@ public class RazorSemanticTokensRangeEndpointBenchmark : RazorLanguageServerBenc

private DocumentContext DocumentContext { get; set; }

private Range Range { get; set; }
private LspRange Range { get; set; }

private string PagesDirectory { get; set; }

Expand Down Expand Up @@ -74,7 +72,7 @@ public async Task InitializeRazorSemanticAsync()
SemanticTokensRangeEndpoint = new SemanticTokensRangeEndpoint(RazorSemanticTokenService, razorSemanticTokensLegendService, razorOptionsMonitor, telemetryReporter: null);

var text = await DocumentContext.GetSourceTextAsync(CancellationToken.None).ConfigureAwait(false);
Range = VsLspFactory.CreateRange(
Range = LspFactory.CreateRange(
start: (0, 0),
end: (text.Lines.Count - 1, text.Lines[^1].Span.Length - 1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using static Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer.RazorSemanticTokensBenchmark;
using Range = Microsoft.VisualStudio.LanguageServer.Protocol.Range;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer;

Expand All @@ -28,7 +26,7 @@ public class RazorSemanticTokensScrollingBenchmark : RazorLanguageServerBenchmar

private IDocumentSnapshot DocumentSnapshot => DocumentContext.Snapshot;

private Range Range { get; set; }
private LspRange Range { get; set; }

private string PagesDirectory { get; set; }

Expand All @@ -52,7 +50,7 @@ public async Task InitializeRazorSemanticAsync()
DocumentContext = new DocumentContext(documentUri, documentSnapshot, projectContext: null);

var text = await DocumentSnapshot.GetTextAsync().ConfigureAwait(false);
Range = VsLspFactory.CreateRange(
Range = LspFactory.CreateRange(
start: (0, 0),
end: (text.Lines.Count - 1, 0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\src\Microsoft.AspNetCore.Razor.LanguageServer\GlobalUsings.cs" Link="GlobalUsings.cs" />
<Compile Include="..\..\test\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Workspaces\TestServices.cs">
<Link>TestServices\%(FileName)%(Extension)</Link>
</Compile>
Expand All @@ -54,6 +55,8 @@
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.DiaSymReader" />

<PackageReference Include="Microsoft.CodeAnalysis.LanguageServer.Protocol" Aliases="RLSP" />
</ItemGroup>

<Import Project="..\..\..\Shared\Microsoft.AspNetCore.Razor.Serialization.Json\Microsoft.AspNetCore.Razor.Serialization.Json.projitems" Label="Shared" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Completion;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.CodeAnalysis.Razor.Completion;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using StreamJsonRpc;

namespace Microsoft.AspNetCore.Razor.LanguageServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.RpcContracts.Settings;
using Microsoft.VisualStudio.Threading;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.CommonLanguageServerProtocol.Framework;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using StreamJsonRpc;

namespace Microsoft.AspNetCore.Razor.LanguageServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down Expand Up @@ -262,7 +261,7 @@ private static RazorVSInternalCodeAction CreateFQNCodeAction(
{
var codeDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier() { Uri = context.Request.TextDocument.Uri };

var fqnTextEdit = VsLspFactory.CreateTextEdit(fqnDiagnostic.Range, fullyQualifiedName);
var fqnTextEdit = LspFactory.CreateTextEdit(fqnDiagnostic.Range, fullyQualifiedName);

var fqnWorkspaceEditDocumentChange = new TextDocumentEdit()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using StreamJsonRpc;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Text.Json.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Text.Json.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Razor;

Expand Down Expand Up @@ -62,10 +61,10 @@ public static TextEdit[] CreateFormattedTextEdit(RazorCodeDocument code, string
codeBlockStartText = $"{Environment.NewLine}{codeBlockStartText}";
}

var eofRange = VsLspFactory.CreateZeroWidthRange(lastCharacterLocation.LineNumber, insertCharacterIndex);
var start = VsLspFactory.CreateTextEdit(eofRange, codeBlockStartText);
var method = VsLspFactory.CreateTextEdit(eofRange, indentedMethod);
var end = VsLspFactory.CreateTextEdit(eofRange, Environment.NewLine + "}");
var eofRange = LspFactory.CreateZeroWidthRange(lastCharacterLocation.LineNumber, insertCharacterIndex);
var start = LspFactory.CreateTextEdit(eofRange, codeBlockStartText);
var method = LspFactory.CreateTextEdit(eofRange, indentedMethod);
var end = LspFactory.CreateTextEdit(eofRange, Environment.NewLine + "}");

return [start, method, end];
}
Expand Down Expand Up @@ -95,7 +94,7 @@ public static TextEdit[] CreateFormattedTextEdit(RazorCodeDocument code, string
? closeBraceLocation.CharacterIndex
: 0;

return [VsLspFactory.CreateTextEdit(insertLineLocation.LineIndex, insertCharacter, formattedGeneratedMethod)];
return [LspFactory.CreateTextEdit(insertLineLocation.LineIndex, insertCharacter, formattedGeneratedMethod)];
}

private static string FormatMethodInCodeBlock(
Expand Down
Loading
Loading