azdavis / millet

A language server for Standard ML.
https://azdavis.net/posts/millet
Apache License 2.0
210 stars 12 forks source link

neovim and coc.nvim setup does not work #36

Closed mnegovanovic closed 1 year ago

mnegovanovic commented 1 year ago

Steps to reproduce

configure coc.nvim to point to millet binary and open .sml file inside .mlb project ... errors and warnings are displayed on the left hand side. However this is the only time millet seems to be working. Type "aaaaaaa" inside the .sml file and save it, expected behaviour would be that new error is picked up ... but not. Millet seems not to be working except for that initial file opening.

Expected behavior

millet re-runs on file saving and displays the newly introduced errors and warnings.

Regards

azdavis commented 1 year ago

I don't have the most experience with (neo)vim. Is it possible to add more logging to nvim/millet to see if e.g. nvim is sending millet file update messages and millet is ignoring them, or if nvim is not even sending anything? For millet, if the environment variable RUST_LOG is set to e.g. info then there should be a bunch of messages shown to stderr.

Additionally, if you give more detail for how to set up nvim with millet, I can try investigating on my end. As I mentioned I don't use nvim, so I'd appreciate instructions for a minimal reproducer that includes:

mnegovanovic commented 1 year ago

To install neovim: brew install neovim or pacman -S neovim

Install plug (the easiest for plugins): curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Create minimal config file for nvim (~/.config/nvim/init.vim):

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath

" vim-plug
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release', 'do': 'yarn install --frozen-lockfile'}
call plug#end()

" minimal COC setup
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
set updatetime=250

let g:coc_disable_startup_warning = 1

Now we can start nvim and sync the COC install (in nvim): :PlugUpdate

Now we need to tell COC to use millet (~/.config/nvim/coc-settings.json):

{
  "languageserver": {
    "sml": {
      "command": "/opt/homebrew/bin/millet-ls",
      "filetypes": ["sml"]
    }
  }
}

COC requires node and yarn installed and in PATH. That should be it. Open SML project and you will be able to see what i am talking about.

Regards

mnegovanovic commented 1 year ago

I will try and enable debugging in nvim and coc.nvim and see how far i get.

Regards

azdavis commented 1 year ago

I believe the issue is that:

I'm not sure if this is an issue with millet or the client. I can report that using watched file change events works in e.g. vs code (my primary editor). maybe while we investigate the root cause i can add a setting for millet that says: do not try to register for watched file change events, even if the client says they support them. you could then turn that on and millet would not attempt to ask the client to use watched file events, and just always use the text document events and not ignore them.

azdavis commented 1 year ago

As of 0dc5a5add58fcca01b5716de453e96f1a49c0c20, under "initializationOptions", you can add "fs_watcher": false to your ~/.config/nvim/coc-settings.json:

{
  "languageserver": {
    "sml": {
      "command": "...",
      "filetypes": ["sml"],
      "initializationOptions": {
        "fs_watcher": false
      }
    }
  }
}

This corresponds with the new VS Code extension setting millet.server.fileSystemWatcher.enable which I have documented.

More generally, I've also written up a bit about configuring non-VS-Code editors with the language server init options.

azdavis commented 1 year ago

I have also released v0.10.1 with these changes.