@@ -1190,7 +1190,9 @@ await requestContext.SendResult(new TextEdit[1]
1190
1190
1191
1191
#region Event Handlers
1192
1192
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 )
1194
1196
{
1195
1197
1196
1198
// TODO Get settings
@@ -1199,47 +1201,43 @@ private async Task<Tuple<string, Range>> Format(string documentUri, Range range)
1199
1201
1200
1202
// TODO raise an error event incase format returns null;
1201
1203
string formattedScript ;
1204
+ Range editRange ;
1205
+ int sl , sc , el , ec ;
1202
1206
if ( range == null )
1203
1207
{
1204
1208
formattedScript = await editorSession . AnalysisService . Format ( scriptFile . Contents ) ;
1209
+ sl = - 1 ;
1210
+ sc = - 1 ;
1211
+ el = - 1 ;
1212
+ ec = - 1 ;
1205
1213
}
1206
1214
else
1207
1215
{
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 ;
1214
1220
}
1215
1221
1216
-
1217
- formattedScript = formattedScript ?? scriptFile . Contents ;
1218
1222
var extent = scriptFile . ScriptAst . Extent ;
1219
1223
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
1223
1226
{
1224
- editRange = new Range
1227
+ Start = new Position
1225
1228
{
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
+ } ;
1242
1238
1239
+ formattedScript = await editorSession . AnalysisService . Format ( scriptFile . Contents , sl , sc , el , ec ) ;
1240
+ formattedScript = formattedScript ?? scriptFile . Contents ;
1243
1241
return Tuple . Create ( formattedScript , editRange ) ;
1244
1242
}
1245
1243
0 commit comments