diff --git a/runtimes/protocol/index.ts b/runtimes/protocol/index.ts index ed08e1a8..2cc0dc4e 100644 --- a/runtimes/protocol/index.ts +++ b/runtimes/protocol/index.ts @@ -11,6 +11,7 @@ export * from './identity-management' export * from './lsp' export * from './notification' export * from './telemetry' +export * from './terminal' export * from './configuration' export * from './window' export * from './workspace' diff --git a/runtimes/protocol/terminal.ts b/runtimes/protocol/terminal.ts new file mode 100644 index 00000000..2b33d344 --- /dev/null +++ b/runtimes/protocol/terminal.ts @@ -0,0 +1,75 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { RequestType } from 'vscode-languageserver-protocol' + +/** + * Parameters for executing a command in the IDE terminal + */ +export interface ExecuteTerminalCommandParams { + /** + * The command to execute + */ + command: string + + /** + * Working directory for command execution + */ + cwd?: string + + /** + * Environment variables to set for the command + */ + env?: Record + + /** + * Whether to create a new terminal or reuse existing one + */ + createNew?: boolean + + /** + * Name for the terminal (if creating new) + */ + terminalName?: string +} + +/** + * Result of terminal command execution + */ +export interface ExecuteTerminalCommandResult { + /** + * Exit code of the command + */ + exitCode: number + + /** + * Standard output from the command + */ + stdout: string + + /** + * Standard error from the command + */ + stderr: string + + /** + * Whether the command executed successfully + */ + success: boolean + + /** + * Optional message providing additional context + */ + message?: string +} + +/** + * Request type for executing commands in terminal + */ +export const executeTerminalCommandRequest = new RequestType< + ExecuteTerminalCommandParams, + ExecuteTerminalCommandResult, + void +>('aws/terminal/executeCommand') diff --git a/runtimes/runtimes/base-runtime.ts b/runtimes/runtimes/base-runtime.ts index a30fe049..b111f24a 100644 --- a/runtimes/runtimes/base-runtime.ts +++ b/runtimes/runtimes/base-runtime.ts @@ -62,6 +62,7 @@ import { listAvailableModelsRequestType, subscriptionDetailsNotificationType, subscriptionUpgradeNotificationType, + executeTerminalCommandRequest, getSupplementalContextRequestType, } from '../protocol' import { createConnection } from 'vscode-languageserver/browser' @@ -306,6 +307,10 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag lspConnection.onNotification(didChangeDependencyPathsNotificationType, handler) }, }, + terminal: { + executeCommand: (params, token) => + lspConnection.sendRequest(executeTerminalCommandRequest, params, token), + }, } const sdkInitializator: SDKInitializator = Object.assign( diff --git a/runtimes/runtimes/standalone.ts b/runtimes/runtimes/standalone.ts index 36b58f39..d91075ef 100644 --- a/runtimes/runtimes/standalone.ts +++ b/runtimes/runtimes/standalone.ts @@ -36,6 +36,7 @@ import { getMfaCodeRequestType, CheckDiagnosticsParams, OpenWorkspaceFileParams, + executeTerminalCommandRequest, getSupplementalContextRequestType, } from '../protocol' import { ProposedFeatures, createConnection } from 'vscode-languageserver/node' @@ -451,6 +452,10 @@ export const standalone = (props: RuntimeProps) => { lspConnection.onRequest(getSupplementalContextRequestType, handler) }, }, + terminal: { + executeCommand: (params, token) => + lspConnection.sendRequest(executeTerminalCommandRequest, params, token), + }, } const isExperimentalProxy = process.env.EXPERIMENTAL_HTTP_PROXY_SUPPORT === 'true' diff --git a/runtimes/server-interface/lsp.ts b/runtimes/server-interface/lsp.ts index f65cb147..6a7c45ec 100644 --- a/runtimes/server-interface/lsp.ts +++ b/runtimes/server-interface/lsp.ts @@ -65,6 +65,9 @@ import { CheckDiagnosticsResult, OpenWorkspaceFileParams, OpenWorkspaceFileResult, + ExecuteTerminalCommandParams, + ExecuteTerminalCommandResult, + CancellationToken, GetSupplementalContextParams, SupplementalContextItem, } from '../protocol' @@ -197,4 +200,16 @@ export type Lsp = { handler: RequestHandler ) => void } + terminal: { + /** + * Execute a command in the IDE terminal + * @param params Terminal command execution parameters + * @param token Optional cancellation token + * @returns Promise that resolves with the execution result + */ + executeCommand: ( + params: ExecuteTerminalCommandParams, + token?: CancellationToken + ) => Promise + } }