Skip to content

Commit 05fcc6a

Browse files
committed
feat: sync log level settings with lsp
1 parent 3c1796d commit 05fcc6a

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

packages/amazonq/src/lsp/chat/activation.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { LanguageClient } from 'vscode-languageclient'
88
import { AmazonQChatViewProvider } from './webviewProvider'
99
import { registerCommands } from './commands'
1010
import { registerLanguageServerEventListener, registerMessageListeners } from './messages'
11-
import { Commands, getLogger, globals, undefinedIfEmpty } from 'aws-core-vscode/shared'
11+
import { Commands, getLogger, globals, Settings, undefinedIfEmpty } from 'aws-core-vscode/shared'
1212
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1313
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
1414
import { AuthUtil, getSelectedCustomization } from 'aws-core-vscode/codewhisperer'
1515
import {
1616
DidChangeConfigurationNotification,
1717
updateConfigurationRequestType,
1818
} from '@aws/language-server-runtimes/protocol'
19+
import { getLspLogSettings, lspSettingsSection } from '../config'
1920

2021
export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
2122
const disposables = globals.context.subscriptions
@@ -85,6 +86,10 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
8586
type: 'customization',
8687
customization: undefinedIfEmpty(getSelectedCustomization().arn),
8788
})
89+
}),
90+
Settings.instance.onDidChangeSection(lspSettingsSection, () => {
91+
void pushConfigUpdate(languageClient, { type: 'logging', ...getLspLogSettings() })
92+
getLogger().info('LSP settings changed, sending to lsp')
8893
})
8994
)
9095
}
@@ -108,6 +113,10 @@ async function pushConfigUpdate(client: LanguageClient, config: QConfigs) {
108113
section: 'aws.q',
109114
settings: { customization: config.customization },
110115
})
116+
} else if (config.type === 'logging') {
117+
client.sendNotification(DidChangeConfigurationNotification.type.method, {
118+
section: 'aws.logLevel',
119+
})
111120
}
112121
}
113122
type ProfileConfig = {
@@ -118,4 +127,8 @@ type CustomizationConfig = {
118127
type: 'customization'
119128
customization: string | undefined
120129
}
121-
type QConfigs = ProfileConfig | CustomizationConfig
130+
interface LoggingConfig extends ReturnType<typeof getLspLogSettings> {
131+
type: 'logging'
132+
}
133+
134+
type QConfigs = ProfileConfig | CustomizationConfig | LoggingConfig

packages/amazonq/src/lsp/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export async function startLanguageServer(
6565
const documentSelector = [{ scheme: 'file', language: '*' }]
6666
const lspLogSettings = getLspLogSettings()
6767

68-
getLogger('amazonqLsp').info(`Sending log settings to lsp: %O`, lspLogSettings)
69-
7068
await validateNodeExe(resourcePaths.node, resourcePaths.lsp, argv, logger)
7169

7270
// Options to control the language client
@@ -114,6 +112,9 @@ export async function startLanguageServer(
114112
},
115113
]
116114
}
115+
if (params.items[0].section === 'aws.logLevel') {
116+
return [getLspLogSettings().lspLogLevel]
117+
}
117118
return config
118119
},
119120
},

packages/amazonq/src/lsp/config.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import { DevSettings, getLogger, getServiceEnvVarConfig, Settings } from 'aws-core-vscode/shared'
77
import { LspConfig } from 'aws-core-vscode/amazonq'
88

9-
// Taken from language server runtimes since they are not exported:
10-
// https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10
11-
const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug']
129
export interface ExtendedAmazonQLSPConfig extends LspConfig {
1310
ui?: string
1411
}
@@ -30,9 +27,14 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig {
3027
}
3128
}
3229

33-
// TODO: expose lsp logging settings to users and re-send on update.
34-
export function getLspLogSettings() {
35-
const lspSettings = Settings.instance.getSection('lsp')
30+
// Taken from language server runtimes since they are not exported:
31+
// https://github.com/aws/language-server-runtimes/blob/eae85672c345d8adaf4c8cbd741260b8a59750c4/runtimes/runtimes/util/loggingUtil.ts#L4-L10
32+
const validLspLogLevels = ['error', 'warn', 'info', 'log', 'debug'] as const
33+
export type LspLogLevel = (typeof validLspLogLevels)[number]
34+
export const lspSettingsSection = 'amazonQ.lsp'
35+
36+
export function getLspLogSettings(): { traceChannelEnabled: boolean; lspLogLevel: LspLogLevel } {
37+
const lspSettings = Settings.instance.getSection(lspSettingsSection)
3638
const lspLogLevel = lspSettings.get('logLevel', 'info')
3739
const traceChannelEnabled = lspSettings.get('trace', false)
3840

@@ -42,12 +44,16 @@ export function getLspLogSettings() {
4244
}
4345
}
4446

45-
export function sanitizeLogLevel(lspLogLevel: string) {
46-
if (!validLspLogLevels.includes(lspLogLevel)) {
47+
export function sanitizeLogLevel(lspLogLevel: string): LspLogLevel {
48+
if (!isValidLspLogLevel(lspLogLevel)) {
4749
getLogger('amazonqLsp').warn(
4850
`Invalid log level for amazonq.lsp.logLevel: ${lspLogLevel}. Defaulting to 'info'.`
4951
)
5052
return 'info'
5153
}
5254
return lspLogLevel
5355
}
56+
57+
function isValidLspLogLevel(value: unknown): value is LspLogLevel {
58+
return typeof value === 'string' && validLspLogLevels.includes(value as LspLogLevel)
59+
}

0 commit comments

Comments
 (0)