49
49
[Arguments] ${args}
50
50
# TODO: implement keyword "${name}".
51
51
Fail Not Implemented
52
-
53
52
"""
54
53
)
55
54
58
57
${name}
59
58
# TODO: implement keyword "${name}".
60
59
Fail Not Implemented
61
-
62
60
"""
63
61
)
64
62
@@ -265,13 +263,13 @@ async def _apply_create_keyword(self, document: TextDocument, insert_text: str)
265
263
keyword_sections = find_keyword_sections (model )
266
264
keyword_section = keyword_sections [- 1 ] if keyword_sections else None
267
265
268
- if keyword_section is not None :
269
- node_range = range_from_node (keyword_section )
266
+ lines = document .get_lines ()
270
267
268
+ if keyword_section is not None :
269
+ node_range = range_from_node (keyword_section , skip_non_data = True , allow_comments = True )
271
270
insert_pos = Position (node_range .end .line + 1 , 0 )
272
271
insert_range = Range (insert_pos , insert_pos )
273
-
274
- insert_text = f"\n { insert_text } "
272
+ insert_text = f"\n \n { insert_text } "
275
273
else :
276
274
if namespace .languages is None or not namespace .languages .languages :
277
275
keywords_text = "Keywords"
@@ -280,14 +278,27 @@ async def _apply_create_keyword(self, document: TextDocument, insert_text: str)
280
278
281
279
insert_text = f"\n \n *** { keywords_text } ***\n { insert_text } "
282
280
283
- lines = document .get_lines ()
284
281
end_line = len (lines ) - 1
285
282
while end_line >= 0 and not lines [end_line ].strip ():
286
283
end_line -= 1
287
284
doc_pos = Position (end_line + 1 , 0 )
288
285
289
286
insert_range = Range (doc_pos , doc_pos )
290
287
288
+ if insert_range .start .line >= len (lines ) and lines [- 1 ].strip ():
289
+ doc_pos = Position (len (lines ) - 1 , len (lines [- 1 ]))
290
+ insert_range = Range (doc_pos , doc_pos )
291
+ insert_text = "\n " + insert_text
292
+
293
+ if insert_range .start .line <= len (lines ) and lines [insert_range .start .line ].startswith ("*" ):
294
+ insert_text = insert_text + "\n \n "
295
+ if (
296
+ insert_range .start .line + 1 <= len (lines )
297
+ and not lines [insert_range .start .line ].strip ()
298
+ and lines [insert_range .start .line + 1 ].startswith ("*" )
299
+ ):
300
+ insert_text = insert_text + "\n "
301
+
291
302
we = WorkspaceEdit (
292
303
document_changes = [
293
304
TextDocumentEdit (
0 commit comments