From 6426f6a59b8c20091b18024c1d811839ddb6515f Mon Sep 17 00:00:00 2001 From: Lingling Tong Date: Thu, 4 Mar 2021 08:52:38 -0800 Subject: [PATCH 1/4] Add Xaml command hanler for CreateEventHandler command --- .../Features/Commands/IXamlCommandService.cs | 24 ++++++++ .../Features/Commands/XamlEventDescription.cs | 16 ++++++ .../Features/Completion/XamlCompletionItem.cs | 2 + .../LanguageClient/XamlCapabilities.cs | 2 + .../Commands/CreateEventCommandHandler.cs | 55 +++++++++++++++++++ .../CreateEventCommandHandlerProvider.cs | 32 +++++++++++ .../Handler/Completion/CompletionHandler.cs | 14 ++++- src/VisualStudio/Xaml/Impl/Resources.resx | 3 + src/VisualStudio/Xaml/Impl/StringConstants.cs | 2 + .../Xaml/Impl/xlf/Resources.cs.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.de.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.es.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.fr.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.it.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.ja.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.ko.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.pl.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.pt-BR.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.ru.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.tr.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.zh-Hans.xlf | 5 ++ .../Xaml/Impl/xlf/Resources.zh-Hant.xlf | 5 ++ 22 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs create mode 100644 src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs create mode 100644 src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs create mode 100644 src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs diff --git a/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs b/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs new file mode 100644 index 0000000000000..fe916c179c374 --- /dev/null +++ b/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs @@ -0,0 +1,24 @@ +// 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.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Host; + +namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands +{ + internal interface IXamlCommandService : ILanguageService + { + /// + /// Execute the with the on server + /// + /// TextDocument command was triggered on + /// The command that will be executed + /// The arguments need by the command + /// cancellationToken + /// True if the command has been executed, otherwise false + Task ExecuteCommandAsync(TextDocument document, string command, object[]? commandArguments, CancellationToken cancellationToken); + } +} diff --git a/src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs b/src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs new file mode 100644 index 0000000000000..99a7e56a2e75f --- /dev/null +++ b/src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs @@ -0,0 +1,16 @@ +// 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.Collections.Immutable; + +namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands +{ + internal struct XamlEventDescription + { + public string ClassName { get; set; } + public string EventName { get; set; } + public string ReturnType { get; set; } + public ImmutableArray<(string Name, string ParameterType, string Modifier)> Parameters { get; set; } + } +} diff --git a/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs index 2d9333a069249..98b120926023e 100644 --- a/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs +++ b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands; using Microsoft.VisualStudio.Text.Adornments; namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Completion @@ -24,5 +25,6 @@ internal class XamlCompletionItem public ClassifiedTextElement Description { get; set; } public ImageElement Icon { get; set; } public ISymbol Symbol { get; set; } + public XamlEventDescription? EventDescription { get; set; } } } diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageClient/XamlCapabilities.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageClient/XamlCapabilities.cs index bb74700399b6f..b484da7f669fb 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageClient/XamlCapabilities.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageClient/XamlCapabilities.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.CodeAnalysis.Editor.Xaml; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.LanguageServices.Xaml.LanguageServer.Handler; @@ -28,6 +29,7 @@ internal static class XamlCapabilities }, SupportsDiagnosticRequests = true, OnTypeRenameProvider = new DocumentOnTypeRenameOptions { WordPattern = OnTypeRenameHandler.NamePattern }, + ExecuteCommandProvider = new ExecuteCommandOptions { Commands = new[] { StringConstants.CreateEventHandlerCommand } }, }; /// diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs new file mode 100644 index 0000000000000..2464105305af6 --- /dev/null +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs @@ -0,0 +1,55 @@ +// 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.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Editor.Xaml; +using Microsoft.CodeAnalysis.LanguageServer.Handler; +using Microsoft.CodeAnalysis.LanguageServer.Handler.Commands; +using Microsoft.VisualStudio.LanguageServer.Protocol; +using Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands; +using Newtonsoft.Json.Linq; +using Roslyn.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageServer.Handler.Commands +{ + /// + /// Handle the command that adds an event handler method in code + /// + internal class CreateEventCommandHandler : AbstractExecuteWorkspaceCommandHandler + { + public override string Command => StringConstants.CreateEventHandlerCommand; + + public override bool MutatesSolutionState => false; + + public override bool RequiresLSPSolution => true; + + public override TextDocumentIdentifier? GetTextDocumentIdentifier(ExecuteCommandParams request) + => ((JToken)request.Arguments.FirstOrDefault())?.ToObject(); + + public override async Task HandleRequestAsync(ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken) + { + Contract.ThrowIfNull(request.Arguments); + + var document = context.Document; + if (document == null) + { + return false; + } + + var commandService = document.Project.LanguageServices.GetService(); + if (commandService == null) + { + return false; + } + + // request.Arguments has two argument for CreateEventHandlerCommand + // Arguments[0]: TextDocumentIdentifier + // Arguments[1]: XamlEventDescription + var arguments = new object[] { ((JToken)request.Arguments[1]).ToObject() }; + return await commandService.ExecuteCommandAsync(document, request.Command, arguments, cancellationToken).ConfigureAwait(false); + } + } +} diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs new file mode 100644 index 0000000000000..1d48505031e9b --- /dev/null +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs @@ -0,0 +1,32 @@ +// 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; +using System.Collections.Immutable; +using System.Composition; +using Microsoft.CodeAnalysis.Editor.Xaml; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.LanguageServer.Handler; +using Microsoft.CodeAnalysis.LanguageServer.Handler.Commands; +using Microsoft.VisualStudio.LanguageServer.Protocol; + +namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageServer.Handler.Commands +{ + [ExportLspRequestHandlerProvider(StringConstants.XamlLanguageName), Shared] + [ProvidesMethod(Methods.WorkspaceExecuteCommandName)] + [ProvidesCommand(StringConstants.CreateEventHandlerCommand)] + internal class CreateEventCommandHandlerProvider : AbstractRequestHandlerProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public CreateEventCommandHandlerProvider() + { + } + + public override ImmutableArray CreateRequestHandlers() + { + return ImmutableArray.Create(new CreateEventCommandHandler()); + } + } +} diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs index ec80fc6f061dd..aae44e719c02b 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs @@ -58,12 +58,12 @@ public CompletionHandler() return new VSCompletionList { - Items = completionResult.Completions.Select(c => CreateCompletionItem(c, document.Id, text, request.Position)).ToArray(), + Items = completionResult.Completions.Select(c => CreateCompletionItem(c, document.Id, text, request.Position, request.TextDocument)).ToArray(), SuggestionMode = false, }; } - private static CompletionItem CreateCompletionItem(XamlCompletionItem xamlCompletion, DocumentId documentId, SourceText text, Position position) + private static CompletionItem CreateCompletionItem(XamlCompletionItem xamlCompletion, DocumentId documentId, SourceText text, Position position, TextDocumentIdentifier textDocument) { var item = new VSCompletionItem { @@ -89,6 +89,16 @@ private static CompletionItem CreateCompletionItem(XamlCompletionItem xamlComple }; } + if (xamlCompletion.EventDescription.HasValue) + { + item.Command = new Command() + { + CommandIdentifier = StringConstants.CreateEventHandlerCommand, + Arguments = new object[] { textDocument, xamlCompletion.EventDescription }, + Title = Resources.CreateEventHandler + }; + } + return item; } diff --git a/src/VisualStudio/Xaml/Impl/Resources.resx b/src/VisualStudio/Xaml/Impl/Resources.resx index 0d254409cfb00..13136974eddf0 100644 --- a/src/VisualStudio/Xaml/Impl/Resources.resx +++ b/src/VisualStudio/Xaml/Impl/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Create Event Handler + Remove &and Sort Namespaces diff --git a/src/VisualStudio/Xaml/Impl/StringConstants.cs b/src/VisualStudio/Xaml/Impl/StringConstants.cs index 92588cb0f0757..c39d0222bd8ee 100644 --- a/src/VisualStudio/Xaml/Impl/StringConstants.cs +++ b/src/VisualStudio/Xaml/Impl/StringConstants.cs @@ -13,5 +13,7 @@ internal static class StringConstants public const string XamlFileExtension = ".xaml"; public const string EnableLspIntelliSense = "Xaml.EnableLspIntelliSense"; + + public const string CreateEventHandlerCommand = "Xaml.CreateEventHandler"; } } diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf index 81f5e90eec306..1ae25e9ef2cc4 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces &Odebrat a seřadit obory názvů diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf index 8fdf44577a8e6..db6bff7e5c9ff 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces N&amespaces entfernen und sortieren diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf index 9e5436e1847c4..fdd81e99a04db 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Quitar &y ordenar espacios de nombres diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf index 5bca29bf02dbf..60b82afe90f8b 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Supprimer &et trier les espaces de noms diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf index ad38bcea623fd..84ccbead19c65 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Ri&muovi e ordina spazi dei nomi diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf index 819d150ca12e3..6b8b60a325487 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces 名前空間の削除と並び替え(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf index fd25824b1cf8d..5eca9440aede1 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces 네임스페이스 제거 및 정렬(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf index 447ddeb132399..881c7a7ee9757 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Usuń &i posortuj przestrzenie nazw diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf index 12b198750208c..03736526b3b39 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Remover &e Classificar Namespaces diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf index 2e88234ff0bed..448d842348fd7 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Удалить &и сортировать пространства имен diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf index 8c28cdf33e838..0fb18da1b782e 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces Ad Alanlarını Kaldır &ve Sırala diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf index ddcb444de9c81..250fd1c2cd90a 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces 删除命名空间并排序(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf index dde036c6c76e8..5dcb876f6304f 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf @@ -2,6 +2,11 @@ + + Create Event Handler + Create Event Handler + + Remove &and Sort Namespaces 移除並排序命名空間(&A) From be7b175b9f06847fa12e3c92b218632fca4a2e00 Mon Sep 17 00:00:00 2001 From: Lingling Tong Date: Thu, 4 Mar 2021 13:40:07 -0800 Subject: [PATCH 2/4] code review comments --- .../Xaml/Impl/Features/Commands/IXamlCommandService.cs | 2 +- .../Xaml/Impl/Features/Completion/XamlCompletionItem.cs | 1 - .../{Commands => Completion}/XamlEventDescription.cs | 2 +- .../Handler/Commands/CreateEventCommandHandler.cs | 1 + .../Handler/Commands/CreateEventCommandHandlerProvider.cs | 2 -- .../LanguageServer/Handler/Completion/CompletionHandler.cs | 2 +- src/VisualStudio/Xaml/Impl/Resources.resx | 3 --- src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf | 5 ----- src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf | 5 ----- 20 files changed, 4 insertions(+), 74 deletions(-) rename src/VisualStudio/Xaml/Impl/Features/{Commands => Completion}/XamlEventDescription.cs (98%) diff --git a/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs b/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs index fe916c179c374..5bb7ba3f02beb 100644 --- a/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs +++ b/src/VisualStudio/Xaml/Impl/Features/Commands/IXamlCommandService.cs @@ -12,7 +12,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands internal interface IXamlCommandService : ILanguageService { /// - /// Execute the with the on server + /// Execute the with the /// /// TextDocument command was triggered on /// The command that will be executed diff --git a/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs index 98b120926023e..eef4527d759cc 100644 --- a/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs +++ b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlCompletionItem.cs @@ -6,7 +6,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; -using Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands; using Microsoft.VisualStudio.Text.Adornments; namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Completion diff --git a/src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlEventDescription.cs similarity index 98% rename from src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs rename to src/VisualStudio/Xaml/Impl/Features/Completion/XamlEventDescription.cs index 99a7e56a2e75f..5742b057b2a45 100644 --- a/src/VisualStudio/Xaml/Impl/Features/Commands/XamlEventDescription.cs +++ b/src/VisualStudio/Xaml/Impl/Features/Completion/XamlEventDescription.cs @@ -4,7 +4,7 @@ using System.Collections.Immutable; -namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands +namespace Microsoft.VisualStudio.LanguageServices.Xaml.Features.Completion { internal struct XamlEventDescription { diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs index 2464105305af6..69e237b0f3886 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.LanguageServer.Handler.Commands; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.LanguageServices.Xaml.Features.Commands; +using Microsoft.VisualStudio.LanguageServices.Xaml.Features.Completion; using Newtonsoft.Json.Linq; using Roslyn.Utilities; diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs index 1d48505031e9b..cae2e2ced22ad 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandlerProvider.cs @@ -9,12 +9,10 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.Handler; using Microsoft.CodeAnalysis.LanguageServer.Handler.Commands; -using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.VisualStudio.LanguageServices.Xaml.Implementation.LanguageServer.Handler.Commands { [ExportLspRequestHandlerProvider(StringConstants.XamlLanguageName), Shared] - [ProvidesMethod(Methods.WorkspaceExecuteCommandName)] [ProvidesCommand(StringConstants.CreateEventHandlerCommand)] internal class CreateEventCommandHandlerProvider : AbstractRequestHandlerProvider { diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs index aae44e719c02b..8a98208b3e198 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs @@ -95,7 +95,7 @@ private static CompletionItem CreateCompletionItem(XamlCompletionItem xamlComple { CommandIdentifier = StringConstants.CreateEventHandlerCommand, Arguments = new object[] { textDocument, xamlCompletion.EventDescription }, - Title = Resources.CreateEventHandler + Title = "Create Event Handler" }; } diff --git a/src/VisualStudio/Xaml/Impl/Resources.resx b/src/VisualStudio/Xaml/Impl/Resources.resx index 13136974eddf0..0d254409cfb00 100644 --- a/src/VisualStudio/Xaml/Impl/Resources.resx +++ b/src/VisualStudio/Xaml/Impl/Resources.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Create Event Handler - Remove &and Sort Namespaces diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf index 1ae25e9ef2cc4..81f5e90eec306 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.cs.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces &Odebrat a seřadit obory názvů diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf index db6bff7e5c9ff..8fdf44577a8e6 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.de.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces N&amespaces entfernen und sortieren diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf index fdd81e99a04db..9e5436e1847c4 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.es.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Quitar &y ordenar espacios de nombres diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf index 60b82afe90f8b..5bca29bf02dbf 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.fr.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Supprimer &et trier les espaces de noms diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf index 84ccbead19c65..ad38bcea623fd 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.it.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Ri&muovi e ordina spazi dei nomi diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf index 6b8b60a325487..819d150ca12e3 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ja.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces 名前空間の削除と並び替え(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf index 5eca9440aede1..fd25824b1cf8d 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ko.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces 네임스페이스 제거 및 정렬(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf index 881c7a7ee9757..447ddeb132399 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.pl.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Usuń &i posortuj przestrzenie nazw diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf index 03736526b3b39..12b198750208c 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.pt-BR.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Remover &e Classificar Namespaces diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf index 448d842348fd7..2e88234ff0bed 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.ru.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Удалить &и сортировать пространства имен diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf index 0fb18da1b782e..8c28cdf33e838 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.tr.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces Ad Alanlarını Kaldır &ve Sırala diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf index 250fd1c2cd90a..ddcb444de9c81 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hans.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces 删除命名空间并排序(&A) diff --git a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf index 5dcb876f6304f..dde036c6c76e8 100644 --- a/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf +++ b/src/VisualStudio/Xaml/Impl/xlf/Resources.zh-Hant.xlf @@ -2,11 +2,6 @@ - - Create Event Handler - Create Event Handler - - Remove &and Sort Namespaces 移除並排序命名空間(&A) From f50de7cc58e71210000da60e1cd0baca540b3f64 Mon Sep 17 00:00:00 2001 From: Lingling Tong Date: Thu, 4 Mar 2021 13:49:19 -0800 Subject: [PATCH 3/4] address cr comments --- .../Handler/Commands/CreateEventCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs index 69e237b0f3886..42f6fe81d6a0d 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Commands/CreateEventCommandHandler.cs @@ -28,7 +28,7 @@ internal class CreateEventCommandHandler : AbstractExecuteWorkspaceCommandHandle public override bool RequiresLSPSolution => true; public override TextDocumentIdentifier? GetTextDocumentIdentifier(ExecuteCommandParams request) - => ((JToken)request.Arguments.FirstOrDefault())?.ToObject(); + => ((JToken)request.Arguments.First()).ToObject(); public override async Task HandleRequestAsync(ExecuteCommandParams request, RequestContext context, CancellationToken cancellationToken) { From a41373e80b3bf8c0ab9557cd32aa5507580514e3 Mon Sep 17 00:00:00 2001 From: Lingling Tong Date: Thu, 4 Mar 2021 14:34:42 -0800 Subject: [PATCH 4/4] Move command title to const string --- .../LanguageServer/Handler/Completion/CompletionHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs index 8a98208b3e198..58b1e7989af6a 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Completion/CompletionHandler.cs @@ -27,6 +27,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Xaml.LanguageServer.Handler internal class CompletionHandler : AbstractStatelessRequestHandler { public override string Method => Methods.TextDocumentCompletionName; + private const string CreateEventHandlerCommandTitle = "Create Event Handler"; public override bool MutatesSolutionState => false; public override bool RequiresLSPSolution => true; @@ -95,7 +96,7 @@ private static CompletionItem CreateCompletionItem(XamlCompletionItem xamlComple { CommandIdentifier = StringConstants.CreateEventHandlerCommand, Arguments = new object[] { textDocument, xamlCompletion.EventDescription }, - Title = "Create Event Handler" + Title = CreateEventHandlerCommandTitle }; }