Skip to content

Commit 104498b

Browse files
committed
Add initial EUA prompt scaffolding
1 parent 43b9649 commit 104498b

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

src/PowerShellEditorServices/Services/PowerShell/Handlers/RenameHandler.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
// Licensed under the MIT License.
33
#nullable enable
44

5+
using System;
56
using System.Collections.Generic;
7+
using System.Management.Automation.Language;
68
using System.Threading;
79
using System.Threading.Tasks;
810
using MediatR;
9-
using System.Management.Automation.Language;
1011
using Microsoft.PowerShell.EditorServices.Services;
1112
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1213
using Microsoft.PowerShell.EditorServices.Refactoring;
1314
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1415
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1516
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1617
using OmniSharp.Extensions.LanguageServer.Protocol;
17-
using System;
18+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1819

1920
namespace Microsoft.PowerShell.EditorServices.Handlers;
2021

@@ -23,12 +24,32 @@ namespace Microsoft.PowerShell.EditorServices.Handlers;
2324
/// A handler for <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_prepareRename">textDocument/prepareRename</a>
2425
/// LSP Ref: <see cref="PrepareRename()"/>
2526
/// </summary>
26-
internal class PrepareRenameHandler(WorkspaceService workspaceService) : IPrepareRenameHandler
27+
internal class PrepareRenameHandler(WorkspaceService workspaceService, ILanguageServerFacade lsp, ILanguageServerConfiguration config) : IPrepareRenameHandler
2728
{
2829
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) => capability.PrepareSupport ? new() { PrepareProvider = true } : new();
2930

3031
public async Task<RangeOrPlaceholderRange?> Handle(PrepareRenameParams request, CancellationToken cancellationToken)
3132
{
33+
// FIXME: Config actually needs to be read and implemented, this is to make the referencing satisfied
34+
config.ToString();
35+
ShowMessageRequestParams reqParams = new ShowMessageRequestParams
36+
{
37+
Type = MessageType.Warning,
38+
Message = "Test Send",
39+
Actions = new MessageActionItem[] {
40+
new MessageActionItem() { Title = "I Accept" },
41+
new MessageActionItem() { Title = "I Accept [Workspace]" },
42+
new MessageActionItem() { Title = "Decline" }
43+
}
44+
};
45+
46+
MessageActionItem result = await lsp.SendRequest(reqParams, cancellationToken).ConfigureAwait(false);
47+
if (result.Title == "Test Action")
48+
{
49+
// FIXME: Need to accept
50+
Console.WriteLine("yay");
51+
}
52+
3253
ScriptFile scriptFile = workspaceService.GetFile(request.TextDocument.Uri);
3354

3455
// TODO: Is this too aggressive? We can still rename inside a var/function even if dotsourcing is in use in a file, we just need to be clear it's not supported to take rename actions inside the dotsourced file.

test/PowerShellEditorServices.Test/Refactoring/PrepareRenameHandlerTests.cs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33
#nullable enable
4-
4+
using System;
5+
using System.Collections.Generic;
56
using System.Threading;
67
using System.Threading.Tasks;
8+
using MediatR;
9+
using Microsoft.Extensions.Configuration;
710
using Microsoft.Extensions.Logging.Abstractions;
11+
using Microsoft.Extensions.Primitives;
812
using Microsoft.PowerShell.EditorServices.Handlers;
913
using Microsoft.PowerShell.EditorServices.Services;
1014
using Microsoft.PowerShell.EditorServices.Test.Shared;
15+
using Newtonsoft.Json.Linq;
16+
using OmniSharp.Extensions.JsonRpc;
1117
using OmniSharp.Extensions.LanguageServer.Protocol;
1218
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
19+
using OmniSharp.Extensions.LanguageServer.Protocol.Progress;
20+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1321
using Xunit;
1422
using static PowerShellEditorServices.Test.Handlers.RefactorFunctionTests;
1523
using static PowerShellEditorServices.Test.Refactoring.RefactorUtilities;
@@ -27,7 +35,9 @@ public PrepareRenameHandlerTests()
2735
{
2836
Uri = DocumentUri.FromFileSystemPath(TestUtilities.GetSharedPath("Refactoring"))
2937
});
30-
handler = new(workspace);
38+
// FIXME: Need to make a Mock<ILanguageServerFacade> to pass to the ExtensionService constructor
39+
40+
handler = new(workspace, new fakeLspSendMessageRequestFacade("I Accept"), new fakeConfigurationService());
3141
}
3242

