From 95ea5321433ac8e5ab6aa3911f361bb2540a19ce Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Tue, 25 Mar 2025 13:14:40 +0100 Subject: [PATCH] All symbols have "children" field now --- src/multilspy/language_server.py | 12 +++++------- src/multilspy/multilspy_types.py | 4 +--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/multilspy/language_server.py b/src/multilspy/language_server.py index 746ab937..8ed1cfa3 100644 --- a/src/multilspy/language_server.py +++ b/src/multilspy/language_server.py @@ -702,7 +702,7 @@ class LanguageServer: item['body'] = self.retrieve_symbol_body(item) item[LSPConstants.CHILDREN] = item.get(LSPConstants.CHILDREN, []) - symbols_without_children: List[multilspy_types.UnifiedSymbolInformation] = [] + flat_all_symbol_list: List[multilspy_types.UnifiedSymbolInformation] = [] assert isinstance(response, list) root_nodes: List[multilspy_types.UnifiedSymbolInformation] = [] for item in response: @@ -722,18 +722,16 @@ class LanguageServer: turn_item_into_symbol_with_children(node) assert LSPConstants.CHILDREN in node children = node[LSPConstants.CHILDREN] - node_without_children = node.copy() - del node_without_children[LSPConstants.CHILDREN] - l.append(node_without_children) + l.append(node) for child in children: l.extend(visit_tree_nodes_and_build_tree_repr(child)) return l - symbols_without_children.extend(visit_tree_nodes_and_build_tree_repr(item)) + flat_all_symbol_list.extend(visit_tree_nodes_and_build_tree_repr(item)) else: - symbols_without_children.append(multilspy_types.UnifiedSymbolInformation(**item)) + flat_all_symbol_list.append(multilspy_types.UnifiedSymbolInformation(**item)) - result = symbols_without_children, root_nodes + result = flat_all_symbol_list, root_nodes self.logger.log(f"Caching document symbols for {relative_file_path}", logging.DEBUG) self._document_symbols_cache[cache_key] = (file_data.content_hash, result) self._cache_has_changed = True diff --git a/src/multilspy/multilspy_types.py b/src/multilspy/multilspy_types.py index 55ec0d7e..982959ad 100644 --- a/src/multilspy/multilspy_types.py +++ b/src/multilspy/multilspy_types.py @@ -215,14 +215,12 @@ class UnifiedSymbolInformation(TypedDict): body: NotRequired[str] """ The body of the symbol. """ - children: NotRequired[List[UnifiedSymbolInformation]] + children: List[UnifiedSymbolInformation] """ The children of the symbol. Added to be compatible with `lsp_types.DocumentSymbol`, since it is sometimes useful to have the children of the symbol as a user-facing feature.""" -TreeRepr = Dict[int, List['TreeRepr']] - class MarkupKind(Enum): """Describes the content type that a client supports in various result literals like `Hover`, `ParameterInfo` or `CompletionItem`.