0
# IDE Integration
1
2
Deep integration capabilities for IDEs and code editors with context awareness, file monitoring, installation utilities, and communication protocols.
3
4
## Capabilities
5
6
### IDE Context Management
7
8
Context management system for tracking open files, cursor positions, and IDE state.
9
10
```typescript { .api }
11
/**
12
* IDE context information
13
*/
14
interface IdeContext {
15
/** Array of open files in the IDE */
16
files: File[];
17
/** Current working directory */
18
cwd: string;
19
/** Additional metadata */
20
metadata?: Record<string, any>;
21
}
22
23
/**
24
* Open file information
25
*/
26
interface File {
27
/** File name */
28
name: string;
29
/** Full file path */
30
path: string;
31
/** File content */
32
content: string;
33
/** Cursor position (optional) */
34
cursor?: {
35
line: number;
36
column: number;
37
};
38
/** Selection range (optional) */
39
selection?: {
40
start: { line: number; column: number };
41
end: { line: number; column: number };
42
};
43
/** Language identifier */
44
language?: string;
45
/** Whether file has unsaved changes */
46
isDirty?: boolean;
47
}
48
49
/**
50
* IDE context notification schema
51
*/
52
interface IdeContextNotification {
53
type: 'context_update';
54
context: IdeContext;
55
timestamp: string;
56
}
57
```
58
59
### IDE Client Communication
60
61
Client for communicating with IDE extensions and managing bidirectional data exchange.
62
63
```typescript { .api }
64
/**
65
* IDE client for communication with IDE extensions
66
*/
67
class IdeClient {
68
constructor(config?: IdeClientConfig);
69
70
// Connection management
71
connect(): Promise<void>;
72
disconnect(): Promise<void>;
73
isConnected(): boolean;
74
75
// Context operations
76
getCurrentContext(): Promise<IdeContext>;
77
updateContext(context: Partial<IdeContext>): Promise<void>;
78
79
// File operations
80
openFile(path: string): Promise<void>;
81
closeFile(path: string): Promise<void>;
82
saveFile(path: string): Promise<void>;
83
getFileContent(path: string): Promise<string>;
84
85
// Editor operations
86
setCursorPosition(path: string, line: number, column: number): Promise<void>;
87
setSelection(
88
path: string,
89
start: {line: number, column: number},
90
end: {line: number, column: number}
91
): Promise<void>;
92
insertText(path: string, position: {line: number, column: number}, text: string): Promise<void>;
93
replaceText(
94
path: string,
95
range: {start: {line: number, column: number}, end: {line: number, column: number}},
96
text: string
97
): Promise<void>;
98
99
// Notification handling
100
onContextUpdate(handler: (context: IdeContext) => void): void;
101
onFileChange(handler: (file: File) => void): void;
102
onCursorMove(handler: (position: {line: number, column: number}, file: string) => void): void;
103
104
// Command execution
105
executeCommand(command: string, args?: any[]): Promise<any>;
106
107
// UI operations
108
showMessage(message: string, type?: 'info' | 'warning' | 'error'): Promise<void>;
109
showQuickPick(items: QuickPickItem[], options?: QuickPickOptions): Promise<QuickPickItem | undefined>;
110
showInputBox(options?: InputBoxOptions): Promise<string | undefined>;
111
}
112
113
/**
114
* IDE client configuration
115
*/
116
interface IdeClientConfig {
117
connectionType: 'websocket' | 'stdio' | 'tcp';
118
host?: string;
119
port?: number;
120
timeout?: number;
121
retryAttempts?: number;
122
enableHeartbeat?: boolean;
123
}
124
125
/**
126
* Quick pick item for UI operations
127
*/
128
interface QuickPickItem {
129
label: string;
130
description?: string;
131
detail?: string;
132
value?: any;
133
}
134
135
/**
136
* Quick pick options
137
*/
138
interface QuickPickOptions {
139
title?: string;
140
placeholder?: string;
141
canPickMany?: boolean;
142
matchOnDescription?: boolean;
143
matchOnDetail?: boolean;
144
}
145
146
/**
147
* Input box options
148
*/
149
interface InputBoxOptions {
150
title?: string;
151
placeholder?: string;
152
value?: string;
153
prompt?: string;
154
password?: boolean;
155
validateInput?: (value: string) => string | undefined;
156
}
157
```
158
159
### IDE Detection
160
161
Utilities for detecting the current IDE environment and gathering information about the development setup.
162
163
```typescript { .api }
164
/**
165
* Detected IDE information
166
*/
167
interface DetectedIde {
168
name: string;
169
version?: string;
170
path?: string;
171
processId?: number;
172
capabilities: IdeCapabilities;
173
}
174
175
/**
176
* IDE capabilities
177
*/
178
interface IdeCapabilities {
179
fileOperations: boolean;
180
terminalIntegration: boolean;
181
debuggerSupport: boolean;
182
extensionSupport: boolean;
183
languageServerProtocol: boolean;
184
webviewSupport: boolean;
185
}
186
187
/**
188
* IDE information interface
189
*/
190
interface IdeInfo {
191
name: string;
192
displayName: string;
193
version: string;
194
path: string;
195
configPath?: string;
196
extensionsPath?: string;
197
workspacePath?: string;
198
}
199
200
/**
201
* Get information about the current IDE environment
202
* @returns Detected IDE information or null if not detected
203
*/
204
function getIdeInfo(): Promise<IdeInfo | null>;
205
206
/**
207
* Detect current IDE environment
208
* @returns Detected IDE information
209
*/
210
function detectIde(): Promise<DetectedIde | null>;
211
```
212
213
### IDE Installation
214
215
Utilities for installing and configuring IDE extensions and integrations.
216
217
```typescript { .api }
218
/**
219
* IDE installer for managing extensions and configurations
220
*/
221
class IdeInstaller {
222
constructor(ideInfo: IdeInfo);
223
224
// Extension management
225
installExtension(extensionId: string): Promise<boolean>;
226
uninstallExtension(extensionId: string): Promise<boolean>;
227
isExtensionInstalled(extensionId: string): Promise<boolean>;
228
listInstalledExtensions(): Promise<InstalledExtension[]>;
229
230
// Configuration management
231
updateConfiguration(settings: Record<string, any>): Promise<void>;
232
getConfiguration(): Promise<Record<string, any>>;
233
234
// Workspace management
235
createWorkspace(path: string, settings?: Record<string, any>): Promise<void>;
236
openWorkspace(path: string): Promise<void>;
237
238
// Integration setup
239
setupGeminiIntegration(config: GeminiIntegrationConfig): Promise<boolean>;
240
verifyIntegration(): Promise<IntegrationStatus>;
241
}
242
243
/**
244
* Installed extension information
245
*/
246
interface InstalledExtension {
247
id: string;
248
name: string;
249
version: string;
250
enabled: boolean;
251
publisher: string;
252
description?: string;
253
}
254
255
/**
256
* Gemini integration configuration
257
*/
258
interface GeminiIntegrationConfig {
259
apiKey?: string;
260
model?: string;
261
enableAutoComplete?: boolean;
262
enableInlineChat?: boolean;
263
enableCodeAnalysis?: boolean;
264
shortcuts?: Record<string, string>;
265
}
266
267
/**
268
* Integration status
269
*/
270
interface IntegrationStatus {
271
isInstalled: boolean;
272
isConfigured: boolean;
273
isEnabled: boolean;
274
version?: string;
275
errors?: string[];
276
warnings?: string[];
277
}
278
```
279
280
### Type Schemas
281
282
Zod schemas for validating IDE-related data structures.
283
284
```typescript { .api }
285
import { z } from 'zod';
286
287
/**
288
* File schema for validation
289
*/
290
const FileSchema = z.object({
291
name: z.string(),
292
path: z.string(),
293
content: z.string(),
294
cursor: z.object({
295
line: z.number(),
296
column: z.number()
297
}).optional(),
298
selection: z.object({
299
start: z.object({
300
line: z.number(),
301
column: z.number()
302
}),
303
end: z.object({
304
line: z.number(),
305
column: z.number()
306
})
307
}).optional(),
308
language: z.string().optional(),
309
isDirty: z.boolean().optional()
310
});
311
312
/**
313
* IDE context schema for validation
314
*/
315
const IdeContextSchema = z.object({
316
files: z.array(FileSchema),
317
cwd: z.string(),
318
metadata: z.record(z.any()).optional()
319
});
320
321
/**
322
* IDE context notification schema for validation
323
*/
324
const IdeContextNotificationSchema = z.object({
325
type: z.literal('context_update'),
326
context: IdeContextSchema,
327
timestamp: z.string()
328
});
329
330
// Type exports from schemas
331
type File = z.infer<typeof FileSchema>;
332
type IdeContext = z.infer<typeof IdeContextSchema>;
333
type IdeContextNotification = z.infer<typeof IdeContextNotificationSchema>;
334
```
335
336
### IDE Constants
337
338
Constants and configuration values for IDE integration.
339
340
```typescript { .api }
341
/**
342
* IDE-related constants
343
*/
344
const IDE_CONSTANTS = {
345
// Connection settings
346
DEFAULT_WEBSOCKET_PORT: 8080,
347
DEFAULT_TCP_PORT: 9090,
348
CONNECTION_TIMEOUT: 30000,
349
HEARTBEAT_INTERVAL: 30000,
350
351
// File watching
352
WATCH_DEBOUNCE_MS: 300,
353
MAX_FILE_SIZE: 10 * 1024 * 1024, // 10MB
354
355
// Extension IDs
356
VSCODE_EXTENSION_ID: 'google.gemini-vscode',
357
INTELLIJ_PLUGIN_ID: 'com.google.gemini-intellij',
358
359
// Configuration paths
360
VSCODE_CONFIG_PATH: '.vscode/settings.json',
361
INTELLIJ_CONFIG_PATH: '.idea/gemini.xml',
362
363
// Supported file extensions
364
SUPPORTED_LANGUAGES: [
365
'typescript', 'javascript', 'python', 'java', 'go',
366
'rust', 'cpp', 'c', 'csharp', 'php', 'ruby'
367
]
368
};
369
```
370
371
**Usage Examples:**
372
373
```typescript
374
import {
375
IdeClient,
376
getIdeInfo,
377
detectIde,
378
IdeInstaller,
379
IdeContext,
380
File
381
} from '@google/gemini-cli-core';
382
383
// Detect current IDE
384
const ideInfo = await getIdeInfo();
385
if (ideInfo) {
386
console.log(`Detected IDE: ${ideInfo.displayName} v${ideInfo.version}`);
387
388
// Setup installer
389
const installer = new IdeInstaller(ideInfo);
390
391
// Install Gemini extension
392
const installed = await installer.installExtension('google.gemini-vscode');
393
if (installed) {
394
console.log('Gemini extension installed successfully');
395
396
// Configure integration
397
await installer.setupGeminiIntegration({
398
apiKey: process.env.GEMINI_API_KEY,
399
model: 'gemini-1.5-flash',
400
enableAutoComplete: true,
401
enableInlineChat: true
402
});
403
}
404
}
405
406
// IDE client communication
407
const ideClient = new IdeClient({
408
connectionType: 'websocket',
409
port: 8080,
410
timeout: 30000
411
});
412
413
// Connect to IDE
414
await ideClient.connect();
415
console.log('Connected to IDE');
416
417
// Get current context
418
const context = await ideClient.getCurrentContext();
419
console.log(`Current directory: ${context.cwd}`);
420
console.log(`Open files: ${context.files.length}`);
421
422
// Listen for context updates
423
ideClient.onContextUpdate((newContext) => {
424
console.log('Context updated:', newContext);
425
});
426
427
// Listen for file changes
428
ideClient.onFileChange((file) => {
429
console.log(`File changed: ${file.path}`);
430
if (file.isDirty) {
431
console.log('File has unsaved changes');
432
}
433
});
434
435
// Open a file
436
await ideClient.openFile('/path/to/file.ts');
437
438
// Insert text at cursor position
439
await ideClient.insertText('/path/to/file.ts', {line: 10, column: 0}, '// TODO: Implement this\n');
440
441
// Show a message to user
442
await ideClient.showMessage('Analysis complete!', 'info');
443
444
// Show quick pick for user selection
445
const selected = await ideClient.showQuickPick([
446
{ label: 'Option 1', description: 'First option' },
447
{ label: 'Option 2', description: 'Second option' }
448
], {
449
title: 'Choose an option',
450
placeholder: 'Select one...'
451
});
452
453
if (selected) {
454
console.log(`User selected: ${selected.label}`);
455
}
456
```