Skip to content

Commit 4dd0e37

Browse files
author
Kapil Borle
committed
Update list of active PSSA rules
1 parent c3d46fd commit 4dd0e37

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

src/PowerShellEditorServices.Protocol/LanguageServer/GetPSSARulesRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class GetPSSARulesRequest
1111
{
1212
public static readonly
1313
RequestType<string, object> Type =
14-
RequestType<string, object>.Create("powerShell/GetPSSARules");
14+
RequestType<string, object>.Create("powerShell/getPSSARules");
1515
}
1616
}
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+
class SetPSSARulesRequest
11+
{
12+
public static readonly
13+
RequestType<object, object> Type =
14+
RequestType<object, object>.Create("powerShell/setPSSARules");
15+
}
16+
}

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Compile Include="LanguageServer\FindModuleRequest.cs" />
6262
<Compile Include="LanguageServer\InstallModuleRequest.cs" />
6363
<Compile Include="LanguageServer\PowerShellVersionRequest.cs" />
64+
<Compile Include="LanguageServer\SetPSSARulesRequest.cs" />
6465
<Compile Include="MessageProtocol\Channel\NamedPipeClientChannel.cs" />
6566
<Compile Include="MessageProtocol\Channel\NamedPipeServerChannel.cs" />
6667
<Compile Include="MessageProtocol\Channel\TcpSocketClientChannel.cs" />

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected override void Initialize()
110110
this.SetRequestHandler(DebugAdapterMessages.EvaluateRequest.Type, this.HandleEvaluateRequest);
111111

112112
this.SetRequestHandler(GetPSSARulesRequest.Type, this.HandleGetPSSARulesRequest);
113+
this.SetRequestHandler(SetPSSARulesRequest.Type, this.HandleSetPSSARulesRequest);
113114

114115
// Initialize the extension service
115116
// TODO: This should be made awaited once Initialize is async!
@@ -182,6 +183,28 @@ protected async Task HandleShowOnlineHelpRequest(
182183
await requestContext.SendResult(null);
183184
}
184185

186+
private async Task HandleSetPSSARulesRequest(
187+
object param,
188+
RequestContext<object> requestContext)
189+
{
190+
if (editorSession.AnalysisService != null)
191+
{
192+
var activeRules = new List<string>();
193+
var dynParam = param as dynamic;
194+
foreach (dynamic ruleInfo in dynParam)
195+
{
196+
197+
if ((Boolean) ruleInfo.IsEnabled)
198+
{
199+
activeRules.Add((string) ruleInfo.Name);
200+
}
201+
}
202+
editorSession.AnalysisService.ActiveRules = activeRules.ToArray();
203+
}
204+
205+
await requestContext.SendResult(null);
206+
}
207+
185208
private async Task HandleGetPSSARulesRequest(
186209
object param,
187210
RequestContext<object> requestContext)

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ public class AnalysisService : IDisposable
5555

5656
public string[] ActiveRules
5757
{
58-
get { return activeRules != null ? activeRules.ToArray() : null; }
58+
get
59+
{
60+
return activeRules != null ? activeRules.ToArray() : null;
61+
}
62+
set
63+
{
64+
activeRules = new List<string>(value); // TODO check the argument
65+
}
5966
}
6067

6168
/// <summary>

0 commit comments

Comments
 (0)