Skip to content

Commit 43b7209

Browse files
committed
Fix LSP kind for Jedi string completions
1 parent a362006 commit 43b7209

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎pylsp/plugins/jedi_completion.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"keyword": lsp.CompletionItemKind.Keyword,
2727
"property": lsp.CompletionItemKind.Property, # added in Jedi 0.18
2828
"statement": lsp.CompletionItemKind.Variable,
29+
"string": lsp.CompletionItemKind.Value,
2930
}
3031

3132
# Types of parso nodes for which snippet is not included in the completion

‎test/plugins/test_completion.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ def test_jedi_completion_type(case, config, workspace):
133133
assert items[case.label]["kind"] == case.expected
134134

135135

136+
@pytest.mark.parametrize("enum_name", ["Kind", "Foo"])
137+
def test_jedi_dictionary_key_completion_type(enum_name, config, workspace):
138+
source = (
139+
"from enum import Enum\n"
140+
f"class {enum_name}(str, Enum):\n"
141+
" something = 'value'\n"
142+
"def foo():\n"
143+
f" a = {{'some_key': {enum_name}.something}}\n"
144+
" a['some"
145+
)
146+
doc = Document(DOC_URI, workspace, source)
147+
items = pylsp_jedi_completions(config, doc, {"line": 5, "character": 11})
148+
149+
assert items
150+
item = next(item for item in items if item["label"].strip("'") == "some_key")
151+
assert item["kind"] == lsp.CompletionItemKind.Value
152+
assert item["insertText"] == item["label"]
153+
154+
136155
def test_jedi_completion(config, workspace) -> None:
137156
# Over 'i' in os.path.isabs(...)
138157
com_position = {"line": 1, "character": 15}

0 commit comments

Comments
 (0)