|
| 1 | +# Symbol Documentation Tool Implementation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Symbol Documentation Tool is a feature added to Roo Code that enables retrieving documentation, type information, and hover details for symbols in the codebase. This document details the implementation of this feature, which extends Roo's capabilities to provide better code understanding and navigation. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +The implementation follows a standard pattern for Roo tools, with changes made to the following components: |
| 10 | + |
| 11 | +1. **Tool Definition** |
| 12 | + |
| 13 | + - Added to toolUseNames and toolParamNames arrays in `src/core/assistant-message/index.ts` |
| 14 | + - Created a GetSymbolDocumentationToolUse interface |
| 15 | + |
| 16 | +2. **Tool Prompt** |
| 17 | + |
| 18 | + - Added tool description in `src/core/prompts/tools/get-symbol-documentation.ts` |
| 19 | + - Registered in `src/core/prompts/tools/index.ts` |
| 20 | + |
| 21 | +3. **Tool Group Assignment** |
| 22 | + |
| 23 | + - Added to the "read" tool group in `src/shared/tool-groups.ts` |
| 24 | + - Added display name "look up symbols" |
| 25 | + |
| 26 | +4. **Core Implementation** |
| 27 | + - Implemented in `src/core/Cline.ts` with the `getSymbolDocumentation` method |
| 28 | + |
| 29 | +## Implementation Details |
| 30 | + |
| 31 | +### Parameters |
| 32 | + |
| 33 | +The tool accepts two parameters: |
| 34 | + |
| 35 | +- `symbol_name` (required): The name of the symbol to look up (function, class, method, etc.) |
| 36 | +- `path` (optional): Path to a file where the symbol is used/referenced, to scope the search |
| 37 | + |
| 38 | +### Search Strategy |
| 39 | + |
| 40 | +The implementation follows a multi-stage approach to find symbols and their documentation: |
| 41 | + |
| 42 | +1. **File-Scoped Search** (when path is provided): |
| 43 | + |
| 44 | + - First tries to find the symbol defined in the document using `vscode.executeDocumentSymbolProvider` |
| 45 | + - If not found as a defined symbol, searches for occurrences of the symbol name in the file text |
| 46 | + - For each occurrence, attempts to retrieve hover information directly or at the definition site |
| 47 | + |
| 48 | +2. **Workspace-Wide Search** (fallback or when no path provided): |
| 49 | + |
| 50 | + - Uses `vscode.executeWorkspaceSymbolProvider` to find symbols across the workspace |
| 51 | + - Retrieves hover information at the symbol's location |
| 52 | + |
| 53 | +3. **Documentation Extraction**: |
| 54 | + - Uses `vscode.executeHoverProvider` to get hover information (documentation, type info) |
| 55 | + - Processes hover results from VS Code's language servers and formats them for display |
| 56 | + |
| 57 | +### VS Code Language Services Used |
| 58 | + |
| 59 | +The implementation leverages several VS Code API services: |
| 60 | + |
| 61 | +1. **Document Symbol Provider**: |
| 62 | + |
| 63 | + - Gets symbols defined within a specific file |
| 64 | + - Recursive search through the symbol hierarchy |
| 65 | + |
| 66 | +2. **Workspace Symbol Provider**: |
| 67 | + |
| 68 | + - Gets symbols defined anywhere in the workspace |
| 69 | + - Useful for finding global definitions |
| 70 | + |
| 71 | +3. **Hover Provider**: |
| 72 | + |
| 73 | + - Gets documentation, type information, and other details for a symbol |
| 74 | + - Works at both usage sites and definition sites |
| 75 | + |
| 76 | +4. **Definition Provider**: |
| 77 | + - Gets the location where a symbol is defined |
| 78 | + - Used to jump from a usage site to the definition for better documentation |
| 79 | + |
| 80 | +### Symbol Type Handling |
| 81 | + |
| 82 | +The implementation handles different types of symbols: |
| 83 | + |
| 84 | +1. **Locally Defined Symbols**: |
| 85 | + |
| 86 | + - Found directly in the document symbol hierarchy |
| 87 | + - Documentation retrieved at the definition site |
| 88 | + |
| 89 | +2. **Imported/Referenced Symbols**: |
| 90 | + |
| 91 | + - Located by searching for occurrences in the file text |
| 92 | + - Documentation may be retrieved at the usage site or by following the definition |
| 93 | + |
| 94 | +3. **Workspace Symbols**: |
| 95 | + - Global definitions found across the workspace |
| 96 | + - Used as a fallback when file-scoped search fails |
| 97 | + |
| 98 | +### Output Format |
| 99 | + |
| 100 | +The tool returns a formatted string with the following information: |
| 101 | + |
| 102 | +``` |
| 103 | +Symbol: [name] |
| 104 | +Location: [file path]:[line]:[column] |
| 105 | +Kind: [symbol kind] |
| 106 | +Status: [Defined in file/Imported/Referenced] |
| 107 | +[Container information if available] |
| 108 | +[Referenced in information if relevant] |
| 109 | +
|
| 110 | +Documentation: |
| 111 | +[Hover text from language server] |
| 112 | +``` |
| 113 | + |
| 114 | +## Error Handling |
| 115 | + |
| 116 | +The implementation handles several error cases: |
| 117 | + |
| 118 | +1. Symbol not found in specified file |
| 119 | +2. Symbol not found in workspace |
| 120 | +3. File not found or can't be opened |
| 121 | +4. Documentation not available for a symbol |
| 122 | +5. Language server errors |
| 123 | + |
| 124 | +## Example Usage |
| 125 | + |
| 126 | +``` |
| 127 | +<get_symbol_documentation> |
| 128 | +<symbol_name>User</symbol_name> |
| 129 | +<path>src/controllers/auth.ts</path> |
| 130 | +</get_symbol_documentation> |
| 131 | +``` |
| 132 | + |
| 133 | +This would look for the `User` symbol in the `auth.ts` file, retrieve its documentation, and return the formatted result to the LLM. |
| 134 | + |
| 135 | +## Performance Considerations |
| 136 | + |
| 137 | +The implementation is designed to be efficient by: |
| 138 | + |
| 139 | +1. First searching within a specific file when provided |
| 140 | +2. Using VS Code's optimized providers that leverage language servers |
| 141 | +3. Finding one match and retrieving its documentation rather than searching exhaustively |
| 142 | +4. Taking advantage of contextual information (file path) when available |
| 143 | + |
| 144 | +## Integration with Existing Capabilities |
| 145 | + |
| 146 | +This tool complements Roo's existing code navigation and understanding tools: |
| 147 | + |
| 148 | +- `read_file`: Gets full file content |
| 149 | +- `list_code_definition_names`: Lists top-level definitions in files |
| 150 | +- `search_files`: Finds patterns across files |
| 151 | + |
| 152 | +The Symbol Documentation Tool provides deeper, more specific information about individual symbols, making it valuable for understanding API details, type information, and documentation without having to read through entire files. |
0 commit comments