Skip to content

Commit 5eaa6b4

Browse files
committed
Added a getting started guide to setup and configure PowerShell Editor Services with Neovim.
1 parent b8c2817 commit 5eaa6b4

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

docs/guide/getting_started.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Getting Started
2+
PowerShell Editor Services project provides a Language Server Protocol (LSP)
3+
HTTP server that runs outside the editor. The server supplies rich editor
4+
functionality like code completion, syntax highlighting, and code annotation.
5+
This document will guide you through getting a minimal setup working with
6+
several editors.
7+
8+
## Editors
9+
1. [Neovim](#neovim)
10+
11+
## Neovim
12+
13+
### Install the Server
14+
Download and extract the PowerShell Editor Services [releases page](https://github.com/PowerShell/PowerShellEditorServices/releases)
15+
server to a directory of your choice. Remember the path that you extract the
16+
project into.
17+
```powershell
18+
$DownloadUrl = 'https://github.com/PowerShell/PowerShellEditorServices/releases/latest/download/PowerShellEditorServices.zip';
19+
$ZipPath = "$HOME/Desktop/PowerShellEditorServices.zip";
20+
$InstallPath = "$HOME/Desktop/PowerShellEditorServices";
21+
Invoke-WebRequest -Method 'GET' -Uri $DownloadUrl -OutFile $ZipPath;
22+
Expand-Archive -Path $ZipPath -DestinationPath $InstallPath;
23+
```
24+
25+
### Install Neovim's Basic LSP Configurations
26+
Neovim has a repository of basic LSP configurations for a number of languages,
27+
including PowerShell. Install the LSP configuration into one of the package
28+
directories inside `$XDG_CONFIG_HOME`. The path `$XDG_CONFIG_HOME will vary
29+
depending on which operating system you are on:
30+
31+
| OS | Path |
32+
| ---------- | -------------------------- |
33+
| Windows | `$HOME/AppData/local/nvim` |
34+
| *nix/macOS | `$HOME/.config/nvim` |
35+
36+
The easiest way is to install the configuration is to clone the repository
37+
using git:
38+
```powershell
39+
git clone https://github.com/neovim/nvim-lspconfig.git "$HOME/AppData/local/nvim/pack/complete/start/nvim-lspconfig"
40+
```
41+
42+
Alternatively, you can extract the zip file into the same place:
43+
```powershell
44+
$DownloadUrl = 'https://github.com/neovim/nvim-lspconfig/archive/refs/heads/master.zip';
45+
$ZipPath = "$HOME/AppData/local/nvim/nvim-lspconfig.zip";
46+
$InstallPath = "$HOME/AppData/local/nvim/nvim-lspconfig";
47+
Invoke-WebRequest -Method 'GET' Uri $DownloadUrl -OutFile $ZipPath;
48+
Expand-Archive -Path $ZipPath -DestinationPath "$HOME/AppData/local/nvim/pack/complete/start/nvim-lspconfig";
49+
```
50+
51+
> NOTE: If the corresponding neovim configuration and package directories have
52+
> not been created yet, create them before cloning the LSP configuration
53+
> repository.
54+
55+
### Configure the Server
56+
Once the basic language configurations have been installed, you should add this
57+
to your init.lua:
58+
```lua
59+
local on_attach = function(client, bufnr)
60+
-- Enable completion triggered by <c-x><c-o>
61+
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
62+
63+
local bufopts = { noremap = true, silent = true, buffer = bufnr }
64+
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
65+
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
66+
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
67+
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
68+
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
69+
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
70+
vim.keymap.set('n', '<Leader>ca', vim.lsp.buf.code_action, bufopts)
71+
vim.keymap.set('n', '<Leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
72+
vim.keymap.set('n', '<Leader>rn', vim.lsp.buf.rename, bufopts)
73+
vim.keymap.set('n', '<Leader>td', vim.lsp.buf.type_definition, bufopts)
74+
end
75+
76+
local bundle_path = '<Path to where PowerShell Editor Services was installed>'
77+
78+
require('lspconfig')['powershell_es'].setup {
79+
bundle_path = bundle_path,
80+
on_attach = on_attach
81+
}
82+
```
83+
84+
> NOTE: Be sure to set the bundle_path variable, otherwise the server will not
85+
> know the path to start the server.
86+
87+
To further configure the server, you can supply settings to the setup table.
88+
For example, you can set the code formatting preset to one true brace style
89+
(OTBS).
90+
```lua
91+
require('lspconfig')['powershell_es'].setup {
92+
bundle_path = bundle_path,
93+
on_attach = on_attach,
94+
settings = { powershell = { codeFormatting = { Preset = 'OTBS' } } }
95+
}
96+
```
97+
98+
As another example, you can set the bundled PSScriptAnalyzer's custom rule path
99+
like so:
100+
```lua
101+
require('lspconfig')['powershell_es'].setup {
102+
bundle_path = bundle_path,
103+
on_attach = on_attach,
104+
settings = { powershell = { scriptAnalysis = { settingsPath = os.getenv('HOME') .. 'PSScriptAnalyzerSettings.psd1' } } }
105+
}
106+
```

0 commit comments

Comments
 (0)