3343
// TODO: Test an untitled document (maybe that belongs in E2E tests)
@@ -55,3 +65,52 @@ public async Task FindsSymbol(RenameSymbolParamsSerialized param)
5565
Assert.True(result.Range.Contains(position));
5666
}
5767
}
68+
69+
public class fakeLspSendMessageRequestFacade(string title) : ILanguageServerFacade
70+
{
71+
public async Task<TResponse> SendRequest<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken)
72+
{
73+
if (request is ShowMessageRequestParams)
74+
{
75+
return (TResponse)(object)new MessageActionItem { Title = title };
76+
}
77+
else
78+
{
79+
throw new NotSupportedException();
80+
}
81+
}
82+
83+
public ITextDocumentLanguageServer TextDocument => throw new NotImplementedException();
84+
public INotebookDocumentLanguageServer NotebookDocument => throw new NotImplementedException();
85+
public IClientLanguageServer Client => throw new NotImplementedException();
86+
public IGeneralLanguageServer General => throw new NotImplementedException();
87+
public IWindowLanguageServer Window => throw new NotImplementedException();
88+
public IWorkspaceLanguageServer Workspace => throw new NotImplementedException();
89+
public IProgressManager ProgressManager => throw new NotImplementedException();
90+
public InitializeParams ClientSettings => throw new NotImplementedException();
91+
public InitializeResult ServerSettings => throw new NotImplementedException();
92+
public object GetService(Type serviceType) => throw new NotImplementedException();
93+
public IDisposable Register(Action<ILanguageServerRegistry> registryAction) => throw new NotImplementedException();
94+
public void SendNotification(string method) => throw new NotImplementedException();
95+
public void SendNotification<T>(string method, T @params) => throw new NotImplementedException();
96+
public void SendNotification(IRequest request) => throw new NotImplementedException();
97+
public IResponseRouterReturns SendRequest(string method) => throw new NotImplementedException();
98+
public IResponseRouterReturns SendRequest<T>(string method, T @params) => throw new NotImplementedException();
99+
public bool TryGetRequest(long id, out string method, out TaskCompletionSource<JToken> pendingTask) => throw new NotImplementedException();
100+
}
101+
102+
public class fakeConfigurationService : ILanguageServerConfiguration
103+
{
104+
public string this[string key] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
105+
106+
public bool IsSupported => throw new NotImplementedException();
107+
108+
public ILanguageServerConfiguration AddConfigurationItems(IEnumerable<ConfigurationItem> configurationItems) => throw new NotImplementedException();
109+
public IEnumerable<IConfigurationSection> GetChildren() => throw new NotImplementedException();
110+
public Task<IConfiguration> GetConfiguration(params ConfigurationItem[] items) => throw new NotImplementedException();
111+
public IChangeToken GetReloadToken() => throw new NotImplementedException();
112+
public Task<IScopedConfiguration> GetScopedConfiguration(DocumentUri scopeUri, CancellationToken cancellationToken) => throw new NotImplementedException();
113+
public IConfigurationSection GetSection(string key) => throw new NotImplementedException();
114+
public ILanguageServerConfiguration RemoveConfigurationItems(IEnumerable<ConfigurationItem> configurationItems) => throw new NotImplementedException();
115+
public bool TryGetScopedConfiguration(DocumentUri scopeUri, out IScopedConfiguration configuration) => throw new NotImplementedException();
116+
}

0 commit comments

Comments
 (0)