README.md•3.01 kB
# Semantic Code Analysis Tools
## Overview
Integrates Serena MCP's LSP-based semantic analysis capabilities into Hi-AI to provide more powerful code understanding abilities.
## Proposed Tool List
### 1. find_symbol
- **Function**: Search for symbols (functions, classes, variables) across the entire project
- **Keywords**: "find function", "where is class", "find function", "where is class"
- **LSP Usage**: Precise symbol location identification
### 2. go_to_definition
- **Function**: Navigate to a symbol's definition
- **Keywords**: "show definition", "declaration location", "go to definition", "show declaration"
- **LSP Usage**: Accurate definition location tracking
### 3. find_references
- **Function**: Find all locations where a symbol is used
- **Keywords**: "where used", "find references", "find usages", "show references"
- **LSP Usage**: Project-wide reference analysis
### 4. semantic_code_search
- **Function**: Semantic-based code search (more accurate than regex)
- **Keywords**: "find semantically", "semantic search", "semantic search"
- **LSP Usage**: AST-based semantic search
### 5. rename_symbol
- **Function**: Rename a symbol across the entire project
- **Keywords**: "rename", "rename everywhere", "rename everywhere"
- **LSP Usage**: Safe refactoring
### 6. extract_function
- **Function**: Extract a code block into a function
- **Keywords**: "extract to function", "extract method"
- **LSP Usage**: Automatic refactoring
### 7. get_call_hierarchy
- **Function**: Analyze function call hierarchy structure
- **Keywords**: "call structure", "call hierarchy", "who calls this"
- **LSP Usage**: Call relationship tracking
### 8. get_type_info
- **Function**: Provide type information for variables/expressions
- **Keywords**: "what type", "what type", "type info"
- **LSP Usage**: Type inference and display
## Implementation Methods
### Option 1: Using vscode-languageserver-node
```typescript
import {
createConnection,
TextDocuments,
ProposedFeatures
} from 'vscode-languageserver/node';
```
### Option 2: typescript-language-server integration
```typescript
import { TypeScriptLanguageService } from 'typescript-language-server';
```
### Option 3: Direct LSP client implementation
```typescript
import { spawn } from 'child_process';
// Run LSP server for each language
```
## Required Dependencies
```json
{
"dependencies": {
"vscode-languageserver": "^9.0.0",
"vscode-languageserver-textdocument": "^1.0.0",
"typescript-language-server": "^4.0.0"
}
}
```
## Benefits
1. **Accuracy**: Real code semantic understanding, not simple text matching
2. **Safety**: Prevent mistakes during refactoring
3. **Productivity**: IDE-level code navigation capabilities
4. **Multi-language Support**: All languages that support LSP
## Expected Effects
- Significant improvement in Hi-AI's code analysis accuracy
- Serena's strengths + Hi-AI's natural language processing = Best combination
- Dramatic improvement in developer experience