Skip to content

Commit

Permalink
Merge pull request #171 from pappasam/fix-document-symbols
Browse files Browse the repository at this point in the history
Fix document symbols
  • Loading branch information
pappasam authored Oct 26, 2021
2 parents 91ff1e2 + d9e8e89 commit b41a22e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

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).

## 0.34.8

### Fixed

- 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)

## 0.34.7

### Added
Expand Down
19 changes: 14 additions & 5 deletions jedi_language_server/jedi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
if parent.type == "module":
# add module-level variables to list
results.append(symbol)
if name.type == "class":
# if they're a class, they can also be a namespace
_name_lookup[name] = symbol
elif (

if name.type in ["class", "function"]:
# if they're a class, they can also be a namespace
_name_lookup[name] = symbol

if (
parent.type == "class"
and name.type == "function"
and name.name in {"__init__"}
Expand Down Expand Up @@ -186,11 +188,18 @@ def lsp_document_symbols(names: List[Name]) -> List[DocumentSymbol]:
# far as code is concerned, @property-decorated items should be
# considered "methods" since do more than just assign a value.
symbol.kind = SymbolKind.Method
else:
elif name.type != "class":
symbol.kind = SymbolKind.Property
parent_symbol = _name_lookup[parent]
assert parent_symbol.children is not None
parent_symbol.children.append(symbol)
elif parent.type == "function":
# only show nested classes and functions to avoid excessive info
# could be controlled by an initialization option
if name.type in ["class", "function"]:
parent_symbol = _name_lookup[parent]
assert parent_symbol.children is not None
parent_symbol.children.append(symbol)
return results


Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ line_length = 79

[tool.poetry]
name = "jedi-language-server"
version = "0.34.7"
version = "0.34.8"
description = "A language server for Jedi!"
authors = ["Sam Roeca <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit b41a22e

Please sign in to comment.