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

Extract To Component: Code handling capabilities #10760

Open
wants to merge 29 commits into
base: features/extract-to-component
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9e84b15
Arranging selection logic
marcarro Jul 8, 2024
aa15f7b
Completed and corrected selected range extraction functionality
marcarro Jul 15, 2024
55588d6
Include only dependencies included in the selected range
marcarro Jul 19, 2024
5753836
Base component dependency functionality and fixed range selection bug
marcarro Jul 18, 2024
459605e
Added method to scan identifiers
marcarro Aug 1, 2024
1e8168b
Corrected naming and nits
marcarro Aug 5, 2024
419055b
Set up basic end to end test for extract component
marcarro Aug 7, 2024
80d7b18
Refactoring: responsibilities to resolver and not provider
marcarro Aug 16, 2024
2ec6a8d
Handle code case: Method and field promotion
marcarro Aug 19, 2024
78a6d4c
Nits and reverted some changes that werent supposed to make it
marcarro Aug 19, 2024
5278bd8
Added support for MarkupTagHelperElements
marcarro Aug 19, 2024
8cf4f66
Adapted for roslyn endpoint rename, and added tests
marcarro Aug 21, 2024
7795d9f
Refactoring of TryProcessMultiPointSelection and FindContainingSiblin…
marcarro Aug 21, 2024
2b67a3b
Change to FindContainingSiblingPair
marcarro Aug 21, 2024
426ed28
Modified forwared constant fields
marcarro Aug 22, 2024
b9492f2
Preemptively added suggestions from previous PR feedback
marcarro Aug 25, 2024
462062a
Naming fixes and simplified promoted method string generation
marcarro Aug 25, 2024
96221e5
Adjust indentation for component extraction and some more tests
marcarro Aug 27, 2024
0f547f3
Removed unnecessary usings and separated end to end tests
marcarro Aug 27, 2024
b37e6d8
Updated functionality to match Roslyn endpoint response, finished att…
marcarro Sep 3, 2024
5b76f23
Rebase. Made some mistakes while rebasing, I'm sorry.
marcarro Sep 3, 2024
cec455e
Updated to reflect changes in Roslyn API
marcarro Sep 3, 2024
d76d535
PR Feedback
marcarro Sep 4, 2024
e08e1d3
Corrected logic for searching through ancestors in IsInsideMarkupTag
marcarro Sep 4, 2024
1dfb8fd
Cleaned up usings and integrated PR Feedback for IsInsideMarkupTag
marcarro Sep 5, 2024
268e303
Ignore previous commit message!
marcarro Sep 5, 2024
65daa58
Changed GetUsingDirectivesInRange to use a SyntaxNode instead of a Sy…
marcarro Sep 5, 2024
310da7d
Added more tests
marcarro Sep 7, 2024
1393e15
Final refactoring: moved selection validation methods to resolver to …
marcarro Sep 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;

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

Expand All @@ -14,15 +15,15 @@ internal sealed class ExtractToComponentCodeActionParams
[JsonPropertyName("uri")]
public required Uri Uri { get; set; }

[JsonPropertyName("extractStart")]
public int ExtractStart { get; set; }
[JsonPropertyName("selectStart")]
public required Position SelectStart { get; set; }

[JsonPropertyName("extractEnd")]
public int ExtractEnd { get; set; }
[JsonPropertyName("selectEnd")]
public required Position SelectEnd { get; set; }

[JsonPropertyName("absoluteIndex")]
public required int AbsoluteIndex { get; set; }

[JsonPropertyName("namespace")]
public required string Namespace { get; set; }

[JsonPropertyName("usingDirectives")]
public required List<string> usingDirectives { get; set; }
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

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

namespace Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;

