Skip to content

Commit d8bf331

Browse files
author
Kapil Borle
committed
Update AnalysisService.Format method
The format method now takes start/end line/column numbers to allow formatting in a given range. We cannot use Range type in AnalysisService form some strange reason, probably because it leads to circular dependency. Therefore we resort to passing in the integer parameters.
1 parent 2f50051 commit d8bf331

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,14 @@ public IEnumerable<string> GetPSScriptAnalyzerRules()
251251
/// </summary>
252252
/// <param name="scriptDefinition">Script text to be formatted</param>
253253
/// <returns>The formatted script text.</returns>
254-
public async Task<string> Format(string scriptDefinition)
254+
public async Task<string> Format(
255+
string scriptDefinition,
256+
int startLineNumber = -1,
257+
int startColumnNumber = -1,
258+
int endLineNumber = -1,
259+
int endColumnNumber = -1)
255260
{
261+
// we cannot use Range type therefore this workaround of using -1 default value
256262
if (!hasScriptAnalyzerModule)
257263
{
258264
return null;
@@ -261,7 +267,11 @@ public async Task<string> Format(string scriptDefinition)
261267
var result = await InvokePowerShellAsync(
262268
"Invoke-Formatter",
263269
new Dictionary<string, object> {
264-
{"ScriptDefinition", scriptDefinition}
270+
{"ScriptDefinition", scriptDefinition},
271+
{"StartLineNumber", startLineNumber},
272+
{"StartColumnNumber", startColumnNumber},
273+
{"EndLineNumber", endLineNumber},
274+
{"EndColumnNumber", endColumnNumber}
265275
});
266276

267277
return result?.Select(r => r.ImmediateBaseObject as string).FirstOrDefault();

0 commit comments

Comments
 (0)