Skip to content

Commit 1fb415e

Browse files
committed
Initial commit for PS Gallery
1 parent b83a7a8 commit 1fb415e

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

src/PowerShellEditorServices.Host/LanguageServer.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public void Initialize()
5757

5858
this.AddRequestHandler(ShowOnlineHelpRequest.Type, this.HandleShowOnlineHelpRequest);
5959

60+
this.AddRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest);
61+
6062
this.AddRequestHandler(DebugAdapterMessages.EvaluateRequest.Type, this.HandleEvaluateRequest);
6163
}
6264

@@ -152,6 +154,30 @@ await editorSession.PowerShellContext.ExecuteCommand<object>(
152154
await requestContext.SendResult(null);
153155
}
154156

157+
private async Task HandleFindModuleRequest(
158+
string helpParams,
159+
EditorSession editorSession,
160+
RequestContext<object, object> requestContext)
161+
{
162+
var psCommand = new PSCommand();
163+
psCommand.AddScript("Find-Module | Select Name, Description");
164+
165+
var modules = await editorSession.PowerShellContext.ExecuteCommand<PSObject>(
166+
psCommand);
167+
168+
var moduleList = new List<PSModuleMessage>();
169+
170+
if (modules != null)
171+
{
172+
foreach (dynamic m in modules)
173+
{
174+
moduleList.Add(new PSModuleMessage { Name = m.Name, Description = m.Description });
175+
}
176+
}
177+
178+
await requestContext.SendResult(new PSModuleResponse { ModuleList = moduleList });
179+
}
180+
155181
protected Task HandleExitNotification(
156182
object exitParams,
157183
EditorSession editorSession,
@@ -235,7 +261,7 @@ protected async Task HandleDidChangeConfigurationNotification(
235261
EditorSession editorSession,
236262
EventContext eventContext)
237263
{
238-
bool oldScriptAnalysisEnabled =
264+
bool oldScriptAnalysisEnabled =
239265
this.currentSettings.ScriptAnalysis.Enable.HasValue;
240266

241267
this.currentSettings.Update(
@@ -887,8 +913,8 @@ await eventContext.SendEvent(
887913
new PublishDiagnosticsNotification
888914
{
889915
Uri = scriptFile.ClientFilePath,
890-
Diagnostics =
891-
allMarkers
916+
Diagnostics =
917+
allMarkers
892918
.Select(GetDiagnosticFromMarker)
893919
.ToArray()
894920
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
9+
{
10+
public class FindModuleRequest
11+
{
12+
public static readonly
13+
RequestType<string, object, object> Type =
14+
RequestType<string, object, object>.Create("powerShell/findModule");
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
9+
{
10+
public class PSModuleMessage
11+
{
12+
public string Name { get; set; }
13+
public string Description { get; set; }
14+
}
15+
16+
public class PSModuleResponse
17+
{
18+
public List<PSModuleMessage> ModuleList { get; set; }
19+
}
20+
}

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
<Compile Include="LanguageServer\Definition.cs" />
9494
<Compile Include="LanguageServer\DocumentHighlight.cs" />
9595
<Compile Include="LanguageServer\Hover.cs" />
96+
<Compile Include="LanguageServer\FindModuleRequest.cs" />
97+
<Compile Include="LanguageServer\PSModuleMessage.cs" />
9698
<Compile Include="LanguageServer\ShowOnlineHelpRequest.cs" />
9799
<Compile Include="LanguageServer\SignatureHelp.cs" />
98100
<Compile Include="LanguageServer\WorkspaceSymbols.cs" />

0 commit comments

Comments
 (0)