MCPcopy Index your code
hub / github.com/codeaashu/claude-code / createLSPClient

Function createLSPClient

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

Source from the content-addressed store, hash-verified

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

Callers 1

createLSPServerInstanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected