Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Enable Amazon Q LSP in AL2 instances"
}
6 changes: 4 additions & 2 deletions packages/amazonq/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
maybeShowMinVscodeWarning,
Experiments,
isSageMaker,
isAmazonInternalOs,
} from 'aws-core-vscode/shared'
import { ExtStartUpSources } from 'aws-core-vscode/telemetry'
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
Expand All @@ -43,7 +44,7 @@ import { registerCommands } from './commands'
import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat'
import { activate as activateAmazonqLsp } from './lsp/activation'
import { activate as activateInlineCompletion } from './app/inline/activation'
import { isAmazonInternalOs } from 'aws-core-vscode/shared'
import { hasGlibcPatch } from './lsp/client'

export const amazonQContextPrefix = 'amazonq'

Expand Down Expand Up @@ -122,9 +123,10 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
await activateCodeWhisperer(extContext as ExtContext)
if (
(Experiments.instance.get('amazonqLSP', true) || Auth.instance.isInternalAmazonUser()) &&
!isAmazonInternalOs()
(!isAmazonInternalOs() || (await hasGlibcPatch()))
) {
// start the Amazon Q LSP for internal users first
// for AL2, start LSP if glibc patch is found
await activateAmazonqLsp(context)
}
if (!Experiments.instance.get('amazonqLSPInline', false)) {
Expand Down
32 changes: 27 additions & 5 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import vscode, { env, version } from 'vscode'
import * as nls from 'vscode-nls'
import * as crypto from 'crypto'
import * as path from 'path'
import { LanguageClient, LanguageClientOptions, RequestType, State } from 'vscode-languageclient'
import { InlineCompletionManager } from '../app/inline/completion'
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
Expand All @@ -32,14 +33,21 @@ import {
getLogger,
undefinedIfEmpty,
getOptOutPreference,
isAmazonInternalOs,
fs,
} from 'aws-core-vscode/shared'
import { activate } from './chat/activation'
import { AmazonQResourcePaths } from './lspInstaller'
import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config'
import { chmodSync } from 'fs' // eslint-disable-line no-restricted-imports

const localize = nls.loadMessageBundle()
const logger = getLogger('amazonqLsp.lspClient')

export async function hasGlibcPatch(): Promise<boolean> {
return await fs.exists('/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2')
Copy link
Contributor Author

@leigaol leigaol May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up: Check if aarch64 has this issue or not.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you've only configured this for x86_64. If you want this to work on aarch64, then you'll need to point to ld-linux-aarch64.so.1.

Please check out my overall comment.

}

export async function startLanguageServer(
extensionContext: vscode.ExtensionContext,
resourcePaths: AmazonQResourcePaths
Expand All @@ -55,18 +63,32 @@ export async function startLanguageServer(
'--pre-init-encryption',
'--set-credentials-encryption-key',
]

const documentSelector = [{ scheme: 'file', language: '*' }]

const clientId = 'amazonq'
const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`)

// apply the GLIBC 2.28 path to node js runtime binary
if (isAmazonInternalOs() && (await hasGlibcPatch())) {
const nodeWrapper = `
#! /bin/bash
exec /opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2 --library-path /opt/vsc-sysroot/lib64 ${resourcePaths.node} "$@"
`
const nodeWrapperPath = path.join(path.dirname(resourcePaths.node), 'node-wrapper')
await fs.writeFile(nodeWrapperPath, nodeWrapper)
chmodSync(nodeWrapperPath, 0o755)
resourcePaths.node = nodeWrapperPath
getLogger('amazonqLsp').info(`Patched node runtime with GLIBC to ${resourcePaths.node}`)
}

const serverOptions = createServerOptions({
encryptionKey,
executable: resourcePaths.node,
serverModule,
execArgv: argv,
})

const documentSelector = [{ scheme: 'file', language: '*' }]

const clientId = 'amazonq'
const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`)

await validateNodeExe(resourcePaths.node, resourcePaths.lsp, argv, logger)

// Options to control the language client
Expand Down
Loading