@@ -39,15 +39,13 @@ import { fs } from '../../shared/fs/fs'
3939import { getLogger } from '../../shared/logger/logger'
4040import globals from '../../shared/extensionGlobals'
4141import { ResourcePaths } from '../../shared/lsp/types'
42- import { createServerOptions } from '../../shared/lsp/utils/platform'
42+ import { createServerOptions , validateNodeExe } from '../../shared/lsp/utils/platform'
4343import { waitUntil } from '../../shared/utilities/timeoutUtils'
44- import { ToolkitError } from '../../shared/errors'
45- import { ChildProcess } from '../../shared/utilities/processUtils'
4644
4745const localize = nls . loadMessageBundle ( )
4846
4947const key = crypto . randomBytes ( 32 )
50- const logger = getLogger ( 'amazonqLsp.lspClient ' )
48+ const logger = getLogger ( 'amazonqWorkspaceLsp ' )
5149
5250/**
5351 * LspClient manages the API call between VS Code extension and LSP server
@@ -226,53 +224,6 @@ export class LspClient {
226224 }
227225}
228226
229- /**
230- * Checks that we can actually run the `node` executable and execute code with it.
231- */
232- async function validateNodeExe ( nodePath : string , lsp : string , args : string [ ] ) {
233- // Check that we can start `node` by itself.
234- const proc = new ChildProcess ( nodePath , [ '-e' , 'console.log("ok " + process.version)' ] , { logging : 'no' } )
235- const r = await proc . run ( )
236- const ok = r . exitCode === 0 && r . stdout . includes ( 'ok' )
237- if ( ! ok ) {
238- const msg = `failed to run basic "node -e" test (exitcode=${ r . exitCode } ): ${ proc . toString ( false , true ) } `
239- logger . error ( msg )
240- throw new ToolkitError ( `amazonqLsp: ${ msg } ` )
241- }
242-
243- // Check that we can start `node …/lsp.js --stdio …`.
244- const lspProc = new ChildProcess ( nodePath , [ lsp , ...args ] , { logging : 'no' } )
245- try {
246- // Start asynchronously (it never stops; we need to stop it below).
247- lspProc . run ( ) . catch ( ( e ) => logger . error ( 'failed to run: %s' , lspProc . toString ( false , true ) ) )
248-
249- const ok2 =
250- ! lspProc . stopped &&
251- ( await waitUntil (
252- async ( ) => {
253- return lspProc . pid ( ) !== undefined
254- } ,
255- {
256- timeout : 5000 ,
257- interval : 100 ,
258- truthy : true ,
259- }
260- ) )
261- const selfExit = await waitUntil ( async ( ) => lspProc . stopped , {
262- timeout : 500 ,
263- interval : 100 ,
264- truthy : true ,
265- } )
266- if ( ! ok2 || selfExit ) {
267- throw new ToolkitError (
268- `amazonqLsp: failed to run (exitcode=${ lspProc . exitCode ( ) } ): ${ lspProc . toString ( false , true ) } `
269- )
270- }
271- } finally {
272- lspProc . stop ( true )
273- }
274- }
275-
276227/**
277228 * Activates the language server (assumes the LSP server has already been downloaded):
278229 * 1. start LSP server running over IPC protocol.
@@ -312,7 +263,7 @@ export async function activate(extensionContext: ExtensionContext, resourcePaths
312263
313264 const documentSelector = [ { scheme : 'file' , language : '*' } ]
314265
315- await validateNodeExe ( resourcePaths . node , resourcePaths . lsp , debugOptions . execArgv )
266+ await validateNodeExe ( resourcePaths . node , resourcePaths . lsp , debugOptions . execArgv , logger )
316267
317268 // Options to control the language client
318269 const clientOptions : LanguageClientOptions = {
0 commit comments