Skip to content

Commit 6d917eb

Browse files
author
Kapil Borle
committed
Add methods to help with code formatting
1 parent ffa27f8 commit 6d917eb

File tree

5 files changed

+69
-11
lines changed

5 files changed

+69
-11
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 ScriptFileMarkersRequest
11+
{
12+
public static readonly
13+
RequestType<ScriptFileMarkerRequestParams, ScriptFileMarkerRequestResultParams> Type =
14+
RequestType<ScriptFileMarkerRequestParams, ScriptFileMarkerRequestResultParams>.Create("powerShell/getScriptFileMarkers");
15+
}
16+
17+
class ScriptFileMarkerRequestParams
18+
{
19+
public string filePath;
20+
public string[] rules;
21+
}
22+
23+
class ScriptFileMarkerRequestResultParams
24+
{
25+
public ScriptFileMarker[] markers;
26+
}
27+
}

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<Compile Include="LanguageServer\InstallModuleRequest.cs" />
6464
<Compile Include="LanguageServer\PowerShellVersionRequest.cs" />
6565
<Compile Include="LanguageServer\RunspaceChanged.cs" />
66+
<Compile Include="LanguageServer\ScriptFileMarkersRequest.cs" />
6667
<Compile Include="LanguageServer\SetPSSARulesRequest.cs" />
6768
<Compile Include="LanguageServer\ProjectTemplate.cs" />
6869
<Compile Include="MessageProtocol\Channel\NamedPipeClientChannel.cs" />

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ protected override void Initialize()
123123
this.SetRequestHandler(GetPSSARulesRequest.Type, this.HandleGetPSSARulesRequest);
124124
this.SetRequestHandler(SetPSSARulesRequest.Type, this.HandleSetPSSARulesRequest);
125125

126+
this.SetRequestHandler(ScriptFileMarkersRequest.Type, this.HandleScriptFileMarkersRequest);
127+
126128
// Initialize the extension service
127129
// TODO: This should be made awaited once Initialize is async!
128130
this.editorSession.ExtensionService.Initialize(
@@ -230,6 +232,21 @@ await RunScriptDiagnostics(
230232
await sendresult;
231233
}
232234

235+
private async Task HandleScriptFileMarkersRequest(
236+
ScriptFileMarkerRequestParams requestParams,
237+
RequestContext<ScriptFileMarkerRequestResultParams> requestContext)
238+
{
239+
var markers = editorSession.AnalysisService.GetSemanticMarkers(
240+
editorSession.Workspace.GetFile(requestParams.filePath),
241+
requestParams.rules,
242+
null);
243+
markers = markers.Reverse().ToArray();
244+
//markers.OrderByDescending(x => x.Correction.Edits[0].StartLineNumber).ToArray()
245+
await requestContext.SendResult(new ScriptFileMarkerRequestResultParams {
246+
markers = markers
247+
});
248+
}
249+
233250
private async Task HandleGetPSSARulesRequest(
234251
object param,
235252
RequestContext<object> requestContext)

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
127127

128128
#region Public Methods
129129

130-
/// <summary>
131-
/// Performs semantic analysis on the given ScriptFile and returns
132-
/// an array of ScriptFileMarkers.
133-
/// </summary>
134-
/// <param name="file">The ScriptFile which will be analyzed for semantic markers.</param>
135-
/// <returns>An array of ScriptFileMarkers containing semantic analysis results.</returns>
136-
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
130+
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file, string[] rules, string settingsPath)
137131
{
138132
if (this.scriptAnalyzerModuleInfo != null && file.IsAnalysisEnabled)
139133
{
@@ -145,7 +139,7 @@ public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
145139
() =>
146140
{
147141
return
148-
GetDiagnosticRecords(file)
142+
GetDiagnosticRecords(file, rules, settingsPath)
149143
.Select(ScriptFileMarker.FromDiagnosticRecord)
150144
.ToArray();
151145
},
@@ -162,6 +156,17 @@ public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
162156
}
163157
}
164158

159+
/// <summary>
160+
/// Performs semantic analysis on the given ScriptFile and returns
161+
/// an array of ScriptFileMarkers.
162+
/// </summary>
163+
/// <param name="file">The ScriptFile which will be analyzed for semantic markers.</param>
164+
/// <returns>An array of ScriptFileMarkers containing semantic analysis results.</returns>
165+
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
166+
{
167+
return GetSemanticMarkers(file, activeRules, settingsPath);
168+
}
169+
165170
/// <summary>
166171
/// Returns a list of builtin-in PSScriptAnalyzer rules
167172
/// </summary>
@@ -291,6 +296,11 @@ private void InitializePSScriptAnalyzer()
291296
}
292297

293298
private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
299+
{
300+
return GetDiagnosticRecords(file, this.activeRules, this.settingsPath);
301+
}
302+
303+
private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file, string[] rules, string settingsPath)
294304
{
295305
IEnumerable<PSObject> diagnosticRecords = Enumerable.Empty<PSObject>();
296306

@@ -310,13 +320,13 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
310320
.AddParameter("ScriptDefinition", file.Contents);
311321

312322
// Use a settings file if one is provided, otherwise use the default rule list.
313-
if (!string.IsNullOrWhiteSpace(this.SettingsPath))
323+
if (!string.IsNullOrWhiteSpace(settingsPath))
314324
{
315-
powerShell.AddParameter("Settings", this.SettingsPath);
325+
powerShell.AddParameter("Settings", settingsPath);
316326
}
317327
else
318328
{
319-
powerShell.AddParameter("IncludeRule", activeRules);
329+
powerShell.AddParameter("IncludeRule", rules);
320330
}
321331

322332
diagnosticRecords = powerShell.Invoke();

src/PowerShellEditorServices/Nano.PowerShellEditorServices.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<Compile Include="..\PowerShellEditorServices.Protocol\LanguageServer\GetPSSARulesRequest.cs">
4040
<Link>GetPSSARulesRequest.cs</Link>
4141
</Compile>
42+
<Compile Include="..\PowerShellEditorServices.Protocol\LanguageServer\ScriptFileMarkersRequest.cs">
43+
<Link>ScriptFileMarkersRequest.cs</Link>
44+
</Compile>
4245
<Compile Include="..\PowerShellEditorServices.Protocol\LanguageServer\SetPSSARulesRequest.cs">
4346
<Link>SetPSSARulesRequest.cs</Link>
4447
</Compile>

0 commit comments

Comments
 (0)