Skip to content

Commit bfcec76

Browse files
author
Kapil Borle
committed
Process settings object instead of hashtable literal
1 parent d41fc26 commit bfcec76

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using System.Collections;
67
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
8+
using System.Collections.Generic;
79

810
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
911
{
@@ -28,9 +30,15 @@ class ScriptFileMarkerRequestParams
2830
public string filePath;
2931

3032
/// <summary>
31-
/// Settings to provided to ScriptAnalyzer to get the markers.
33+
/// Settings to be provided to ScriptAnalyzer to get the markers.
34+
///
35+
/// We have this unusual structure because JSON deserializer
36+
/// does not deserialize nested hashtables. i.e. it won't
37+
/// deserialize a hashtable within a hashtable. But in this case,
38+
/// i.e. a hashtable within a dictionary, it will deserialize
39+
/// the hashtable.
3240
/// </summary>
33-
public string settings;
41+
public Dictionary<string, Hashtable> settings;
3442
}
3543

3644
/// <summary>

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private async Task HandleScriptFileMarkersRequest(
239239
{
240240
var markers = editorSession.AnalysisService.GetSemanticMarkers(
241241
editorSession.Workspace.GetFile(requestParams.filePath),
242-
editorSession.LanguageService.GetHashtableFromString(requestParams.settings));
242+
editorSession.AnalysisService.GetPSSASettingsHashtable(requestParams.settings));
243243
await requestContext.SendResult(new ScriptFileMarkerRequestResultParams {
244244
markers = markers
245245
});

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
175175
return ruleNames;
176176
}
177177

178+
/// <summary>
179+
/// Construct a PSScriptAnalyzer settings hashtable
180+
/// </summary>
181+
/// <param name="ruleSettingsMap">A settings hashtable</param>
182+
/// <returns></returns>
183+
public Hashtable GetPSSASettingsHashtable(IDictionary<string, Hashtable> ruleSettingsMap)
184+
{
185+
var hashtable = new Hashtable();
186+
var ruleSettingsHashtable = new Hashtable();
187+
188+
hashtable["IncludeRules"] = ruleSettingsMap.Keys.ToArray<object>();
189+
hashtable["Rules"] = ruleSettingsHashtable;
190+
191+
foreach (var kvp in ruleSettingsMap)
192+
{
193+
ruleSettingsHashtable.Add(kvp.Key, kvp.Value);
194+
}
195+
196+
return hashtable;
197+
}
198+
178199
/// <summary>
179200
/// Disposes the runspace being used by the analysis service.
180201
/// </summary>

0 commit comments

Comments
 (0)