Skip to content

Commit

Permalink
Merge pull request #244 from pappasam/fix-property-symbol-in-init
Browse files Browse the repository at this point in the history
Props are now children of classes, not methods where defined
  • Loading branch information
pappasam authored Dec 7, 2022
2 parents bd51adb + 89e8763 commit 72471ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

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

## 0.39.0

Expand Down
15 changes: 10 additions & 5 deletions jedi_language_server/jedi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,19 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
elif parent not in _name_lookup:
# unqualified names are not included in the tree
continue
elif name.is_side_effect() and name.get_line_code().strip().startswith(
"self."
elif (
name.is_side_effect()
and parent.name == "__init__"
and name.get_line_code().strip().startswith("self.")
):
# handle attribute creation on __init__ method
symbol.kind = SymbolKind.Property
parent_symbol = _name_lookup[parent]
assert parent_symbol.children is not None
parent_symbol.children.append(symbol)
grandparent_symbol = _name_lookup.get(parent.parent())
if grandparent_symbol is not None and (
grandparent_symbol.kind == SymbolKind.Class
):
assert grandparent_symbol.children is not None
grandparent_symbol.children.append(symbol)
elif parent.type == "class":
# children are added for class scopes
if name.type == "function":
Expand Down
33 changes: 17 additions & 16 deletions tests/lsp_tests/test_document_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

SYMBOL_TEST_ROOT = TEST_DATA / "symbol"

# pylint: disable=line-too-long


def test_document_symbol() -> None:
"""Test document symbol request.
Expand Down Expand Up @@ -121,22 +123,21 @@ def test_document_symbol() -> None:
"end": {"line": 18, "character": 16},
},
"detail": "def __init__",
"children": [
{
"name": "somedata",
"kind": 7,
"range": {
"start": {"line": 19, "character": 8},
"end": {"line": 19, "character": 28},
},
"selectionRange": {
"start": {"line": 19, "character": 13},
"end": {"line": 19, "character": 21},
},
"detail": "self.somedata = arg1",
"children": [],
}
],
"children": [],
},
{
"name": "somedata",
"kind": 7,
"range": {
"start": {"line": 19, "character": 8},
"end": {"line": 19, "character": 28},
},
"selectionRange": {
"start": {"line": 19, "character": 13},
"end": {"line": 19, "character": 21},
},
"detail": "self.somedata = arg1",
"children": [],
},
{
"name": "do_something",
Expand Down

0 comments on commit 72471ae

Please sign in to comment.