|
| 1 | +--- @brief |
| 2 | +--- |
| 3 | +--- https://github.com/PowerShell/PowerShellEditorServices |
| 4 | +--- |
| 5 | +--- Language server for PowerShell. |
| 6 | +--- |
| 7 | +--- To install, download and extract PowerShellEditorServices.zip |
| 8 | +--- from the [releases](https://github.com/PowerShell/PowerShellEditorServices/releases). |
| 9 | +--- To configure the language server, set the property `bundle_path` to the root |
| 10 | +--- of the extracted PowerShellEditorServices.zip. |
| 11 | +--- |
| 12 | +--- ```lua |
| 13 | +--- vim.lsp.config('powershell_es', { |
| 14 | +--- bundle_path = 'c:/w/PowerShellEditorServices', |
| 15 | +--- }) |
| 16 | +--- ``` |
| 17 | +--- |
| 18 | +--- By default the language server is started in `pwsh` (PowerShell Core). This can be changed by specifying `shell`. |
| 19 | +--- |
| 20 | +--- ```lua |
| 21 | +--- vim.lsp.config('powershell_es', { |
| 22 | +--- bundle_path = 'c:/w/PowerShellEditorServices', |
| 23 | +--- shell = 'powershell.exe', |
| 24 | +--- }) |
| 25 | +--- ``` |
| 26 | +--- |
| 27 | +--- Note that the execution policy needs to be set to `Unrestricted` for the languageserver run under PowerShell |
| 28 | +--- |
| 29 | +--- If necessary, specific `cmd` can be defined instead of `bundle_path`. |
| 30 | +--- See [PowerShellEditorServices](https://github.com/PowerShell/PowerShellEditorServices#standard-input-and-output) |
| 31 | +--- to learn more. |
| 32 | +--- |
| 33 | +--- ```lua |
| 34 | +--- vim.lsp.config('powershell_es', { |
| 35 | +--- cmd = {'pwsh', '-NoLogo', '-NoProfile', '-Command', "c:/PSES/Start-EditorServices.ps1 ..."}, |
| 36 | +--- }) |
| 37 | +--- ``` |
| 38 | + |
| 39 | +return { |
| 40 | + cmd = function(dispatchers) |
| 41 | + local temp_path = vim.fn.stdpath('cache') |
| 42 | + local bundle_path = vim.lsp.config.powershell_es.bundlePath |
| 43 | + |
| 44 | + local shell = vim.lsp.config.powershell_es.shell or 'pwsh' |
| 45 | + |
| 46 | + local command_fmt = |
| 47 | + [[& '%s/PowerShellEditorServices/Start-EditorServices.ps1' -BundledModulesPath '%s' -LogPath '%s/powershell_es.log' -SessionDetailsPath '%s/powershell_es.session.json' -FeatureFlags @() -AdditionalModules @() -HostName nvim -HostProfileId 0 -HostVersion 1.0.0 -Stdio -LogLevel Normal]] |
| 48 | + local command = command_fmt:format(bundle_path, bundle_path, temp_path, temp_path) |
| 49 | + local cmd = { shell, '-NoLogo', '-NoProfile', '-Command', command } |
| 50 | + |
| 51 | + return vim.lsp.rpc.start(cmd, dispatchers) |
| 52 | + end, |
| 53 | + filetypes = { 'ps1' }, |
| 54 | + root_markers = { 'PSScriptAnalyzerSettings.psd1', '.git' }, |
| 55 | +} |
0 commit comments