From 6f24178fbb0877e19c023b2be5e1d2fc4cbba0b0 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 30 Jun 2019 17:22:57 +0800 Subject: [PATCH] powershell.execute command --- package-lock.json | 2 +- package.json | 2 +- src/client/extension.ts | 25 +++++++++++++++++++++++-- src/client/utils.ts | 5 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index ee2bb56..a1f1c23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "coc-powershell", - "version": "0.0.3", + "version": "0.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index dfeb514..5b678ec 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/client/extension.ts b/src/client/extension.ts index dace2f0..9cf2d42 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -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"; @@ -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); } diff --git a/src/client/utils.ts b/src/client/utils.ts index 8604c26..a9d0068 100644 --- a/src/client/utils.ts +++ b/src/client/utils.ts @@ -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 {