From c84a91e5b02539f98e4f509ce97e4e1ff6922347 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 26 Jun 2019 01:19:03 -0700 Subject: [PATCH] delete all .vim and run install script --- autoload/coc/powershell.vim | 40 ------------- autoload/coc/powershell/utils.vim | 88 ---------------------------- client/extension.ts | 97 +++++++++++++++++-------------- ftdetect/ps1.vim | 1 - ftplugin/ps1.vim | 50 ---------------- install.ps1 | 5 -- package-lock.json | 91 ++++++++++++++++++++++++++++- package.json | 3 +- 8 files changed, 145 insertions(+), 230 deletions(-) delete mode 100644 autoload/coc/powershell.vim delete mode 100644 autoload/coc/powershell/utils.vim delete mode 100644 ftdetect/ps1.vim delete mode 100644 ftplugin/ps1.vim mode change 100755 => 100644 install.ps1 diff --git a/autoload/coc/powershell.vim b/autoload/coc/powershell.vim deleted file mode 100644 index aa85387..0000000 --- a/autoload/coc/powershell.vim +++ /dev/null @@ -1,40 +0,0 @@ -let s:root = expand(':h:h:h') -let s:is_win = has('win32') || has('win64') -let s:is_mac = !s:is_win && !has('win32unix') - \ && (has('mac') || has('macunix') || has('gui_macvim') || - \ (!isdirectory('/proc') && executable('sw_vers'))) -let s:is_vim = !has('nvim') -let s:install_script = s:root.'/install.ps1' - -function! coc#powershell#install(...) - let s:flags = '' - if(exists('a:1')) - let paramType = type(a:1) - " Type 1 seems to be a string... - if(paramType == 1) - if(a:1 == 'preview') - let s:flags = '-AllowPreRelease' - endif - " Type 4 is a dictionary... - elseif(s:paramType == 4) - if(exists('a:1.preview') && a:1.preview) - let s:flags = '-AllowPreRelease' - endif - endif - endif - let s:powershell_executable = 'pwsh' - if(exists('a:1.powershellExecutable')) - let s:powershell_executable = a:1.powershellExecutable - else - if(s:is_win) - let s:powershell_executable = "powershell" - if(executable("pwsh")) - let s:powershell_executable = "pwsh" - endif - endif - endif - let cwd = getcwd() - exe 'lcd '.s:root - exe '!'.s:powershell_executable.' -NoProfile -ExecutionPolicy Bypass -File '.s:install_script.' '.s:flags - exe 'lcd '.cwd -endfunction diff --git a/autoload/coc/powershell/utils.vim b/autoload/coc/powershell/utils.vim deleted file mode 100644 index b7177d8..0000000 --- a/autoload/coc/powershell/utils.vim +++ /dev/null @@ -1,88 +0,0 @@ -let s:is_win = has('win32') || has('win64') -let s:is_mac = !s:is_win && !has('win32unix') - \ && (has('mac') || has('macunix') || has('gui_macvim') || - \ (!isdirectory('/proc') && executable('sw_vers'))) - -let s:linuxExe = { "versionName": "PowerShell Core", "executablePath": "/usr/bin/pwsh" } -let s:linuxPreviewExe = { "versionName": "PowerShell Core Preview", "executablePath": "/usr/bin/pwsh-preview" } -let s:snapExe = { "versionName": "PowerShell Core Snap", "executablePath": "/snap/bin/pwsh" } -let s:snapPreviewExe = { "versionName": "PowerShell Core Preview Snap", "executablePath": "/snap/bin/pwsh-preview" } -let s:macOSExe = { "versionName": "PowerShell Core", "executablePath": "/usr/local/bin/pwsh" } -let s:macOSPreviewExe = { "versionName": "PowerShell Core Preview", "executablePath": "/usr/local/bin/pwsh-preview" } - -function! s:getAvailablePowerShellExecutables () - let paths = [] - if(s:is_win) - call add(paths, { - \ versionName: "Windows PowerShell", - \ executablePath: "C:\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" - \ }) - - let psCoreInstallPath = "C:\\System32\\PowerShell\\" - if(isdirectory(psCoreInstallPath)) - let psCoreExePaths = split(glob(psCoreInstallPath . "**\\pwsh.exe"), "\n") - if(!empty(psCoreExePaths)) - call add(paths, { - \ versionName: "PowerShell Core", - \ executablePath: psCoreExePaths[0] - \ }) - endif - endif - - return paths - endif - - " macOS and Linux - let powershellExecutables = [ s:linuxExe, s:linuxPreviewExe, s:snapExe, s:snapPreviewExe ] - if(s:is_mac) - let powershellExecutables = [ s:macOSExe, s:macOSPreviewExe ] - endif - - for powershellExecutable in powershellExecutables - if(filereadable(powershellExecutable.executablePath)) - call add(paths, powershellExecutable) - endif - endfor - - return paths -endfunction - -function! coc#powershell#utils#switch_powershell_executable (...) - let s:choice = "" - if(!exists("a:1")) - let powershellExecutables = s:getAvailablePowerShellExecutables() - let index = 1 - let choiceStr = "" - while(index <= len(powershellExecutables)) - let choiceStr = choiceStr . index . " " . powershellExecutables[index - 1].versionName - if(index != len(powershellExecutables)) - let choiceStr = choiceStr . "\n" - endif - let index = index + 1 - endwhile - - let selection = confirm("Which PowerShell executable would you like to use?", choiceStr) - if(selection == 0) - " confirm was aborted, do nothing. - return - endif - - " confirm is 1 indexed (0 being cancelled) so minus 1 for the 0 indexed arrays - let s:choice = powershellExecutables[selection - 1].executablePath - else - let s:choice = a:1 - endif - - if(!executable(s:choice)) - throw "Executable not found: " . s:choice - endif - - if(g:pses_powershell_executable == s:choice) - echo "PowerShell executable already set to: " . s:choice - else - let g:pses_powershell_executable = s:choice - - echo "Restarting coc client to apply change..." - call coc#client#restart_all() - endif -endfunction diff --git a/client/extension.ts b/client/extension.ts index 6056126..4cd4b2f 100644 --- a/client/extension.ts +++ b/client/extension.ts @@ -4,65 +4,76 @@ * ------------------------------------------------------------------------------------------ */ 'use strict'; +import * as fs from 'fs'; import * as path from 'path'; import { workspace, ExtensionContext, commands } from 'coc.nvim'; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'coc.nvim'; import { Range } from 'vscode-languageserver-types'; import { getDefaultPowerShellPath, getPlatformDetails } from './platform'; +import Shell from "node-powershell"; const cocPowerShellRoot = path.join(__dirname, "..", ".."); const bundledModulesPath = path.join(cocPowerShellRoot, "PowerShellEditorServices"); const logPath = path.join(cocPowerShellRoot, "/.pses/logs/1234"); -export function activate(context: ExtensionContext) { - setTimeout(function () { - const pwshPath = getDefaultPowerShellPath(getPlatformDetails()) +export async function activate(context: ExtensionContext) { + const pwshPath = getDefaultPowerShellPath(getPlatformDetails()) + + // If PowerShellEditorServices is not downloaded yet, run the install script to do so. + if (!fs.existsSync(bundledModulesPath)) { + const ps = new Shell({ + executionPolicy: 'Bypass', + noProfile: true + }); + + ps.addCommand(path.join(cocPowerShellRoot, "install.ps1")); + await ps.invoke(); + } - let serverOptions: ServerOptions = { - command: pwshPath, - args: [ - "-NoProfile", - "-NonInteractive", - path.join(bundledModulesPath, "/PowerShellEditorServices/Start-EditorServices.ps1"), - "-HostName", "coc.vim", - "-HostProfileId", "0", - "-HostVersion", "2.0.0", - "-LogPath", path.join(logPath, "log.txt"), - "-LogLevel", "Diagnostic", - "-BundledModulesPath", bundledModulesPath, - "-Stdio", - "-SessionDetailsPath", path.join(logPath, "session")], - transport: TransportKind.stdio - } + let serverOptions: ServerOptions = { + command: pwshPath, + args: [ + "-NoProfile", + "-NonInteractive", + path.join(bundledModulesPath, "/PowerShellEditorServices/Start-EditorServices.ps1"), + "-HostName", "coc.vim", + "-HostProfileId", "0", + "-HostVersion", "2.0.0", + "-LogPath", path.join(logPath, "log.txt"), + "-LogLevel", "Diagnostic", + "-BundledModulesPath", bundledModulesPath, + "-Stdio", + "-SessionDetailsPath", path.join(logPath, "session")], + transport: TransportKind.stdio + } - workspace.addRootPatterns('ps1', ['*.ps1', '*.psd1', '*.psm1', '.vim', '.git', '.hg']) + workspace.addRootPatterns('ps1', ['*.ps1', '*.psd1', '*.psm1', '.vim', '.git', '.hg']) - // Options to control the language client - let clientOptions: LanguageClientOptions = { - // Register the server for F# documents - documentSelector: [{ scheme: 'file', language: 'ps1' }], - synchronize: { - // Synchronize the setting section 'powershell' to the server - configurationSection: 'ps1', - // Notify the server about file changes to PowerShell files contain in the workspace - // TODO: is there a way to configure this via the language server protocol? - fileEvents: [ - workspace.createFileSystemWatcher('**/*.ps1'), - workspace.createFileSystemWatcher('**/*.psd1'), - workspace.createFileSystemWatcher('**/*.psm1') - ] - } + // Options to control the language client + let clientOptions: LanguageClientOptions = { + // Register the server for F# documents + documentSelector: [{ scheme: 'file', language: 'ps1' }], + synchronize: { + // Synchronize the setting section 'powershell' to the server + configurationSection: 'ps1', + // Notify the server about file changes to PowerShell files contain in the workspace + // TODO: is there a way to configure this via the language server protocol? + fileEvents: [ + workspace.createFileSystemWatcher('**/*.ps1'), + workspace.createFileSystemWatcher('**/*.psd1'), + workspace.createFileSystemWatcher('**/*.psm1') + ] } + } - // Create the language client and start the client. - let client = new LanguageClient('ps1', 'PowerShell Language Server', serverOptions, clientOptions); - let disposable = client.start(); + // Create the language client and start the client. + let client = new LanguageClient('ps1', 'PowerShell Language Server', serverOptions, clientOptions); + let disposable = client.start(); - // Push the disposable to the context's subscriptions so that the - // client can be deactivated on extension deactivation - context.subscriptions.push(disposable); - commands.registerCommand('powershell.command.goto', goto); - }, 10000); + // Push the disposable to the context's subscriptions so that the + // client can be deactivated on extension deactivation + context.subscriptions.push(disposable); + commands.registerCommand('powershell.command.goto', goto); } function goto(file: string, startLine: number, startColumn: number, _endLine: number, _endColumn: number) { diff --git a/ftdetect/ps1.vim b/ftdetect/ps1.vim deleted file mode 100644 index 0a965d3..0000000 --- a/ftdetect/ps1.vim +++ /dev/null @@ -1 +0,0 @@ -autocmd BufNewFile,BufRead *.ps*1 setfiletype ps1 diff --git a/ftplugin/ps1.vim b/ftplugin/ps1.vim deleted file mode 100644 index 3388962..0000000 --- a/ftplugin/ps1.vim +++ /dev/null @@ -1,50 +0,0 @@ -if exists('s:loaded_ftplugin') - finish -endif -let s:loaded_ftplugin = 1 -let s:vimscript_dir = expand(':p:h') -" function! s:PSESSetup () -" let g:pses_dir = resolve(expand(s:vimscript_dir . '/../PowerShellEditorServices/PowerShellEditorServices')) -" let g:pses_script = g:pses_dir . "/Start-EditorServices.ps1" - -" " Let the user specify the log directory for PSES. -" " If the user doesn't specify a location, use the root of coc-powershell in a .pses -" " directory. -" if(!exists("g:pses_logs_dir")) -" let g:pses_logs_dir = resolve(expand(s:vimscript_dir . '/../.pses/logs/' . strftime('%Y%m%d') . '-' . getpid())) -" endif - -" if(!exists("g:pses_powershell_executable")) -" let g:pses_powershell_executable = "powershell" -" if(executable("pwsh")) -" let g:pses_powershell_executable = "pwsh" -" endif -" endif - -" call coc#config("languageserver", { -" \ "pses": { -" \ "command": g:pses_powershell_executable, -" \ "filetypes": ["ps1", "psm1", "psd1"], -" \ "rootPatterns": [".pses/", ".vim/", ".git/", ".hg/"], -" \ "trace.server": "verbose", -" \ "cwd": ".", -" \ "args": [ -" \ "-NoProfile", "-NonInteractive", -" \ g:pses_script, -" \ "-HostName", "coc.vim", -" \ "-HostProfileId", "0", -" \ "-HostVersion", "2.0.0", -" \ "-LogPath", g:pses_logs_dir . "/log.txt", -" \ "-LogLevel", "Diagnostic", -" \ "-FeatureFlags", "[]", -" \ "-BundledModulesPath", g:pses_dir . "/../", -" \ "-Stdio", -" \ "-SessionDetailsPath", g:pses_logs_dir . "/session" -" \ ] -" \ } -" \ } -" \) -" endfunction - -" call s:PSESSetup() -" set rtp+=resolve(expand(s:vimscript_dir . '/../package.json')) diff --git a/install.ps1 b/install.ps1 old mode 100755 new mode 100644 index f2e377d..f73e10a --- a/install.ps1 +++ b/install.ps1 @@ -37,9 +37,4 @@ Remove-Item $zip -Force Write-Host PowerShell Editor Services install completed. -Write-Host Installing Node dependencies... - -npm install -npm run compile - Pop-Location diff --git a/package-lock.json b/package-lock.json index 213035f..fc9aabc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,32 @@ "@types/node": { "version": "10.14.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.10.tgz", - "integrity": "sha512-V8wj+w2YMNvGuhgl/MA5fmTxgjmVHVoasfIaxMMZJV6Y8Kk+Ydpi1z2whoShDCJ2BuNVoqH/h1hrygnBxkrw/Q==", - "dev": true + "integrity": "sha512-V8wj+w2YMNvGuhgl/MA5fmTxgjmVHVoasfIaxMMZJV6Y8Kk+Ydpi1z2whoShDCJ2BuNVoqH/h1hrygnBxkrw/Q==" + }, + "@types/node-fetch": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.3.7.tgz", + "integrity": "sha512-+bKtuxhj/TYSSP1r4CZhfmyA0vm/aDRQNo7vbAgf6/cZajn0SAniGGST07yvI4Q+q169WTa2/x9gEHfJrkcALw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/node-powershell": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@types/node-powershell/-/node-powershell-3.1.0.tgz", + "integrity": "sha1-CajWm4I4FU7v7CIMkxiz4Zn6bVg=", + "requires": { + "@types/node": "*" + } + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } }, "async": { "version": "2.6.2", @@ -48,6 +72,16 @@ "node-int64": "^0.4.0" } }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, "coc.nvim": { "version": "0.0.71", "resolved": "https://registry.npmjs.org/coc.nvim/-/coc.nvim-0.0.71.tgz", @@ -71,6 +105,19 @@ "which": "^1.3.1" } }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -94,6 +141,11 @@ "ms": "^2.1.1" } }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, "event-lite": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/event-lite/-/event-lite-0.1.2.tgz", @@ -150,6 +202,11 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", @@ -246,6 +303,11 @@ "isarray": "^1.0.0" } }, + "nanoid": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.3.tgz", + "integrity": "sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==" + }, "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", @@ -256,6 +318,15 @@ "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", "integrity": "sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=" }, + "node-powershell": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/node-powershell/-/node-powershell-4.0.0.tgz", + "integrity": "sha512-WCZMLgwkjW9G/DZsZwyCEAXhMMzShLRUlnYS+EETRqRLSdUMbuO4xiQxIOeAutwQgvj75NvC58CorHFlx0olIA==", + "requires": { + "chalk": "^2.4.1", + "shortid": "^2.2.14" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -284,6 +355,14 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-6.1.2.tgz", "integrity": "sha512-z4PqiCpomGtWj8633oeAdXm1Kn1W++3T8epkZYnwiVgIYIJ0QHszhInYSJTYxebByQH7KVCEAn8R9duzZW2PhQ==" }, + "shortid": { + "version": "2.2.14", + "resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.14.tgz", + "integrity": "sha512-4UnZgr9gDdA1kaKj/38IiudfC3KHKhDc1zi/HSxd9FQDR0VLwH3/y79tZJLsVYPsJgIjeHjqIWaWVRJUj9qZOQ==", + "requires": { + "nanoid": "^2.0.0" + } + }, "streamroller": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-1.0.5.tgz", @@ -306,6 +385,14 @@ } } }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", diff --git a/package.json b/package.json index c0e1863..62d5b7c 100644 --- a/package.json +++ b/package.json @@ -289,10 +289,11 @@ "extensionDependencies": [], "dependencies": { "coc.nvim": "^0.0.71", - "node-fetch": "^2.6.0" + "node-powershell": "^4.0.0" }, "devDependencies": { "@types/node": "^10.3.3", + "@types/node-powershell": "^3.1.0", "typescript": "^3.0.3" } }