dcermak / rpm-spec-language-server

Language Server for RPM spec files
GNU General Public License v2.0
21 stars 4 forks source link

Nothing works in Vim #176

Closed FrostyX closed 3 months ago

FrostyX commented 4 months ago

I am trying a minimal Vim setup (not Neovim), and rpm-spec-language-server doesn't work as expected. It is possible that it is not the fault of rpm-spec-language-server, however, my Vim configuration works fine for other languages, e.g. Python.

My setup:

mkdir -p ~/.vim/pack/vendor/start
git clone https://github.com/prabirshrestha/vim-lsp.git
git clone https://github.com/mattn/vim-lsp-settings.git

My ~/.vimrc:

let g:lsp_diagnostics_enabled = 0

function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> K <plug>(lsp-hover)
endfunction

augroup lsp_install
    au!
    " call s:on_lsp_buffer_enabled only for languages that has the server registered.
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END

When I open a Python file, gd for jumping to definition works, when I press Ctrl+X Ctrl+O in insert mode, I get an omni-completion with all possible keywords and functions, and when I iterate through them with Ctrl+N and Ctrl+P the documentation for the suggested items appears. This is as expected.

However, when I add the following snippet to the ~/.vimrc:

if executable('rpm_lsp_server')
    " dnf install rpm-spec-language-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'rpm_lsp_server',
        \ 'cmd': {server_info->['rpm_lsp_server', '--stdio', '--verbose', '--log_file', '/tmp/testuser-vim-lsp-log']},
        \ 'allowlist': ['spec'],
        \ })
endif

And then open a specfile, none of these work.

The LSP server is running:

:LspStatus
rpm_lsp_server: running

When I press gd on a macro, I get No definition found and this appears in the /tmp/testuser-vim-lsp-log log:

Sending data: {"id": 3, "jsonrpc": "2.0", "result": null}

When I press Ctrl+X Ctrl+O, I get no suggestions and Pattern not found. And this appears in the log:

Sending data: {"id": 11, "jsonrpc": "2.0", "result": {"isIncomplete": false, "items": []}}

I know both of these features should work in rpm-spec-language-server because they work in my Emacs setup.

NeilHanlon commented 4 months ago

I'm able to reproduce this in neovim, as well. I wonder if this is a case of these features not being 'registered' to the lsp plugin; e.g., in a lua buffer, I see WhichKey show me:

image

but in a spec buffer, I see:

image

and get the same log as @FrostyX (if enabled in my config)

I also noted seeing this when trying to gD --

method textDocument/declaration is not supported by any of the servers registered for the current buffer

which perhaps hints towards the problem?

dcermak commented 4 months ago

I have tried to reproduce the issue but it appears that gD works for me with vim.

I have installed vim on Fedora 39 and used @FrostyX' config:

let g:lsp_diagnostics_enabled = 0

function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> K <plug>(lsp-hover)
endfunction

augroup lsp_install
    au!
    " call s:on_lsp_buffer_enabled only for languages that has the server registered.
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END

au User lsp_setup call lsp#register_server({
        \ 'name': 'rpm_lsp_server',
        \ 'cmd': {server_info->['python', '-m', 'rpm_spec_language_server', '--stdio', '--verbose', '--log_file', '/tmp/testuser-vim-lsp-log']},
        \ 'allowlist': ['spec'],
        \ })

However, I'm running the latest version of the language server from git. Could you please retry from git?

FrostyX commented 3 months ago

I installed the language server from a8ee2c3 and it behaves the same.

dcermak commented 3 months ago

This is really odd, because jump to definition appears to work for me when pressing gd in vim using your .vimrc. Auto-completion on the other hand does not appear to be working, but I am not sure if the language server is to blame, because it appears to be sending the correct completion info.

Could it be that you have the server installed from the rpm and it's using an old version instead of the latest git?

FrostyX commented 3 months ago

So, I was working on a minimal container reproducer for you and as it turns out, this is an issue on my and probably @NeilHanlon's machine, not a bug in the code.

FROM quay.io/fedora/fedora:40

RUN dnf -y install git vim wget python3-pip
RUN mkdir -p ~/.vim/pack/vendor/start
RUN git clone https://github.com/prabirshrestha/vim-lsp.git ~/.vim/pack/vendor/start/vim-lsp
RUN git clone https://github.com/dcermak/rpm-spec-language-server.git
RUN pip install ./rpm-spec-language-server
RUN wget https://src.fedoraproject.org/rpms/hello/raw/rawhide/f/hello.spec

RUN cat <<EOF > ~/.vimrc
au User lsp_setup call lsp#register_server({
\ 'name': 'rpm_lsp_server',
\ 'cmd': {server_info->['rpm_lsp_server', '--stdio', '--verbose', '--log_file', '/tmp/testuser-vim-lsp-log']},
\ 'allowlist': ['spec'],
\ })
function! s:on_lsp_buffer_enabled() abort
    setlocal omnifunc=lsp#complete
    nmap <buffer> gd <plug>(lsp-definition)
    nmap <buffer> gr <plug>(lsp-references)
    nmap <buffer> K <plug>(lsp-hover)
endfunction
augroup lsp_install
    au!
    autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
EOF

Downloading the Dockerfile and running

$ podman build . -t rpm-spec-vim-reproducer
$ podman run -it rpm-spec-vim-reproducer bash
[root@b7ddb9406b4e /]# vim hello.spec

everything works as expected there.

dcermak commented 3 months ago

Any idea what the issue is @NeilHanlon or @FrostyX ? If there's anything that the rpm-spec-language-server can do to indicate a problem, then I'd like to add it.

NeilHanlon commented 3 months ago

So, I've tried the reproducer above, and interestingly, I'm finding it not working--or rather, works the same as my nvim setup. Specifically:

I am not really sure what is different between mine and @FrostyX 's setups, given I used the exact docker container.

One thing I did note that is different between my and the reproducer is that upon registration in the reproducer, the LS sends a large amount of data to the editor about macros/names/etc (for completion, I expect), but I don't see this exchange occur in my local setup. I can provide a diff it that is helpful, though I expect this may just be because of how my neovim setup loads things.

FrostyX commented 3 months ago

I don't understand anything anymore but everything started working for me in Vim.

Everything worked properly. @NeilHanlon now it's probably up to you to figure out why it doesn't work for you. Otherwise I am voting for closing the issue.

NeilHanlon commented 3 months ago

I'm good with closing this, if it's working for others. I will figure mine out in due time and, if I figure it out, will update this or make a new ticket if applicable.

Thanks everyone for their work on this language server and troubleshooting this issue.