mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
109
shell-integration-sample/package-lock.json
generated
109
shell-integration-sample/package-lock.json
generated
@ -9,14 +9,14 @@
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.88.0",
|
||||
"@types/vscode": "^1.93.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.14.0",
|
||||
"eslint": "^8.57.0",
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.88.0"
|
||||
"vscode": "^1.93.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aashutoshrathi/word-wrap": {
|
||||
@ -218,9 +218,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/vscode": {
|
||||
"version": "1.88.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.88.0.tgz",
|
||||
"integrity": "sha512-rWY+Bs6j/f1lvr8jqZTyp5arRMfovdxolcqGi+//+cPDOh8SBvzXH90e7BiSXct5HJ9HGW6jATchbRTpTJpEkw==",
|
||||
"version": "1.93.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.93.0.tgz",
|
||||
"integrity": "sha512-kUK6jAHSR5zY8ps42xuW89NLcBpw1kOabah7yv38J8MyiYuOHxLQBi0e7zeXbQgVefDy/mZZetqEFC+Fl5eIEQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin": {
|
||||
@ -259,15 +259,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.6.0.tgz",
|
||||
"integrity": "sha512-usPMPHcwX3ZoPWnBnhhorc14NJw9J4HpSXQX4urF2TPKG0au0XhJoZyX62fmvdHONUkmyUe74Hzm1//XA+BoYg==",
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz",
|
||||
"integrity": "sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "7.6.0",
|
||||
"@typescript-eslint/types": "7.6.0",
|
||||
"@typescript-eslint/typescript-estree": "7.6.0",
|
||||
"@typescript-eslint/visitor-keys": "7.6.0",
|
||||
"@typescript-eslint/scope-manager": "7.18.0",
|
||||
"@typescript-eslint/types": "7.18.0",
|
||||
"@typescript-eslint/typescript-estree": "7.18.0",
|
||||
"@typescript-eslint/visitor-keys": "7.18.0",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@ -286,6 +286,81 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz",
|
||||
"integrity": "sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "7.18.0",
|
||||
"@typescript-eslint/visitor-keys": "7.18.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.18.0 || >=20.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": {
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz",
|
||||
"integrity": "sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^18.18.0 || >=20.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz",
|
||||
"integrity": "sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "7.18.0",
|
||||
"@typescript-eslint/visitor-keys": "7.18.0",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
"minimatch": "^9.0.4",
|
||||
"semver": "^7.6.0",
|
||||
"ts-api-utils": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.18.0 || >=20.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz",
|
||||
"integrity": "sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "7.18.0",
|
||||
"eslint-visitor-keys": "^3.4.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.18.0 || >=20.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.6.0.tgz",
|
||||
@ -1609,9 +1684,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
|
||||
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
|
||||
"version": "5.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz",
|
||||
"integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
||||
@ -4,25 +4,22 @@
|
||||
"description": "",
|
||||
"version": "0.0.1",
|
||||
"engines": {
|
||||
"vscode": "^1.88.0"
|
||||
"vscode": "^1.93.0"
|
||||
},
|
||||
"enabledApiProposals": [
|
||||
"terminalShellIntegration"
|
||||
],
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"terminal": {
|
||||
"profiles": [
|
||||
{
|
||||
"id": "shell-integration-sample.track-editor-directory",
|
||||
"title": "Track Editor Directory"
|
||||
}
|
||||
]
|
||||
}
|
||||
"terminal": {
|
||||
"profiles": [
|
||||
{
|
||||
"id": "shell-integration-sample.track-editor-directory",
|
||||
"title": "Track Editor Directory"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
@ -31,8 +28,8 @@
|
||||
"lint": "eslint src --ext ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/vscode": "^1.88.0",
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.93.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.14.0",
|
||||
"eslint": "^8.57.0",
|
||||
|
||||
@ -1,313 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/145234
|
||||
|
||||
/**
|
||||
* A command that was executed in a terminal.
|
||||
*/
|
||||
export interface TerminalShellExecution {
|
||||
/**
|
||||
* The command line that was executed. The {@link TerminalShellExecutionCommandLineConfidence confidence}
|
||||
* of this value depends on the specific shell's shell integration implementation. This
|
||||
* value may become more accurate after {@link window.onDidEndTerminalShellExecution} is
|
||||
* fired.
|
||||
*
|
||||
* @example
|
||||
* // Log the details of the command line on start and end
|
||||
* window.onDidStartTerminalShellExecution(event => {
|
||||
* const commandLine = event.execution.commandLine;
|
||||
* console.log(`Command started\n${summarizeCommandLine(commandLine)}`);
|
||||
* });
|
||||
* window.onDidEndTerminalShellExecution(event => {
|
||||
* const commandLine = event.execution.commandLine;
|
||||
* console.log(`Command ended\n${summarizeCommandLine(commandLine)}`);
|
||||
* });
|
||||
* function summarizeCommandLine(commandLine: TerminalShellExecutionCommandLine) {
|
||||
* return [
|
||||
* ` Command line: ${command.ommandLine.value}`,
|
||||
* ` Confidence: ${command.ommandLine.confidence}`,
|
||||
* ` Trusted: ${command.ommandLine.isTrusted}
|
||||
* ].join('\n');
|
||||
* }
|
||||
*/
|
||||
readonly commandLine: TerminalShellExecutionCommandLine;
|
||||
|
||||
/**
|
||||
* The working directory that was reported by the shell when this command executed. This
|
||||
* {@link Uri} may represent a file on another machine (eg. ssh into another machine). This
|
||||
* requires the shell integration to support working directory reporting.
|
||||
*/
|
||||
readonly cwd: Uri | undefined;
|
||||
|
||||
/**
|
||||
* Creates a stream of raw data (including escape sequences) that is written to the
|
||||
* terminal. This will only include data that was written after `readData` was called for
|
||||
* the first time, ie. you must call `readData` immediately after the command is executed
|
||||
* via {@link TerminalShellIntegration.executeCommand} or
|
||||
* {@link window.onDidStartTerminalShellExecution} to not miss any data.
|
||||
*
|
||||
* @example
|
||||
* // Log all data written to the terminal for a command
|
||||
* const command = term.shellIntegration.executeCommand({ commandLine: 'echo "Hello world"' });
|
||||
* const stream = command.read();
|
||||
* for await (const data of stream) {
|
||||
* console.log(data);
|
||||
* }
|
||||
*/
|
||||
read(): AsyncIterable<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A command line that was executed in a terminal.
|
||||
*/
|
||||
export interface TerminalShellExecutionCommandLine {
|
||||
/**
|
||||
* The full command line that was executed, including both the command and its arguments.
|
||||
*/
|
||||
readonly value: string;
|
||||
|
||||
/**
|
||||
* Whether the command line value came from a trusted source and is therefore safe to
|
||||
* execute without user additional confirmation, such as a notification that asks "Do you
|
||||
* want to execute (command)?". This verification is likely only needed if you are going to
|
||||
* execute the command again.
|
||||
*
|
||||
* This is `true` only when the command line was reported explicitly by the shell
|
||||
* integration script (ie. {@link TerminalShellExecutionCommandLineConfidence.High high confidence})
|
||||
* and it used a nonce for verification.
|
||||
*/
|
||||
readonly isTrusted: boolean;
|
||||
|
||||
/**
|
||||
* The confidence of the command line value which is determined by how the value was
|
||||
* obtained. This depends upon the implementation of the shell integration script.
|
||||
*/
|
||||
readonly confidence: TerminalShellExecutionCommandLineConfidence;
|
||||
}
|
||||
|
||||
/**
|
||||
* The confidence of a {@link TerminalShellExecutionCommandLine} value.
|
||||
*/
|
||||
enum TerminalShellExecutionCommandLineConfidence {
|
||||
/**
|
||||
* The command line value confidence is low. This means that the value was read from the
|
||||
* terminal buffer using markers reported by the shell integration script. Additionally one
|
||||
* of the following conditions will be met:
|
||||
*
|
||||
* - The command started on the very left-most column which is unusual, or
|
||||
* - The command is multi-line which is more difficult to accurately detect due to line
|
||||
* continuation characters and right prompts.
|
||||
* - Command line markers were not reported by the shell integration script.
|
||||
*/
|
||||
Low = 0,
|
||||
|
||||
/**
|
||||
* The command line value confidence is medium. This means that the value was read from the
|
||||
* terminal buffer using markers reported by the shell integration script. The command is
|
||||
* single-line and does not start on the very left-most column (which is unusual).
|
||||
*/
|
||||
Medium = 1,
|
||||
|
||||
/**
|
||||
* The command line value confidence is high. This means that the value was explicitly sent
|
||||
* from the shell integration script or the command was executed via the
|
||||
* {@link TerminalShellIntegration.executeCommand} API.
|
||||
*/
|
||||
High = 2
|
||||
}
|
||||
|
||||
export interface Terminal {
|
||||
/**
|
||||
* An object that contains [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration)-powered
|
||||
* features for the terminal. This will always be `undefined` immediately after the terminal
|
||||
* is created. Listen to {@link window.onDidActivateTerminalShellIntegration} to be notified
|
||||
* when shell integration is activated for a terminal.
|
||||
*
|
||||
* Note that this object may remain undefined if shell integation never activates. For
|
||||
* example Command Prompt does not support shell integration and a user's shell setup could
|
||||
* conflict with the automatic shell integration activation.
|
||||
*/
|
||||
readonly shellIntegration: TerminalShellIntegration | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Shell integration](https://code.visualstudio.com/docs/terminal/shell-integration)-powered capabilities owned by a terminal.
|
||||
*/
|
||||
export interface TerminalShellIntegration {
|
||||
/**
|
||||
* The current working directory of the terminal. This {@link Uri} may represent a file on
|
||||
* another machine (eg. ssh into another machine). This requires the shell integration to
|
||||
* support working directory reporting.
|
||||
*/
|
||||
readonly cwd: Uri | undefined;
|
||||
|
||||
/**
|
||||
* Execute a command, sending ^C as necessary to interrupt any running command if needed.
|
||||
*
|
||||
* @param commandLine The command line to execute, this is the exact text that will be sent
|
||||
* to the terminal.
|
||||
*
|
||||
* @example
|
||||
* // Execute a command in a terminal immediately after being created
|
||||
* const myTerm = window.createTerminal();
|
||||
* window.onDidActivateTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
|
||||
* if (terminal === myTerm) {
|
||||
* const command = shellIntegration.executeCommand('echo "Hello world"');
|
||||
* const code = await command.exitCode;
|
||||
* console.log(`Command exited with code ${code}`);
|
||||
* }
|
||||
* }));
|
||||
* // Fallback to sendText if there is no shell integration within 3 seconds of launching
|
||||
* setTimeout(() => {
|
||||
* if (!myTerm.shellIntegration) {
|
||||
* myTerm.sendText('echo "Hello world"');
|
||||
* // Without shell integration, we can't know when the command has finished or what the
|
||||
* // exit code was.
|
||||
* }
|
||||
* }, 3000);
|
||||
*
|
||||
* @example
|
||||
* // Send command to terminal that has been alive for a while
|
||||
* const commandLine = 'echo "Hello world"';
|
||||
* if (term.shellIntegration) {
|
||||
* const command = term.shellIntegration.executeCommand({ commandLine });
|
||||
* const code = await command.exitCode;
|
||||
* console.log(`Command exited with code ${code}`);
|
||||
* } else {
|
||||
* term.sendText(commandLine);
|
||||
* // Without shell integration, we can't know when the command has finished or what the
|
||||
* // exit code was.
|
||||
* }
|
||||
*/
|
||||
executeCommand(commandLine: string): TerminalShellExecution;
|
||||
|
||||
/**
|
||||
* Execute a command, sending ^C as necessary to interrupt any running command if needed.
|
||||
*
|
||||
* *Note* This is not guaranteed to work as [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration)
|
||||
* must be activated. Check whether {@link TerminalShellExecution.exitCode} is rejected to
|
||||
* verify whether it was successful.
|
||||
*
|
||||
* @param command A command to run.
|
||||
* @param args Arguments to launch the executable with which will be automatically escaped
|
||||
* based on the executable type.
|
||||
*
|
||||
* @example
|
||||
* // Execute a command in a terminal immediately after being created
|
||||
* const myTerm = window.createTerminal();
|
||||
* window.onDidActivateTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
|
||||
* if (terminal === myTerm) {
|
||||
* const command = shellIntegration.executeCommand({
|
||||
* command: 'echo',
|
||||
* args: ['Hello world']
|
||||
* });
|
||||
* const code = await command.exitCode;
|
||||
* console.log(`Command exited with code ${code}`);
|
||||
* }
|
||||
* }));
|
||||
* // Fallback to sendText if there is no shell integration within 3 seconds of launching
|
||||
* setTimeout(() => {
|
||||
* if (!myTerm.shellIntegration) {
|
||||
* myTerm.sendText('echo "Hello world"');
|
||||
* // Without shell integration, we can't know when the command has finished or what the
|
||||
* // exit code was.
|
||||
* }
|
||||
* }, 3000);
|
||||
*
|
||||
* @example
|
||||
* // Send command to terminal that has been alive for a while
|
||||
* const commandLine = 'echo "Hello world"';
|
||||
* if (term.shellIntegration) {
|
||||
* const command = term.shellIntegration.executeCommand({
|
||||
* command: 'echo',
|
||||
* args: ['Hello world']
|
||||
* });
|
||||
* const code = await command.exitCode;
|
||||
* console.log(`Command exited with code ${code}`);
|
||||
* } else {
|
||||
* term.sendText(commandLine);
|
||||
* // Without shell integration, we can't know when the command has finished or what the
|
||||
* // exit code was.
|
||||
* }
|
||||
*/
|
||||
executeCommand(executable: string, args: string[]): TerminalShellExecution;
|
||||
}
|
||||
|
||||
export interface TerminalShellIntegrationChangeEvent {
|
||||
/**
|
||||
* The terminal that shell integration has been activated in.
|
||||
*/
|
||||
readonly terminal: Terminal;
|
||||
|
||||
/**
|
||||
* The shell integration object.
|
||||
*/
|
||||
readonly shellIntegration: TerminalShellIntegration;
|
||||
}
|
||||
|
||||
export interface TerminalShellExecutionStartEvent {
|
||||
/**
|
||||
* The terminal that shell integration has been activated in.
|
||||
*/
|
||||
readonly terminal: Terminal;
|
||||
|
||||
/**
|
||||
* The shell integration object.
|
||||
*/
|
||||
readonly shellIntegration: TerminalShellIntegration;
|
||||
|
||||
/**
|
||||
* The terminal shell execution that has ended.
|
||||
*/
|
||||
readonly execution: TerminalShellExecution;
|
||||
}
|
||||
|
||||
export interface TerminalShellExecutionEndEvent {
|
||||
/**
|
||||
* The terminal that shell integration has been activated in.
|
||||
*/
|
||||
readonly terminal: Terminal;
|
||||
|
||||
/**
|
||||
* The shell integration object.
|
||||
*/
|
||||
readonly shellIntegration: TerminalShellIntegration;
|
||||
|
||||
/**
|
||||
* The terminal shell execution that has ended.
|
||||
*/
|
||||
readonly execution: TerminalShellExecution;
|
||||
|
||||
/**
|
||||
* The exit code reported by the shell. `undefined` means the shell did not report an exit
|
||||
* code or the shell reported a command started before the command finished.
|
||||
*/
|
||||
readonly exitCode: number | undefined;
|
||||
}
|
||||
|
||||
export namespace window {
|
||||
/**
|
||||
* Fires when shell integration activates or one of its properties changes in a terminal.
|
||||
*/
|
||||
export const onDidChangeTerminalShellIntegration: Event<TerminalShellIntegrationChangeEvent>;
|
||||
|
||||
/**
|
||||
* This will be fired when a terminal command is started. This event will fire only when
|
||||
* [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) is
|
||||
* activated for the terminal.
|
||||
*/
|
||||
export const onDidStartTerminalShellExecution: Event<TerminalShellExecutionStartEvent>;
|
||||
|
||||
/**
|
||||
* This will be fired when a terminal command is ended. This event will fire only when
|
||||
* [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) is
|
||||
* activated for the terminal.
|
||||
*/
|
||||
export const onDidEndTerminalShellExecution: Event<TerminalShellExecutionEndEvent>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user