Skip to content

Commit 80fe89c

Browse files
authored
Detect subshell in terminal inline chat (#249)
* Detect subshell in terminal inline chat * Remove unnecessary code * clean up 2 * More clean up * stick to default shell type dep on platform if cant detect shell type * more clean up * Change name for authLearnMore proposed API
1 parent 043c1df commit 80fe89c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,7 @@
37653765
"@types/source-map-support": "^0.5.10",
37663766
"@types/tar": "^6.1.13",
37673767
"@types/vinyl": "^2.0.12",
3768-
"@types/vscode": "^1.96.0",
3768+
"@types/vscode": "^1.102.0",
37693769
"@typescript-eslint/eslint-plugin": "^8.35.0",
37703770
"@typescript-eslint/parser": "^8.32.0",
37713771
"@typescript-eslint/typescript-estree": "^8.26.1",

src/extension/vscode.proposed.authLearnMore.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ declare module 'vscode' {
77

88
// https://github.com/microsoft/vscode/issues/206587
99

10-
export interface AuthenticationForceNewSessionOptions {
10+
export interface AuthenticationGetSessionPresentationOptions {
1111
/**
1212
* An optional Uri to open in the browser to learn more about this authentication request.
1313
*/
1414
learnMore?: Uri;
1515
}
16-
}
16+
}

src/platform/terminal/vscode/terminalBufferListener.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export function getActiveTerminalSelection(): string {
5757
let lastDetectedShellType: string | undefined;
5858
export function getActiveTerminalShellType(): string {
5959
const activeTerminal = window.activeTerminal;
60+
61+
// Prefer the state object as it's the most reliable
62+
if (activeTerminal?.state.shell) {
63+
return activeTerminal.state.shell;
64+
}
65+
6066
if (activeTerminal && 'shellPath' in activeTerminal.creationOptions) {
6167
const shellPath = activeTerminal.creationOptions.shellPath;
6268
if (shellPath) {
@@ -93,10 +99,7 @@ export function getActiveTerminalShellType(): string {
9399

94100
// Fall back to bash or PowerShell, this uses the front end OS so it could give the wrong shell
95101
// when remoting from Windows into non-Windows or vice versa.
96-
if (platform === 'win32') {
97-
return 'powershell';
98-
}
99-
return 'bash';
102+
return platform === 'win32' ? 'powershell' : 'bash';
100103
}
101104

102105
function appendLimitedWindow<T>(target: T[], data: T) {
@@ -109,6 +112,14 @@ function appendLimitedWindow<T>(target: T[], data: T) {
109112

110113
export function installTerminalBufferListeners(): Disposable[] {
111114
return [
115+
window.onDidChangeTerminalState(t => {
116+
if (window.activeTerminal && t.processId === window.activeTerminal.processId) {
117+
const newShellType = t.state.shell;
118+
if (newShellType && newShellType !== lastDetectedShellType) {
119+
lastDetectedShellType = newShellType;
120+
}
121+
}
122+
}),
112123
window.onDidWriteTerminalData(e => {
113124
let dataBuffer = terminalBuffers.get(e.terminal);
114125
if (!dataBuffer) {

src/platform/test/node/simulationWorkspaceServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ class SimulationTerminal extends Disposable implements vscode.Terminal {
844844
) {
845845
super();
846846
this.name = creationOptions.name ?? '';
847-
this.state = { isInteractedWith: false };
847+
this.state = { isInteractedWith: false, shell: undefined };
848848
const cwd = creationOptions.cwd ?? workspace.workspaceFolders[0];
849849
if (typeof cwd === 'string') {
850850
throw new Error('String cwd not implemented');

0 commit comments

Comments
 (0)