Skip to content

Commit

Permalink
split eval n/v
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 1, 2019
1 parent 86de0e8 commit 7fb7e03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ if ($Test.IsPresent) {
if ($Pack.IsPresent) {
npm pack
}

14 changes: 8 additions & 6 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { getDefaultPowerShellPath, getPlatformDetails } from './platform';
import settings = require("./settings");
import * as process from './process';

async function getCurrentSelection() {
async function getCurrentSelection(mode: string) {
let doc = await workspace.document
let { mode: mode, blocking: blocking} = await workspace.nvim.mode

if (mode === "v" || mode === "V") {
let [from, _ ] = await doc.buffer.mark("<")
Expand Down Expand Up @@ -106,18 +105,21 @@ export async function activate(context: ExtensionContext) {
}
})

let cmdEvalSelection = commands.registerCommand("powershell.evaluateSelection", async () => {
let doEval = async function(mode: string) {
let document = await workspace.document
if (!document || document.filetype !== 'ps1') {
return
}

for(let line of await getCurrentSelection())
for(let line of await getCurrentSelection(mode))
{
proc.eval(line)
}
});
}


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[]) => {
let document = await workspace.document
if (!document || document.filetype !== 'ps1') {
Expand All @@ -141,5 +143,5 @@ export async function activate(context: ExtensionContext) {

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable, cmdExecFile, cmdEvalSelection);
context.subscriptions.push(disposable, cmdExecFile, cmdEvalLine, cmdEvalSelection);
}

0 comments on commit 7fb7e03

Please sign in to comment.