solver-sdk 2.8.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +327 -360
- package/dist/cjs/api/chat-api/index.js +23 -49
- package/dist/cjs/api/chat-api/index.js.map +1 -1
- package/dist/cjs/api/chat-api/interfaces.js +1 -0
- package/dist/cjs/api/chat-api/interfaces.js.map +1 -1
- package/dist/cjs/api/context-api.js +6 -1
- package/dist/cjs/api/context-api.js.map +1 -1
- package/dist/cjs/api/models-api.js +43 -60
- package/dist/cjs/api/models-api.js.map +1 -1
- package/dist/cjs/api/projects-api.js +67 -295
- package/dist/cjs/api/projects-api.js.map +1 -1
- package/dist/cjs/api/search-api.js +131 -8
- package/dist/cjs/api/search-api.js.map +1 -1
- package/dist/cjs/code-solver-sdk.js +68 -322
- package/dist/cjs/code-solver-sdk.js.map +1 -1
- package/dist/cjs/index.js +3 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/logger.js +4 -4
- package/dist/cjs/utils/logger.js.map +1 -1
- package/dist/esm/api/chat-api/index.js +22 -48
- package/dist/esm/api/chat-api/index.js.map +1 -1
- package/dist/esm/api/chat-api/interfaces.js +1 -0
- package/dist/esm/api/chat-api/interfaces.js.map +1 -1
- package/dist/esm/api/context-api.js +6 -1
- package/dist/esm/api/context-api.js.map +1 -1
- package/dist/esm/api/models-api.js +43 -60
- package/dist/esm/api/models-api.js.map +1 -1
- package/dist/esm/api/projects-api.js +67 -295
- package/dist/esm/api/projects-api.js.map +1 -1
- package/dist/esm/api/search-api.js +131 -8
- package/dist/esm/api/search-api.js.map +1 -1
- package/dist/esm/code-solver-sdk.js +68 -322
- package/dist/esm/code-solver-sdk.js.map +1 -1
- package/dist/esm/index.js +2 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/logger.js +3 -3
- package/dist/esm/utils/logger.js.map +1 -1
- package/dist/types/api/chat-api/index.d.ts +1 -13
- package/dist/types/api/chat-api/index.d.ts.map +1 -1
- package/dist/types/api/chat-api/interfaces.d.ts +6 -54
- package/dist/types/api/chat-api/interfaces.d.ts.map +1 -1
- package/dist/types/api/chat-api/models.d.ts +3 -26
- package/dist/types/api/chat-api/models.d.ts.map +1 -1
- package/dist/types/api/context-api.d.ts.map +1 -1
- package/dist/types/api/models-api.d.ts +31 -62
- package/dist/types/api/models-api.d.ts.map +1 -1
- package/dist/types/api/projects-api.d.ts +50 -127
- package/dist/types/api/projects-api.d.ts.map +1 -1
- package/dist/types/api/search-api.d.ts +147 -6
- package/dist/types/api/search-api.d.ts.map +1 -1
- package/dist/types/code-solver-sdk.d.ts +36 -86
- package/dist/types/code-solver-sdk.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -14
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/sdk-options.d.ts +18 -66
- package/dist/types/interfaces/sdk-options.d.ts.map +1 -1
- package/dist/types/utils/logger.d.ts +3 -3
- package/dist/types/utils/logger.d.ts.map +1 -1
- package/docs/README.md +53 -37
- package/docs/VSCODE_INTEGRATION.md +208 -371
- package/docs/indexing/INDEXING.md +658 -335
- package/package.json +26 -23
- package/dist/cjs/api/agents-api.js +0 -94
- package/dist/cjs/api/agents-api.js.map +0 -1
- package/dist/cjs/api/chat-api/websocket-helpers.js +0 -211
- package/dist/cjs/api/chat-api/websocket-helpers.js.map +0 -1
- package/dist/cjs/api/dependencies-api.js +0 -286
- package/dist/cjs/api/dependencies-api.js.map +0 -1
- package/dist/cjs/constants/websocket-events.constants.js +0 -170
- package/dist/cjs/constants/websocket-events.constants.js.map +0 -1
- package/dist/cjs/constants/websocket-namespaces.constants.js +0 -22
- package/dist/cjs/constants/websocket-namespaces.constants.js.map +0 -1
- package/dist/cjs/interfaces/websocket/callbacks.interfaces.js +0 -3
- package/dist/cjs/interfaces/websocket/callbacks.interfaces.js.map +0 -1
- package/dist/cjs/interfaces/websocket/client-options.interfaces.js +0 -3
- package/dist/cjs/interfaces/websocket/client-options.interfaces.js.map +0 -1
- package/dist/cjs/interfaces/websocket/events.interfaces.js +0 -3
- package/dist/cjs/interfaces/websocket/events.interfaces.js.map +0 -1
- package/dist/cjs/interfaces/websocket/vscode-command.interfaces.js +0 -42
- package/dist/cjs/interfaces/websocket/vscode-command.interfaces.js.map +0 -1
- package/dist/cjs/simple-indexing-client.js +0 -138
- package/dist/cjs/simple-indexing-client.js.map +0 -1
- package/dist/cjs/utils/code-solver-websocket-client.js +0 -497
- package/dist/cjs/utils/code-solver-websocket-client.js.map +0 -1
- package/dist/cjs/utils/connection-state-manager.js +0 -133
- package/dist/cjs/utils/connection-state-manager.js.map +0 -1
- package/dist/cjs/utils/indexing-websocket-client.js +0 -107
- package/dist/cjs/utils/indexing-websocket-client.js.map +0 -1
- package/dist/cjs/utils/session-manager.js +0 -114
- package/dist/cjs/utils/session-manager.js.map +0 -1
- package/dist/cjs/utils/simple-connection-monitor.js +0 -52
- package/dist/cjs/utils/simple-connection-monitor.js.map +0 -1
- package/dist/cjs/utils/websocket-client.js +0 -638
- package/dist/cjs/utils/websocket-client.js.map +0 -1
- package/dist/cjs/ws/base-ws-client.js +0 -280
- package/dist/cjs/ws/base-ws-client.js.map +0 -1
- package/dist/cjs/ws/dependencies-ws-client.js +0 -11
- package/dist/cjs/ws/dependencies-ws-client.js.map +0 -1
- package/dist/cjs/ws/file-editing-ws-client.js +0 -162
- package/dist/cjs/ws/file-editing-ws-client.js.map +0 -1
- package/dist/cjs/ws/filesystem-ws-client.js +0 -305
- package/dist/cjs/ws/filesystem-ws-client.js.map +0 -1
- package/dist/cjs/ws/indexing-ws-client.js +0 -275
- package/dist/cjs/ws/indexing-ws-client.js.map +0 -1
- package/dist/cjs/ws/notifications-ws-client.js +0 -12
- package/dist/cjs/ws/notifications-ws-client.js.map +0 -1
- package/dist/esm/api/agents-api.js +0 -90
- package/dist/esm/api/agents-api.js.map +0 -1
- package/dist/esm/api/chat-api/websocket-helpers.js +0 -205
- package/dist/esm/api/chat-api/websocket-helpers.js.map +0 -1
- package/dist/esm/api/dependencies-api.js +0 -282
- package/dist/esm/api/dependencies-api.js.map +0 -1
- package/dist/esm/constants/websocket-events.constants.js +0 -167
- package/dist/esm/constants/websocket-events.constants.js.map +0 -1
- package/dist/esm/constants/websocket-namespaces.constants.js +0 -19
- package/dist/esm/constants/websocket-namespaces.constants.js.map +0 -1
- package/dist/esm/interfaces/websocket/callbacks.interfaces.js +0 -2
- package/dist/esm/interfaces/websocket/callbacks.interfaces.js.map +0 -1
- package/dist/esm/interfaces/websocket/client-options.interfaces.js +0 -2
- package/dist/esm/interfaces/websocket/client-options.interfaces.js.map +0 -1
- package/dist/esm/interfaces/websocket/events.interfaces.js +0 -2
- package/dist/esm/interfaces/websocket/events.interfaces.js.map +0 -1
- package/dist/esm/interfaces/websocket/vscode-command.interfaces.js +0 -39
- package/dist/esm/interfaces/websocket/vscode-command.interfaces.js.map +0 -1
- package/dist/esm/simple-indexing-client.js +0 -134
- package/dist/esm/simple-indexing-client.js.map +0 -1
- package/dist/esm/utils/code-solver-websocket-client.js +0 -492
- package/dist/esm/utils/code-solver-websocket-client.js.map +0 -1
- package/dist/esm/utils/connection-state-manager.js +0 -129
- package/dist/esm/utils/connection-state-manager.js.map +0 -1
- package/dist/esm/utils/indexing-websocket-client.js +0 -103
- package/dist/esm/utils/indexing-websocket-client.js.map +0 -1
- package/dist/esm/utils/session-manager.js +0 -109
- package/dist/esm/utils/session-manager.js.map +0 -1
- package/dist/esm/utils/simple-connection-monitor.js +0 -48
- package/dist/esm/utils/simple-connection-monitor.js.map +0 -1
- package/dist/esm/utils/websocket-client.js +0 -634
- package/dist/esm/utils/websocket-client.js.map +0 -1
- package/dist/esm/ws/base-ws-client.js +0 -276
- package/dist/esm/ws/base-ws-client.js.map +0 -1
- package/dist/esm/ws/dependencies-ws-client.js +0 -7
- package/dist/esm/ws/dependencies-ws-client.js.map +0 -1
- package/dist/esm/ws/file-editing-ws-client.js +0 -158
- package/dist/esm/ws/file-editing-ws-client.js.map +0 -1
- package/dist/esm/ws/filesystem-ws-client.js +0 -301
- package/dist/esm/ws/filesystem-ws-client.js.map +0 -1
- package/dist/esm/ws/indexing-ws-client.js +0 -271
- package/dist/esm/ws/indexing-ws-client.js.map +0 -1
- package/dist/esm/ws/notifications-ws-client.js +0 -8
- package/dist/esm/ws/notifications-ws-client.js.map +0 -1
- package/dist/types/api/agents-api.d.ts +0 -141
- package/dist/types/api/agents-api.d.ts.map +0 -1
- package/dist/types/api/chat-api/websocket-helpers.d.ts +0 -40
- package/dist/types/api/chat-api/websocket-helpers.d.ts.map +0 -1
- package/dist/types/api/dependencies-api.d.ts +0 -109
- package/dist/types/api/dependencies-api.d.ts.map +0 -1
- package/dist/types/constants/websocket-events.constants.d.ts +0 -144
- package/dist/types/constants/websocket-events.constants.d.ts.map +0 -1
- package/dist/types/constants/websocket-namespaces.constants.d.ts +0 -17
- package/dist/types/constants/websocket-namespaces.constants.d.ts.map +0 -1
- package/dist/types/interfaces/websocket/callbacks.interfaces.d.ts +0 -30
- package/dist/types/interfaces/websocket/callbacks.interfaces.d.ts.map +0 -1
- package/dist/types/interfaces/websocket/client-options.interfaces.d.ts +0 -51
- package/dist/types/interfaces/websocket/client-options.interfaces.d.ts.map +0 -1
- package/dist/types/interfaces/websocket/events.interfaces.d.ts +0 -165
- package/dist/types/interfaces/websocket/events.interfaces.d.ts.map +0 -1
- package/dist/types/interfaces/websocket/vscode-command.interfaces.d.ts +0 -56
- package/dist/types/interfaces/websocket/vscode-command.interfaces.d.ts.map +0 -1
- package/dist/types/simple-indexing-client.d.ts +0 -66
- package/dist/types/simple-indexing-client.d.ts.map +0 -1
- package/dist/types/utils/code-solver-websocket-client.d.ts +0 -144
- package/dist/types/utils/code-solver-websocket-client.d.ts.map +0 -1
- package/dist/types/utils/connection-state-manager.d.ts +0 -94
- package/dist/types/utils/connection-state-manager.d.ts.map +0 -1
- package/dist/types/utils/indexing-websocket-client.d.ts +0 -123
- package/dist/types/utils/indexing-websocket-client.d.ts.map +0 -1
- package/dist/types/utils/session-manager.d.ts +0 -98
- package/dist/types/utils/session-manager.d.ts.map +0 -1
- package/dist/types/utils/simple-connection-monitor.d.ts +0 -26
- package/dist/types/utils/simple-connection-monitor.d.ts.map +0 -1
- package/dist/types/utils/websocket-client.d.ts +0 -233
- package/dist/types/utils/websocket-client.d.ts.map +0 -1
- package/dist/types/ws/base-ws-client.d.ts +0 -119
- package/dist/types/ws/base-ws-client.d.ts.map +0 -1
- package/dist/types/ws/dependencies-ws-client.d.ts +0 -6
- package/dist/types/ws/dependencies-ws-client.d.ts.map +0 -1
- package/dist/types/ws/file-editing-ws-client.d.ts +0 -85
- package/dist/types/ws/file-editing-ws-client.d.ts.map +0 -1
- package/dist/types/ws/filesystem-ws-client.d.ts +0 -201
- package/dist/types/ws/filesystem-ws-client.d.ts.map +0 -1
- package/dist/types/ws/indexing-ws-client.d.ts +0 -94
- package/dist/types/ws/indexing-ws-client.d.ts.map +0 -1
- package/dist/types/ws/notifications-ws-client.d.ts +0 -5
- package/dist/types/ws/notifications-ws-client.d.ts.map +0 -1
- package/docs/ARCHITECTURE.md +0 -268
- package/docs/QUICK_START.md +0 -126
- package/docs/WEBSOCKET.md +0 -472
|
@@ -1,432 +1,269 @@
|
|
|
1
|
-
# VS Code Integration
|
|
1
|
+
# VS Code Extension Integration
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Практическое руководство интеграции SDK с VS Code Extension**
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 Быстрая интеграция
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
AI Модель → Backend → SDK → VS Code Extension → VS Code Native API
|
|
9
|
-
↑─── HTTP Streaming (45ms) ───↑
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
**Результат:** **10x ускорение** команд - 45ms вместо 443ms! 🚀
|
|
13
|
-
|
|
14
|
-
## 🚀 Быстрый старт
|
|
15
|
-
|
|
16
|
-
### 1. Установка и инициализация
|
|
7
|
+
### 1. Базовая настройка
|
|
17
8
|
|
|
18
9
|
```typescript
|
|
19
|
-
import { CodeSolverSDK
|
|
10
|
+
import { CodeSolverSDK } from 'solver-sdk';
|
|
20
11
|
import * as vscode from 'vscode';
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
// Инициализация SDK
|
|
14
|
+
let sdk: CodeSolverSDK;
|
|
15
|
+
|
|
16
|
+
export async function activate(context: vscode.ExtensionContext) {
|
|
17
|
+
// Создание SDK
|
|
18
|
+
sdk = await CodeSolverSDK.create({
|
|
19
|
+
baseURL: 'http://localhost:3000'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Регистрация команд
|
|
23
|
+
const indexCommand = vscode.commands.registerCommand(
|
|
24
|
+
'myExtension.indexProject',
|
|
25
|
+
indexCurrentWorkspace
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const searchCommand = vscode.commands.registerCommand(
|
|
29
|
+
'myExtension.searchFunctions',
|
|
30
|
+
searchAndNavigate
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
context.subscriptions.push(indexCommand, searchCommand);
|
|
34
|
+
}
|
|
26
35
|
```
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
## 📊 Индексация с прогресс-баром
|
|
29
38
|
|
|
30
39
|
```typescript
|
|
31
|
-
async function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
async function indexCurrentWorkspace() {
|
|
41
|
+
if (!vscode.workspace.workspaceFolders) {
|
|
42
|
+
vscode.window.showErrorMessage('Откройте папку проекта');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const folder = vscode.workspace.workspaceFolders[0];
|
|
47
|
+
const projectPath = folder.uri.fsPath;
|
|
48
|
+
const projectName = folder.name;
|
|
49
|
+
|
|
50
|
+
return vscode.window.withProgress({
|
|
51
|
+
location: vscode.ProgressLocation.Notification,
|
|
52
|
+
title: 'Индексация проекта',
|
|
53
|
+
cancellable: true
|
|
54
|
+
}, async (progress, token) => {
|
|
55
|
+
try {
|
|
56
|
+
progress.report({ message: 'Создание проекта...' });
|
|
57
|
+
const project = await sdk.projects.findOrCreateProject(projectPath, projectName);
|
|
58
|
+
|
|
59
|
+
progress.report({ message: 'Запуск индексации...' });
|
|
60
|
+
await sdk.projects.startIndexing(project.id);
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
while (!token.isCancellationRequested) {
|
|
63
|
+
const status = await sdk.projects.getProjectStatus(project.id);
|
|
64
|
+
|
|
65
|
+
if (status.status === 'ready') {
|
|
66
|
+
vscode.window.showInformationMessage('✅ Проект проиндексирован!');
|
|
67
|
+
return project;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (status.status === 'error') {
|
|
71
|
+
throw new Error(status.error);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const percentage = status.progress || 0;
|
|
75
|
+
progress.report({
|
|
76
|
+
increment: percentage,
|
|
77
|
+
message: `${percentage}% - ${status.currentFile || 'Обработка...'}`
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
40
81
|
}
|
|
82
|
+
|
|
83
|
+
} catch (error) {
|
|
84
|
+
vscode.window.showErrorMessage(`Ошибка: ${error.message}`);
|
|
41
85
|
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Обработка потока
|
|
45
|
-
for await (const chunk of stream) {
|
|
46
|
-
if (chunk.type === 'command_executed') {
|
|
47
|
-
console.log('✅ Команда выполнена:', chunk.commandResult);
|
|
48
|
-
} else if (chunk.type === 'text') {
|
|
49
|
-
console.log('💬 AI ответ:', chunk.text);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
86
|
+
});
|
|
52
87
|
}
|
|
53
88
|
```
|
|
54
89
|
|
|
55
|
-
|
|
90
|
+
## 🔍 Поиск функций с навигацией
|
|
56
91
|
|
|
57
92
|
```typescript
|
|
58
|
-
async function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
async function searchAndNavigate() {
|
|
94
|
+
const projects = await sdk.projects.getReadyProjects();
|
|
95
|
+
|
|
96
|
+
if (projects.length === 0) {
|
|
97
|
+
vscode.window.showWarningMessage('Нет проиндексированных проектов');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const query = await vscode.window.showInputBox({
|
|
102
|
+
prompt: 'Поиск функций',
|
|
103
|
+
placeholder: 'Введите название функции или описание...'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!query) return;
|
|
62
107
|
|
|
63
108
|
try {
|
|
64
|
-
|
|
109
|
+
const results = await sdk.search.searchFunctions(projects[0].id, {
|
|
110
|
+
query,
|
|
111
|
+
limit: 20
|
|
112
|
+
});
|
|
65
113
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
114
|
+
if (results.results.length === 0) {
|
|
115
|
+
vscode.window.showInformationMessage('Ничего не найдено');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
71
118
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
119
|
+
const functionItems = results.results.map(fn => ({
|
|
120
|
+
label: `$(symbol-function) ${fn.name}`,
|
|
121
|
+
description: fn.signature,
|
|
122
|
+
detail: `${fn.filePath}:${fn.startLine}`,
|
|
123
|
+
function: fn
|
|
124
|
+
}));
|
|
79
125
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## 📋 Поддерживаемые команды
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import { VSCodeCommands } from 'solver-sdk';
|
|
96
|
-
|
|
97
|
-
// Создание файлов
|
|
98
|
-
VSCodeCommands.CREATE_FILE = 'aiSolver.native.createFile'
|
|
99
|
-
// Использование: ['src/Button.tsx', 'export const Button = () => <button>Click</button>']
|
|
100
|
-
|
|
101
|
-
// Редактирование файлов
|
|
102
|
-
VSCodeCommands.EDIT_FILE = 'aiSolver.native.editFile'
|
|
103
|
-
// Использование: ['src/App.tsx', { line: 10, content: 'new code' }]
|
|
104
|
-
|
|
105
|
-
// Bulk операции
|
|
106
|
-
VSCodeCommands.BULK_EDIT = 'aiSolver.native.bulkEdit'
|
|
107
|
-
// Использование: [{ file: 'src/A.tsx', changes: [...] }, { file: 'src/B.tsx', changes: [...] }]
|
|
108
|
-
|
|
109
|
-
// Поиск файлов
|
|
110
|
-
VSCodeCommands.FIND_FILES = 'vscode.workspace.findFiles'
|
|
111
|
-
// Использование: ['**/*.tsx', '**/node_modules/**']
|
|
112
|
-
|
|
113
|
-
// Текстовый поиск
|
|
114
|
-
VSCodeCommands.FIND_TEXT = 'vscode.workspace.findTextInFiles'
|
|
115
|
-
// Использование: ['useState', { include: '**/*.tsx' }]
|
|
116
|
-
|
|
117
|
-
// Терминал
|
|
118
|
-
VSCodeCommands.TERMINAL = 'aiSolver.native.terminal'
|
|
119
|
-
// Использование: ['npm install react', { cwd: '/path/to/project' }]
|
|
120
|
-
|
|
121
|
-
// Стандартные команды
|
|
122
|
-
VSCodeCommands.SAVE_FILE = 'workbench.action.files.save'
|
|
123
|
-
VSCodeCommands.SAVE_ALL = 'workbench.action.files.saveAll'
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## 🛠️ Продвинутые сценарии
|
|
127
|
-
|
|
128
|
-
### Обработка различных типов команд
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
async function advancedCommandHandler(command: VSCodeCommandEvent) {
|
|
132
|
-
const { command: cmd, args, metadata } = command;
|
|
133
|
-
|
|
134
|
-
switch (cmd) {
|
|
135
|
-
case VSCodeCommands.CREATE_FILE:
|
|
136
|
-
return await handleCreateFile(args[0], args[1]);
|
|
137
|
-
|
|
138
|
-
case VSCodeCommands.EDIT_FILE:
|
|
139
|
-
return await handleEditFile(args[0], args[1]);
|
|
140
|
-
|
|
141
|
-
case VSCodeCommands.BULK_EDIT:
|
|
142
|
-
return await handleBulkEdit(args[0]);
|
|
143
|
-
|
|
144
|
-
case VSCodeCommands.FIND_FILES:
|
|
145
|
-
return await handleFindFiles(args[0], args[1]);
|
|
146
|
-
|
|
147
|
-
case VSCodeCommands.TERMINAL:
|
|
148
|
-
return await handleTerminal(args[0], args[1]);
|
|
149
|
-
|
|
150
|
-
default:
|
|
151
|
-
// Fallback для любых других команд
|
|
152
|
-
return await handleGenericCommand(cmd, args);
|
|
126
|
+
const selectedFunction = await vscode.window.showQuickPick(functionItems);
|
|
127
|
+
|
|
128
|
+
if (selectedFunction) {
|
|
129
|
+
await navigateToFunction(selectedFunction.function);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
} catch (error) {
|
|
133
|
+
vscode.window.showErrorMessage(`Ошибка поиска: ${error.message}`);
|
|
153
134
|
}
|
|
154
135
|
}
|
|
155
136
|
|
|
156
|
-
async function
|
|
137
|
+
async function navigateToFunction(fn: any) {
|
|
157
138
|
try {
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
await vscode.workspace.fs.writeFile(uri, encoder.encode(content));
|
|
139
|
+
const doc = await vscode.workspace.openTextDocument(fn.filePath);
|
|
140
|
+
const editor = await vscode.window.showTextDocument(doc);
|
|
161
141
|
|
|
162
|
-
|
|
163
|
-
|
|
142
|
+
const range = new vscode.Range(
|
|
143
|
+
fn.startLine - 1, 0,
|
|
144
|
+
fn.endLine - 1, 0
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
editor.selection = new vscode.Selection(range.start, range.end);
|
|
148
|
+
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
|
|
164
149
|
|
|
165
|
-
return {
|
|
166
|
-
success: true,
|
|
167
|
-
result: { created: true, path, opened: true }
|
|
168
|
-
};
|
|
169
150
|
} catch (error) {
|
|
170
|
-
|
|
171
|
-
success: false,
|
|
172
|
-
error: `Не удалось создать файл: ${error.message}`
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function handleBulkEdit(operations: Array<{file: string, changes: any[]}>) {
|
|
178
|
-
const edit = new vscode.WorkspaceEdit();
|
|
179
|
-
const results = [];
|
|
180
|
-
|
|
181
|
-
for (const op of operations) {
|
|
182
|
-
try {
|
|
183
|
-
const uri = vscode.Uri.file(op.file);
|
|
184
|
-
|
|
185
|
-
for (const change of op.changes) {
|
|
186
|
-
const range = new vscode.Range(
|
|
187
|
-
change.startLine, change.startChar,
|
|
188
|
-
change.endLine, change.endChar
|
|
189
|
-
);
|
|
190
|
-
edit.replace(uri, range, change.newText);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
results.push({ file: op.file, success: true });
|
|
194
|
-
} catch (error) {
|
|
195
|
-
results.push({
|
|
196
|
-
file: op.file,
|
|
197
|
-
success: false,
|
|
198
|
-
error: error.message
|
|
199
|
-
});
|
|
200
|
-
}
|
|
151
|
+
vscode.window.showErrorMessage(`Ошибка навигации: ${error.message}`);
|
|
201
152
|
}
|
|
202
|
-
|
|
203
|
-
const applied = await vscode.workspace.applyEdit(edit);
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
success: applied,
|
|
207
|
-
result: { operations: results, totalApplied: applied }
|
|
208
|
-
};
|
|
209
153
|
}
|
|
210
154
|
```
|
|
211
155
|
|
|
212
|
-
|
|
156
|
+
## 💬 AI Chat интеграция
|
|
213
157
|
|
|
214
158
|
```typescript
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
159
|
+
async function askAI() {
|
|
160
|
+
const editor = vscode.window.activeTextEditor;
|
|
161
|
+
if (!editor) {
|
|
162
|
+
vscode.window.showWarningMessage('Откройте файл в редакторе');
|
|
163
|
+
return;
|
|
220
164
|
}
|
|
221
165
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const time = result.executionTime;
|
|
225
|
-
|
|
226
|
-
this.outputChannel.appendLine(
|
|
227
|
-
`${status} [${time}ms] ${command.command} - ${command.requestId}`
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
if (!result.success) {
|
|
231
|
-
this.outputChannel.appendLine(` Error: ${result.error}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Показываем панель при ошибках
|
|
235
|
-
if (!result.success) {
|
|
236
|
-
this.outputChannel.show();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
166
|
+
const selection = editor.selection;
|
|
167
|
+
const selectedText = editor.document.getText(selection);
|
|
239
168
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
169
|
+
let contextText = '';
|
|
170
|
+
if (selectedText) {
|
|
171
|
+
contextText = `
|
|
172
|
+
|
|
173
|
+
Выделенный код:
|
|
174
|
+
\`\`\`${editor.document.languageId}
|
|
175
|
+
${selectedText}
|
|
176
|
+
\`\`\``;
|
|
245
177
|
}
|
|
178
|
+
|
|
179
|
+
const question = await vscode.window.showInputBox({
|
|
180
|
+
prompt: 'Задайте вопрос AI',
|
|
181
|
+
placeholder: 'Что делает этот код? Как его улучшить?'
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (!question) return;
|
|
185
|
+
|
|
186
|
+
return vscode.window.withProgress({
|
|
187
|
+
location: vscode.ProgressLocation.Notification,
|
|
188
|
+
title: 'AI анализирует код...',
|
|
189
|
+
cancellable: false
|
|
190
|
+
}, async (progress) => {
|
|
191
|
+
try {
|
|
192
|
+
const response = await sdk.chat.chat([{
|
|
193
|
+
role: 'user',
|
|
194
|
+
content: question + contextText
|
|
195
|
+
}], {
|
|
196
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
197
|
+
maxTokens: 8192
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const doc = await vscode.workspace.openTextDocument({
|
|
201
|
+
content: `Q: ${question}
|
|
202
|
+
|
|
203
|
+
A: ${response.content[0].text}`,
|
|
204
|
+
language: 'markdown'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await vscode.window.showTextDocument(doc);
|
|
208
|
+
|
|
209
|
+
} catch (error) {
|
|
210
|
+
vscode.window.showErrorMessage(`Ошибка AI: ${error.message}`);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
246
213
|
}
|
|
247
214
|
```
|
|
248
215
|
|
|
249
|
-
##
|
|
250
|
-
|
|
251
|
-
### package.json
|
|
216
|
+
## ⚙️ Конфигурация package.json
|
|
252
217
|
|
|
253
218
|
```json
|
|
254
219
|
{
|
|
220
|
+
"name": "my-code-assistant",
|
|
221
|
+
"displayName": "AI Code Assistant",
|
|
222
|
+
"description": "AI помощник для анализа и поиска кода",
|
|
223
|
+
"version": "1.0.0",
|
|
224
|
+
"engines": {
|
|
225
|
+
"vscode": "^1.60.0"
|
|
226
|
+
},
|
|
227
|
+
"categories": ["Other"],
|
|
228
|
+
"activationEvents": [
|
|
229
|
+
"onStartupFinished"
|
|
230
|
+
],
|
|
231
|
+
"main": "./out/extension.js",
|
|
255
232
|
"contributes": {
|
|
256
233
|
"commands": [
|
|
257
234
|
{
|
|
258
|
-
"command": "
|
|
259
|
-
"title": "
|
|
260
|
-
|
|
261
|
-
{
|
|
262
|
-
"command": "aiSolver.native.editFile",
|
|
263
|
-
"title": "AI Solver: Edit File"
|
|
235
|
+
"command": "myExtension.indexProject",
|
|
236
|
+
"title": "📊 Проиндексировать проект",
|
|
237
|
+
"category": "AI Assistant"
|
|
264
238
|
},
|
|
265
239
|
{
|
|
266
|
-
"command": "
|
|
267
|
-
"title": "
|
|
240
|
+
"command": "myExtension.searchFunctions",
|
|
241
|
+
"title": "🔍 Поиск функций",
|
|
242
|
+
"category": "AI Assistant"
|
|
268
243
|
},
|
|
269
244
|
{
|
|
270
|
-
"command": "
|
|
271
|
-
"title": "
|
|
245
|
+
"command": "myExtension.askAI",
|
|
246
|
+
"title": "💬 Спросить AI",
|
|
247
|
+
"category": "AI Assistant"
|
|
272
248
|
}
|
|
273
249
|
],
|
|
274
|
-
"
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
"
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
"
|
|
283
|
-
|
|
284
|
-
"default": 30000,
|
|
285
|
-
"description": "Command execution timeout (ms)"
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Активация extension
|
|
294
|
-
|
|
295
|
-
```typescript
|
|
296
|
-
export function activate(context: vscode.ExtensionContext) {
|
|
297
|
-
const logger = new VSCodeIntegrationLogger();
|
|
298
|
-
const sdk = initializeSDK();
|
|
299
|
-
|
|
300
|
-
// Регистрация команд
|
|
301
|
-
const createFileCommand = vscode.commands.registerCommand(
|
|
302
|
-
'aiSolver.native.createFile',
|
|
303
|
-
async (path: string, content: string) => {
|
|
304
|
-
// Реализация создания файла
|
|
305
|
-
}
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
const editFileCommand = vscode.commands.registerCommand(
|
|
309
|
-
'aiSolver.native.editFile',
|
|
310
|
-
async (path: string, changes: any) => {
|
|
311
|
-
// Реализация редактирования файла
|
|
312
|
-
}
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
context.subscriptions.push(createFileCommand, editFileCommand);
|
|
316
|
-
|
|
317
|
-
// Инициализация сервиса интеграции
|
|
318
|
-
const integrationService = new VSCodeIntegrationService(sdk, logger);
|
|
319
|
-
integrationService.start();
|
|
320
|
-
}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
## 📈 Performance Optimization
|
|
324
|
-
|
|
325
|
-
### Кэширование команд
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
class CommandCache {
|
|
329
|
-
private cache = new Map<string, any>();
|
|
330
|
-
|
|
331
|
-
async executeWithCache(command: VSCodeCommandEvent): Promise<CommandExecutionResult> {
|
|
332
|
-
// Кэшируем результаты для идемпотентных команд
|
|
333
|
-
if (this.isIdempotent(command.command)) {
|
|
334
|
-
const cacheKey = this.getCacheKey(command);
|
|
335
|
-
const cached = this.cache.get(cacheKey);
|
|
336
|
-
|
|
337
|
-
if (cached) {
|
|
338
|
-
return {
|
|
339
|
-
...cached,
|
|
340
|
-
requestId: command.requestId,
|
|
341
|
-
executionTime: 5, // Кэш-хит
|
|
342
|
-
timestamp: Date.now()
|
|
343
|
-
};
|
|
250
|
+
"keybindings": [
|
|
251
|
+
{
|
|
252
|
+
"command": "myExtension.searchFunctions",
|
|
253
|
+
"key": "ctrl+shift+f",
|
|
254
|
+
"mac": "cmd+shift+f"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"command": "myExtension.askAI",
|
|
258
|
+
"key": "ctrl+shift+a",
|
|
259
|
+
"mac": "cmd+shift+a"
|
|
344
260
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// Сохраняем в кэш
|
|
350
|
-
if (result.success && this.isIdempotent(command.command)) {
|
|
351
|
-
const cacheKey = this.getCacheKey(command);
|
|
352
|
-
this.cache.set(cacheKey, result);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return result;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
private isIdempotent(command: string): boolean {
|
|
359
|
-
return [
|
|
360
|
-
VSCodeCommands.FIND_FILES,
|
|
361
|
-
VSCodeCommands.FIND_TEXT
|
|
362
|
-
].includes(command as VSCodeCommands);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
## 🐛 Error Handling
|
|
368
|
-
|
|
369
|
-
### Comprehensive error handling
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
import { CommandErrorType, COMMAND_TIMEOUT } from 'solver-sdk';
|
|
373
|
-
|
|
374
|
-
async function executeWithTimeout(command: VSCodeCommandEvent): Promise<CommandExecutionResult> {
|
|
375
|
-
const timeout = new Promise<CommandExecutionResult>((_, reject) => {
|
|
376
|
-
setTimeout(() => {
|
|
377
|
-
reject(new Error(`Command timeout after ${COMMAND_TIMEOUT}ms`));
|
|
378
|
-
}, COMMAND_TIMEOUT);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const execution = executeVSCodeCommand(command);
|
|
382
|
-
|
|
383
|
-
try {
|
|
384
|
-
return await Promise.race([execution, timeout]);
|
|
385
|
-
} catch (error: any) {
|
|
386
|
-
let errorType: CommandErrorType;
|
|
387
|
-
|
|
388
|
-
if (error.message.includes('timeout')) {
|
|
389
|
-
errorType = CommandErrorType.TIMEOUT;
|
|
390
|
-
} else if (error.message.includes('not found')) {
|
|
391
|
-
errorType = CommandErrorType.NOT_FOUND;
|
|
392
|
-
} else if (error.message.includes('invalid')) {
|
|
393
|
-
errorType = CommandErrorType.INVALID_ARGS;
|
|
394
|
-
} else {
|
|
395
|
-
errorType = CommandErrorType.EXECUTION_ERROR;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return {
|
|
399
|
-
requestId: command.requestId,
|
|
400
|
-
success: false,
|
|
401
|
-
error: `[${errorType}] ${error.message}`,
|
|
402
|
-
executionTime: COMMAND_TIMEOUT,
|
|
403
|
-
timestamp: Date.now()
|
|
404
|
-
};
|
|
261
|
+
]
|
|
262
|
+
},
|
|
263
|
+
"dependencies": {
|
|
264
|
+
"solver-sdk": "^3.0.0"
|
|
405
265
|
}
|
|
406
266
|
}
|
|
407
267
|
```
|
|
408
268
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
### До интеграции:
|
|
412
|
-
- ⏱️ **443ms** среднее время выполнения команд
|
|
413
|
-
- 🔄 Сложная архитектура с множественными хопами
|
|
414
|
-
- 🐛 Проблемы с синхронизацией
|
|
415
|
-
|
|
416
|
-
### После интеграции v2.7.0:
|
|
417
|
-
- ⚡ **45ms** среднее время выполнения команд (**10x ускорение!**)
|
|
418
|
-
- 🎯 Прямое взаимодействие с VS Code API
|
|
419
|
-
- 🛡️ Надежная error handling
|
|
420
|
-
- 📊 Real-time мониторинг производительности
|
|
421
|
-
|
|
422
|
-
```typescript
|
|
423
|
-
// Пример конечного результата
|
|
424
|
-
const performanceMetrics = {
|
|
425
|
-
averageLatency: '45ms', // vs 443ms old
|
|
426
|
-
successRate: '99.2%', // vs 87% old
|
|
427
|
-
commandsPerSecond: 22, // vs 2.3 old
|
|
428
|
-
errorRecoveryTime: '150ms' // vs 2.1s old
|
|
429
|
-
};
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
🎉 **VS Code Extension теперь работает со скоростью нативного IDE!**
|
|
269
|
+
SDK готов для интеграции в VS Code Extension! 🚀
|