by PMunch

PMunch / nimlsp

Language Server Protocol implementation for Nim

158 Stars 11 Forks Last release: Not found MIT License 79 Commits 5 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Nim Language Server Protocol

This is a

Language Server Protocol
_ implementation in Nim, for Nim. It is based on nimsuggest, which means that every editor that supports LSP will now have the same quality of suggestions that has previously only been available in supported editors.


If you have installed Nim through

(recommended) the easiest way to install
is to use

.. code:: bash

nimble install nimlsp

This will compile and install it in the

binary directory, which if you have set up
correctly it should be in your path. When compiling and using
it needs to have Nims sources available in order to work. With Nim installed through
these should already be on your system and
should be able to find and use them automatically. However if you have installed
in a different way you might run into issues where it can't find certain files during compilation/running. To fix this you need to grab a copy of Nim sources and then point
at them on compile-time by using
, where
is where you have your Nim sources. You can also pass them at run-time (if for example you're working with a custom copy of the stdlib by passing it as an argument to
. How exectly to do that will depend on the LSP client.


If you want more control over the compilation feel free to clone the repository.

depends on the
sources which is in the main Nim repository, so make you you have a copy of that somewhere. Manually having a copy of Nim this way means the default source path will not work so you need to set it explicitly on compilation with
and point to it on runtime (technically the runtime should only need the stdlib, so omitting it will make
try to find it from your Nim install).

To do the standard build run:

.. code:: bash

nimble build

Or if you want debug output when

is running:

.. code:: bash

nimble debug

Or if you want even more debug output from the LSP format:

.. code:: bash

nimble debug -d:debugLogging

Supported Protocol features

====== ================================ Status LSP Command ====== ================================ ☑ DONE textDocument/didChange ☑ DONE textDocument/didClose ☑ DONE textDocument/didOpen ☑ DONE textDocument/didSave ☐ TODO textDocument/codeAction ☑ DONE textDocument/completion ☑ DONE textDocument/definition ☐ TODO textDocument/documentHighlight ☐ TODO textDocument/documentSymbol ☐ TODO textDocument/executeCommand ☐ TODO textDocument/format ☑ DONE textDocument/hover ☑ DONE textDocument/rename ☑ DONE textDocument/references ☐ TODO textDocument/signatureHelp ☑ DONE textDocument/publishDiagnostics ☐ TODO workspace/symbol ====== ================================

Setting up


First you need a LSP client, the one that's been tested is It's certainly not perfect, but it works well enough.

Once you have it installed you'll want to grab NimLime as well. NimLime can perform many of the same features that

does, but we're only interested in syntax highlighting and some definitions. If you know how to disable the overlapping features or achieve this in another way please update this section.

Now in order to set up LSP itself enter it's settings and add this:

.. code:: js

{ "clients": { "nim": { "command": [ "/nimlsp" // This can be changed if you put nimlsp in your PATH ], "enabled": true, "env": { "PATH": "/.nimble/bin" // To be able to find nimsuggest, can be changed if you have nimsuggest in your PATH }, "languageId": "nim", "scopes": [ "source.nim" ], "syntaxes": [ "Packages/NimLime/Syntaxes/Nim.tmLanguage" ] } }, // These are mostly for debugging feel free to remove them // If you build nimlsp without debug information it doesn't // write anything to stderr "logpayloads": true, "logstderr": true }


To use

in Vim install the
plugin and dependencies:

.. code:: vim

Plugin 'prabirshrestha/asyncomplete.vim' Plugin 'prabirshrestha/async.vim' Plugin 'prabirshrestha/vim-lsp' Plugin 'prabirshrestha/asyncomplete-lsp.vim'

Then set it up to use

for Nim files:

.. code:: vim

let s:nimlspexecutable = "nimlsp" let g:lsplogverbose = 1 let g:lsplogfile = expand('/tmp/vim-lsp.log') " for asyncomplete.vim log let g:asyncompletelogfile = expand('/tmp/asyncomplete.log')

let g:asyncompleteautopopup = 0

if has('win32') let s:nimlspexecutable = "nimlsp.cmd" " Windows has no /tmp directory, but has $TEMP environment variable let g:lsplogfile = expand('$TEMP/vim-lsp.log') let g:asyncompletelogfile = expand('$TEMP/asyncomplete.log') endif if executable(s:nimlspexecutable) au User lspsetup call lsp#registerserver({ \ 'name': 'nimlsp', \ 'cmd': {server_info->[s:nimlspexecutable]}, \ 'whitelist': ['nim'], \ }) endif

function! s:checkbackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~ '\s' endfunction

inoremap \ pumvisible() ? "<C-n>" : \ checkbackspace() ? "<TAB>" : \ asyncomplete#force_refresh() inoremap pumvisible() ? "<C-p>" : "<C-h>"

This configuration allows you to hit Tab to get auto-complete, and to call various functions to rename and get definitions. Of course you are free to configure this any way you'd like.


With lsp-mode and use-package:

.. code:: emacs-lisp

(use-package nim-mode :ensure t :hook (nim-mode . lsp))

Run Tests

Not too many at the moment unfortunately, but they can be run with:

.. code:: bash

nimble test

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.