-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension/src: support stream $/progress message in log style
If the $/progress's begin message start with style: log, the all message for this progress token will be streamed to a terminal. Because executeCommand extends workDoneProgress, if response from executeCommand contains progress token, the result will be streamed to the same terminal. Gopls side change CL 645695. For #3572 Change-Id: I3ad4db2604423a2285a7c0f57b8a4d66d2c1933a Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/645116 kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Madeline Kalil <mkalil@google.com>
- Loading branch information
Showing
4 changed files
with
149 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2025 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
import vscode = require('vscode'); | ||
|
||
import { ProgressToken } from 'vscode-languageclient'; | ||
|
||
// ActiveProgressTerminals maps progress tokens to their corresponding terminals. | ||
// Entries are added when terminals are created for workdone progress and | ||
// deleted when closed by the user, which is interpreted as the user discarding | ||
// any further information. | ||
// There is no guarantee a terminal will remain available for the entire | ||
// duration of a workdone progress notification. | ||
// Logs can be appended to the terminal even after the workdone progress | ||
// notification finishes, allowing responses from requests extending | ||
// WorkDoneProgressOptions to be displayed in the same terminal. | ||
export const ActiveProgressTerminals = new Map<ProgressToken, IProgressTerminal>(); | ||
|
||
export interface IProgressTerminal { | ||
appendLine: (str: string) => void; | ||
show: (preserveFocus?: boolean) => void; | ||
exit: () => void; | ||
} | ||
export class ProgressTerminal implements IProgressTerminal { | ||
private progressToken?: ProgressToken; | ||
private term: vscode.Terminal; | ||
private writeEmitter = new vscode.EventEmitter<string>(); | ||
|
||
// Buffer messages emitted before vscode is ready. VSC calls pty.open when it is ready. | ||
private ptyReady = false; | ||
private buf: string[] = []; | ||
|
||
// Constructor function to stub during test. | ||
static Open(name = 'progress', token?: ProgressToken): IProgressTerminal { | ||
return new ProgressTerminal(name, token); | ||
} | ||
|
||
// ProgressTerminal created with token will be managed by map | ||
// ActiveProgressTerminals. | ||
private constructor(name: string, token?: ProgressToken) { | ||
const pty: vscode.Pseudoterminal = { | ||
onDidWrite: this.writeEmitter.event, | ||
handleInput: () => this.exit(), | ||
open: () => { | ||
this.ptyReady = true; | ||
this.buf.forEach((l) => this.writeEmitter.fire(l)); | ||
this.buf = []; | ||
}, | ||
close: () => { | ||
if (this.progressToken !== undefined) { | ||
ActiveProgressTerminals.delete(this.progressToken); | ||
} | ||
} | ||
}; | ||
this.term = vscode.window.createTerminal({ name: name, pty }); // TODO: iconPath | ||
if (token !== undefined) { | ||
this.progressToken = token; | ||
ActiveProgressTerminals.set(this.progressToken, this); | ||
} | ||
} | ||
|
||
appendLine(str: string) { | ||
if (!str.endsWith('\n')) { | ||
str += '\n'; | ||
} | ||
str = str.replace(/\n/g, '\n\r'); // replaceAll('\n', '\n\r'). | ||
if (!this.ptyReady) { | ||
this.buf.push(str); // print when `open` is called. | ||
} else { | ||
this.writeEmitter.fire(str); | ||
} | ||
} | ||
|
||
show(preserveFocus?: boolean) { | ||
this.term.show(preserveFocus); | ||
} | ||
|
||
exit() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters