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
Unintended whitespace removal #368
Comments
@rwols LSP plugin does not control how to completion gets inserted, this is completely up-to SublimeText. My change #295 was trimming the completion text according to expected insertion place, but not altering insertion point, so it cannot remove space that is already there. Beyond this point LSP plugin no longer control what happens. You can enable debugging to confirm that Btw. I have tried to reproduce the problem, but for me it works as intended, see: |
Maybe related to this, if not, I will delete this comment. Using felixfbecker/php-language-server, I have a problem where the
# changed this in plugin/completion.py
- items = sorted(items, key=lambda item: item.get("sortText", item["label"]))
+ items = sorted(items, key=lambda item: item.get("sortText") or item["label"]) After changing this code in - insert_text = self.text_edit_text(item) or item.get("insertText") or label
+ insert_text = item.get("insertText") or label |
@predragnikolic I have managed to reproduce the problem. I will try to work on the fix this weekend. Indeed there is some problem that |
Ok Adam, no hurries :-) |
@predragnikolic @rwols @tomv564 Sorry to say that, but it seems that Sublime autocompletion behavior is kind of erratic (at least) as I have described in my comment at sublimehq/sublime_text#1281. ST is replacing more than the prefix, which is rather unexpected - leading to swallowing
Now #295 introduced a mitigation that
This is IMHO correct server behavior, but this is unfortunately (or fortunately?!) not handled by my Nevertheless, I believe for sake of correctness we should handle both cases in This all will work under the assumption that Sublime replaces the prefix, and nothing less or more, which is not true at the moment sublimehq/sublime_text#1281 🤣 |
So I finally figured out how this happens. clangd recently changed how it returns completion labels. There's this experimental feature where an
So, we end up with completions for ST like this
Now remember that, according to the ST API, ST sees the first element simply as the completion trigger (it is not a label). So when I type the word I guess a deeper problem is that there is really no place to put the label of an LSP completion. We put it in the the completion trigger for ST but we then assume that the label is going to have the same prefix as the the completion trigger. |
Made a workaround for clangd for this issue here: https://reviews.llvm.org/D49967, so from my point of view we can close this issue. Users with a fairly new clangd source should add the command-line option |
Nice research. Specifically to interface CompletionItem {
/**
* The label of this completion item. By default
* also the text that is inserted when selecting
* this completion.
*/
label: string; https://microsoft.github.io/language-server-protocol/specification#textDocument_completion |
How do you infer this from the docs? If an |
Ah right, forgot that it's the server that calls the shots here :) |
Looking at #294 I see that both examples would be broken by the mismatching I think LSP should use the same value for trigger and content, where the simplest completions for these language servers would be: I'm not convinced by the use of textEdit, especially given the work needed to stick the Some additional observations on #294:
Other languages servers tend to only complete from word boundaries, but for powershell this could be addressed by removing
|
No pbm about making However, I don't understand your statement that Sublime and VS Code And for PHP and sticking And if I read LSP proto docs correctly, label is insertable as long as And last thing in defence of |
Mismatching trigger and content results in lost/extra chars. Fix for #368
Flag |
@tomv564 Thanks for your support! |
Didn't get a chance to reply to your comments @nanoant, but I share your conclusions about the protocol and the best way to use it (textEdit). Unfortunately as long as we return completion content instead of inserting completions ourselves, we will have issues when sublime recognises word boundaries :/ |
Bug:
The problem here is that a whitespace character is removed, while that should not happen. @nanoant, I remember seeing a pull request from you where you tried to change the insertion behavior for Powershell. Can this be an unintended side-effect?
The text was updated successfully, but these errors were encountered: