From 0aff18be7dfdf1816ceab49d32efebc09f4aa384 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 25 Apr 2025 17:59:21 -0400 Subject: [PATCH 01/12] feat: add setting to configure lsp log level --- packages/amazonq/src/lsp/client.ts | 11 ++++++----- packages/amazonq/src/lsp/config.ts | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index 1373c026a9c..23f7e12eec3 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -22,7 +22,6 @@ import { } from '@aws/language-server-runtimes/protocol' import { AuthUtil, CodeWhispererSettings, getSelectedCustomization } from 'aws-core-vscode/codewhisperer' import { - Settings, oidcClientName, createServerOptions, globals, @@ -36,6 +35,7 @@ import { } from 'aws-core-vscode/shared' import { activate } from './chat/activation' import { AmazonQResourcePaths } from './lspInstaller' +import { getLspLogLevel } from './config' const localize = nls.loadMessageBundle() const logger = getLogger('amazonqLsp.lspClient') @@ -61,11 +61,11 @@ export async function startLanguageServer( serverModule, execArgv: argv, }) - + const clientId = `amazonq` const documentSelector = [{ scheme: 'file', language: '*' }] + const lspLogSettings = getLspLogLevel(clientId) - const clientId = 'amazonq' - const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`) + getLogger('amazonqLsp').info(`Sending log settings to lsp: %O`, lspLogSettings) await validateNodeExe(resourcePaths.node, resourcePaths.lsp, argv, logger) @@ -139,6 +139,7 @@ export async function startLanguageServer( }, }, }, + logLevel: lspLogSettings.lspLogLevel, credentials: { providesBearerToken: true, }, @@ -148,7 +149,7 @@ export async function startLanguageServer( * When trace server is enabled, logs go to a seperate "Amazon Q Language Server" output. * Otherwise, logs go to the regular "Amazon Q Logs" channel. */ - ...(traceServerEnabled + ...(lspLogSettings.seperateTraceChannel ? {} : { outputChannel: globals.logOutputChannel, diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index 62bba1ac93d..41c389e1266 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { DevSettings, getServiceEnvVarConfig } from 'aws-core-vscode/shared' +import { DevSettings, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' import { LspConfig } from 'aws-core-vscode/amazonq' export interface ExtendedAmazonQLSPConfig extends LspConfig { @@ -26,3 +26,16 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig { ...getServiceEnvVarConfig('amazonqLsp', Object.keys(defaultAmazonQLspConfig)), } } + +// TODO: expose lsp logging settings to users +// trace.server -> pipe LSP logs to seperate output channel. +// lsp.logLevel -> log level to pass to the lsp. +export function getLspLogLevel(clientId: string) { + const traceServerSetting = `${clientId}.trace.server` + const lspLogLevelSetting = `${clientId}.lsp.logLevel` + + return { + seperateTraceChannel: Settings.instance.get(traceServerSetting), + lspLogLevel: Settings.instance.get(lspLogLevelSetting, String, 'info'), + } +} From e033744e227e4808c8dcad18be5669bfdd50dba4 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 25 Apr 2025 18:22:19 -0400 Subject: [PATCH 02/12] refactor: clean up --- packages/amazonq/src/lsp/client.ts | 4 ++-- packages/amazonq/src/lsp/config.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index 23f7e12eec3..cb10f3c208a 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -35,7 +35,7 @@ import { } from 'aws-core-vscode/shared' import { activate } from './chat/activation' import { AmazonQResourcePaths } from './lspInstaller' -import { getLspLogLevel } from './config' +import { getLspLogSettings } from './config' const localize = nls.loadMessageBundle() const logger = getLogger('amazonqLsp.lspClient') @@ -63,7 +63,7 @@ export async function startLanguageServer( }) const clientId = `amazonq` const documentSelector = [{ scheme: 'file', language: '*' }] - const lspLogSettings = getLspLogLevel(clientId) + const lspLogSettings = getLspLogSettings(clientId) getLogger('amazonqLsp').info(`Sending log settings to lsp: %O`, lspLogSettings) diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index 41c389e1266..4ec997f410f 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -27,10 +27,8 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig { } } -// TODO: expose lsp logging settings to users -// trace.server -> pipe LSP logs to seperate output channel. -// lsp.logLevel -> log level to pass to the lsp. -export function getLspLogLevel(clientId: string) { +// TODO: expose lsp logging settings to users and re-send on update. +export function getLspLogSettings(clientId: string) { const traceServerSetting = `${clientId}.trace.server` const lspLogLevelSetting = `${clientId}.lsp.logLevel` From fecfa5904ae339b9ff3e6146b31f789704b76dd8 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 25 Apr 2025 20:46:07 -0400 Subject: [PATCH 03/12] test: add tests for logic --- packages/amazonq/src/lsp/config.ts | 20 +++++++++++++++--- .../test/unit/amazonq/lsp/chat/config.test.ts | 21 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 packages/amazonq/test/unit/amazonq/lsp/chat/config.test.ts diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index 4ec997f410f..deccc6971bc 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -3,9 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { DevSettings, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' +import { DevSettings, getLogger, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' import { LspConfig } from 'aws-core-vscode/amazonq' +// Taken from https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 +const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] export interface ExtendedAmazonQLSPConfig extends LspConfig { ui?: string } @@ -31,9 +33,21 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig { export function getLspLogSettings(clientId: string) { const traceServerSetting = `${clientId}.trace.server` const lspLogLevelSetting = `${clientId}.lsp.logLevel` + const seperateTraceChannel = Settings.instance.get(traceServerSetting) + const lspLogLevel = Settings.instance.get(lspLogLevelSetting, String, 'info') + + if (!validLspLogLevels.includes(lspLogLevel)) { + getLogger('amazonqLsp').warn( + `Invalid log level for ${lspLogLevelSetting}: ${lspLogLevel}. Defaulting to 'info'.` + ) + return { + seperateTraceChannel, + lspLogLevel: 'info', + } + } return { - seperateTraceChannel: Settings.instance.get(traceServerSetting), - lspLogLevel: Settings.instance.get(lspLogLevelSetting, String, 'info'), + seperateTraceChannel, + lspLogLevel: lspLogLevel, } } diff --git a/packages/amazonq/test/unit/amazonq/lsp/chat/config.test.ts b/packages/amazonq/test/unit/amazonq/lsp/chat/config.test.ts new file mode 100644 index 00000000000..57110e3be12 --- /dev/null +++ b/packages/amazonq/test/unit/amazonq/lsp/chat/config.test.ts @@ -0,0 +1,21 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import assert from 'assert' +import { sanitizeLogLevel } from '../../../../../src/lsp/config' + +describe('sanitizeLogLevel', function () { + it('should return the log level if it is valid', function () { + const logLevel = 'info' + const sanitizedLogLevel = sanitizeLogLevel(logLevel) + assert.strictEqual(sanitizedLogLevel, logLevel) + }) + + it('should default to info if it is invalid', function () { + const logLevel = 'verbose' + const sanitizedLogLevel = sanitizeLogLevel(logLevel) + assert.strictEqual(sanitizedLogLevel, 'info') + }) +}) From db8c544cdae6e6f16e5757a234784e5a06d3397f Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 25 Apr 2025 20:57:05 -0400 Subject: [PATCH 04/12] docs: update comment --- packages/amazonq/src/lsp/config.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index deccc6971bc..fe98a0a7b30 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -6,7 +6,8 @@ import { DevSettings, getLogger, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' import { LspConfig } from 'aws-core-vscode/amazonq' -// Taken from https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 +// Taken from language server repo since they are not exported: +// https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] export interface ExtendedAmazonQLSPConfig extends LspConfig { ui?: string @@ -36,18 +37,18 @@ export function getLspLogSettings(clientId: string) { const seperateTraceChannel = Settings.instance.get(traceServerSetting) const lspLogLevel = Settings.instance.get(lspLogLevelSetting, String, 'info') + return { + seperateTraceChannel, + lspLogLevel: sanitizeLogLevel(lspLogLevel), + } +} + +export function sanitizeLogLevel(lspLogLevel: string) { if (!validLspLogLevels.includes(lspLogLevel)) { getLogger('amazonqLsp').warn( - `Invalid log level for ${lspLogLevelSetting}: ${lspLogLevel}. Defaulting to 'info'.` + `Invalid log level for amazonq.lsp.logLevel: ${lspLogLevel}. Defaulting to 'info'.` ) - return { - seperateTraceChannel, - lspLogLevel: 'info', - } - } - - return { - seperateTraceChannel, - lspLogLevel: lspLogLevel, + return 'info' } + return lspLogLevel } From e456dae27d954bba4524aaa173ad8048702798bd Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 25 Apr 2025 21:05:31 -0400 Subject: [PATCH 05/12] docs: update comment --- packages/amazonq/src/lsp/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index fe98a0a7b30..b273b8162c6 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -6,7 +6,7 @@ import { DevSettings, getLogger, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' import { LspConfig } from 'aws-core-vscode/amazonq' -// Taken from language server repo since they are not exported: +// Taken from language server runtimes since they are not exported: // https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] export interface ExtendedAmazonQLSPConfig extends LspConfig { From 3c1796d105fc62a3439f1ef5c5da82ac6bb75903 Mon Sep 17 00:00:00 2001 From: hkobew Date: Sat, 26 Apr 2025 15:19:55 -0400 Subject: [PATCH 06/12] feat: add settings section for ls specific settings --- packages/amazonq/package.json | 17 +++++++++++++++++ packages/amazonq/src/lsp/client.ts | 4 ++-- packages/amazonq/src/lsp/config.ts | 11 +++++------ packages/core/package.nls.json | 2 ++ .../core/src/shared/settings-amazonq.gen.ts | 4 +++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/amazonq/package.json b/packages/amazonq/package.json index 1d285913708..3d8524dc6cd 100644 --- a/packages/amazonq/package.json +++ b/packages/amazonq/package.json @@ -209,6 +209,23 @@ "items": { "type": "string" } + }, + "amazonQ.lsp.traceChannel": { + "type": "boolean", + "markdownDescription": "%AWS.configuration.description.amazonq.lsp.traceChannel%", + "default": false + }, + "amazonQ.lsp.logLevel": { + "type": "string", + "markdownDescription": "%AWS.configuration.description.amazonq.lsp.logLevel%", + "default": "info", + "enum": [ + "error", + "warn", + "info", + "log", + "debug" + ] } } }, diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index cb10f3c208a..000426b8ea8 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -63,7 +63,7 @@ export async function startLanguageServer( }) const clientId = `amazonq` const documentSelector = [{ scheme: 'file', language: '*' }] - const lspLogSettings = getLspLogSettings(clientId) + const lspLogSettings = getLspLogSettings() getLogger('amazonqLsp').info(`Sending log settings to lsp: %O`, lspLogSettings) @@ -149,7 +149,7 @@ export async function startLanguageServer( * When trace server is enabled, logs go to a seperate "Amazon Q Language Server" output. * Otherwise, logs go to the regular "Amazon Q Logs" channel. */ - ...(lspLogSettings.seperateTraceChannel + ...(lspLogSettings.traceChannelEnabled ? {} : { outputChannel: globals.logOutputChannel, diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index b273b8162c6..de6bd6acba2 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -31,14 +31,13 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig { } // TODO: expose lsp logging settings to users and re-send on update. -export function getLspLogSettings(clientId: string) { - const traceServerSetting = `${clientId}.trace.server` - const lspLogLevelSetting = `${clientId}.lsp.logLevel` - const seperateTraceChannel = Settings.instance.get(traceServerSetting) - const lspLogLevel = Settings.instance.get(lspLogLevelSetting, String, 'info') +export function getLspLogSettings() { + const lspSettings = Settings.instance.getSection('lsp') + const lspLogLevel = lspSettings.get('logLevel', 'info') + const traceChannelEnabled = lspSettings.get('trace', false) return { - seperateTraceChannel, + traceChannelEnabled, lspLogLevel: sanitizeLogLevel(lspLogLevel), } } diff --git a/packages/core/package.nls.json b/packages/core/package.nls.json index 81f56a32c57..33b5c97be18 100644 --- a/packages/core/package.nls.json +++ b/packages/core/package.nls.json @@ -98,6 +98,8 @@ "AWS.configuration.description.amazonq.workspaceIndexIgnoreFilePatterns": "File patterns to ignore when indexing your workspace files", "AWS.configuration.description.amazonq.workspaceIndexCacheDirPath": "The path to the directory that contains the cache of the index of your workspace files", "AWS.configuration.description.amazonq.ignoredSecurityIssues": "Specifies a list of code issue identifiers that Amazon Q should ignore when reviewing your workspace. Each item in the array should be a unique string identifier for a specific code issue. This allows you to suppress notifications for known issues that you've assessed and determined to be false positives or not applicable to your project. Use this setting with caution, as it may cause you to miss important security alerts.", + "AWS.configuration.description.amazonq.lsp.traceChannel": "View detailed log messages sent to/from the language server in a seperate output channel named 'Amazon Q Language Server'. All language server logs will be routed to this output channel instead.", + "AWS.configuration.description.amazonq.lsp.logLevel": "Set the logging level of the language server.", "AWS.command.apig.copyUrl": "Copy URL", "AWS.command.apig.invokeRemoteRestApi": "Invoke in the cloud", "AWS.command.apig.invokeRemoteRestApi.cn": "Invoke on Amazon", diff --git a/packages/core/src/shared/settings-amazonq.gen.ts b/packages/core/src/shared/settings-amazonq.gen.ts index 88324e10475..eebd226fcbc 100644 --- a/packages/core/src/shared/settings-amazonq.gen.ts +++ b/packages/core/src/shared/settings-amazonq.gen.ts @@ -35,7 +35,9 @@ export const amazonqSettings = { "amazonQ.workspaceIndexMaxFileSize": {}, "amazonQ.workspaceIndexCacheDirPath": {}, "amazonQ.workspaceIndexIgnoreFilePatterns": {}, - "amazonQ.ignoredSecurityIssues": {} + "amazonQ.ignoredSecurityIssues": {}, + "amazonQ.lsp.traceChannel": {}, + "amazonQ.lsp.logLevel": {} } export default amazonqSettings From 05fcc6a75160dd97bd7a30fa76a218c59d7a3017 Mon Sep 17 00:00:00 2001 From: hkobew Date: Sat, 26 Apr 2025 17:04:38 -0400 Subject: [PATCH 07/12] feat: sync log level settings with lsp --- packages/amazonq/src/lsp/chat/activation.ts | 17 ++++++++++++++-- packages/amazonq/src/lsp/client.ts | 5 +++-- packages/amazonq/src/lsp/config.ts | 22 +++++++++++++-------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/amazonq/src/lsp/chat/activation.ts b/packages/amazonq/src/lsp/chat/activation.ts index 33795219bff..71b09e57307 100644 --- a/packages/amazonq/src/lsp/chat/activation.ts +++ b/packages/amazonq/src/lsp/chat/activation.ts @@ -8,7 +8,7 @@ import { LanguageClient } from 'vscode-languageclient' import { AmazonQChatViewProvider } from './webviewProvider' import { registerCommands } from './commands' import { registerLanguageServerEventListener, registerMessageListeners } from './messages' -import { Commands, getLogger, globals, undefinedIfEmpty } from 'aws-core-vscode/shared' +import { Commands, getLogger, globals, Settings, undefinedIfEmpty } from 'aws-core-vscode/shared' import { activate as registerLegacyChatListeners } from '../../app/chat/activation' import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq' import { AuthUtil, getSelectedCustomization } from 'aws-core-vscode/codewhisperer' @@ -16,6 +16,7 @@ import { DidChangeConfigurationNotification, updateConfigurationRequestType, } from '@aws/language-server-runtimes/protocol' +import { getLspLogSettings, lspSettingsSection } from '../config' export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) { const disposables = globals.context.subscriptions @@ -85,6 +86,10 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu type: 'customization', customization: undefinedIfEmpty(getSelectedCustomization().arn), }) + }), + Settings.instance.onDidChangeSection(lspSettingsSection, () => { + void pushConfigUpdate(languageClient, { type: 'logging', ...getLspLogSettings() }) + getLogger().info('LSP settings changed, sending to lsp') }) ) } @@ -108,6 +113,10 @@ async function pushConfigUpdate(client: LanguageClient, config: QConfigs) { section: 'aws.q', settings: { customization: config.customization }, }) + } else if (config.type === 'logging') { + client.sendNotification(DidChangeConfigurationNotification.type.method, { + section: 'aws.logLevel', + }) } } type ProfileConfig = { @@ -118,4 +127,8 @@ type CustomizationConfig = { type: 'customization' customization: string | undefined } -type QConfigs = ProfileConfig | CustomizationConfig +interface LoggingConfig extends ReturnType { + type: 'logging' +} + +type QConfigs = ProfileConfig | CustomizationConfig | LoggingConfig diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index 000426b8ea8..9521dac445d 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -65,8 +65,6 @@ export async function startLanguageServer( const documentSelector = [{ scheme: 'file', language: '*' }] const lspLogSettings = getLspLogSettings() - getLogger('amazonqLsp').info(`Sending log settings to lsp: %O`, lspLogSettings) - await validateNodeExe(resourcePaths.node, resourcePaths.lsp, argv, logger) // Options to control the language client @@ -114,6 +112,9 @@ export async function startLanguageServer( }, ] } + if (params.items[0].section === 'aws.logLevel') { + return [getLspLogSettings().lspLogLevel] + } return config }, }, diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index de6bd6acba2..60702082d46 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -6,9 +6,6 @@ import { DevSettings, getLogger, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared' import { LspConfig } from 'aws-core-vscode/amazonq' -// Taken from language server runtimes since they are not exported: -// https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 -const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] export interface ExtendedAmazonQLSPConfig extends LspConfig { ui?: string } @@ -30,9 +27,14 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig { } } -// TODO: expose lsp logging settings to users and re-send on update. -export function getLspLogSettings() { - const lspSettings = Settings.instance.getSection('lsp') +// Taken from language server runtimes since they are not exported: +// https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10 +const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] as const +export type LspLogLevel = (typeof validLspLogLevels)[number] +export const lspSettingsSection = 'amazonQ.lsp' + +export function getLspLogSettings(): { traceChannelEnabled: boolean; lspLogLevel: LspLogLevel } { + const lspSettings = Settings.instance.getSection(lspSettingsSection) const lspLogLevel = lspSettings.get('logLevel', 'info') const traceChannelEnabled = lspSettings.get('trace', false) @@ -42,8 +44,8 @@ export function getLspLogSettings() { } } -export function sanitizeLogLevel(lspLogLevel: string) { - if (!validLspLogLevels.includes(lspLogLevel)) { +export function sanitizeLogLevel(lspLogLevel: string): LspLogLevel { + if (!isValidLspLogLevel(lspLogLevel)) { getLogger('amazonqLsp').warn( `Invalid log level for amazonq.lsp.logLevel: ${lspLogLevel}. Defaulting to 'info'.` ) @@ -51,3 +53,7 @@ export function sanitizeLogLevel(lspLogLevel: string) { } return lspLogLevel } + +function isValidLspLogLevel(value: unknown): value is LspLogLevel { + return typeof value === 'string' && validLspLogLevels.includes(value as LspLogLevel) +} From 718ce7ef91528a2b028cf39818b8ba17048bcae8 Mon Sep 17 00:00:00 2001 From: hkobew Date: Sat, 26 Apr 2025 17:18:37 -0400 Subject: [PATCH 08/12] docs: remove extra logging statement --- packages/amazonq/src/lsp/chat/activation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/amazonq/src/lsp/chat/activation.ts b/packages/amazonq/src/lsp/chat/activation.ts index 71b09e57307..1777eaa1b57 100644 --- a/packages/amazonq/src/lsp/chat/activation.ts +++ b/packages/amazonq/src/lsp/chat/activation.ts @@ -89,7 +89,6 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu }), Settings.instance.onDidChangeSection(lspSettingsSection, () => { void pushConfigUpdate(languageClient, { type: 'logging', ...getLspLogSettings() }) - getLogger().info('LSP settings changed, sending to lsp') }) ) } From 2102ce1f7013a59a705f51e3729084ae2e3504d3 Mon Sep 17 00:00:00 2001 From: hkobew Date: Sun, 27 Apr 2025 13:52:37 -0400 Subject: [PATCH 09/12] refactor: avoid duplicating variable --- packages/amazonq/src/lsp/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index 60702082d46..8ae9f45bb8a 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -47,7 +47,7 @@ export function getLspLogSettings(): { traceChannelEnabled: boolean; lspLogLevel export function sanitizeLogLevel(lspLogLevel: string): LspLogLevel { if (!isValidLspLogLevel(lspLogLevel)) { getLogger('amazonqLsp').warn( - `Invalid log level for amazonq.lsp.logLevel: ${lspLogLevel}. Defaulting to 'info'.` + `Invalid log level for ${lspSettingsSection}.logLevel: ${lspLogLevel}. Defaulting to 'info'.` ) return 'info' } From ec7c8a59cdf1a3397cf0e588ab399f2dc8058014 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 28 Apr 2025 08:33:07 -0400 Subject: [PATCH 10/12] docs: update docs --- docs/lsp.md | 6 ++---- packages/core/package.nls.json | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/lsp.md b/docs/lsp.md index 42d94d334a4..ab15e144b2b 100644 --- a/docs/lsp.md +++ b/docs/lsp.md @@ -26,9 +26,7 @@ sequenceDiagram ## Language Server Debugging -1. Clone https://github.com/aws/language-servers.git and set it up in the same workspace as this project by cmd+shift+p and "add folder to workspace" and selecting the language-servers folder that you just cloned. Your VS code folder structure should look like below. - - +1. Clone https://github.com/aws/language-servers.git and set it up in the same workspace as this project by cmd+shift+p and "add folder to workspace" and selecting the language-servers folder that you just cloned. Your VS code folder structure should look like below. ``` /aws-toolkit-vscode @@ -55,7 +53,7 @@ sequenceDiagram ``` 4. Uncomment the `__AMAZONQLSP_PATH` and `__AMAZONQLSP_UI` variables in the `amazonq/.vscode/launch.json` extension configuration 5. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server -6. (Optional): Enable `"amazonq.trace.server": "on"` or `"amazonq.trace.server": "verbose"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel +6. (Optional): Enable `"amazonq.lsp.trace": "on"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel. `"amazonq.lsp.logLevel"` can be used to configure the log level for the language server. ## Amazon Q Inline Activation diff --git a/packages/core/package.nls.json b/packages/core/package.nls.json index 33b5c97be18..7812eaf90ce 100644 --- a/packages/core/package.nls.json +++ b/packages/core/package.nls.json @@ -98,7 +98,7 @@ "AWS.configuration.description.amazonq.workspaceIndexIgnoreFilePatterns": "File patterns to ignore when indexing your workspace files", "AWS.configuration.description.amazonq.workspaceIndexCacheDirPath": "The path to the directory that contains the cache of the index of your workspace files", "AWS.configuration.description.amazonq.ignoredSecurityIssues": "Specifies a list of code issue identifiers that Amazon Q should ignore when reviewing your workspace. Each item in the array should be a unique string identifier for a specific code issue. This allows you to suppress notifications for known issues that you've assessed and determined to be false positives or not applicable to your project. Use this setting with caution, as it may cause you to miss important security alerts.", - "AWS.configuration.description.amazonq.lsp.traceChannel": "View detailed log messages sent to/from the language server in a seperate output channel named 'Amazon Q Language Server'. All language server logs will be routed to this output channel instead.", + "AWS.configuration.description.amazonq.lsp.traceChannel": "View detailed log messages sent to/from the language server in a seperate output channel named 'Amazon Q Language Server'. All language server logs will be routed to this output channel instead. (Requires reloading to take effect)", "AWS.configuration.description.amazonq.lsp.logLevel": "Set the logging level of the language server.", "AWS.command.apig.copyUrl": "Copy URL", "AWS.command.apig.invokeRemoteRestApi": "Invoke in the cloud", From 89e5c336870b80af951c9d21b9afe8fbb97595b5 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 28 Apr 2025 10:14:35 -0400 Subject: [PATCH 11/12] docs: use traceChannel consistently --- docs/lsp.md | 2 +- packages/amazonq/src/lsp/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/lsp.md b/docs/lsp.md index ab15e144b2b..30259e7cc53 100644 --- a/docs/lsp.md +++ b/docs/lsp.md @@ -53,7 +53,7 @@ sequenceDiagram ``` 4. Uncomment the `__AMAZONQLSP_PATH` and `__AMAZONQLSP_UI` variables in the `amazonq/.vscode/launch.json` extension configuration 5. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server -6. (Optional): Enable `"amazonq.lsp.trace": "on"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel. `"amazonq.lsp.logLevel"` can be used to configure the log level for the language server. +6. (Optional): Enable `"amazonq.lsp.traceChannel": "on"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel. `"amazonq.lsp.logLevel"` can be used to configure the log level for the language server. ## Amazon Q Inline Activation diff --git a/packages/amazonq/src/lsp/config.ts b/packages/amazonq/src/lsp/config.ts index 8ae9f45bb8a..1a630040a08 100644 --- a/packages/amazonq/src/lsp/config.ts +++ b/packages/amazonq/src/lsp/config.ts @@ -36,7 +36,7 @@ export const lspSettingsSection = 'amazonQ.lsp' export function getLspLogSettings(): { traceChannelEnabled: boolean; lspLogLevel: LspLogLevel } { const lspSettings = Settings.instance.getSection(lspSettingsSection) const lspLogLevel = lspSettings.get('logLevel', 'info') - const traceChannelEnabled = lspSettings.get('trace', false) + const traceChannelEnabled = lspSettings.get('traceChannel', false) return { traceChannelEnabled, From 9cd96986c833f5acec530965104908072792df86 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 28 Apr 2025 10:27:33 -0400 Subject: [PATCH 12/12] docs: update docs to include information about the new settings --- CONTRIBUTING.md | 4 ++++ docs/lsp.md | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fa18d38dc81..ed479c5105a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -388,6 +388,10 @@ If you need to report an issue attach these to give the most detailed informatio 5. Now you should see additional `[debug]` prefixed logs in the output. - ![](./docs/images/logsDebugLog.png) +#### Language Server Logs + +For information related to configuring the logs produced by the AmazonQ language server, see [Language Server Logging](./docs/lsp.md#language-server-logging). + ### Telemetry - See [docs/telemetry.md](./docs/telemetry.md) for guidelines on developing telemetry in this project. diff --git a/docs/lsp.md b/docs/lsp.md index 30259e7cc53..fc7619d7bcf 100644 --- a/docs/lsp.md +++ b/docs/lsp.md @@ -53,7 +53,14 @@ sequenceDiagram ``` 4. Uncomment the `__AMAZONQLSP_PATH` and `__AMAZONQLSP_UI` variables in the `amazonq/.vscode/launch.json` extension configuration 5. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server -6. (Optional): Enable `"amazonq.lsp.traceChannel": "on"` in your VSCode settings to view detailed log messages sent to/from the language server. These log messages will show up in the "Amazon Q Language Server" output channel. `"amazonq.lsp.logLevel"` can be used to configure the log level for the language server. +6. (Optional): To customize logging options, see [Language Server Logging](#language-server-logging) + +## Language Server Logging + +There are two settings that allow us to configure the language server logging. + +- `amazonq.lsp.logLevel`: the logging level the language server should use. Options include `'error'`, `'warn'`, `'info'`, `'log'`, and `'debug'`. The default level is info. See the [implementation](<(https://github.com/aws/language-server-runtimes/blob/main/runtimes/runtimes/util/loggingUtil.ts#L4-L10)>) on the lanaguage server side for more information. +- `amazonq.lsp.traceChannel`: View detailed log messages sent to/from the language server in a seperate output channel named 'Amazon Q Language Server'. All language server logs will be routed to this output channel instead. (Requires reloading to take effect). ## Amazon Q Inline Activation