@@ -406,13 +406,17 @@ def complete_sort_name(name: Completion, append_text: str) -> str:
406
406
return "v" + append_text
407
407
408
408
409
- def clean_completion_name (name : str , char_before_cursor : str ) -> str :
409
+ def clean_completion_name (
410
+ name : str , char_before_cursor : str , char_after_cursor : str
411
+ ) -> str :
410
412
"""Clean the completion name, stripping bad surroundings.
411
413
412
414
Currently, removes surrounding " and '.
413
415
"""
414
416
if char_before_cursor in {"'" , '"' }:
415
- return name .lstrip (char_before_cursor )
417
+ name = name .lstrip (char_before_cursor )
418
+ if char_after_cursor in {"'" , '"' }:
419
+ name = name .rstrip (char_after_cursor )
416
420
return name
417
421
418
422
@@ -484,18 +488,21 @@ def clear_completions_cache() -> None:
484
488
def lsp_completion_item (
485
489
completion : Completion ,
486
490
char_before_cursor : str ,
491
+ char_after_cursor : str ,
487
492
enable_snippets : bool ,
488
493
resolve_eagerly : bool ,
489
494
markup_kind : MarkupKind ,
490
495
sort_append_text : str = "" ,
491
496
) -> CompletionItem :
492
497
"""Using a Jedi completion, obtain a jedi completion item."""
493
498
completion_name = completion .name
494
- name_clean = clean_completion_name (completion_name , char_before_cursor )
499
+ name_clean = clean_completion_name (
500
+ completion_name , char_before_cursor , char_after_cursor
501
+ )
495
502
lsp_type = get_lsp_completion_type (completion .type )
496
503
completion_item = CompletionItem (
497
- label = completion_name ,
498
- filter_text = completion_name ,
504
+ label = name_clean ,
505
+ filter_text = name_clean ,
499
506
kind = lsp_type ,
500
507
sort_text = complete_sort_name (completion , sort_append_text ),
501
508
insert_text = name_clean ,
@@ -521,7 +528,7 @@ def lsp_completion_item(
521
528
snippet_signature = get_snippet_signature (signatures [0 ])
522
529
except Exception :
523
530
return completion_item
524
- new_text = completion_name + snippet_signature
531
+ new_text = name_clean + snippet_signature
525
532
completion_item .insert_text = new_text
526
533
completion_item .insert_text_format = InsertTextFormat .Snippet
527
534
return completion_item
0 commit comments