Replies: 4 comments 5 replies
|
Thanks for the report. I am converting this to a discussion as you didn't follow the issue reporting template (why? It has such bold letters...) Nevertheless, rest assured that I have understood a good part of your clear description, and you are correct that there are two separate behavior here here. The first one is clearly an error in Eglot, the second one, I'm not so sure. I don't use "on type formatting", though I helped implement it (with @nemethf ). |
You did provide pertinent information, just not what constitutes this maintainer's relatively narrow definition of an issue report. But the information is very pertinent, relevant and clear. |
Yes, that is a great idea. It's not complicated, I just couldn't muster the effort. I was thinking something like https://github.com/vitejs/vite/blob/main/.github/ISSUE_TEMPLATE/bug_report.yml, but adapted to Eglot's LSP reality. |
|
I think I'm also seeing this in ruby-lsp - if I type (with cursor represented by if foo|and hit enter, I end up with the cursor placed after the closing if foo
end|I'd expect it to be here - if foo
|
endLet me know if I should open this as an issue, either here or with ruby-lsp. For now I've just disabled onTypeFormatting with (after! eglot
(add-to-list 'eglot-ignored-server-capabilities :documentOnTypeFormattingProvider)) |
Uh oh!
There was an error while loading. Please reload this page.
Hello there, I encountered two issues when trying to get on type formatting working with the Scala Metal server. Fixing the first issue, led me to discover the second issue:
firstTriggerCharacterfor on type formatting is\n, on type formatting does not trigger at all.Both issues can be reproduced with this sample Scala project and the the Scala Metals server. In
src/main/scala/commons/Main.scala, insert: (point will be represented with^)(point is after the pipe)
and hit enter.
What should happen is that Eglot should request for
onTypeFormattingfrom the Metals and produce this:The point should be after the pipe. But Eglot does not send the
onTypeFormattingrequest and just inserts a newline as per usual. This is caused by issue 1.I debugged the issue and identified that this is happening because in
eglot--post-self-insert-hook,last-input-eventis used to determine if theonTypeFormattingrequest should be made. After hitting enter, thelast-input-eventis'return, but thefirstTriggerCharactersent by Metals is\n(See transcript below). So the(eglot-format)ineglot--post-self-insert-hookis not triggered. I fixed this locally by doing this:Basically checking if the
last-input-eventis a'returnand changing it to a\nif so. I am pretty sure there are better ways to do this, but I am not familiar enough with elisp. With this, Eglot now sends theonTypeFormattingrequest (see the transcript below for the sample request and response).This leads to the second issue. With the same example as above, hitting enter now results in this:
The point is behind the pipe instead of after the pipe. This seems to be caused by the
save-excursionineglot--apply-text-edits. I suspect this is happening because the new line is inserted first, causing the point to be at the start of the new line, then the text edit is applied. Then the point is restored (because ofsave-excursion) to the start of the line. I don't really know whysave-excursionis necessary, but removing thesave-excursionfixes the issue and point is at the correct location after the text edit.Please let me know if additional information is required. Thanks!
Additional information
LSP transcript - M-x eglot-events-buffer (mandatory unless Emacs inoperable)
I have only displayed the relevant parts here
All reactions