This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclients.ts
52 lines (46 loc) · 1.64 KB
/
clients.ts
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
import { z } from 'zod';
import { getTypeScriptServer } from '@/languages/typescript';
import { TRPCError } from '@trpc/server';
import { getPythonServer } from '@/languages/python';
import { getSourceKitServer } from '@/languages/sourcekit';
import { getSwiplServer } from '@/languages/siwpl';
export type Client = ReturnType<typeof getTypeScriptServer>['stream'];
export const lspRouterInputSchema = z.object({
language: z
.literal('typescript')
.or(z.literal('python'))
.or(z.literal('c'))
.or(z.literal('swift'))
.or(z.literal('prolog')),
workspaceID: z.string(),
});
export type LspRouterInput = z.infer<typeof lspRouterInputSchema>;
export type Language = LspRouterInput['language'];
export const clients = new Map<string, Client>();
export const getClient = (language: Language, workspaceID: string) => {
let client = clients.get(language + workspaceID);
if (!client) {
switch (language) {
case 'typescript':
client = getTypeScriptServer().stream;
break;
case 'python':
client = getPythonServer().stream;
break;
case 'c':
case 'swift':
client = getSourceKitServer().stream;
break;
case 'prolog':
client = getSwiplServer().stream;
break;
default:
throw new TRPCError({
code: 'NOT_IMPLEMENTED',
message: 'Not implemented',
});
}
clients.set(language + workspaceID, client as Client);
}
return client;
};