Add tests and documentation for CodexLens LSP tool

- Introduced a new test script for the CodexLens LSP tool to validate core functionalities including symbol search, find definition, find references, and get hover.
- Created comprehensive documentation for the MCP endpoint design, detailing the architecture, features, and integration with the CCW MCP Manager.
- Developed a detailed implementation plan for transitioning to a real LSP server, outlining phases, architecture, and acceptance criteria.
This commit is contained in:
catlog22
2026-01-19 23:26:35 +08:00
parent eeaefa7208
commit 3fe630f221
24 changed files with 3044 additions and 509 deletions

View File

@@ -0,0 +1,7 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
tsconfig.json
**/*.map
**/*.ts

View File

@@ -0,0 +1,70 @@
# CCW VSCode Bridge
This extension provides a bridge between the CCW MCP server and VSCode's live Language Server Protocol (LSP) features.
## Features
- Exposes VSCode LSP features via HTTP API on `http://127.0.0.1:3457`
- Supports:
- Go to Definition
- Find References
- Hover Information
- Document Symbols
## Installation
1. Install dependencies:
```bash
npm install
```
2. Compile the extension:
```bash
npm run compile
```
3. Press F5 in VSCode to launch the extension in debug mode, or:
- Run `vsce package` to create a VSIX file
- Install the VSIX file in VSCode
## API Endpoints
All endpoints accept POST requests with JSON body:
### `/get_definition`
```json
{
"file_path": "/absolute/path/to/file.ts",
"line": 10,
"character": 5
}
```
### `/get_references`
```json
{
"file_path": "/absolute/path/to/file.ts",
"line": 10,
"character": 5
}
```
### `/get_hover`
```json
{
"file_path": "/absolute/path/to/file.ts",
"line": 10,
"character": 5
}
```
### `/get_document_symbols`
```json
{
"file_path": "/absolute/path/to/file.ts"
}
```
## Usage with CCW MCP
The CCW MCP server includes a `vscode_lsp` tool that communicates with this extension automatically.

View File

@@ -0,0 +1,27 @@
{
"name": "ccw-vscode-bridge",
"displayName": "CCW VSCode Bridge",
"description": "Bridge between CCW MCP server and VSCode LSP features",
"version": "0.1.0",
"publisher": "ccw",
"engines": {
"vscode": "^1.80.0"
},
"categories": [
"Other"
],
"activationEvents": [
"*"
],
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/vscode": "^1.80.0",
"typescript": "^5.0.0"
}
}

View File

@@ -0,0 +1,165 @@
import * as vscode from 'vscode';
import * as http from 'http';
const PORT = 3457; // Port for the bridge server
interface LSPRequest {
file_path: string;
line?: number;
character?: number;
}
export function activate(context: vscode.ExtensionContext) {
const server = http.createServer(async (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
// Handle CORS preflight
if (req.method === 'OPTIONS') {
res.writeHead(200);
return res.end();
}
if (req.method !== 'POST' || !req.url) {
res.writeHead(405);
return res.end(JSON.stringify({ error: 'Method Not Allowed' }));
}
let body = '';
req.on('data', (chunk) => {
body += chunk.toString();
});
req.on('end', async () => {
try {
const payload: LSPRequest = JSON.parse(body);
const { file_path, line, character } = payload;
const uri = vscode.Uri.file(file_path);
let result: unknown;
switch (req.url) {
case '/get_definition': {
if (line === undefined || character === undefined) {
res.writeHead(400);
return res.end(JSON.stringify({ error: 'line and character are required' }));
}
const position = new vscode.Position(line - 1, character - 1); // VSCode API is 0-based
result = await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
uri,
position
);
break;
}
case '/get_references': {
if (line === undefined || character === undefined) {
res.writeHead(400);
return res.end(JSON.stringify({ error: 'line and character are required' }));
}
const position = new vscode.Position(line - 1, character - 1);
result = await vscode.commands.executeCommand(
'vscode.executeReferenceProvider',
uri,
position
);
break;
}
case '/get_hover': {
if (line === undefined || character === undefined) {
res.writeHead(400);
return res.end(JSON.stringify({ error: 'line and character are required' }));
}
const position = new vscode.Position(line - 1, character - 1);
const hovers = await vscode.commands.executeCommand<vscode.Hover[]>(
'vscode.executeHoverProvider',
uri,
position
);
// Convert hover markdown to plain text for easier consumption
result = hovers?.map(hover => ({
contents: hover.contents.map(content => {
if (typeof content === 'string') {
return content;
} else if (content instanceof vscode.MarkdownString) {
return content.value;
} else {
return content.value;
}
}),
range: hover.range ? {
start: { line: hover.range.start.line, character: hover.range.start.character },
end: { line: hover.range.end.line, character: hover.range.end.character }
} : undefined
}));
break;
}
case '/get_document_symbols': {
const symbols = await vscode.commands.executeCommand<vscode.DocumentSymbol[]>(
'vscode.executeDocumentSymbolProvider',
uri
);
// Flatten the symbol tree for easier consumption
const flattenSymbols = (symbols: vscode.DocumentSymbol[], parent?: string): any[] => {
return symbols.flatMap(symbol => {
const current = {
name: symbol.name,
kind: vscode.SymbolKind[symbol.kind],
range: {
start: { line: symbol.range.start.line, character: symbol.range.start.character },
end: { line: symbol.range.end.line, character: symbol.range.end.character }
},
selectionRange: {
start: { line: symbol.selectionRange.start.line, character: symbol.selectionRange.start.character },
end: { line: symbol.selectionRange.end.line, character: symbol.selectionRange.end.character }
},
detail: symbol.detail,
parent
};
return [current, ...flattenSymbols(symbol.children || [], symbol.name)];
});
};
result = symbols ? flattenSymbols(symbols) : [];
break;
}
default:
res.writeHead(404);
return res.end(JSON.stringify({ error: 'Not Found' }));
}
res.writeHead(200);
res.end(JSON.stringify({ success: true, result }));
} catch (error) {
console.error('CCW VSCode Bridge error:', error);
res.writeHead(500);
res.end(JSON.stringify({
success: false,
error: error instanceof Error ? error.message : String(error)
}));
}
});
});
server.listen(PORT, '127.0.0.1', () => {
console.log(`CCW VSCode Bridge listening on http://127.0.0.1:${PORT}`);
vscode.window.showInformationMessage(`CCW VSCode Bridge is active on port ${PORT}`);
});
context.subscriptions.push({
dispose: () => {
server.close();
console.log('CCW VSCode Bridge server closed');
}
});
}
export function deactivate() {
console.log('CCW VSCode Bridge deactivated');
}

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"outDir": "out",
"lib": ["ES2020"],
"sourceMap": true,
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules", ".vscode-test"]
}