66import vscode , { env , version } from 'vscode'
77import * as nls from 'vscode-nls'
88import * as crypto from 'crypto'
9+ import * as path from 'path'
910import { LanguageClient , LanguageClientOptions , RequestType , State } from 'vscode-languageclient'
1011import { InlineCompletionManager } from '../app/inline/completion'
1112import { AmazonQLspAuth , encryptionKey , notificationTypes } from './auth'
@@ -32,14 +33,21 @@ import {
3233 getLogger ,
3334 undefinedIfEmpty ,
3435 getOptOutPreference ,
36+ isAmazonInternalOs ,
37+ fs ,
3538} from 'aws-core-vscode/shared'
3639import { activate } from './chat/activation'
3740import { AmazonQResourcePaths } from './lspInstaller'
3841import { ConfigSection , isValidConfigSection , toAmazonQLSPLogLevel } from './config'
42+ import { chmodSync } from 'fs'
3943
4044const localize = nls . loadMessageBundle ( )
4145const logger = getLogger ( 'amazonqLsp.lspClient' )
4246
47+ export async function hasGlibcPatch ( ) : Promise < boolean > {
48+ return await fs . exists ( '/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2' )
49+ }
50+
4351export async function startLanguageServer (
4452 extensionContext : vscode . ExtensionContext ,
4553 resourcePaths : AmazonQResourcePaths
@@ -55,18 +63,32 @@ export async function startLanguageServer(
5563 '--pre-init-encryption' ,
5664 '--set-credentials-encryption-key' ,
5765 ]
66+
67+ const documentSelector = [ { scheme : 'file' , language : '*' } ]
68+
69+ const clientId = 'amazonq'
70+ const traceServerEnabled = Settings . instance . isSet ( `${ clientId } .trace.server` )
71+
72+ // apply the GLIBC 2.28 path to node js runtime binary
73+ if ( isAmazonInternalOs ( ) && ( await hasGlibcPatch ( ) ) ) {
74+ const nodeWrapper = `
75+ #! /bin/bash
76+ exec /opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2 --library-path /opt/vsc-sysroot/lib64 ${ resourcePaths . node } "$@"
77+ `
78+ const nodeWrapperPath = path . join ( path . dirname ( resourcePaths . node ) , 'node-wrapper' )
79+ await fs . writeFile ( nodeWrapperPath , nodeWrapper )
80+ chmodSync ( nodeWrapperPath , 0o755 )
81+ resourcePaths . node = nodeWrapperPath
82+ getLogger ( 'amazonqLsp' ) . info ( `Patched node runtime with GLIBC to ${ resourcePaths . node } ` )
83+ }
84+
5885 const serverOptions = createServerOptions ( {
5986 encryptionKey,
6087 executable : resourcePaths . node ,
6188 serverModule,
6289 execArgv : argv ,
6390 } )
6491
65- const documentSelector = [ { scheme : 'file' , language : '*' } ]
66-
67- const clientId = 'amazonq'
68- const traceServerEnabled = Settings . instance . isSet ( `${ clientId } .trace.server` )
69-
7092 await validateNodeExe ( resourcePaths . node , resourcePaths . lsp , argv , logger )
7193
7294 // Options to control the language client
0 commit comments