Skip to content

Commit 76bca76

Browse files
committed
feat: added protocol for context commands
1 parent 8e4e416 commit 76bca76

File tree

9 files changed

+44
-9
lines changed

9 files changed

+44
-9
lines changed

runtimes/protocol/chat.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import {
3939
FILE_CLICK_NOTIFICATION_METHOD,
4040
ChatUpdateParams,
4141
FileClickParams,
42+
CONTEXT_COMMAND_NOTIFICATION_METHOD,
43+
ContextCommandParams,
4244
} from './lsp'
4345

4446
export const chatRequestType = new AutoParameterStructuresProtocolRequestType<
@@ -91,3 +93,6 @@ export const chatUpdateNotificationType = new ProtocolNotificationType<ChatUpdat
9193
export const fileClickNotificationType = new ProtocolNotificationType<FileClickParams, void>(
9294
FILE_CLICK_NOTIFICATION_METHOD
9395
)
96+
export const contextCommandsNotificationType = new ProtocolNotificationType<ContextCommandParams, void>(
97+
CONTEXT_COMMAND_NOTIFICATION_METHOD
98+
)

runtimes/runtimes/auth/auth.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function clearHandlers() {
4848
authHandlers.bearerDeleteHandler = () => {}
4949
}
5050

51-
const serverLspConnectionMock = <Connection>{
51+
const serverLspConnectionMock = {
5252
onRequest: (requestType: any, handler: any) => {
5353
if (requestType.method === credentialsProtocolMethodNames.iamCredentialsUpdate) {
5454
authHandlers.iamUpdateHandler = handler
@@ -83,7 +83,7 @@ const serverLspConnectionMock = <Connection>{
8383
onExecuteCommand: (handler: ServerRequestHandler<ExecuteCommandParams, any, never, void>) => {},
8484
onInitialize: (handler: ServerRequestHandler<InitializeParams, InitializeResult, never, InitializeError>) => {},
8585
onInitialized: (handler: NotificationHandler<InitializedParams>) => {},
86-
}
86+
} as Connection
8787

8888
const lspRouter = new LspRouter(serverLspConnectionMock, 'name')
8989

runtimes/runtimes/base-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
selectWorkspaceItemRequestType,
3939
chatUpdateNotificationType,
4040
fileClickNotificationType,
41+
contextCommandsNotificationType,
4142
} from '../protocol'
4243
import { createConnection } from 'vscode-languageserver/browser'
4344
import {
@@ -141,6 +142,7 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
141142
openTab: params => lspConnection.sendRequest(openTabRequestType.method, params),
142143
sendChatUpdate: params => lspConnection.sendNotification(chatUpdateNotificationType.method, params),
143144
onFileClicked: handler => lspConnection.onNotification(fileClickNotificationType.method, handler),
145+
sendContextCommands: params => lspConnection.sendNotification(contextCommandsNotificationType.method),
144146
}
145147

146148
const identityManagement: IdentityManagement = {

runtimes/runtimes/chat/baseChat.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
chatUpdateNotificationType,
3737
FileClickParams,
3838
fileClickNotificationType,
39+
ContextCommandParams,
40+
contextCommandsNotificationType,
3941
} from '../../protocol'
4042
import { Chat } from '../../server-interface'
4143

@@ -105,4 +107,8 @@ export class BaseChat implements Chat {
105107
public onFileClicked(handler: NotificationHandler<FileClickParams>) {
106108
this.connection.onNotification(fileClickNotificationType.method, handler)
107109
}
110+
111+
public sendContextCommands(params: ContextCommandParams) {
112+
this.connection.sendNotification(contextCommandsNotificationType.method, params)
113+
}
108114
}

runtimes/runtimes/encoding.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { WebBase64Encoding } from './encoding'
33
import sinon, { StubbedInstance, stubInterface } from 'ts-sinon'
44

55
describe('WebBase64Encoding', () => {
6-
const wdw = <WindowOrWorkerGlobalScope>{}
6+
const wdw = {} as WindowOrWorkerGlobalScope
77
const encoding = new WebBase64Encoding(wdw)
88

99
it('encodes and decodes string', () => {

runtimes/runtimes/lsp/router/lspRouter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ describe('LspRouter', () => {
2828
encode: (value: string) => value,
2929
decode: (value: string) => value,
3030
}
31-
const logging = <Logging>{
31+
const logging = {
3232
log: sandbox.stub(),
3333
debug: sandbox.stub(),
3434
error: sandbox.stub(),
3535
warn: sandbox.stub(),
3636
info: sandbox.stub(),
37-
}
37+
} as Logging
3838
const lspConnection = stubLspConnection()
3939

4040
let executeCommandHandler: RequestHandler<ExecuteCommandParams, any | undefined | null, void>
@@ -613,7 +613,7 @@ describe('LspRouter', () => {
613613
})
614614

615615
function stubLspConnection(overrides = {}): Connection {
616-
return <Connection>{
616+
return {
617617
console: {
618618
info: (message: any) => {},
619619
},
@@ -627,7 +627,7 @@ describe('LspRouter', () => {
627627
onNotification: (handler: any) => {},
628628
onDidChangeConfiguration: (handler: any) => {},
629629
...overrides,
630-
}
630+
} as Connection
631631
}
632632

633633
function newServer({

runtimes/runtimes/lsp/router/routerByServerName.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { EventIdentifier, FollowupIdentifier } from '../../../protocol'
44
import { RouterByServerName } from './routerByServerName'
55

66
describe('RouterByServerName', () => {
7-
const encoding = <Encoding>{
7+
const encoding = {
88
encode: value => Buffer.from(value).toString('base64'),
99
decode: value => Buffer.from(value, 'base64').toString('utf-8'),
10-
}
10+
} as Encoding
1111
const serverName = 'Server_XXX'
1212

1313
let router: RouterByServerName<Partial<EventIdentifier>, FollowupIdentifier>

runtimes/server-interface/chat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
OpenTabResult,
2121
ChatUpdateParams,
2222
FileClickParams,
23+
ContextCommandParams,
2324
} from '../protocol'
2425

2526
/**
@@ -44,4 +45,5 @@ export type Chat = {
4445
onFollowUpClicked: (handler: NotificationHandler<FollowUpClickParams>) => void
4546
sendChatUpdate: (params: ChatUpdateParams) => void
4647
onFileClicked: (handler: NotificationHandler<FileClickParams>) => void
48+
sendContextCommands: (params: ContextCommandParams) => void
4749
}

types/chat.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const FOLLOW_UP_CLICK_NOTIFICATION_METHOD = 'aws/chat/followUpClick'
1717
export const OPEN_TAB_REQUEST_METHOD = 'aws/chat/openTab'
1818
export const CHAT_UPDATE_NOTIFICATION_METHOD = 'aws/chat/sendChatUpdate'
1919
export const FILE_CLICK_NOTIFICATION_METHOD = 'aws/chat/fileClick'
20+
export const CONTEXT_COMMAND_NOTIFICATION_METHOD = 'aws/chat/sendContextCommands'
2021

2122
export interface ChatItemAction {
2223
pillText: string
@@ -112,6 +113,7 @@ export interface QuickActionCommand {
112113
command: string
113114
description?: string
114115
placeholder?: string
116+
icon?: IconType
115117
}
116118

117119
/**
@@ -242,3 +244,21 @@ export interface FileClickParams {
242244
filePath: string
243245
action?: FileAction
244246
}
247+
248+
export interface ContextCommandGroup {
249+
groupName?: string
250+
commands: ContextCommand[]
251+
}
252+
253+
export type IconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic' | 'help' | 'trash'
254+
255+
export interface ContextCommand extends QuickActionCommand {
256+
id?: string
257+
route?: string[]
258+
label?: 'file' | 'folder' | 'code'
259+
children?: ContextCommandGroup[]
260+
}
261+
262+
export interface ContextCommandParams {
263+
contextCommandGroups: ContextCommandGroup[]
264+
}

0 commit comments

Comments
 (0)