Skip to content

Commit 1e78f29

Browse files
committed
feat(amazonq): handle context command and open file for chat with lsp
1 parent ce3dd61 commit 1e78f29

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
QuickActionResult,
2222
QuickActionParams,
2323
insertToCursorPositionNotificationType,
24+
contextCommandsNotificationType,
25+
ContextCommandParams,
2426
} from '@aws/language-server-runtimes/protocol'
2527
import { v4 as uuidv4 } from 'uuid'
2628
import * as vscode from 'vscode'
@@ -184,6 +186,13 @@ export function registerMessageListeners(
184186
break
185187
}
186188
}, undefined)
189+
190+
languageClient.onNotification(contextCommandsNotificationType.method, (params: ContextCommandParams) => {
191+
void provider.webview?.postMessage({
192+
command: contextCommandsNotificationType.method,
193+
params: params,
194+
})
195+
})
187196
}
188197

189198
function isServerEvent(command: string) {

packages/amazonq/src/lsp/client.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
import vscode, { env, version } from 'vscode'
77
import * as nls from 'vscode-nls'
88
import * as crypto from 'crypto'
9-
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient'
9+
import { LanguageClient, LanguageClientOptions, ResponseError } from 'vscode-languageclient'
1010
import { InlineCompletionManager } from '../app/inline/completion'
1111
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
1212
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
13-
import { ConnectionMetadata } from '@aws/language-server-runtimes/protocol'
13+
import {
14+
ConnectionMetadata,
15+
ShowDocumentParams,
16+
ShowDocumentRequest,
17+
ShowDocumentResult,
18+
} from '@aws/language-server-runtimes/protocol'
1419
import { Settings, oidcClientName, createServerOptions, globals, Experiments, Commands } from 'aws-core-vscode/shared'
1520
import { activate } from './chat/activation'
1621
import { AmazonQResourcePaths } from './lspInstaller'
@@ -101,7 +106,17 @@ export async function startLanguageServer(
101106
},
102107
}
103108
})
109+
104110
await auth.refreshConnection()
111+
client.onRequest<ShowDocumentParams, ShowDocumentResult>(
112+
ShowDocumentRequest.method,
113+
async (params: ShowDocumentParams): Promise<ShowDocumentParams | ResponseError<ShowDocumentResult>> => {
114+
const uri = vscode.Uri.parse(params.uri)
115+
const doc = await vscode.workspace.openTextDocument(uri)
116+
await vscode.window.showTextDocument(doc, { preview: false })
117+
return params
118+
}
119+
)
105120

106121
if (Experiments.instance.get('amazonqLSPInline', false)) {
107122
const inlineManager = new InlineCompletionManager(client)

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@
441441
"devDependencies": {
442442
"@aws-sdk/types": "^3.13.1",
443443
"@aws/chat-client-ui-types": "^0.1.12",
444-
"@aws/language-server-runtimes": "^0.2.49",
444+
"@aws/language-server-runtimes": "^0.2.53",
445445
"@aws/language-server-runtimes-types": "^0.1.10",
446446
"@cspotcode/source-map-support": "^0.8.1",
447447
"@sinonjs/fake-timers": "^10.0.2",

0 commit comments

Comments
 (0)