All symbols have "children" field now

This commit is contained in:
Michael Panchenko committed 2025-03-25 13:14:40 +01:00
1 parent 6db78993e3
commit 95ea532143
2 files changed
+6 -10

No files matched your search

+5 -7
View File
@@ -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
+1 -3
View File
@@ -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`.