Skip to content

Commit

Permalink
Merge pull request #8207 from davidwengier/SendVSInternalTypesToWebTools
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored Feb 3, 2023
2 parents 37311b9 + ab789e6 commit 512e5f8
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ private string GetFileContents(FileTypes fileType)
[Benchmark(Description = "Lightbulbs")]
public async Task RazorLightbulbAsync()
{
var request = new CodeActionParams
var request = new VSCodeActionParams
{
Range = RazorCodeActionRange!,
Context = new VSInternalCodeActionContext(),
TextDocument = new TextDocumentIdentifier
TextDocument = new VSTextDocumentIdentifier
{
Uri = DocumentUri!
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public CodeActionEndpoint(
_allAvailableCodeActionNames = GetAllAvailableCodeActionNames();
}

public async Task<SumType<Command, CodeAction>[]?> HandleRequestAsync(CodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
public async Task<SumType<Command, CodeAction>[]?> HandleRequestAsync(VSCodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
{
if (request is null)
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public RegistrationExtensionResult GetRegistration(VSInternalClientCapabilities
}

// internal for testing
internal async Task<RazorCodeActionContext?> GenerateRazorCodeActionContextAsync(CodeActionParams request, DocumentSnapshot documentSnapshot)
internal async Task<RazorCodeActionContext?> GenerateRazorCodeActionContextAsync(VSCodeActionParams request, DocumentSnapshot documentSnapshot)
{
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync().ConfigureAwait(false);
if (codeDocument.IsUnsupported())
Expand Down Expand Up @@ -358,7 +358,7 @@ private static ImmutableHashSet<string> GetAllAvailableCodeActionNames()
return availableCodeActionNames.ToImmutableHashSet();
}

public TextDocumentIdentifier GetTextDocumentIdentifier(CodeActionParams request)
public TextDocumentIdentifier GetTextDocumentIdentifier(VSCodeActionParams request)
{
return request.TextDocument;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Runtime.Serialization;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;

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

Expand All @@ -14,7 +14,7 @@ internal class DelegatedCodeActionParams
public int HostDocumentVersion { get; set; }

[DataMember(Name = "codeActionParams")]
public required CodeActionParams CodeActionParams { get; set; }
public required VSCodeActionParams CodeActionParams { get; set; }

[DataMember(Name = "languageKind")]
public RazorLanguageKind LanguageKind { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

using System;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;

internal sealed class RazorCodeActionContext
{
public RazorCodeActionContext(
CodeActionParams request,
VSCodeActionParams request,
DocumentSnapshot documentSnapshot,
RazorCodeDocument codeDocument,
SourceLocation location,
Expand All @@ -29,7 +29,7 @@ public RazorCodeActionContext(
SupportsCodeActionResolve = supportsCodeActionResolve;
}

public CodeActionParams Request { get; }
public VSCodeActionParams Request { get; }
public DocumentSnapshot DocumentSnapshot { get; }
public RazorCodeDocument CodeDocument { get; }
public SourceLocation Location { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;

[LanguageServerEndpoint(Methods.TextDocumentCodeActionName)]
internal interface IVSCodeActionEndpoint : IRazorRequestHandler<CodeActionParams, SumType<Command, CodeAction>[]?>, IRegistrationExtension
internal interface IVSCodeActionEndpoint : IRazorRequestHandler<VSCodeActionParams, SumType<Command, CodeAction>[]?>, IRegistrationExtension
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

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

namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;

/// <summary>
/// We can't use the CodeActionParams defined in MS.VS.LS.Protocol, so need our own version, because the platform only
/// converts on read, not write. ie, if it gets a request for a CodeActionParams, it will happily deserialize the Context
/// property to VSInternalCodeActionContext, but in our case we need to send a request to our CustomMessageTarget, and so
/// we need the Context property serialized as the internal type.
/// </summary>
[DataContract]
internal class VSCodeActionParams
{
//
// Summary:
// Gets or sets the document identifier indicating where the command was invoked.
[DataMember(Name = "textDocument")]
public required VSTextDocumentIdentifier TextDocument { get; set; }

//
// Summary:
// Gets or sets the range in the document for which the command was invoked.
[DataMember(Name = "range")]
public required Range Range { get; set; }

//
// Summary:
// Gets or sets the additional diagnostic information about the code action context.
[DataMember(Name = "context")]
public required VSInternalCodeActionContext Context { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer;
using Microsoft.AspNetCore.Razor.LanguageServer.ColorPresentation;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.LanguageServer.ColorPresentation;
using Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;
using Microsoft.AspNetCore.Razor.LanguageServer.DocumentColor;
using Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Folding;
using Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
Expand Down Expand Up @@ -346,7 +347,7 @@ public override async Task<RazorDocumentRangeFormattingResponse> RazorRangeForma
codeActionParams.CodeActionParams.TextDocument.Uri = virtualDocumentSnapshot.Uri;

var textBuffer = virtualDocumentSnapshot.Snapshot.TextBuffer;
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<CodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<VSCodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
textBuffer,
Methods.TextDocumentCodeActionName,
SupportsCodeActionResolve,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
Expand Down Expand Up @@ -46,11 +47,11 @@ public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction()
var contents = "@code { $$Path; }";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand Down Expand Up @@ -78,11 +79,11 @@ public async Task ProvideAsync_SupportsCodeActionResolveFalse_ValidCodeActions_R
var contents = "@code { $$Path; }";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand All @@ -107,11 +108,11 @@ public async Task ProvideAsync_FunctionsBlock_SingleLine_ValidCodeActions_Return
var contents = "@functions { $$Path; }";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand Down Expand Up @@ -141,11 +142,11 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceSameLine_ValidCodeActions
}";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand Down Expand Up @@ -176,11 +177,11 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceNextLine_ValidCodeActions
}";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand Down Expand Up @@ -208,11 +209,11 @@ public async Task ProvideAsync_InvalidCodeActions_ReturnsNoCodeActions()
var contents = "@code { $$Path; }";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand Down Expand Up @@ -254,11 +255,11 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction()
""";
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);

var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
};

var location = new SourceLocation(cursorPosition, -1, -1);
Expand All @@ -279,7 +280,7 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction()
}

private static RazorCodeActionContext CreateRazorCodeActionContext(
CodeActionParams request,
VSCodeActionParams request,
SourceLocation location,
string filePath,
string text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.AspNetCore.Razor.Language.Components;
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces.Extensions;
Expand All @@ -33,11 +34,11 @@ public async Task Handle_MissingDiagnostics_ReturnsEmpty()
// Arrange
var documentPath = "c:/Test.razor";
var contents = "";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
// Even though the DTO declares this as non-null, we want to make sure we behave
Diagnostics = null!
Expand Down Expand Up @@ -70,11 +71,11 @@ public async Task Handle_InvalidDiagnostics_VSCode_ReturnsEmpty()
// Arrange
var documentPath = "c:/Test.razor";
var contents = "";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = new Diagnostic[] {
new Diagnostic()
Expand Down Expand Up @@ -126,11 +127,11 @@ public async Task Handle_EmptyCodeActions_ReturnsEmpty()
// Arrange
var documentPath = "c:/Test.razor";
var contents = "";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = new Diagnostic[] {
new Diagnostic()
Expand Down Expand Up @@ -167,11 +168,11 @@ public async Task Handle_ValidDiagnostic_ValidCodeAction_VSCode_ReturnsCodeActio
// Arrange
var documentPath = "c:/Test.razor";
var contents = "@code { Path; }";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = new Diagnostic[] {
new Diagnostic()
Expand Down Expand Up @@ -246,11 +247,11 @@ public async Task Handle_CodeActionInSingleLineDirective_VS_ReturnsOnlyUsingCode
// Arrange
var documentPath = "c:/Test.razor";
var contents = "@inject Path";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = Array.Empty<Diagnostic>()
}
Expand Down Expand Up @@ -298,11 +299,11 @@ public async Task Handle_ValidCodeAction_VS_ReturnsCodeActions()
// Arrange
var documentPath = "c:/Test.razor";
var contents = "@code { Path; }";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = Array.Empty<Diagnostic>()
}
Expand Down Expand Up @@ -356,11 +357,11 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns
// Arrange
var documentPath = "c:/Test.razor";
var contents = "@code { Path; }";
var request = new CodeActionParams()
var request = new VSCodeActionParams()
{
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
Range = new Range(),
Context = new CodeActionContext()
Context = new VSInternalCodeActionContext()
{
Diagnostics = new Diagnostic[] {
new Diagnostic()
Expand Down Expand Up @@ -444,7 +445,7 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns
}

private static RazorCodeActionContext CreateRazorCodeActionContext(
CodeActionParams request,
VSCodeActionParams request,
SourceLocation location,
string filePath,
string text,
Expand Down
Loading

0 comments on commit 512e5f8

Please sign in to comment.