Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing works in Vim #176

Closed
FrostyX opened this issue May 17, 2024 · 9 comments
Closed

Nothing works in Vim #176

FrostyX opened this issue May 17, 2024 · 9 comments

Comments

@FrostyX
Copy link

FrostyX commented May 17, 2024

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
Copy link

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
Copy link
Owner

dcermak commented Jun 7, 2024

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
Copy link
Author

FrostyX commented Jun 12, 2024

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

@dcermak
Copy link
Owner

dcermak commented Jun 12, 2024

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
Copy link
Author

FrostyX commented Jun 13, 2024

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
Copy link
Owner

dcermak commented Jun 15, 2024

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
Copy link

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:

  • autocompletion works (C-x C-o) as expected
  • hover does not work ("No hover information found in server - rpm_lsp_server)
  • goto def doesn't work (No definition found)
  • goto ref doesn't work (Retrieving references not supported for filetype 'spec')

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
Copy link
Author

FrostyX commented Jun 21, 2024

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

  • I tested the container reproducer once again and tried it both for F40 and F39
  • I tested it natively on my system as a testuser with minimal Vim configuration and the LSP sever installed from PyPI
  • I tested it natively as my user with my messy 15 years old ~/.vimrc and rpm-spec-language-server package from Fedora which is in 0.0.1 version

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
Copy link

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.

@FrostyX FrostyX closed this as completed Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants