Skip to content

Commit b41a22e

Browse files
authored
Merge pull request #171 from pappasam/fix-document-symbols
Fix document symbols
2 parents 91ff1e2 + d9e8e89 commit b41a22e

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.34.8
8+
9+
### Fixed
10+
11+
- Fixed bug where classes nested inside functions cause exceptions in textDocument/documentSymbol. This release avoids the crash and includes info about classes and functions nested inside functions. See [this issue](https://github.com/pappasam/jedi-language-server/issues/170)
12+
713
## 0.34.7
814

915
### Added

jedi_language_server/jedi_utils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
154154
if parent.type == "module":
155155
# add module-level variables to list
156156
results.append(symbol)
157-
if name.type == "class":
158-
# if they're a class, they can also be a namespace
159-
_name_lookup[name] = symbol
160-
elif (
157+
158+
if name.type in ["class", "function"]:
159+
# if they're a class, they can also be a namespace
160+
_name_lookup[name] = symbol
161+
162+
if (
161163
parent.type == "class"
162164
and name.type == "function"
163165
and name.name in {"__init__"}
@@ -186,11 +188,18 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
186188
# far as code is concerned, @property-decorated items should be
187189
# considered "methods" since do more than just assign a value.
188190
symbol.kind = SymbolKind.Method
189-
else:
191+
elif name.type != "class":
190192
symbol.kind = SymbolKind.Property
191193
parent_symbol = _name_lookup[parent]
192194
assert parent_symbol.children is not None
193195
parent_symbol.children.append(symbol)
196+
elif parent.type == "function":
197+
# only show nested classes and functions to avoid excessive info
198+
# could be controlled by an initialization option
199+
if name.type in ["class", "function"]:
200+
parent_symbol = _name_lookup[parent]
201+
assert parent_symbol.children is not None
202+
parent_symbol.children.append(symbol)
194203
return results
195204

196205

poetry.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ line_length = 79
1111

1212
[tool.poetry]
1313
name = "jedi-language-server"
14-
version = "0.34.7"
14+
version = "0.34.8"
1515
description = "A language server for Jedi!"
1616
authors = ["Sam Roeca <samuel.roeca@gmail.com>"]
1717
readme = "README.md"

0 commit comments

Comments
 (0)