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

Add Xaml command hanler for CreateEventHandler command #51670

Merged
merged 4 commits into from
Mar 5, 2021

Conversation

LinglingTong
Copy link
Contributor

This PR added code to handler when the CreateEventHandler command gets triggered and allow XAML language service to execute the command.

When a XamlCompletionItem has an EventDescription, we will set this CreateEventHandlerCommand on the CompletionItem, and the command will be triggered when the completionItem gets committed.

@LinglingTong LinglingTong requested a review from a team as a code owner March 4, 2021 18:42
@LinglingTong
Copy link
Contributor Author

@dibarbet @mgoertz-msft

namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageServer.Handler.Commands
{
[ExportLspRequestHandlerProvider(StringConstants.XamlLanguageName), Shared]
[ProvidesMethod(Methods.WorkspaceExecuteCommandName)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just want ProvidesCommand, ProvidesMethod shouldn't be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I have removed the ProvidesMethod.

{
CommandIdentifier = StringConstants.CreateEventHandlerCommand,
Arguments = new object[] { textDocument, xamlCompletion.EventDescription },
Title = Resources.CreateEventHandler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the title shown anywhere for completion commands? If it's not we may not need to localize it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a good point. I am not aware the title is shown anywhere so far. I have removed the string from the resources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small improvement, make it a const string in this class.


In reply to: 587847403 [](ancestors = 587847403)

// request.Arguments has two argument for CreateEventHandlerCommand
// Arguments[0]: TextDocumentIdentifier
// Arguments[1]: XamlEventDescription
var arguments = new object[] { ((JToken)request.Arguments[1]).ToObject<XamlEventDescription>() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see arguments[0] being used anywhere, do we actually need that item?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is used in line 29 GetTextDocumentIdentifier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed that. It looks like if we get the command it must have that argument, so I'd recommend First()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me.

internal interface IXamlCommandService : ILanguageService
{
/// <summary>
/// Execute the <paramref name="command"/> with the <paramref name="commandArguments"/> on server
Copy link
Contributor

@mgoertz-msft mgoertz-msft Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on server [](start = 96, length = 9)

That's just an implementation detail that's not relevant to the description of the interface #Closed

Copy link
Contributor Author

@LinglingTong LinglingTong Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will update the comment. #Closed

using System.Collections.Immutable;

namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands
{
Copy link
Contributor

@mgoertz-msft mgoertz-msft Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should live under Completion and not Commands. We just happen to pass it around as a command parameter. #Closed

Copy link
Contributor Author

@LinglingTong LinglingTong Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I have been moving this struct between Commands and Completion too. Now as you vote for completion I guess completion wins. :) #Closed

public CreateEventCommandHandlerProvider()
{
}

Copy link
Contributor

@mgoertz-msft mgoertz-msft Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed? We're not importing anything in here. #Closed

Copy link
Contributor Author

@LinglingTong LinglingTong Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required by the ExportLspRequestHandlerProvider. I will get warning if I don't have an importing constructor. #Closed

Copy link
Contributor

@mgoertz-msft mgoertz-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mgoertz-msft mgoertz-msft merged commit b8f5462 into dotnet:main Mar 5, 2021
@allisonchou allisonchou added this to the Next milestone Mar 12, 2021
@allisonchou allisonchou modified the milestones: Next, 16.10.P2 Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants