diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-15 23:42:25 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-15 23:42:25 -0700 |
commit | 1ba5e81852f8af85f0f88536545f075ee45b454b (patch) | |
tree | b939c54c3490521ada2d84e9da9c8f160534b27a /extension | |
parent | 661ce01334b82a74426f2c30df59318c3e847f4f (diff) | |
download | sncontinue-1ba5e81852f8af85f0f88536545f075ee45b454b.tar.gz sncontinue-1ba5e81852f8af85f0f88536545f075ee45b454b.tar.bz2 sncontinue-1ba5e81852f8af85f0f88536545f075ee45b454b.zip |
handle and explain tracebacks
Diffstat (limited to 'extension')
-rw-r--r-- | extension/src/activation/activate.ts | 32 | ||||
-rw-r--r-- | extension/src/continueIdeClient.ts | 10 | ||||
-rw-r--r-- | extension/src/terminal/terminalEmulator.ts | 50 |
3 files changed, 80 insertions, 12 deletions
diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts index 135a8ec7..77010241 100644 --- a/extension/src/activation/activate.ts +++ b/extension/src/activation/activate.ts @@ -8,6 +8,7 @@ import * as path from "path"; import IdeProtocolClient from "../continueIdeClient"; import { getContinueServerUrl } from "../bridge"; import { setupDebugPanel, ContinueGUIWebviewViewProvider } from "../debugPanel"; +import { CapturedTerminal } from "../terminal/terminalEmulator"; export let extensionContext: vscode.ExtensionContext | undefined = undefined; @@ -47,5 +48,36 @@ export function activateExtension( ); })(); + // All opened terminals should be replaced by our own terminal + vscode.window.onDidOpenTerminal((terminal) => { + if (terminal.name === "Continue") { + return; + } + const options = terminal.creationOptions; + const capturedTerminal = new CapturedTerminal({ + ...options, + name: "Continue", + }); + terminal.dispose(); + }); + + // If any terminals are open to start, replace them + vscode.window.terminals.forEach((terminal) => { + if (terminal.name === "Continue") { + return; + } + const options = terminal.creationOptions; + const capturedTerminal = new CapturedTerminal( + { + ...options, + name: "Continue", + }, + (commandOutput: string) => { + ideProtocolClient.sendCommandOutput(commandOutput); + } + ); + terminal.dispose(); + }); + extensionContext = context; } diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index ef9a91c8..a889d3dc 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -326,13 +326,19 @@ class IdeProtocolClient { private continueTerminal: CapturedTerminal | undefined; async runCommand(command: string) { - if (!this.continueTerminal) { - this.continueTerminal = new CapturedTerminal("Continue"); + if (!this.continueTerminal || this.continueTerminal.isClosed()) { + this.continueTerminal = new CapturedTerminal({ + name: "Continue", + }); } this.continueTerminal.show(); return await this.continueTerminal.runCommand(command); } + + sendCommandOutput(output: string) { + this.messenger?.send("commandOutput", { output }); + } } export default IdeProtocolClient; diff --git a/extension/src/terminal/terminalEmulator.ts b/extension/src/terminal/terminalEmulator.ts index b3031baf..35f02ac0 100644 --- a/extension/src/terminal/terminalEmulator.ts +++ b/extension/src/terminal/terminalEmulator.ts @@ -62,21 +62,29 @@ export class CapturedTerminal { this.terminal.show(); } + isClosed(): boolean { + return this.terminal.exitStatus !== undefined; + } + private commandQueue: [string, (output: string) => void][] = []; private hasRunCommand: boolean = false; + private dataEndsInPrompt(strippedData: string): boolean { + const lines = this.dataBuffer.split("\n"); + return ( + lines.length > 0 && + (lines[lines.length - 1].includes("bash-") || + lines[lines.length - 1].includes(") $ ")) && + lines[lines.length - 1].includes("$") + ); + } + private async waitForCommandToFinish() { return new Promise<string>((resolve, reject) => { this.onDataListeners.push((data: any) => { const strippedData = stripAnsi(data); this.dataBuffer += strippedData; - const lines = this.dataBuffer.split("\n"); - if ( - lines.length > 0 && - (lines[lines.length - 1].includes("bash-") || - lines[lines.length - 1].includes(") $ ")) && - lines[lines.length - 1].includes("$") - ) { + if (this.dataEndsInPrompt(strippedData)) { resolve(this.dataBuffer); this.dataBuffer = ""; this.onDataListeners = []; @@ -112,8 +120,30 @@ export class CapturedTerminal { private readonly writeEmitter: vscode.EventEmitter<string>; - constructor(terminalName: string) { - this.shellCmd = "bash"; // getDefaultShell(); + private splitByCommandsBuffer: string = ""; + private readonly onCommandOutput: ((output: string) => void) | undefined; + + splitByCommandsListener(data: string) { + // Split the output by commands so it can be sent to Continue Server + + const strippedData = stripAnsi(data); + this.splitByCommandsBuffer += strippedData; + if (this.dataEndsInPrompt(strippedData)) { + if (this.onCommandOutput) { + this.onCommandOutput(this.splitByCommandsBuffer); + } + this.dataBuffer = ""; + } + } + + constructor( + options: { name: string } & Partial<vscode.ExtensionTerminalOptions>, + onCommandOutput?: (output: string) => void + ) { + this.onCommandOutput = onCommandOutput; + + // this.shellCmd = "bash"; // getDefaultShell(); + this.shellCmd = getDefaultShell(); const env = { ...(process.env as any) }; if (os.platform() !== "win32") { @@ -154,7 +184,7 @@ export class CapturedTerminal { // Create and clear the terminal this.terminal = vscode.window.createTerminal({ - name: terminalName, + ...options, pty: newPty, }); this.terminal.show(); |