feat: Enhance GetSymbolsOverviewTool with nested symbol retrieval #826
+83
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Enhances the symbol overview functionality by adding support for nested symbol retrieval with intelligent filtering. This PR resolves the TODO comment in
LanguageServerSymbolRetriever.get_symbol_overview()by refactoring the underlying API to support depth-based traversal and kind-based filtering, while maintaining backward compatibility.Motivation & Problem
Current Limitations
get_symbols_overviewonly returned minimal information about top-level symbols (name_path and kind)SymbolOverviewElementdataclass was defined but never used outside its definitionget_symbol_overviewmethod to access nested symbolsTODO Comment Context
This TODO had two parts:
Interestingly, the language server already returns complete symbol trees with children—the capability just wasn't exposed through the API!
Changes
1. Refactored
LanguageServerSymbolRetriever.get_symbol_overview()(symbol.py)Before:
After:
2. Simplified
GetSymbolsOverviewTool.apply()(symbol_tools.py)Before (would need ~48 lines to support depth):
After:
Example Usage
Default behavior (backward compatible, depth=0)
Returns:
[ { "name": "UserManager", "name_path": "UserManager", "kind": "Class", "location": { "line": 10, "column": 6, "relative_path": "src/main.py" }, "body_location": { "start_line": 10, "end_line": 50 } }, { "name": "process_data", "name_path": "process_data", "kind": "Function", "location": {"line": 52, "column": 0}, "body_location": {"start_line": 52, "end_line": 60} } ]Get overview with methods (depth=1)
Returns:
[ { "name": "UserManager", "name_path": "UserManager", "kind": "Class", "location": { "line": 10, "column": 6, "relative_path": "src/main.py" }, "body_location": { "start_line": 10, "end_line": 50 }, "children": [ { "name": "__init__", "name_path": "UserManager/__init__", "kind": "Method", "location": {"line": 12, "column": 8}, "body_location": {"start_line": 12, "end_line": 15} }, { "name": "add_user", "name_path": "UserManager/add_user", "kind": "Method", "location": {"line": 17, "column": 8}, "body_location": {"start_line": 17, "end_line": 25} } ] } ]Note: Variable symbols are automatically filtered out by default when
depth > 0.