Skip to content

Commit 1db5dfa

Browse files
authored
Improve param hints info and formatting (#370)
* Fix info about param hints; apply dprint formatter. * Add dprint config to gitignore.
1 parent ef0d109 commit 1db5dfa

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ tests/all
88
nimble.develop
99
nimble.paths
1010
nimbledeps
11+
dprint.json

README.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Nim Language Server, or `nimlangserver`, is a language server for Nim.
1111
### Installing binaries
1212

1313
_NB:_ `nimlangserver` requires `nimsuggest` version that supports `--v3`:
14+
1415
- `devel` containing [19826](https://github.com/nim-lang/Nim/pull/19826)
1516
- 1.6+ containing [19892](https://github.com/nim-lang/Nim/pull/19892)
1617

@@ -27,19 +28,24 @@ nimble build
2728
```
2829

2930
### VSCode
31+
3032
- [vscode-nim](https://github.com/nim-lang/vscode-nim) has support for `nimlangserver`. Follow the instructions at:
31-
https://github.com/nim-lang/vscode-nim#using
33+
https://github.com/nim-lang/vscode-nim#using
3234

3335
### Sublime Text
36+
3437
Install [LSP-nimlangserver](https://packagecontrol.io/packages/LSP-nimlangserver) from Package Control.
3538

3639
### Zed Editor
40+
3741
Install [Nim Extenstion](https://github.com/foxoman/zed-nim) from the Zed Editor extensions.
3842

3943
### Helix
44+
4045
Just install the langserver with Nimble and make sure it's on your PATH.
4146

4247
To verify that everything is set up, run:
48+
4349
```shell
4450
$ hx --health nim
4551
Configured language servers:
@@ -54,7 +60,9 @@ Configured language servers:
5460
```
5561

5662
### Neovim
63+
5764
- [lsp](https://neovim.io/doc/user/lsp.html) Neovim has built-in LSP support. Although, you might want to use something like [lsp-config](https://github.com/neovim/nvim-lspconfig) to take care of the boilerplate code for the most LSP configurations. Install `lsp-config` using your favourite plugin manager an place the following code into your `init.vim` config:
65+
5866
```lua
5967
lua <<EOF
6068

@@ -68,12 +76,15 @@ require'lspconfig'.nim_langserver.setup{
6876

6977
EOF
7078
```
79+
7180
Change configuration to your liking (most probably you don't need to provide any settings at all, defaults should work fine for the majority of the users). You might also want to read `lsp-config` documentation to setup key bindings, autocompletion and so on.
7281

7382
**IMPORTANT** you might want to use latest build of the `nimlangserver` and/or build it from source.
7483

7584
### VIM/Neovim
85+
7686
- [coc.nvim](https://github.com/neoclide/coc.nvim) supports both classical VIM as well as Neovim. It also supports vscode-like `coc-settings.json` for LSP configuration. Install the plugin via your favourite plugin manager, create `coc-settings.json` alongside your `init.vim` and add the following contents to it:
87+
7788
```json
7889
{
7990
"languageserver": {
@@ -90,14 +101,14 @@ Change configuration to your liking (most probably you don't need to provide any
90101
}
91102
}
92103
```
93-
Of course, change the configuration to your liking. You might also want to read `coc.nvim` documentation to setup key bindings, autocompletion and so on.
94104

105+
Of course, change the configuration to your liking. You might also want to read `coc.nvim` documentation to setup key bindings, autocompletion and so on.
95106

96107
## Configuration Options
97108

98109
- `nim.projectMapping` - configure how `nimsuggest` should be started. Here it is sample configuration for `VScode`. We don't want `nimlangserver` to start `nimsuggest` for each file and this configuration will allow configuring pair `projectFile`/`fileRegex` so when one of the regexp in the list matches current file then `nimls` will use `root` to start `nimsuggest`. In case there are no matches `nimlangserver` will try to guess the most suitable project root.
99110

100-
``` json
111+
```json
101112
{
102113
"nim.projectMapping": [{
103114
// open files under tests using one nimsuggest instance started with root = test/all.nim
@@ -110,7 +121,8 @@ Of course, change the configuration to your liking. You might also want to read
110121
}]
111122
}
112123
```
113-
Note when in a nimble project, `nimble` will drive the entry points for `nimsuggest`.
124+
125+
Note when in a nimble project, `nimble` will drive the entry points for `nimsuggest`.
114126

115127
- `nim.timeout` - the request timeout in ms after which `nimlangserver` will restart the language server. If not specified the default is 2 minutes.
116128
- `nim.nimsuggestPath` - the path to the `nimsuggest`. The default is `"nimsuggest"`.
@@ -136,19 +148,22 @@ Inlay hints are visual snippets displayed by the editor inside your code.
136148
Typical usage for inlay hints is displaying type information but it can go beyond that and provide all sorts of useful context.
137149

138150
nimlangserver offers three kinds of inlay hints:
151+
139152
- **Type hints**. Show variable types.
140-
- **Parameter hints**. TODO
141153
- **Exception hints**. Highlight functions that raise exceptions.
154+
- **Parameter hints**. Hints for param names in function calls.
155+
- **Note:** This kind of inlay hints is not implemented yet so enabling it won't do anything at the moment. See [issue 183](https://github.com/nim-lang/langserver/issues/183).
142156

143157
Here's how inlay hints look like in VSCode
158+
144159
- type hint: ![](./vscode_type_hint.png)
145160
- exception hint: ![](./vscode_exception_hint.png)
146161

147162
Here are the same hints in Helix:
163+
148164
- ![](./helix_type_hint.png)
149165
- ![](./helix_exception_hint.png)
150166

151-
152167
In VSCode, inlay hints are enabled by default. You can toggle different kinds of hints in the settings:
153168

154169
1. Go to **Settings**.
@@ -157,7 +172,7 @@ In VSCode, inlay hints are enabled by default. You can toggle different kinds of
157172

158173
![](./vscode_settings.png)
159174

160-
To enable inlay hints in Neovim, configure lspconfig in your `init.vim`:
175+
To enable inlay hints in Neovim, configure lspconfig in your `init.vim`:
161176

162177
```lua
163178
lua << EOF
@@ -167,8 +182,8 @@ lspconfig.nim_langserver.setup({
167182
nim = {
168183
inlayHints = {
169184
typeHints = true,
170-
parameterHints = true,
171185
exceptionHints = true,
186+
parameterHints = true,
172187
}
173188
}
174189
},
@@ -190,7 +205,7 @@ To enable inlay hints in Helix, add this langserver configuration to your `langu
190205

191206
```toml
192207
[language-server.nimlangserver.config.nim]
193-
inlayHints = { typeHints = true, parameterHints = true, exceptionHints = true }
208+
inlayHints = { typeHints = true, exceptionHints = true, parameterHints = true }
194209
```
195210

196211
## Features
@@ -220,31 +235,38 @@ inlayHints = { typeHints = true, parameterHints = true, exceptionHints = true }
220235
You can install `nimlangserver` using the instructions for your text editor below:
221236

222237
### Extension methods
238+
223239
In addition to the standard `LSP` methods, `nimlangserver` provides additional nim specific methods.
224240

225241
### `extension/macroExpand`
226242

227-
* Request:
243+
- Request:
244+
228245
```nim
229246
type
230247
ExpandTextDocumentPositionParams* = ref object of RootObj
231248
textDocument*: TextDocumentIdentifier
232249
position*: Position
233250
level*: Option[int]
234251
```
252+
235253
Where:
254+
236255
- `position` is the position in the document.
237256
- `textDocument` is the document.
238257
- `level` is the how much levels to expand from the current position
239258

240259
* Response:
241-
``` nim
260+
261+
```nim
242262
type
243263
ExpandResult* = ref object of RootObj
244264
range*: Range
245265
content*: string
246266
```
267+
247268
Where:
269+
248270
- `content` is the expand result
249271
- `range` is the original range of the request.
250272

@@ -278,7 +300,6 @@ Result: {
278300
},
279301
"content": " block:\n template field1(): untyped =\n a.field1\n\n template field2(): untyped =\n a.field2\n\n field1 = field2"
280302
}
281-
282303
```
283304

284305
### VSCode
@@ -290,13 +311,14 @@ Install the `vscode-nim` extension from [here](https://github.com/nim-lang/vscod
290311
- Install [lsp-mode](https://github.com/emacs-lsp/lsp-mode) and `nim-mode` from melpa and add the following to your
291312
config:
292313

293-
``` elisp
314+
```elisp
294315
(add-hook 'nim-mode-hook #'lsp)
295316
```
296317

297318
## Transport
298319

299320
`nimlangserver` supports two transport modes:
321+
300322
- stdio
301323
- socket
302324

@@ -310,11 +332,11 @@ In order to list and run tests the test library `unittest2 >= 0.2.4` must be use
310332

311333
- [nimlsp](https://github.com/PMunch/nimlsp)
312334

313-
Both `nimlangserver` and `nimlsp` are based on `nimsuggest`, but the main
314-
difference is that `nimlsp` has a single specific version of `nimsuggest`
315-
embedded in the server executable, while `nimlangserver` launches `nimsuggest`
316-
as an external process. This allows `nimlangserver` to handle any `nimsuggest`
317-
crashes more gracefully.
335+
Both `nimlangserver` and `nimlsp` are based on `nimsuggest`, but the main
336+
difference is that `nimlsp` has a single specific version of `nimsuggest`
337+
embedded in the server executable, while `nimlangserver` launches `nimsuggest`
338+
as an external process. This allows `nimlangserver` to handle any `nimsuggest`
339+
crashes more gracefully.
318340

319341
## License
320342

0 commit comments

Comments
 (0)