Skip to content

Commit 39c62a5

Browse files
committed
Address comments
1 parent 8ac648f commit 39c62a5

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

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

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ import {
3636
ShowSaveFileDialogParams,
3737
LSPErrorCodes,
3838
tabBarActionRequestType,
39-
ShowDocumentParams,
40-
ShowDocumentResult,
41-
ShowDocumentRequest,
4239
contextCommandsNotificationType,
4340
ContextCommandParams,
4441
openFileDiffNotificationType,
@@ -58,7 +55,7 @@ import { Disposable, LanguageClient, Position, TextDocumentIdentifier } from 'vs
5855
import * as jose from 'jose'
5956
import { AmazonQChatViewProvider } from './webviewProvider'
6057
import { AuthUtil, ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
61-
import { amazonQDiffScheme, AmazonQPromptSettings, getLogger, messages, openUrl } from 'aws-core-vscode/shared'
58+
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
6259
import {
6360
DefaultAmazonQAppInitContext,
6461
messageDispatcher,
@@ -423,31 +420,6 @@ export function registerMessageListeners(
423420
}
424421
})
425422

426-
languageClient.onRequest<ShowDocumentParams, ShowDocumentResult>(
427-
ShowDocumentRequest.method,
428-
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {
429-
try {
430-
const uri = vscode.Uri.parse(params.uri)
431-
if (uri.scheme.startsWith('http')) {
432-
try {
433-
await openUrl(vscode.Uri.parse(params.uri))
434-
return params
435-
} catch (err: any) {
436-
getLogger().error(`Failed to open http from LSP: error: %s`, err)
437-
}
438-
}
439-
const doc = await vscode.workspace.openTextDocument(uri)
440-
await vscode.window.showTextDocument(doc, { preview: false })
441-
return params
442-
} catch (e) {
443-
return new ResponseError(
444-
LSPErrorCodes.RequestFailed,
445-
`Failed to open document: ${(e as Error).message}`
446-
)
447-
}
448-
}
449-
)
450-
451423
languageClient.onNotification(contextCommandsNotificationType.method, (params: ContextCommandParams) => {
452424
void provider.webview?.postMessage({
453425
command: contextCommandsNotificationType.method,

packages/amazonq/src/lsp/client.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import {
2626
ShowMessageRequest,
2727
ShowMessageRequestParams,
2828
ConnectionMetadata,
29+
ShowDocumentRequest,
30+
ShowDocumentParams,
31+
ShowDocumentResult,
32+
ResponseError,
33+
LSPErrorCodes,
2934
} from '@aws/language-server-runtimes/protocol'
3035
import { AuthUtil, CodeWhispererSettings, getSelectedCustomization } from 'aws-core-vscode/codewhisperer'
3136
import {
@@ -41,9 +46,10 @@ import {
4146
isAmazonInternalOs,
4247
fs,
4348
oidcClientName,
49+
openUrl,
4450
} from 'aws-core-vscode/shared'
4551
import { processUtils } from 'aws-core-vscode/shared'
46-
import { activate } from './chat/activation'
52+
import { activate as activateChat } from './chat/activation'
4753
import { AmazonQResourcePaths } from './lspInstaller'
4854
import { auth2 } from 'aws-core-vscode/auth'
4955
import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config'
@@ -127,7 +133,7 @@ export async function startLanguageServer(
127133
name: env.appName,
128134
version: version,
129135
extension: {
130-
name: clientName,
136+
name: 'AmazonQ-For-VSCode',
131137
version: '0.0.1',
132138
},
133139
clientId: crypto.randomUUID(),
@@ -186,6 +192,31 @@ export async function startLanguageServer(
186192
}
187193
)
188194

195+
client.onRequest<ShowDocumentParams, ShowDocumentResult>(
196+
ShowDocumentRequest.method,
197+
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {
198+
try {
199+
const uri = vscode.Uri.parse(params.uri)
200+
if (uri.scheme.startsWith('http')) {
201+
try {
202+
await openUrl(vscode.Uri.parse(params.uri))
203+
return params
204+
} catch (err: any) {
205+
getLogger().error(`Failed to open http from LSP: error: %s`, err)
206+
}
207+
}
208+
const doc = await vscode.workspace.openTextDocument(uri)
209+
await vscode.window.showTextDocument(doc, { preview: false })
210+
return params
211+
} catch (e) {
212+
return new ResponseError(
213+
LSPErrorCodes.RequestFailed,
214+
`Failed to open document: ${(e as Error).message}`
215+
)
216+
}
217+
}
218+
)
219+
189220
const sendProfileToLsp = async () => {
190221
try {
191222
const result = await client.sendRequest(updateConfigurationRequestType.method, {
@@ -251,7 +282,7 @@ export async function startLanguageServer(
251282
)
252283
}
253284

254-
await activate(client, encryptionKey, resourcePaths.ui)
285+
await activateChat(client, encryptionKey, resourcePaths.ui)
255286

256287
toDispose.push(
257288
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(sendProfileToLsp),

0 commit comments

Comments
 (0)