Skip to content

Commit

Permalink
prepare for F8
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 1, 2019
1 parent 2e31f64 commit 86a3da0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ import { getDefaultPowerShellPath, getPlatformDetails } from './platform';
import settings = require("./settings");
import * as process from './process';

async function getCurrentSelection() {
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("<")
let [to, __ ] = await doc.buffer.mark(">")
let result: string[] = []
for(let i = from; i <= to; ++i)
{
result.push(doc.getline(i))
}
return result
}
else if (mode === "n") {
let line = await workspace.nvim.call('line', '.')
return [doc.getline(line)]
}
else if (mode === "i") {
// TODO what to do in insert mode?
}
else if (mode === "t") {
//TODO what to do in terminal mode?
}

return []
}

export async function activate(context: ExtensionContext) {

let config = settings.load()
Expand Down Expand Up @@ -78,6 +106,18 @@ export async function activate(context: ExtensionContext) {
}
})

let cmdEvalSeleection = commands.registerCommand("powershell.evaluateSelection", async () => {
let document = await workspace.document
if (!document || document.filetype !== 'ps1') {
return
}

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

let cmdExecFile = commands.registerCommand("powershell.execute", async (...args: any[]) => {
let document = await workspace.document
if (!document || document.filetype !== 'ps1') {
Expand Down
6 changes: 6 additions & 0 deletions src/client/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ export class PowerShellProcess {
}
}

public eval(line: string) {
if (this.consoleTerminal) {
this.consoleTerminal.sendText(line)
}
}

public dispose() {

// Clean up the session file
Expand Down

0 comments on commit 86a3da0

Please sign in to comment.