-
Notifications
You must be signed in to change notification settings - Fork 824
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
Is the any form of autocompletion/insertion in the LSP? #715
Comments
I don't think there's anything that exists specifically for this. But I think that you could probably use I.e. your server will be listening for document change events and you will receive these when a user types something. Then in response to these events you could use https://microsoft.github.io/language-server-protocol/specification#workspace_applyEdit |
I agree applyEdit seems good enough.
…--
Mickael Istria
Eclipse IDE <https://www.eclipse.org/downloads/eclipse-packages/>
developer, for Red Hat Developers <https://developers.redhat.com/>
|
Thanks guys for your feedback. The main problem with our XML Language Server is that it doesn't support incremental parsing (like the VSCode HTML LSP). So it think it will be hard to implement applyEdit in this case. And I think it's one reason why VSode HTML lsp provide too a custom command to manage this auto insert tag. @NikolasKomonen I have started to implement basic incremental parsing that you can try, but it's very very basic and I think there are some bugs. once this incremental parsing will be available, I think we will abele to manage applyEdit. |
I don't think you need incremental parsing for this to be implemented. |
Are you sure? My understand is to track change of document and trigger an event for applyEdit to manage auto close. To track document change, LSP provide |
You can store the current content of the document in the LS, and when you receive |
We have already that.
I would like to avoid doing that. We have today a big problem of performance with large XML file (same problem with HTML LS). As soon as you type some character in large file, the editor freezes because the whole content is pushed from client to server. I would like to support incremental support (already done but not stable for the moment) and after we will able to manage applyEdit with easy mean. |
This seems like an issue related to transfer, and not to storage. So I don't think storing the document would have an impact on the duration of the transfer.
Sure, that would be the best solution. In any case, it seems like we agree there is no need for extra-feature in LSP and this ticket can be closed ? |
Exactly!
VSCode has the same problem.
We are agree, that's cool:)
Please wait for @NikolasKomonen answer to be sure that we can close it. |
My main issue was with possible performance issues with using a diff. I'll implement this method and report back with my findings. |
@NikolasKomonen IMHO instead of implementing a diff, I suggest you that you activate incremental support and fix bugs of this feature. |
I second @angelozerr's proposition; in my own language server I implemented a basic diff algorithm somewhere, and my code for incremental support is shorter and simpler than that |
@angelozerr Are the bugs documented anywhere? If not, could you list some known issues? |
Unfortunately, no -( I'm really sorry, I had implemented that quickly. See eclipse-lemminx/lemminx#133 for incremental support issue. |
In rust-anlyzer, I [ab]use OnTypeFormatting to do this: https://github.com/rust-analyzer/rust-analyzer/blob/e6e2571bdf780d304c792d4317bbaf1d6f5d7a0a/crates/ra_lsp_server/src/main_loop/handlers.rs#L94-L122. It works pretty well, except for the fact that I can't intercept |
Let me loop in @aeschli. He implements the HTML language server. If something is missing to make the LSP nice here I am open to do so. |
I would like to note that we've implemented the same work-around used in the HTML language server. |
What makes you say it's a workaround? |
IMO if it requires a custom command/ isn't using a dedicated/intended LSP command. |
What would such a command do better or more easily than an "applyEdit"? What would be the input/output to better serve the purpose? What would be the sequence of message? |
I think applyEdit is fine as a response. My search was more for a dedicated command/client-request that would be sent to the server with information such as the last character change(s), and defined server capabilities for auto-completion trigger characters. |
All you really have to do is enable 'incremental' document change events. Then the client will not send you whole documents but only the small changes that happen as a user types. Disabling this and then trying to compute your own diffs seems like much more difficult than just telling the client you want to be receiving the diffs. Then it is up to you to applying these diffs to your locally stored copy of the document. But that really isn't terribly hard. To boot it may avoid a lot of the performance issues you are talking about with large documents. (It is going to be a lot more efficient for the client to send you a small one character diff instead of the whole document contents every time user types a character in the editor). |
Totally agree with you.
It's exactly that I have started experimenting in lsp4xml https://github.com/angelozerr/lsp4xml/blob/master/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/commons/TextDocument.java#L139 @NikolasKomonen I'm sorry to insist, but IMHO we should try to enable this incremental support (we must write tests for that) |
@angelozerr Don't worry, I am still going to to work on incremental support. My main concern is with the protocol in general. Without a dedicated auto-completion command, servers are forced to implement incremental parsing if they want the ability to autocomplete. |
It's a really cool news. Thanks!
Ok |
Pinging @aeschli again. Is there anything you would recommend from your HTML work that would make the LSP better in this case. |
I would also favour a dedicated LSP-request.. APIwise it would look a lot like OnTypeFormatting. Actually I wasn't aware that OnTypeFormatting is so similar. But I always thought that 'formatting' should only add/remove whitespaces... |
When would a client trigger such a request? On typing like with formatting |
There's a set of trigger characters are maybe character sequences that the server will tell the client on initialization. |
What about adding a flag to CompletionItem's to indicate if it should be automatically inserted? Separately, another possible requirement for the protocol and auto completion could be access to the previous AST before the trigger character was inserted. I'm assuming An example in our XML language server is the automatic removal of end tags after the starting one is <a></a> <a/></a> <-- insert '/' <a/> It would be a lot easier to check the old AST, than the new invalid one:
This might be a small use case, but could be something to consider. |
I was looking to implement auto-close features for my Go templating language templ. I initially implemented it using I realised it was simpler to use the autocompletion snippets instead, because you can use snippet syntax to set the final caret position with the So far, I've implemented a couple of HTML tags and the templating language constructs, the migration between the two approaches (document change vs snippets) is in this commit: a-h/templ@15e40f0 The result looks like this in VS Code: |
@aeschli might help you here since he implemented something custom for HTML as well. |
I now see many language servers have custom operations for that. The use-case seems common enough and there is now enough maturity to probably extract a standard solution from the current workarounds. So maybe the simplest thing to do wold be to add to applyEdit the capability to send snippets? |
Isn't this already supported through |
This doesn't seem to use snippets, which are necessary for the use-cases mentioned above. |
Im working on the XML Language Server and we've implemented a custom service to auto insert the end tag of an element.
Start with:
<a
Type the '>' character:
<a>
Without any user interaction
'</a>'
is automatically inserted:Does something currently exist/is being considered in the protocol that would provide the same functionality?
The text was updated successfully, but these errors were encountered: