From 2fec4a1893f20a34214f41bb378da9d992d54636 Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Mon, 25 Oct 2021 23:26:16 -0700 Subject: [PATCH 1/3] Nested classes in functions no longer raise error --- jedi_language_server/jedi_utils.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/jedi_language_server/jedi_utils.py b/jedi_language_server/jedi_utils.py index a22a754..9bd6964 100644 --- a/jedi_language_server/jedi_utils.py +++ b/jedi_language_server/jedi_utils.py @@ -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__"} @@ -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 From 50530556361285012e9b633cf7443df7b5475f88 Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Mon, 25 Oct 2021 23:28:30 -0700 Subject: [PATCH 2/3] Run poetry update --- poetry.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index 5a781f0..9a9ea13 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,6 +1,6 @@ [[package]] name = "astroid" -version = "2.8.3" +version = "2.8.4" description = "An abstract syntax tree for Python with inference support." category = "dev" optional = false @@ -544,7 +544,7 @@ tomlkit = ">=0.5.8" [[package]] name = "tomli" -version = "1.2.1" +version = "1.2.2" description = "A lil' TOML parser" category = "dev" optional = false @@ -687,8 +687,8 @@ content-hash = "02149126b3245d9bebe72923c403af568dcccbfabc40397e3e77d136f85b3fd3 [metadata.files] astroid = [ - {file = "astroid-2.8.3-py3-none-any.whl", hash = "sha256:f9d66e3a4a0e5b52819b2ff41ac2b179df9d180697db71c92beb33a60c661794"}, - {file = "astroid-2.8.3.tar.gz", hash = "sha256:0e361da0744d5011d4f5d57e64473ba9b7ab4da1e2d45d6631ebd67dd28c3cce"}, + {file = "astroid-2.8.4-py3-none-any.whl", hash = "sha256:0755c998e7117078dcb7d0bda621391dd2a85da48052d948c7411ab187325346"}, + {file = "astroid-2.8.4.tar.gz", hash = "sha256:1e83a69fd51b013ebf5912d26b9338d6643a55fec2f20c787792680610eed4a2"}, ] atomicwrites = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, @@ -1023,8 +1023,8 @@ toml-sort = [ {file = "toml_sort-0.19.0-py3-none-any.whl", hash = "sha256:ca7c7100b0bd14faf3056361ddff478411a609fbaabd00c27d48569e62ab55bc"}, ] tomli = [ - {file = "tomli-1.2.1-py3-none-any.whl", hash = "sha256:8dd0e9524d6f386271a36b41dbf6c57d8e32fd96fd22b6584679dc569d20899f"}, - {file = "tomli-1.2.1.tar.gz", hash = "sha256:a5b75cb6f3968abb47af1b40c1819dc519ea82bcc065776a866e8d74c5ca9442"}, + {file = "tomli-1.2.2-py3-none-any.whl", hash = "sha256:f04066f68f5554911363063a30b108d2b5a5b1a010aa8b6132af78489fe3aade"}, + {file = "tomli-1.2.2.tar.gz", hash = "sha256:c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee"}, ] tomlkit = [ {file = "tomlkit-0.7.2-py2.py3-none-any.whl", hash = "sha256:173ad840fa5d2aac140528ca1933c29791b79a374a0861a80347f42ec9328117"}, From d9e8e89635bf1420f9278621810f7f50c01e360a Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Mon, 25 Oct 2021 23:30:07 -0700 Subject: [PATCH 3/3] Bump version, update changelog --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55429ff..5b9c009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 701b5a5..cb6bbfc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md"