Skip to content

Commit b408d68

Browse files
authored
Merge pull request #127 from pappasam/test-self-in-snippets
Add test addressing self in snippet completions
2 parents 1d30a5a + 7c53f09 commit b408d68

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/lsp_tests/test_completion.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,49 @@ def test_eager_lsp_completion() -> None:
113113
],
114114
}
115115
assert_that(actual, is_(expected))
116+
117+
118+
def test_lsp_completion_class_method() -> None:
119+
"""Checks whether completion returns self unnecessarily.
120+
121+
References: https://github.com/pappasam/jedi-language-server/issues/121
122+
123+
Note: I resolve eagerly to make test simpler
124+
"""
125+
with session.LspSession() as ls_session:
126+
# Initialize, asking for eager resolution.
127+
initialize_params = copy.deepcopy(VSCODE_DEFAULT_INITIALIZE)
128+
initialize_params["initializationOptions"] = {
129+
"completion": {"resolveEagerly": True}
130+
}
131+
ls_session.initialize(initialize_params)
132+
133+
uri = as_uri(COMPLETION_TEST_ROOT / "completion_test_class_self.py")
134+
actual = ls_session.text_document_completion(
135+
{
136+
"textDocument": {"uri": uri},
137+
"position": {"line": 7, "character": 13},
138+
"context": {"triggerKind": 1},
139+
}
140+
)
141+
142+
# pylint: disable=line-too-long
143+
expected = {
144+
"isIncomplete": False,
145+
"items": [
146+
{
147+
"label": "some_method",
148+
"kind": 3,
149+
"detail": "def some_method",
150+
"documentation": {
151+
"kind": "markdown",
152+
"value": "```\nsome_method(x)\n\nGreat method.\n```\n",
153+
},
154+
"sortText": "z",
155+
"filterText": "some_method",
156+
"insertText": "some_method(${1:x})$0",
157+
"insertTextFormat": 2,
158+
}
159+
],
160+
}
161+
assert_that(actual, is_(expected))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class SomeClass:
2+
def some_method(self, x):
3+
"""Great method."""
4+
return x
5+
6+
7+
instance = SomeClass()
8+
instance.some

0 commit comments

Comments
 (0)