Replies: 3 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 ). |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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:
firstTriggerCharacter
for 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
onTypeFormatting
from the Metals and produce this:The point should be after the pipe. But Eglot does not send the
onTypeFormatting
request 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-event
is used to determine if theonTypeFormatting
request should be made. After hitting enter, thelast-input-event
is'return
, but thefirstTriggerCharacter
sent by Metals is\n
(See transcript below). So the(eglot-format)
ineglot--post-self-insert-hook
is not triggered. I fixed this locally by doing this:Basically checking if the
last-input-event
is a'return
and changing it to a\n
if 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 theonTypeFormatting
request (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-excursion
ineglot--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-excursion
is necessary, but removing thesave-excursion
fixes 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
Beta Was this translation helpful? Give feedback.
All reactions