Skip to content

Support servers defined at the workspace-folder level for launching Lite Terminal from Servers tree view #1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/commands/webSocketTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class WebSocketTerminal implements vscode.Pseudoterminal {
// eslint-disable-next-line no-control-regex
private _colorsRegex = /\x1b[^m]*?m/g;

constructor(private readonly _targetUri: vscode.Uri) {}
constructor(
private readonly _targetUri: vscode.Uri,
private readonly _nsOverride?: string
) {}

/** Hide the cursor, write `data` to the terminal, then show the cursor again. */
private _hideCursorWrite(data: string): void {
Expand Down Expand Up @@ -201,6 +204,7 @@ class WebSocketTerminal implements vscode.Pseudoterminal {

open(initialDimensions?: vscode.TerminalDimensions): void {
const api = new AtelierAPI(this._targetUri);
if (this._nsOverride) api.setNamespace(this._nsOverride);
this._cols = initialDimensions?.columns ?? 100000;
try {
// Open the WebSocket
Expand Down Expand Up @@ -728,7 +732,8 @@ function reportError(msg: string, throwErrors = false) {
function terminalConfigForUri(
api: AtelierAPI,
targetUri: vscode.Uri,
throwErrors = false
throwErrors: boolean,
nsOverride?: string
): vscode.ExtensionTerminalOptions | undefined {
// Make sure the server connection is active
if (!api.active || api.ns == "") {
Expand All @@ -751,13 +756,13 @@ function terminalConfigForUri(
vscode.window.terminals.length > 0
? vscode.TerminalLocation.Editor
: vscode.TerminalLocation.Panel,
pty: new WebSocketTerminal(targetUri),
pty: new WebSocketTerminal(targetUri, nsOverride),
isTransient: true,
iconPath: iscIcon,
};
}

export async function launchWebSocketTerminal(targetUri?: vscode.Uri): Promise<void> {
export async function launchWebSocketTerminal(targetUri?: vscode.Uri, nsOverride?: string): Promise<void> {
// Determine the server to connect to
if (targetUri) {
// Uri passed as command argument might be for a server we haven't yet resolved
Expand All @@ -779,7 +784,7 @@ export async function launchWebSocketTerminal(targetUri?: vscode.Uri): Promise<v
await api.serverInfo();

// Get the terminal configuration
const terminalOpts = terminalConfigForUri(api, targetUri);
const terminalOpts = terminalConfigForUri(api, targetUri, false, nsOverride);
if (terminalOpts) {
// Launch the terminal
const terminal = vscode.window.createTerminal(terminalOpts);
Expand Down
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1709,10 +1709,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
(namespaceTreeItem) => {
sendCommandTelemetryEvent("intersystems-servermanager.webterminal");
const idArray = namespaceTreeItem.id.split(":");
const serverId = idArray[1];
const namespace = idArray[3];
const targetUri = vscode.Uri.from({ scheme: "isfs", authority: `${serverId}:${namespace}` });
launchWebSocketTerminal(targetUri);
const serverTreeItem = namespaceTreeItem?.parent?.parent;
const isWsFolderServer =
serverTreeItem?.label.includes("(") && typeof serverTreeItem?.params?.serverSummary?.scope?.uri == "object";
launchWebSocketTerminal(
// Support servers that are defined at the workspace-folder level
isWsFolderServer
? serverTreeItem?.params?.serverSummary?.scope?.uri
: vscode.Uri.from({ scheme: "isfs", authority: `${idArray[1]}:${namespace}` }),
isWsFolderServer ? namespace : undefined
);
}
),
vscode.commands.registerCommand("vscode-objectscript.ObjectScriptExplorer.webterminal", (node: NodeBase) => {
Expand Down