Skip to content

Commit

Permalink
docs(contributing): add ViM instructions to setup gnols (gnolang#1282)
Browse files Browse the repository at this point in the history
Relates to gnolang#1274 

What works with this setup:
- code completion after `.` but only for stdlibs packages
- code hover tooltip with `:LspHover` command (again limited to stdlibs)
- format on save (only gofmt for now)
- code Lens with `:LspCodeLens` command (only when the buffer is
`_test.gno` file) which display a list of possible `gno test` executions
with different scopes (package, files or function).
Note that test executions are using the LSP `workspace/executeCommand`
and actually `vim-lsp` doesn't handle well the output of that. That
means, tests are running, but you don't get the ouput. I'm still unsure
about how to setup that properly (see
prabirshrestha/vim-lsp#1461).

The good thing is the limitations can be removed by contributing to
[gnols](https://github.com/gno-playground/gnols), for instance :
- Expand code completion to all imported types
- Expand code hover to all imported types
- Add the *go-to-definition* feature
- Add the *rename* feature
- ...

---------

Co-authored-by: Morgan <git@howl.moe>
  • Loading branch information
2 people authored and gfanton committed Nov 9, 2023
1 parent 04c13e5 commit f3d63e1
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ There currently is an unofficial [Visual Studio Code](https://marketplace.visual
extension (primarily developed by a core team member) for working with `*.gno`
files.

#### ViM Support
#### ViM Support (without LSP)

Add to your `.vimrc` file:

Expand All @@ -104,9 +104,68 @@ To use *gofumpt* instead of *gofmt*, as hinted in the comment, you may either ha
cexpr system('go run -modfile </path/to/gno>/misc/devdeps/go.mod mvdan.cc/gofumpt -w ' . expand('%'))
```

### ViM Support (with LSP)

There is an experimental and unofficial [Gno Language Server](https://github.com/jdkato/gnols)
developed by the community, with an installation guide for Neovim.

For ViM purists, you have to install the [`vim-lsp`](https://github.com/prabirshrestha/vim-lsp)
plugin and then register the LSP server in your `.vimrc` file:

```vim
augroup gno_autocmd
autocmd!
autocmd BufNewFile,BufRead *.gno
\ set filetype=gno |
\ set syntax=go
augroup END
if (executable('gnols'))
au User lsp_setup call lsp#register_server({
\ 'name': 'gnols',
\ 'cmd': ['gnols'],
\ 'allowlist': ['gno'],
\ 'config': {},
\ 'workspace_config': {
\ 'root' : '/path/to/gno_repo',
\ 'gno' : '/path/to/gno_bin',
\ 'precompileOnSave' : v:true,
\ 'buildOnSave' : v:false,
\ },
\ 'languageId': {server_info->'gno'},
\ })
else
echomsg 'gnols binary not found: LSP disabled for Gno files'
endif
function! s:on_lsp_buffer_enabled() abort
" Autocompletion
setlocal omnifunc=lsp#complete
" Format on save
autocmd BufWritePre <buffer> LspDocumentFormatSync
" Some optionnal mappings
nmap <buffer> <leader>i <Plug>(lsp-hover)
" Following mappings are not supported yet by gnols
" nmap <buffer> gd <plug>(lsp-definition)
" nmap <buffer> <leader>rr <plug>(lsp-rename)
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
```

Note that unlike the previous ViM setup without LSP, here it is required by
`vim-lsp` to have a specific `filetype=gno`. Syntax highlighting is preserved
thanks to `syntax=go`.

Inside `lsp#register_server()`, you also have to replace
`workspace_config.root` and `workspace_config.gno` with the correct directories
from your machine.

Additionaly, it's not possible to use `gofumpt` for code formatting with
`gnols` for now.

#### Emacs Support

1. Install [go-mode.el](https://github.com/dominikh/go-mode.el).
Expand Down

0 comments on commit f3d63e1

Please sign in to comment.