Skip to content

Commit 89e8763

Browse files
committed
Props are now children of classes, not methods where defined
1 parent bd51adb commit 89e8763

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1414

1515
- `pygls` 1.0!
1616
- Diagnostics (for syntax errors) are once-again enabled by default.
17+
- Properties are now children of classes, not the methods where they are defined. Resolves <https://github.com/pappasam/jedi-language-server/issues/240>
1718

1819
## 0.39.0
1920

jedi_language_server/jedi_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,19 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
233233
elif parent not in _name_lookup:
234234
# unqualified names are not included in the tree
235235
continue
236-
elif name.is_side_effect() and name.get_line_code().strip().startswith(
237-
"self."
236+
elif (
237+
name.is_side_effect()
238+
and parent.name == "__init__"
239+
and name.get_line_code().strip().startswith("self.")
238240
):
239241
# handle attribute creation on __init__ method
240242
symbol.kind = SymbolKind.Property
241-
parent_symbol = _name_lookup[parent]
242-
assert parent_symbol.children is not None
243-
parent_symbol.children.append(symbol)
243+
grandparent_symbol = _name_lookup.get(parent.parent())
244+
if grandparent_symbol is not None and (
245+
grandparent_symbol.kind == SymbolKind.Class
246+
):
247+
assert grandparent_symbol.children is not None
248+
grandparent_symbol.children.append(symbol)
244249
elif parent.type == "class":
245250
# children are added for class scopes
246251
if name.type == "function":

tests/lsp_tests/test_document_symbol.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
SYMBOL_TEST_ROOT = TEST_DATA / "symbol"
1313

14+
# pylint: disable=line-too-long
15+
1416

1517
def test_document_symbol() -> None:
1618
"""Test document symbol request.
@@ -121,22 +123,21 @@ def test_document_symbol() -> None:
121123
"end": {"line": 18, "character": 16},
122124
},
123125
"detail": "def __init__",
124-
"children": [
125-
{
126-
"name": "somedata",
127-
"kind": 7,
128-
"range": {
129-
"start": {"line": 19, "character": 8},
130-
"end": {"line": 19, "character": 28},
131-
},
132-
"selectionRange": {
133-
"start": {"line": 19, "character": 13},
134-
"end": {"line": 19, "character": 21},
135-
},
136-
"detail": "self.somedata = arg1",
137-
"children": [],
138-
}
139-
],
126+
"children": [],
127+
},
128+
{
129+
"name": "somedata",
130+
"kind": 7,
131+
"range": {
132+
"start": {"line": 19, "character": 8},
133+
"end": {"line": 19, "character": 28},
134+
},
135+
"selectionRange": {
136+
"start": {"line": 19, "character": 13},
137+
"end": {"line": 19, "character": 21},
138+
},
139+
"detail": "self.somedata = arg1",
140+
"children": [],
140141
},
141142
{
142143
"name": "do_something",

0 commit comments

Comments
 (0)