Skip to content

Commit 281a9c2

Browse files
refactor: move function to different file
This function makes more sense to live in the lsp config folder as it is a general function that pushes a config to the lsp Signed-off-by: nkomonen-amazon <[email protected]>
1 parent ffe91a2 commit 281a9c2

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

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

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import { Commands, getLogger, globals, undefinedIfEmpty } from 'aws-core-vscode/
1212
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
1313
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
1414
import { AuthUtil, getSelectedCustomization, notifyNewCustomizations } from 'aws-core-vscode/codewhisperer'
15-
import {
16-
DidChangeConfigurationNotification,
17-
updateConfigurationRequestType,
18-
} from '@aws/language-server-runtimes/protocol'
15+
import { pushConfigUpdate } from '../config'
1916

2017
export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
2118
const disposables = globals.context.subscriptions
@@ -124,47 +121,3 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu
124121
})
125122
}
126123
}
127-
128-
/**
129-
* Request/Notify a config value to the language server, effectively updating it with the
130-
* latest configuration from the client.
131-
*
132-
* The issue is we need to push certain configs to different places, since there are
133-
* different handlers for specific configs. So this determines the correct place to
134-
* push the given config.
135-
*
136-
* TODO: Move this to somewhere more appropriate
137-
*/
138-
async function pushConfigUpdate(client: LanguageClient, config: QConfigs) {
139-
switch (config.type) {
140-
case 'profile':
141-
await client.sendRequest(updateConfigurationRequestType.method, {
142-
section: 'aws.q',
143-
settings: { profileArn: config.profileArn },
144-
})
145-
break
146-
case 'customization':
147-
client.sendNotification(DidChangeConfigurationNotification.type.method, {
148-
section: 'aws.q',
149-
settings: { customization: config.customization },
150-
})
151-
break
152-
case 'logLevel':
153-
client.sendNotification(DidChangeConfigurationNotification.type.method, {
154-
section: 'aws.logLevel',
155-
})
156-
break
157-
}
158-
}
159-
type ProfileConfig = {
160-
type: 'profile'
161-
profileArn: string | undefined
162-
}
163-
type CustomizationConfig = {
164-
type: 'customization'
165-
customization: string | undefined
166-
}
167-
type LogLevelConfig = {
168-
type: 'logLevel'
169-
}
170-
type QConfigs = ProfileConfig | CustomizationConfig | LogLevelConfig

packages/amazonq/src/lsp/config.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import * as vscode from 'vscode'
66
import { DevSettings, getServiceEnvVarConfig } from 'aws-core-vscode/shared'
77
import { LspConfig } from 'aws-core-vscode/amazonq'
8+
import { LanguageClient } from 'vscode-languageclient'
9+
import {
10+
DidChangeConfigurationNotification,
11+
updateConfigurationRequestType,
12+
} from '@aws/language-server-runtimes/protocol'
813

914
export interface ExtendedAmazonQLSPConfig extends LspConfig {
1015
ui?: string
@@ -54,3 +59,45 @@ export function getAmazonQLspConfig(): ExtendedAmazonQLSPConfig {
5459
export function toAmazonQLSPLogLevel(logLevel: vscode.LogLevel): LspLogLevel {
5560
return lspLogLevelMapping.get(logLevel) ?? 'info'
5661
}
62+
63+
/**
64+
* Request/Notify a config value to the language server, effectively updating it with the
65+
* latest configuration from the client.
66+
*
67+
* The issue is we need to push certain configs to different places, since there are
68+
* different handlers for specific configs. So this determines the correct place to
69+
* push the given config.
70+
*/
71+
export async function pushConfigUpdate(client: LanguageClient, config: QConfigs) {
72+
switch (config.type) {
73+
case 'profile':
74+
await client.sendRequest(updateConfigurationRequestType.method, {
75+
section: 'aws.q',
76+
settings: { profileArn: config.profileArn },
77+
})
78+
break
79+
case 'customization':
80+
client.sendNotification(DidChangeConfigurationNotification.type.method, {
81+
section: 'aws.q',
82+
settings: { customization: config.customization },
83+
})
84+
break
85+
case 'logLevel':
86+
client.sendNotification(DidChangeConfigurationNotification.type.method, {
87+
section: 'aws.logLevel',
88+
})
89+
break
90+
}
91+
}
92+
type ProfileConfig = {
93+
type: 'profile'
94+
profileArn: string | undefined
95+
}
96+
type CustomizationConfig = {
97+
type: 'customization'
98+
customization: string | undefined
99+
}
100+
type LogLevelConfig = {
101+
type: 'logLevel'
102+
}
103+
type QConfigs = ProfileConfig | CustomizationConfig | LogLevelConfig

0 commit comments

Comments
 (0)