autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

Error in vim: "Unknown function: nvim_buf_add_highlight" #1018

Closed ipkiss42 closed 3 years ago

ipkiss42 commented 4 years ago

Describe the bug

When running :call LanguageClient#textDocument_documentHighlight() (either manually or via an autocommand) in Vim 8.2, I get the following error:

[LC] Error: Failure { jsonrpc: Some(V2), error: Error { code: InternalError, message: "\'Vim(let):E117: Unknown function: nvim_buf_add_highlight\'", data: None }, id: Num(42) }

From the name, it looks like a nvim-specific function which should not be called in Vim.

Environment

To Reproduce

Steps to reproduce the behavior:

I'm sure you will manage :) Let me know if not.

martskins commented 4 years ago

I see where the issue is. The correct thing to do would be to delegate the vim/neovim function call to a function of our own where we clear the previous highlights (if any) and set the new ones. The setting part is matchaddpos in vim and nvim_buf_add_highlight in neovim. The clearing is the one I don't know in vim, I'll investigate on that, but if anyone knows the answer to it please ping me.

martskins commented 4 years ago

(Sorry clicked wrong button)

iddinev commented 3 years ago

Any update on the issue ?? Looking at the vim help - the clearing of 'matchaddpos' is done with 'clearmatches' or with 'matchdelete(id)' for a single, specific match (id is obtained by 'getmatches').

martskins commented 3 years ago

I have something in the works, but the highlight code is spread all over the place so it might take a while for me to finish this and validate it's working correctly. If someone wants to give it a go I'm happy to try and help.

iddinev commented 3 years ago

I'm pretty new to the whole LSP thing (I still can't configure the servers to work as intended with the LanguageClient on vim 8.2) so I'd probably be of even less help :(

martskins commented 3 years ago

@iddinev @ipkiss42 Opened #1123 which I believe should fix this. If any of you are able to test it out it would be great.


As for the difficulty you're having with configuring the servers @iddinev, if you want to open an issue I can give you a hand there, and we can probably update the readme after that to make it clearer.

iddinev commented 3 years ago

@martskins I'll first replicate my config on neovim, because I am still not sure whether the problems I'm having are because of: LanguageClient configs, LS configs, vim configs or me missing some LSP knowledge.

martskins commented 3 years ago

Closing via #1123

iddinev commented 3 years ago

Ok, I've played around with LC and have a bit more clarification on my part, but I still have some stuff that are unclear to me. If not specified - I'm asking for both nvim and vim.

Q1 - Is there a way to configure LC to show the full text, or is this a design issue ? I'm only asking because in some cases the hover text that get for some symbol is wildly different from the one that LC got in the 'handle*' method. For example - if I hover that stdout, from the example below, I get a oneliner help text. When using the palantir/python-lc and get the additional completion info from deoplete, LC logs a 'languageClient/handleCompleteDone' (when I chose a particular option from the menu) method which has the full documentation text that it got from the server and the abbreviated version (read: cut after a couple of lines) it passes to deoplete and I see on my screen: Screenshot_2020-11-05_22-09-14 Screenshot_2020-11-05_23-05-09

Q2 - Is there a way to get the additional completion info/hover text syntax highlighted ? Sample from github.com/iamcco/vim-language-server (sample gif is, I think, produced with coc.vim) Or am I missing some pluggins/have wrong nvim/vim configs on my part.

martskins commented 3 years ago

I'll answer these here but if you could open an issue it would be great, so we keep it on topic and other people can find it easily.

Q1. I opened a draft PR for this a while ago, but it only works in neovim. It's terribly outdated now, and I didn't merge it because it requires neovim 0.5, but I'll try to find another way to implement that, there surely is a way around that for both vim and neovim.

Q2. Theoretically you should get syntax highlighting in your floating windows if you include something like plasticboy/vim-markdown in your vim plugins. You can also set set conceallevel=2 for markdown files if you want it to display like rendered markdown. But I have been experiencing a weird issue with that in that it only shows the proper highlighting once I move into the floating window. Until I do that, all code is shown in green inside the hover window. Spent a while trying to investigate that these past few days but haven't found anything yet, but I'll continue that investigation and see if I can spot the problem. Also, not sure if it's only me or if everyone else is seeing the same issue.

martskins commented 3 years ago

@iddinev You can try the PR for Q1 in #1043

iddinev commented 3 years ago

@martskins The hover highlighting doesn't seem to work in vim8. The stuff you mentioned in your answer to Q2 kinda does the trick for neovim, but in vim8 I am still seeing:

```python

\`\`\`

Maybe for some reason the hover window doesn't get its filetype properly set to 'markdown' for the markdown plugins to pick it up? Also, I noticed in the logs that LC has some logic of deciding (or is getting this info straight from the server) what the hover text type should be, I think I saw that in some cases LC was prepending/appending the

```python ````

stuff itself.

I'd think that it would be cool if there would be a way to set the hover/completion extra info filetypes depending on the code file opened, as for example, in python although the LS might send the info listed as plaintext/markdown most of these texts are usually taken from the module's doc strings and is 'valid' python syntax. Alas - I am maybe asking too much though..

P.S. If these discussions are to continue I'd suggest some other communication channel as not to spam this issue anymore.