Skip to content

Commit 5c87c41

Browse files
committed
Handle dictionary key completions consistently
1 parent 47ae161 commit 5c87c41

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

jedi_language_server/jedi_utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,17 @@ def complete_sort_name(name: Completion, append_text: str) -> str:
406406
return "v" + append_text
407407

408408

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:
410412
"""Clean the completion name, stripping bad surroundings.
411413
412414
Currently, removes surrounding " and '.
413415
"""
414416
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)
416420
return name
417421

418422

@@ -484,18 +488,21 @@ def clear_completions_cache() -> None:
484488
def lsp_completion_item(
485489
completion: Completion,
486490
char_before_cursor: str,
491+
char_after_cursor: str,
487492
enable_snippets: bool,
488493
resolve_eagerly: bool,
489494
markup_kind: MarkupKind,
490495
sort_append_text: str = "",
491496
) -> CompletionItem:
492497
"""Using a Jedi completion, obtain a jedi completion item."""
493498
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+
)
495502
lsp_type = get_lsp_completion_type(completion.type)
496503
completion_item = CompletionItem(
497-
label=completion_name,
498-
filter_text=completion_name,
504+
label=name_clean,
505+
filter_text=name_clean,
499506
kind=lsp_type,
500507
sort_text=complete_sort_name(completion, sort_append_text),
501508
insert_text=name_clean,
@@ -521,7 +528,7 @@ def lsp_completion_item(
521528
snippet_signature = get_snippet_signature(signatures[0])
522529
except Exception:
523530
return completion_item
524-
new_text = completion_name + snippet_signature
531+
new_text = name_clean + snippet_signature
525532
completion_item.insert_text = new_text
526533
completion_item.insert_text_format = InsertTextFormat.Snippet
527534
return completion_item

0 commit comments

Comments
 (0)