[DataContract]
internal record GetSymbolicInfoParams
{
[DataMember(Name = "document")]
[JsonPropertyName("document")]
public required TextDocumentIdentifier Document { get; set; }

[DataMember(Name = "project")]
[JsonPropertyName("project")]
public required TextDocumentIdentifier Project { get; set; }

[DataMember(Name = "hostDocumentVersion")]
[JsonPropertyName("hostDocumentVersion")]
public required int HostDocumentVersion { get; set; }

[DataMember(Name = "generatedDocumentRanges")]
[JsonPropertyName("generatedDocumentRanges")]
public required Range[] GeneratedDocumentRanges { get; set; }
}

internal sealed record MemberSymbolicInfo
{
public required MethodSymbolicInfo[] Methods { get; set; }
public required AttributeSymbolicInfo[] Attributes { get; set; }
}

internal sealed record MethodSymbolicInfo
{
public required string Name { get; set; }

public required string ReturnType { get; set; }

public required string[] ParameterTypes { get; set; }
}

internal sealed record AttributeSymbolicInfo
{
public required string Name { get; set; }
public required string Type { get; set; }
public required bool IsValueType { get; set; }
public required bool IsWrittenTo { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.CodeAnalysis.Razor.Protocol;
internal static class CustomMessageNames
{
// VS Windows only
public const string RazorGetSymbolicInfoEndpointName = "razor/getSymbolicInfo";
public const string RazorInlineCompletionEndpoint = "razor/inlineCompletion";
public const string RazorValidateBreakpointRangeName = "razor/validateBreakpointRange";
public const string RazorOnAutoInsertEndpointName = "razor/onAutoInsert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class CodeActions

public const string ExtractToCodeBehindAction = "ExtractToCodeBehind";

public const string ExtractToNewComponentAction = "ExtractToNewComponent";
public const string ExtractToComponentAction = "ExtractToComponent";

public const string CreateComponentFromTag = "CreateComponentFromTag";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public async override Task<ReinvokeResponse<TOut>> ReinvokeRequestOnServerAsync<
}

var response = await _languageServiceBroker.RequestAsync(
new GeneralRequest<TIn, TOut> { LanguageServerName = languageServerName, Method = method, Request = parameters },
cancellationToken);
new GeneralRequest<TIn, TOut> { LanguageServerName = languageServerName, Method = method, Request = parameters },
cancellationToken);

// No callers actually use the languageClient when handling the response.
var result = response is not null ? new ReinvokeResponse<TOut>(languageClient: null!, response) : default;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using StreamJsonRpc;

namespace Microsoft.VisualStudio.Razor.LanguageClient.Endpoints;

internal partial class RazorCustomMessageTarget
{
[JsonRpcMethod(CustomMessageNames.RazorGetSymbolicInfoEndpointName, UseSingleObjectParameterDeserialization = true)]
public async Task<MemberSymbolicInfo?> RazorGetSymbolicInfoAsync(GetSymbolicInfoParams request, CancellationToken cancellationToken)
{
var (synchronized, virtualDocumentSnapshot) = await TrySynchronizeVirtualDocumentAsync<CSharpVirtualDocumentSnapshot>(request.HostDocumentVersion, request.Document, cancellationToken);
if (!synchronized || virtualDocumentSnapshot is null)
{
return null;
}

request.Document.Uri = virtualDocumentSnapshot.Uri;
ReinvokeResponse<MemberSymbolicInfo?> response;

try
{
response = await _requestInvoker.ReinvokeRequestOnServerAsync<GetSymbolicInfoParams, MemberSymbolicInfo?>(
RazorLSPConstants.RoslynGetSymbolicInfoEndpointName,
RazorLSPConstants.RazorCSharpLanguageServerName,
request,
cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed at Endpoint: Failed to retrieve Razor component information.", ex);
}

return response.Result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ internal static class RazorLSPConstants

public const string RoslynFormatNewFileEndpointName = "roslyn/formatNewFile";

public const string RoslynGetSymbolicInfoEndpointName = "roslyn/getSymbolicInfo";

public const string RoslynSemanticTokenRangesEndpointName = "roslyn/semanticTokenRanges";
}
Loading