forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
534 lines (477 loc) · 12.9 KB
/
types.ts
File metadata and controls
534 lines (477 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import type {
LSPClient,
LSPClientConfig,
LSPClientExtension,
Transport,
Workspace,
WorkspaceFile,
} from "@codemirror/lsp-client";
import type { ChangeSet, Extension, MapMode, Text } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import type {
Diagnostic as LSPDiagnostic,
FormattingOptions as LSPFormattingOptions,
Position,
Range,
TextEdit,
} from "vscode-languageserver-types";
export type {
LSPClient,
LSPClientConfig,
LSPClientExtension,
LSPDiagnostic,
LSPFormattingOptions,
Position,
Range,
TextEdit,
Transport,
Workspace,
WorkspaceFile,
};
export interface WorkspaceFileUpdate {
file: WorkspaceFile;
prevDoc: Text;
changes: ChangeSet;
}
// ============================================================================
// Transport Types
// ============================================================================
export type TransportKind = "websocket" | "stdio" | "external";
type MaybePromise<T> = T | Promise<T>;
export interface WebSocketTransportOptions {
binary?: boolean;
timeout?: number;
reconnect?: boolean;
maxReconnectAttempts?: number;
}
export interface TransportDescriptor {
kind: TransportKind;
url?: string;
command?: string;
args?: string[];
options?: WebSocketTransportOptions;
protocols?: string[];
create?: (
server: LspServerDefinition,
context: TransportContext,
) => TransportHandle;
}
export interface TransportHandle {
transport: Transport;
dispose: () => Promise<void> | void;
ready: Promise<void>;
}
export interface TransportContext {
uri?: string;
file?: AcodeFile;
view?: EditorView;
languageId?: string;
rootUri?: string | null;
originalRootUri?: string;
debugWebSocket?: boolean;
/** Dynamically discovered port from auto-port discovery */
dynamicPort?: number;
}
// ============================================================================
// Server Registry Types
// ============================================================================
export interface BridgeConfig {
kind: "axs";
/** Optional port - if not provided, auto-port discovery will be used */
port?: number;
command: string;
args?: string[];
/** Session ID for port file naming (defaults to command name) */
session?: string;
}
export type InstallerKind =
| "apk"
| "npm"
| "pip"
| "cargo"
| "github-release"
| "manual"
| "shell";
export interface LauncherInstallConfig {
kind?: InstallerKind;
command?: string;
updateCommand?: string;
uninstallCommand?: string;
label?: string;
source?: string;
executable?: string;
packages?: string[];
pipCommand?: string;
npmCommand?: string;
pythonCommand?: string;
global?: boolean;
breakSystemPackages?: boolean;
repo?: string;
assetNames?: Record<string, string>;
archiveType?: "zip" | "binary";
extractFile?: string;
binaryPath?: string;
}
export interface LauncherConfig {
command?: string;
args?: string[];
startCommand?: string | string[];
checkCommand?: string;
versionCommand?: string;
updateCommand?: string;
uninstallCommand?: string;
install?: LauncherInstallConfig;
bridge?: BridgeConfig;
}
export interface BuiltinExtensionsConfig {
hover?: boolean;
completion?: boolean;
signature?: boolean;
keymaps?: boolean;
diagnostics?: boolean;
inlayHints?: boolean;
formatting?: boolean;
}
export interface AcodeClientConfig {
useDefaultExtensions?: boolean;
builtinExtensions?: BuiltinExtensionsConfig;
extensions?: (Extension | LSPClientExtension)[];
notificationHandlers?: Record<
string,
(client: LSPClient, params: unknown) => boolean
>;
workspace?: (client: LSPClient) => Workspace;
rootUri?: string;
timeout?: number;
}
export interface LanguageResolverContext {
languageId: string;
languageName?: string;
uri?: string;
file?: AcodeFile;
}
export interface DocumentUriContext extends RootUriContext {
normalizedUri?: string | null;
}
export interface LspServerManifest {
id?: string;
label?: string;
enabled?: boolean;
languages?: string[];
transport?: TransportDescriptor;
initializationOptions?: Record<string, unknown>;
clientConfig?: Record<string, unknown> | AcodeClientConfig;
startupTimeout?: number;
capabilityOverrides?: Record<string, unknown>;
rootUri?:
| ((uri: string, context: unknown) => MaybePromise<string | null>)
| ((uri: string, context: RootUriContext) => MaybePromise<string | null>)
| null;
documentUri?:
| ((
uri: string,
context: DocumentUriContext,
) => MaybePromise<string | null | undefined>)
| null;
resolveLanguageId?:
| ((context: LanguageResolverContext) => string | null)
| null;
launcher?: LauncherConfig;
useWorkspaceFolders?: boolean;
}
export interface LspServerBundle {
id: string;
label?: string;
getServers: () => LspServerManifest[];
getExecutable?: (
serverId: string,
manifest: LspServerManifest,
) => string | null | undefined;
checkInstallation?: (
serverId: string,
manifest: LspServerManifest,
) => Promise<InstallCheckResult | null | undefined>;
installServer?: (
serverId: string,
manifest: LspServerManifest,
mode: "install" | "update" | "reinstall",
options?: { promptConfirm?: boolean },
) => Promise<boolean>;
uninstallServer?: (
serverId: string,
manifest: LspServerManifest,
options?: { promptConfirm?: boolean },
) => Promise<boolean>;
}
export type LspServerProvider = LspServerBundle;
export interface LspServerDefinition {
id: string;
label: string;
enabled: boolean;
languages: string[];
transport: TransportDescriptor;
initializationOptions?: Record<string, unknown>;
clientConfig?: AcodeClientConfig;
startupTimeout?: number;
capabilityOverrides?: Record<string, unknown>;
rootUri?:
| ((uri: string, context: RootUriContext) => MaybePromise<string | null>)
| null;
documentUri?:
| ((
uri: string,
context: DocumentUriContext,
) => MaybePromise<string | null | undefined>)
| null;
resolveLanguageId?:
| ((context: LanguageResolverContext) => string | null)
| null;
launcher?: LauncherConfig;
/**
* When true, uses a single server instance with workspace folders
* instead of starting separate servers per project root.
* Heavy LSP servers like TypeScript and rust-analyzer should use this.
*/
useWorkspaceFolders?: boolean;
}
export interface RootUriContext {
uri?: string;
file?: AcodeFile;
view?: EditorView;
languageId?: string;
rootUri?: string;
}
export type RegistryEventType = "register" | "unregister" | "update";
export type RegistryEventListener = (
event: RegistryEventType,
server: LspServerDefinition,
) => void;
// ============================================================================
// Client Manager Types
// ============================================================================
export interface FileMetadata {
uri: string;
languageId?: string;
languageName?: string;
view?: EditorView;
file?: AcodeFile;
rootUri?: string;
}
export interface FormattingOptions {
tabSize?: number;
insertSpaces?: boolean;
[key: string]: unknown;
}
export interface ClientManagerOptions {
diagnosticsUiExtension?: Extension | Extension[];
clientExtensions?: Extension | Extension[];
resolveRoot?: (context: RootUriContext) => Promise<string | null>;
displayFile?: (uri: string) => Promise<EditorView | null>;
openFile?: (uri: string) => Promise<EditorView | null>;
resolveLanguageId?: (uri: string) => string | null;
onClientIdle?: (info: ClientIdleInfo) => void;
}
export interface ClientIdleInfo {
server: LspServerDefinition;
client: LSPClient;
rootUri: string | null;
}
export interface ClientState {
server: LspServerDefinition;
client: LSPClient;
transport: TransportHandle;
rootUri: string | null;
attach: (uri: string, view: EditorView, aliases?: string[]) => void;
detach: (uri: string, view?: EditorView) => void;
dispose: () => Promise<void>;
}
export interface NormalizedRootUri {
normalizedRootUri: string | null;
originalRootUri: string | null;
}
// ============================================================================
// Server Launcher Types
// ============================================================================
export interface ManagedServerEntry {
uuid: string;
command: string;
startedAt: number;
/** Port number for the axs proxy (for stats endpoint) */
port?: number;
}
export type InstallStatus = "present" | "declined" | "failed";
export interface InstallCheckResult {
status: "present" | "missing" | "failed" | "unknown";
version?: string | null;
canInstall: boolean;
canUpdate: boolean;
message?: string;
}
/**
* Port information from auto-port discovery
*/
export interface PortInfo {
/** The discovered port number */
port: number;
/** Path to the port file */
filePath: string;
/** Session ID used for the port file */
session: string;
}
export interface WaitOptions {
attempts?: number;
delay?: number;
probeTimeout?: number;
}
/**
* Result from ensureServerRunning
*/
export interface EnsureServerResult {
uuid: string | null;
/** Port discovered from port file (for auto-port discovery) */
discoveredPort?: number;
}
/**
* Stats returned from the axs proxy /status endpoint
*/
export interface LspServerStats {
program: string;
processes: Array<{
pid: number;
uptime_secs: number;
memory_bytes: number;
}>;
}
/**
* Formatted stats for UI display
*/
export interface LspServerStatsFormatted {
memoryBytes: number;
memoryFormatted: string;
uptimeSeconds: number;
uptimeFormatted: string;
pid: number | null;
processCount: number;
}
// ============================================================================
// Workspace Types
// ============================================================================
export interface WorkspaceOptions {
displayFile?: (uri: string) => Promise<EditorView | null>;
openFile?: (uri: string) => Promise<EditorView | null>;
resolveLanguageId?: (uri: string) => string | null;
}
// ============================================================================
// Diagnostics Types
// ============================================================================
export interface LspDiagnostic {
from: number;
to: number;
severity: "error" | "warning" | "info" | "hint";
message: string;
source?: string;
/** Related diagnostic information (e.g., location of declaration for 'unused' errors) */
relatedInformation?: DiagnosticRelatedInformation[];
}
/** Related information for a diagnostic (mapped to editor positions) */
export interface DiagnosticRelatedInformation {
/** Document URI */
uri: string;
/** Start position (offset in document) */
from: number;
/** End position (offset in document) */
to: number;
/** Message describing the relationship */
message: string;
}
export interface PublishDiagnosticsParams {
uri: string;
version?: number;
diagnostics: RawDiagnostic[];
}
export interface RawDiagnostic {
range: Range;
severity?: number;
code?: number | string;
source?: string;
message: string;
/** Related diagnostic locations from LSP (raw positions) */
relatedInformation?: RawDiagnosticRelatedInformation[];
}
/** Raw related information from LSP (before position mapping) */
export interface RawDiagnosticRelatedInformation {
location: {
uri: string;
range: Range;
};
message: string;
}
// ============================================================================
// Formatter Types
// ============================================================================
export interface AcodeApi {
registerFormatter: (
id: string,
extensions: string[],
formatter: () => Promise<boolean>,
label: string,
) => void;
}
/**
* Uri utility interface
*/
export interface ParsedUri {
docId?: string;
rootUri?: string;
isFileUri?: boolean;
}
/**
* Interface representing the LSPPlugin instance API.
*/
export interface LSPPluginAPI {
/** The document URI this plugin is attached to */
uri: string;
/** The LSP client instance */
client: LSPClient & { sync: () => void; connected?: boolean };
/** Convert a document offset to an LSP Position */
toPosition: (offset: number) => { line: number; character: number };
/** Convert an LSP Position to a document offset */
fromPosition: (
pos: { line: number; character: number },
doc?: unknown,
) => number;
/** The currently synced document state */
syncedDoc: { length: number };
/** Pending changes that haven't been synced yet */
unsyncedChanges: {
mapPos: (pos: number, assoc?: number, mode?: MapMode) => number | null;
empty: boolean;
};
/** Clear pending changes */
clear: () => void;
}
/**
* Interface for workspace file with view access
*/
export interface WorkspaceFileWithView {
version: number;
getView: () => EditorView | null;
}
/**
* Interface for workspace with file access
*/
export interface WorkspaceWithFileAccess {
getFile: (uri: string) => WorkspaceFileWithView | null;
}
/**
* LSPClient with workspace access (for type casting in notification handlers)
*/
export interface LSPClientWithWorkspace {
workspace: WorkspaceWithFileAccess;
}
// Extend the LSPClient with Acode-specific properties
declare module "@codemirror/lsp-client" {
interface LSPClient {
__acodeLoggedInfo?: boolean;
}
}