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
Make it easier to remove the text inserted by completion and to apply edits afterwards #2898
Comments
Related: #2347 |
Running InsertCompletionHide before inserting the user selected character would be a bit tricky, but we can definitely change the parameter to pass the set of inserted ranges. Would that be sufficient to fix your use case ? |
Yes, providing inserted ranges would be enough. To double-check that we understand each other let me use a specific example:
and completions menu is open and shows
I'd expect ranges provided by InsertCompletionHide to be something like this: |
Hum, in the case you describe, I would have expected |
Oh right, I included character which was selected before insertion, sorry for confusion. What you described is more logical and convenient behaviour. |
I consider that fix experimental, please give it a go, but I must say I am not entirely happy about it in the end (it feels a bit brittle) |
Thank you! I think I'll have time to play with it soon. Can't wait to finally resolve kak-lsp#40 =) |
… menu Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: mawww#2898 [snippets]: kakoune-lsp/kakoune-lsp#616 (comment) [LSP text edits] kakoune-lsp/kakoune-lsp#40
… menu Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: mawww#2898 [snippets]: kakoune-lsp/kakoune-lsp#616 (comment) [LSP text edits]: kakoune-lsp/kakoune-lsp#40
… menu Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: mawww#2898 [snippets]: kakoune-lsp/kakoune-lsp#616 (comment) [LSP text edits]: kakoune-lsp/kakoune-lsp#40
… menu Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: mawww#2898 [snippets]: kakoune-lsp/kakoune-lsp#616 (comment) [LSP text edits]: kakoune-lsp/kakoune-lsp#40
Use case: kak-lsp receives completions as text edits from language server and need to discard completion item suffix inserted by Kakoune's completions system to apply text edit properly. Also, kak-lsp need to be able to do it for all selections before it fans out text edit on them.
I mostly solved this problem by doing some selection based on the cursor positions when completion was triggered and the length of the label provided to completion system. But when a user commits completion candidate with
<ret>
things get tricky because of the lines shift.I would be nice to trigger
InsertCompletionHide
before inserting the character which user pressed a key for. It will solve removing suffix and translating text edit to multiple selections.As a further improvement,
InsertCompletionHide
could provideselection_descs
ashook_param
for inserted suffixes so removal could happen inlsp.kak
without need to generate command on a Rust side of the plugin.The text was updated successfully, but these errors were encountered: