diff --git a/package.json b/package.json index ab7a35e..f385978 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,16 @@ "author": "Yatao Li, Tyler Leonhardt, Cory Knox", "license": "MIT", "readme": "README.md", - "version": "0.0.22", + "version": "0.1.0", "publisher": "yatli, tylerl0706, corbob", "repository": { "type": "git", - "url": "https://github.com/yatli/coc-powershell" + "url": "https://github.com/coc-extensions/coc-powershell" }, + "bugs": { + "url": "https://github.com/coc-extensions/coc-powershell/issues" + }, + "homepage": "https://github.com/coc-extensions/coc-powershell#readme", "engines": { "coc": ">=0.0.77" }, @@ -250,6 +254,11 @@ "default": true, "description": "Switches focus to the console when a script selection is run or a script file is debugged. This is an accessibility feature. To disable it, set to false." }, + "powershell.integratedConsole.executeInCurrentScope": { + "type": "boolean", + "default": false, + "description": "Decides whether or not to use the call operator `& script.ps1` (default) or the dot source operator `. script.ps1` to run the script using the `powershell.execute` command." + }, "powershell.debugging.createTemporaryIntegratedConsole": { "type": "boolean", "default": false, diff --git a/src/client/extension.ts b/src/client/extension.ts index abbd932..1d9edf4 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -77,10 +77,14 @@ function startREPLProc(context: ExtensionContext, config: settings.ISettings, pw } client.sendRequest(EvaluateRequestMessage, evaluateArgs) - await proc.showTerminalIfVisible(); + await proc.showTerminalIfNotVisible(); } + let cmdShowTerminal = commands.registerCommand("powershell.showTerminal", () => proc.showTerminal()); + let cmdHideTerminal = commands.registerCommand("powershell.hideTerminal", () => proc.hideTerminal()); + let cmdToggleTerminal = commands.registerCommand("powershell.toggleTerminal", () => proc.toggleTerminal()); + let cmdEvalLine = commands.registerCommand("powershell.evaluateLine", async () => doEval('n')); let cmdEvalSelection = commands.registerCommand("powershell.evaluateSelection", async () => doEval('v')); let cmdExecFile = commands.registerCommand("powershell.execute", async (...args: any[]) => { @@ -117,16 +121,19 @@ function startREPLProc(context: ExtensionContext, config: settings.ISettings, pw await workspace.nvim.command('w'); } + const config = settings.load(); + const exeChar = config.integratedConsole.executeInCurrentScope ? "." : "&"; const evaluateArgs: IEvaluateRequestArguments = { - expression: `& '${filePath}'`, + expression: `${exeChar} '${filePath}'`, }; + await client.sendRequest(EvaluateRequestMessage, evaluateArgs); - await proc.showTerminalIfVisible(); + await proc.showTerminalIfNotVisible(); }) // Push the disposable to the context's subscriptions so that the // client can be deactivated on extension deactivation - context.subscriptions.push(disposable, cmdExecFile, cmdEvalLine, cmdEvalSelection); + context.subscriptions.push(disposable, cmdExecFile, cmdEvalLine, cmdEvalSelection, cmdShowTerminal, cmdHideTerminal, cmdToggleTerminal ); return proc.onExited } diff --git a/src/client/process.ts b/src/client/process.ts index 590a9dd..045c0a7 100644 --- a/src/client/process.ts +++ b/src/client/process.ts @@ -122,16 +122,34 @@ export class PowerShellProcess { return this.sessionDetails } - public async showTerminalIfVisible() { + public async showTerminalIfNotVisible() { if (this.consoleTerminal) { const winid: number = await vscode.workspace.nvim.eval(`bufwinid(${this.consoleTerminal.bufnr})`) as number; - // If winid is -1, it means the window is not visible/is hidden. - if (winid > -1) { - this.consoleTerminal.show(!this.config.integratedConsole.focusConsoleOnExecute); + // Show terminal if it's hidden when running "execute" commands or if focusConsoleOnExecute, + // this will cause the cursor to jump down into the terminal. + if (this.config.integratedConsole.focusConsoleOnExecute || winid == -1) { + this.consoleTerminal.show(); } } } + + public showTerminal() { + this.consoleTerminal.show(); + } + + public hideTerminal() { + this.consoleTerminal.hide(); + } + + public async toggleTerminal() { + const winid: number = await vscode.workspace.nvim.eval(`bufwinid(${this.consoleTerminal.bufnr})`) as number; + if (winid == -1) { + this.consoleTerminal.show(); + } else { + this.consoleTerminal.hide(); + } + } public dispose() { diff --git a/src/client/settings.ts b/src/client/settings.ts index ea1a8c9..05d6674 100644 --- a/src/client/settings.ts +++ b/src/client/settings.ts @@ -97,6 +97,7 @@ export interface ISettings { export interface IIntegratedConsoleSettings { showOnStartup?: boolean; focusConsoleOnExecute?: boolean; + executeInCurrentScope?: boolean; } export function load(): ISettings { @@ -157,6 +158,7 @@ export function load(): ISettings { const defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = { showOnStartup: true, focusConsoleOnExecute: true, + executeInCurrentScope: false, }; return {