Skip to content

Commit

Permalink
feat: Provide cwd for che terminal creation
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <[email protected]>

rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
RomanNikitenko committed Jul 12, 2024
1 parent c41d0ab commit 3852a7e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion code/extensions/che-terminal/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<Api> {

// containerName is undefined in case the user closed the QuickPick
if (containerName) {
const pty = new MachineExecPTY(machineExecClient, containerName);
const cwd = await getCwd();
const pty = new MachineExecPTY(machineExecClient, containerName, undefined, cwd);
const terminal = vscode.window.createTerminal({ name: `${containerName} container`, pty });
terminal.show();
}
Expand Down Expand Up @@ -127,3 +128,20 @@ export class MachineExecPTY implements vscode.Pseudoterminal {

export function deactivate(): void {
}

async function getCwd(): Promise<string | undefined> {
const folders = vscode.workspace.workspaceFolders;
if (folders === undefined || folders.length < 1) {
return process.env.PROJECTS_ROOT as string;
}

if (folders.length === 1) {
return folders[0].uri.path
}

const options = {
placeHolder: "Select current working directory for new terminal"
};
const workspace: vscode.WorkspaceFolder = await vscode.commands.executeCommand('_workbench.pickWorkspaceFolder', [options]);
return workspace.uri.path;
}

0 comments on commit 3852a7e

Please sign in to comment.