From c9946e01bff068f23014d1a36303424a684ed8a1 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Fri, 19 Mar 2021 17:35:21 +0100 Subject: [PATCH] Improve/finish task variables --- src/manager.ts | 16 ++++++++-------- src/pseudoTerminal.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/manager.ts b/src/manager.ts index 3ac51eb..016f6a4 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import { getConfig, getConfigs, loadConfigsRaw } from './config'; import { Connection, ConnectionManager } from './connection'; import type { FileSystemConfig } from './fileSystemConfig'; -import { Logging } from './logging'; +import { Logging, LOGGING_NO_STACKTRACE } from './logging'; import { isSSHPseudoTerminal } from './pseudoTerminal'; import type { SSHFileSystem } from './sshFileSystem'; import { catchingPromise, toPromise } from './toPromise'; @@ -173,20 +173,20 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider } public async promptReconnect(name: string) { const config = getConfig(name); - console.log('config', name, config); if (!config) return; const choice = await vscode.window.showWarningMessage(`SSH FS ${config.label || config.name} disconnected`, 'Ignore', 'Disconnect'); if (choice === 'Disconnect') this.commandDisconnect(name); } /* TaskProvider */ protected async replaceTaskVariables(value: string, config: FileSystemConfig): Promise { - return value.replace(/\$\{(\w+)\}/g, (str, match: string) => { + return value.replace(/\$\{(.*?)\}/g, (str, match: string) => { if (!match.startsWith('remote')) return str; // Our variables always start with "remote" // https://github.com/microsoft/vscode/blob/bebd06640734c37f6d5f1a82b13297ce1d297dd1/src/vs/workbench/services/configurationResolver/common/variableResolver.ts#L156 const [key, argument] = match.split(':') as [string, string?]; const getFilePath = (): vscode.Uri => { const uri = vscode.window.activeTextEditor?.document?.uri; - if (uri) return uri; + if (uri && uri.scheme === 'ssh') return uri; + if (uri) throw new Error(`Variable ${str}: Active editor is not a ssh:// file`); throw new Error(`Variable ${str} can not be resolved. Please open an editor.`); } const getFolderPathForFile = (): vscode.Uri => { @@ -202,7 +202,8 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider const { workspaceFolders = [] } = vscode.workspace; if (argument) { const uri = workspaceFolders.find(ws => ws.name === argument)?.uri; - if (uri) return uri; + if (uri && uri.scheme === 'ssh') return uri; + if (uri) throw new Error(`Variable ${str}: Workspace folder '${argument}' is not a ssh:// folder`); throw new Error(`Variable ${str} can not be resolved. No such folder '${argument}'.`); } if (sshFolder) return sshFolder.uri; @@ -211,7 +212,7 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider } throw new Error(`Variable ${str} can not be resolved. Please open an ssh:// folder.`); }; - switch (key.toLowerCase()) { + switch (key) { case 'remoteWorkspaceRoot': case 'remoteWorkspaceFolder': return this.getRemotePath(config, getFolderUri()); @@ -251,7 +252,7 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider return path.posix.sep; default: const msg = `Unrecognized task variable '${str}' starting with 'remote', ignoring`; - Logging.warning(msg); + Logging.warning(msg, LOGGING_NO_STACKTRACE); vscode.window.showWarningMessage(msg); return str; } @@ -315,7 +316,6 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider if (!isSSHPseudoTerminal(pty)) return; const conn = this.connectionManager.getActiveConnections().find(c => c.terminals.includes(pty)); if (!conn) return; // Connection died, which means the terminal should also be closed already? - console.log('provideTerminalLinks', line, pty.config.root, conn ? conn.filesystems.length : 'No connection?'); const links: TerminalLinkUri[] = []; const PATH_REGEX = /\/\S+/g; while (true) { diff --git a/src/pseudoTerminal.ts b/src/pseudoTerminal.ts index 7c6a2aa..4e34d0f 100644 --- a/src/pseudoTerminal.ts +++ b/src/pseudoTerminal.ts @@ -134,6 +134,6 @@ export function createTextTerminal(initialText?: string): TextTerminal { onDidWrite: onDidWrite.event, onDidClose: onDidClose.event, onDidOpen: onDidOpen.event, - open: () => initialText && (onDidWrite.fire(initialText), onDidClose.fire(1)), + open: () => initialText && (onDidWrite.fire(initialText + '\r\n'), onDidClose.fire(1)), }; }