@@ -259,6 +259,13 @@ async def surround_with_command(
259
259
if document is None :
260
260
return
261
261
262
+ lines = document .get_lines ()
263
+ need_return = False
264
+ if insert_range .end .line >= len (lines ):
265
+ insert_range .end .line == len (lines ) - 1
266
+ insert_range .end .character = len (lines [- 1 ])
267
+ need_return = True
268
+
262
269
spaces = "" .join (itertools .takewhile (str .isspace , document .get_lines ()[insert_range .start .line ]))
263
270
264
271
edits : List [Union [TextEdit , AnnotatedTextEdit ]] = [
@@ -281,7 +288,9 @@ async def surround_with_command(
281
288
AnnotatedTextEdit (
282
289
"add_clause" ,
283
290
Range (start = Position (insert_range .end .line , 0 ), end = Position (insert_range .end .line , 0 )),
284
- f"{ spaces } EXCEPT message\n { spaces } Fail implement this\n { spaces } END\n " ,
291
+ ("\n " if need_return else "" )
292
+ + f"{ spaces } EXCEPT message\n { spaces } Fail implement this\n { spaces } END"
293
+ + ("\n " if not need_return else "" ),
285
294
)
286
295
)
287
296
p = Position (insert_range .end .line + 1 , len (spaces ) + 6 + 4 )
@@ -293,7 +302,9 @@ async def surround_with_command(
293
302
AnnotatedTextEdit (
294
303
"add_clause" ,
295
304
Range (start = Position (insert_range .end .line , 0 ), end = Position (insert_range .end .line , 0 )),
296
- f"{ spaces } FINALLY\n { spaces } Fail implement this\n { spaces } END\n " ,
305
+ ("\n " if need_return else "" )
306
+ + f"{ spaces } FINALLY\n { spaces } Fail implement this\n { spaces } END"
307
+ + ("\n " if not need_return else "" ),
297
308
)
298
309
)
299
310
p = Position (insert_range .end .line + 2 , len (spaces ) + 4 )
@@ -304,11 +315,11 @@ async def surround_with_command(
304
315
AnnotatedTextEdit (
305
316
"add_clause" ,
306
317
Range (start = Position (insert_range .end .line , 0 ), end = Position (insert_range .end .line , 0 )),
307
- f"{ spaces } EXCEPT message\n "
318
+ ( " \n " if need_return else "" ) + f"{ spaces } EXCEPT message\n "
308
319
f"{ spaces } Fail implement this\n "
309
320
f"{ spaces } FINALLY\n "
310
321
f"{ spaces } Fail implement this\n "
311
- f"{ spaces } END\n " ,
322
+ f"{ spaces } END" + ( " \n " if not need_return else "" ) ,
312
323
)
313
324
)
314
325
p = Position (insert_range .end .line + 1 , len (spaces ) + 6 + 4 )
0 commit comments