Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix document symbols #171

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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