swyddfa / esbonio

A language server for working with Sphinx projects.

Home Page:https://docs.esbon.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Excess characters when using autocompletion in Kate

seifertm opened this issue · comments

First of all, I want to say thanks for esbonio. I learned of the project during your lightning talk at PyCon.UK this year. I started a similar effort with rst-language-server, because most of the existing solutions seemed to be usable with VSCode only. I recently decided to deprecate rst-language-server in favour of esbonio, which is more advanced. Now, the actual bug report:

Autocompletion does not respect existing characters when using Kate. When I type .. and select toctree from the autocompletion, I end up with .... toctree::. I expect the result to be .. toctree:: with only two leading dots.

I believe the reason is that there's room for interpretation when LSP clients receive a CompletionItem with insertText (see the insertText docs for CompletionItem). Kate seems to interpret that differently than some other editors.

I want to say thanks for esbonio.

Much appreciated 😄 hopefully it can live up to the hype I gave it during the talk!

The language server tries to be clever and populates the textEdit field of a completion item, which if supported by the client, allows it to rewrite the text in place. However, it really should check to see if the client supports it first and adapt accordingly.

I just looked to see which completion capabilities kate supports and surprisingly it doesn't even provide a textDocument.completion field - I assume that means the correct thing to do would be for the server to set insertText to whatever follows after the ..?

I haven’t forgotten about this, but I was disappointed to realise that textEdit support isn’t actually covered by the client capabilities in the spec, so I can’t think of a "it just works" fix…

So I’m now leaning towards a config option along the lines of completion.preferInsertText that can be enabled to make the server "render" the CompletionItems without the textEdit field set.

v0.16.0 of the language server is now available, with a new server.completion.preferredInsertBehavior option.
If you set it to insert, you should find directive, directive options and role completions behave a lot better in Kate now.

However, there are still places in the language server that don't respect this option, so I expect there will still be a few situations where things are still a bit off. Feel free to open another issue with any edge cases you find 🙂