MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createLSPClient

Function createLSPClient

source code/services/lsp/LSPClient.ts:53–449  ·  view source on GitHub ↗
(
  serverName: string,
  onCrash?: (error: Error) => void,
)

Source from the content-addressed store, hash-verified

51 * to propagate crash state so the server can be restarted on next use.
52 */
53export function createLSPClient(
54 serverName: string,
55 onCrash?: (error: Error) => void,
56): LSPClient {
57 // State variables in closure
58 let process: ChildProcess | undefined
59 let connection: MessageConnection | undefined
60 let capabilities: ServerCapabilities | undefined
61 let isInitialized = false
62 let startFailed = false
63 let startError: Error | undefined
64 let isStopping = false // Track intentional shutdown to avoid spurious error logging
65 // Queue handlers registered before connection ready (lazy initialization support)
66 const pendingHandlers: Array<{
67 method: string
68 handler: (params: unknown) => void
69 }> = []
70 const pendingRequestHandlers: Array<{
71 method: string
72 handler: (params: unknown) => unknown | Promise<unknown>
73 }> = []
74
75 function checkStartFailed(): void {
76 if (startFailed) {
77 throw startError || new Error(`LSP server ${serverName} failed to start`)
78 }
79 }
80
81 return {
82 get capabilities(): ServerCapabilities | undefined {
83 return capabilities
84 },
85
86 get isInitialized(): boolean {
87 return isInitialized
88 },
89
90 async start(
91 command: string,
92 args: string[],
93 options?: {
94 env?: Record<string, string>
95 cwd?: string
96 },
97 ): Promise<void> {
98 try {
99 // 1. Spawn LSP server process
100 process = spawn(command, args, {
101 stdio: ['pipe', 'pipe', 'pipe'],
102 env: { ...subprocessEnv(), ...options?.env },
103 cwd: options?.cwd,
104 // Prevent visible console window on Windows (no-op on other platforms)
105 windowsHide: true,
106 })
107
108 if (!process.stdout || !process.stdin) {
109 throw new Error('LSP server process stdio not available')
110 }

Callers 1

createLSPServerInstanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected