Skip to content

Commit

Permalink
powershell.execute command
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jun 30, 2019
1 parent 371671d commit 6f24178
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "PowerShell Language Support using PowerShell Editor Services",
"author": "Yatao Li, Tyler Leonhardt, Cory Knox",
"license": "MIT",
"version": "0.0.3",
"version": "0.0.4",
"publisher": "yatli, tylerl0706, corbob",
"repository": {
"type": "git",
Expand Down
25 changes: 23 additions & 2 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import * as crypto from "crypto";
import * as fs from 'fs';
import * as path from 'path';
import { workspace, ExtensionContext, events } from 'coc.nvim';
import { commands, workspace, ExtensionContext, events } from 'coc.nvim';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'coc.nvim';
import { getDefaultPowerShellPath, getPlatformDetails } from './platform';
import { fileURLToPath } from './utils'
import * as settings from './settings';
import Shell from "node-powershell";

Expand Down Expand Up @@ -111,8 +112,28 @@ export async function activate(context: ExtensionContext) {
}
})

let cmdExecFile = commands.registerCommand("powershell.execute", async (...args: any[]) => {
let document = await workspace.document
if (!document || document.filetype !== 'ps1') {
return
}

let argStrs = args
? args.map(x => `${x}`)
: []

let filePath = fileURLToPath(document.uri)
logger.appendLine(`executing: ${filePath}`)

await workspace.createTerminal({
name: `PowerShell: ${filePath}`,
shellPath: pwshPath,
shellArgs: ['-NoProfile', filePath].concat(argStrs)
})

})

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
context.subscriptions.push(disposable, cmdExecFile);
}
5 changes: 5 additions & 0 deletions src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import fs = require("fs");
import os = require("os");
import path = require("path");
import { Uri } from 'coc.nvim'

export let PowerShellLanguageId = "powershell";

export function fileURLToPath(x: string) {
return Uri.parse(x).fsPath
}

export function ensurePathExists(targetPath: string) {
// Ensure that the path exists
try {
Expand Down

0 comments on commit 6f24178

Please sign in to comment.