Skip to content

Commit d00e2ca

Browse files
author
Kapil Borle
committed
Fix format wrapper method
1 parent 39d69d4 commit d00e2ca

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,9 @@ await requestContext.SendResult(new TextEdit[1]
11901190

11911191
#region Event Handlers
11921192

1193-
private async Task<Tuple<string, Range>> Format(string documentUri, Range range)
1193+
private async Task<Tuple<string, Range>> Format(
1194+
string documentUri,
1195+
Range range)
11941196
{
11951197

11961198
// TODO Get settings
@@ -1199,47 +1201,43 @@ private async Task<Tuple<string, Range>> Format(string documentUri, Range range)
11991201

12001202
// TODO raise an error event incase format returns null;
12011203
string formattedScript;
1204+
Range editRange;
1205+
int sl, sc, el, ec;
12021206
if (range == null)
12031207
{
12041208
formattedScript = await editorSession.AnalysisService.Format(scriptFile.Contents);
1209+
sl = -1;
1210+
sc = -1;
1211+
el = -1;
1212+
ec = -1;
12051213
}
12061214
else
12071215
{
1208-
formattedScript = await editorSession.AnalysisService.Format(
1209-
scriptFile.Contents,
1210-
range.Start.Line + 1,
1211-
range.Start.Character + 1,
1212-
range.End.Line + 1,
1213-
range.End.Character + 1);
1216+
sl = range.Start.Line + 1;
1217+
sc = range.Start.Character + 1;
1218+
el = range.End.Line + 1;
1219+
ec = range.End.Character + 1;
12141220
}
12151221

1216-
1217-
formattedScript = formattedScript ?? scriptFile.Contents;
12181222
var extent = scriptFile.ScriptAst.Extent;
12191223

1220-
// todo create an extension for this
1221-
Range editRange;
1222-
if (range != null)
1224+
// todo create an extension for converting range to script extent
1225+
editRange = new Range
12231226
{
1224-
editRange = new Range
1227+
Start = new Position
12251228
{
1226-
Start = new Position
1227-
{
1228-
Line = extent.StartLineNumber - 1,
1229-
Character = extent.StartColumnNumber - 1
1230-
},
1231-
End = new Position
1232-
{
1233-
Line = extent.EndLineNumber - 1,
1234-
Character = extent.EndColumnNumber - 1
1235-
}
1236-
};
1237-
}
1238-
else
1239-
{
1240-
editRange = range;
1241-
}
1229+
Line = extent.StartLineNumber - 1,
1230+
Character = extent.StartColumnNumber - 1
1231+
},
1232+
End = new Position
1233+
{
1234+
Line = extent.EndLineNumber - 1,
1235+
Character = extent.EndColumnNumber - 1
1236+
}
1237+
};
12421238

1239+
formattedScript = await editorSession.AnalysisService.Format(scriptFile.Contents, sl, sc, el, ec);
1240+
formattedScript = formattedScript ?? scriptFile.Contents;
12431241
return Tuple.Create(formattedScript, editRange);
12441242
}
12451243

0 commit comments

Comments
 (0)