Skip to content

Commit

Permalink
Merge pull request #94 from TylerLeonhardt/pr/mikeTWC1984/73
Browse files Browse the repository at this point in the history
Add toggle for terminal and allow dot-sourcing for powershell.execute
  • Loading branch information
Yatao Li authored Apr 17, 2020
2 parents f2bdd1f + 710e5f6 commit 4add304
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 11 additions & 4 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down Expand Up @@ -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
}
Expand Down
26 changes: 22 additions & 4 deletions src/client/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
2 changes: 2 additions & 0 deletions src/client/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface ISettings {
export interface IIntegratedConsoleSettings {
showOnStartup?: boolean;
focusConsoleOnExecute?: boolean;
executeInCurrentScope?: boolean;
}

export function load(): ISettings {
Expand Down Expand Up @@ -157,6 +158,7 @@ export function load(): ISettings {
const defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
showOnStartup: true,
focusConsoleOnExecute: true,
executeInCurrentScope: false,
};

return {
Expand Down

0 comments on commit 4add304

Please sign in to comment.