-
Notifications
You must be signed in to change notification settings - Fork 201
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
Doing c-fill-paragraph
in comments causes eglot to parse comments as code and produce errors
#367
Comments
c-fill-paragraph
in comments cause eglot to lose track of code positionc-fill-paragraph
in comments causes eglot to parse comments as code and produce errors
Hmmm. I'd venture to say this is a bug in C mode. You see, the way eglot "catches" changed text is by relying on before- and after- modification hooks, and Can you try a similar thing in Anyway, I'll try to have a look, but it might take a while. |
I tried to get eglot to run ccls in js-mode but it didn't work. I'm happy to try again if you could tell me the steps to follow. I tested c-fill-paragraph in comments with lsp-mode and it doesn't show this bug. I don't know whether it has some workaround for this special case or it just does things differently. |
Also, the funny thing is, |
It should be as simple as But never mind... I just saw |
You know what I'd do? Just set But it that works with |
Hi @joaotavora , I just tested setting fill-paragraph-function to nil in a c++ buffer and I'm still seeing this bug |
That's good! Probably means the bug is in Eglot, or Emacs. I'll have a
look later on.
…On Tue, Dec 10, 2019 at 10:59 AM finalpatch ***@***.***> wrote:
Hi @joaotavora , I just tested setting fill-paragraph-function to nil in a c++ buffer and I'm still seeing this bug
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
--
João Távora
|
I want to add that this bug also occurs occasionally when third party functions modifies the buffer, but I cannot reliably reproduce it. |
Any news? |
No sorry, nothing. You can help by coming up with a reliable reproduction recipe. Try to spot when it happens, and then isolate the case. |
I thought we already have a reliable way to reproduce (fill-paragraph)? |
That is correct, Indeed I misread this thread and focused on your own comment. Then if you can reliably reproduce "your bug", it would be of help. |
I had a look at I'm not an expert but I think that's why eglot breaks when I fill paragraph and use signature expansion for functions in C. |
Thanks for this analysis, it is very promising, but I don't understand some of your sentences, you need to write a bit more. What is the relation with Yasnippet here? Are you saying yasnippet already has a fix for this similar problem? If so, that would be great and wouldn't suprise me, as I (but mostly @npostavs) dealed with a lot of c-mode problems in Yasnippet. |
I have the problem when 1) I use |
Ahh, so you see a similar problem in two distinct situations? And both of them point to a use of |
Let me have a try :-) |
I see a similar problem with go-mode. The following steps can be used to reproduce the problem:
package main
import (
"fmt"
)
// main prints,
// "Hello, world!"
func main() {
fmt.Println("Hello, world!")
}
Eglot marks the line after the comment ( The value of (defun go--fill-paragraph (&rest args)
"Wrap fill-paragraph to set custom fill-prefix."
(let ((fill-prefix (go--fill-prefix))
(fill-paragraph-function nil))
(apply 'fill-paragraph args))) |
I had the same problem with the ada-mode parser; the problem is that an
intermediate step in fill-paragraph leaves the comment lines with no
comment-start syntax; then the parser gets triggered by change hooks and
reports that error.
This is actually a bug in fill-comment; it might be better to fix it.
I worked around this in ada-mode by writing my own
ada-fill-comment-paragraph, and inhibiting parsing until it was done;
there is a flag wisi-inhibit-parse for this purpose (also used in a
couple other places, notably inserting skeletons).
Does eglot have a similar inhibit?
…--
-- Stephe
|
Thanks Miciah and Stephen. Stephen, your insight might be the clue to fix
this. I'll have a better read later on.
…On Tue, Aug 25, 2020, 18:13 Stephen Leake ***@***.***> wrote:
I had the same problem with the ada-mode parser; the problem is that an
intermediate step in fill-paragraph leaves the comment lines with no
comment-start syntax; then the parser gets triggered by change hooks and
reports that error.
This is actually a bug in fill-comment; it might be better to fix it.
I worked around this in ada-mode by writing my own
ada-fill-comment-paragraph, and inhibiting parsing until it was done;
there is a flag wisi-inhibit-parse for this purpose (also used in a
couple other places, notably inserting skeletons).
Does eglot have a similar inhibit?
--
-- Stephe
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#367 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC6PQ56R6YFVLV7ONHVXSLSCPWKPANCNFSM4JXLRFVQ>
.
|
For me these errors are sticky. Shouldn't the change hook fire again after |
|
Offtopic I have a dream: all LSP servers stops publishing diagnostic on every document change. Sorry for the noise :) |
I can confirm that the OP's repro steps work, but also with many different Python files instead of a C++ file. Emacs "27.1.50" ;; Version: 1.6
;; Package-Version: 20201103.1026
;; Package-Commit: 21726416e6e580b20dfa90833c6dab2a8a15ea48 I'll post here the next time I see this with the exact file and cursor position. I've seen this a lot, it just doesn't repro 100%. |
Ok, I have a repro of something related to this, but worse. I want to note that I have also seen the effect of a ghost flymake error being introduced on the use of Start with buffer contents, and cursor at that first docstring, which is too long and needs to be filled, say before the 'T' in 'The': class Foo:
"""The `SSH` platform simply connects to existing targets. The `SSH` platform simply connects to existing targets. The `SSH` platform simply connects to existing targets.
It does not deploy nor delete the target. The default ``host`` is
``localhost`` so this can be used for testing against the user's
system (if SSH is enabled).
"""
def foo(self) -> str:
return "foo" Run Run
(Cool, it's filled, it's just wrong for a Python docstring since it should be indented.) Now run class Foo:
"""The `SSH` platform simply connects to existing targets. The `SSH`
platform simply connects to existing targets. The `SSH` platform
simply connects to existing targets.
It does not deploy nor delete the target. The default ``host`` is
``localhost`` so this can be used for testing against the user's
system (if SSH is enabled).
"""
def foo(self) -> str:
return "foo" It applied the indents to the paragraph below too! And this isn't the thing I've seen. I was first trying to repo the def foo(self) -> str:
return "foo"
return "foo" I futzed around with a different example, and got that to repro, but then as I undid and tried to copy the pieces out, it stopped repro'ing again. So something is up with |
This is hella annoying. The most frustrating thing about it is that the "error" persists, and, at least in |
Don't forget to include the simplest instructions you can on how to download your python ls. |
Wah, trying to get an emacs -Q to load eglot is...not going well...getting |
Look in the Makefile. You need packages if you're not using the latest nightly or something equivalent. |
Oh shoot, yeah that makes sense. Thanks! Forgot that just how much gets wiped by |
Though you should have those packages. Then again, if you're completely sandboxing this init, you need to reinstall them. -Q doesn't wipe packages, as far as I know. But you have to |
Hope this helps: https://github.com/andschwa/eglot-repro |
I can repro all the things from #367 (comment) reliably in this, it's just that the actual sequence of edits which confuses eglot/lsp/pyls are strange. Usually consists of |
Gotta say a whole repo for a reproduction recipe is a first! But I'll take it! :-D |
@andschwa I tried your recipe and idneed I reproduced, something. However, I don't think I reproduced this particular bug. There doesn't seem to be anything inconsistent when you Anyway, that's for another issue. Closing this one. |
Something's wrong is about where I'm at too, when I sat down trying to repro the OP's issue (which I have also seen while working in Python projects). Thanks @joaotavora! |
For what it's worth, while working today, I found that the OP repro does repro for me in Python. Not when filling docstrings, but when filling comments, and it doesn't seem fixed with that commit 😢 |
I've reproduced the problem in terms of a simple repro
Where # indented
# four spaces
def foo():
x = 1
return x and Emacs version is 26.3 and all the packages are up to date. M-q on the first comment and watch it break. @andschwa you can delete that repo. |
And this is what Emacs sends pyls for filling in that paragraph. IT's exactly what it sends for the Go server, as explained here #367 (comment), but the Go server can deal with it correctly, and the Python [client-notification] Tue Dec 15 08:35:30 2020:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
(:textDocument
(:uri "file:///home/capitaomorte/tmp/coiso.py" :version 2)
:contentChanges
[(:range
(:start
(:line 1 :character 0)
:end
(:line 1 :character 2))
:rangeLength 2 :text "")
(:range
(:start
(:line 0 :character 10)
:end
(:line 1 :character 11))
:rangeLength 1 :text " ")]))
[server-notification] Tue Dec 15 08:35:31 2020:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
(:uri "file:///home/capitaomorte/tmp/coiso.py" :diagnostics
[(:source "pycodestyle" :range
(:start
(:line 0 :character 10)
:end
(:line 0 :character 12))
:message "W291 trailing whitespace" :code "W291" :severity 2)])) |
Alright, I pushed a new, more ambitious fix, which I've tested manually in Python and Go modes. Please everybody try that out. |
Cannot reproduce in either |
This seems to have done it! I haven't run into a single issue today. Thank you SO MUCH @joaotavora. 🤩 |
Thanks. You're very welcome. I'll soon be doing some go myself, and it seems to have an excellent LS, so likely I'll devote some more time to Eglot in the near future. |
Now that joaotavora/eglot#367 is fixed, I think we should recommend it as a serious alternative to LSP mode. This change describes both packages, summarizes their different philosophies, and simplifies the example LSP Mode configuration to avoid relying on another unnecessary third-party package. Users who need more detail on alternative configurations should consult the LSP client vendors' pages — we don't need to recapitulate all of that detail here. Change-Id: If125fbde6d609e223ce44936504cc4b08b84dc3d Reviewed-on: https://go-review.googlesource.com/c/tools/+/278774 Reviewed-by: Muir Manders <muir@mnd.rs> Reviewed-by: Rebecca Stambler <rstambler@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
Now that joaotavora/eglot#367 is fixed, I think we should recommend it as a serious alternative to LSP mode. This change describes both packages, summarizes their different philosophies, and simplifies the example LSP Mode configuration to avoid relying on another unnecessary third-party package. Users who need more detail on alternative configurations should consult the LSP client vendors' pages — we don't need to recapitulate all of that detail here. Change-Id: If125fbde6d609e223ce44936504cc4b08b84dc3d Reviewed-on: https://go-review.googlesource.com/c/tools/+/278774 Reviewed-by: Muir Manders <muir@mnd.rs> Reviewed-by: Rebecca Stambler <rstambler@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
M-x fill-paragraph represents some paragraph-fillling changes very summarily. Filling 1 // foo 2 bar Into 1 // foo bar Only makes two changes: a deletion of the "// " and a replacement of a newline with a space character. The second change fooled Eglot's fix for joaotavora/eglot#259, by making a change similar to the one it is made to detect and correct. That fix should taget things that happen on the same line, this not being one of those things. * eglot.el (eglot--after-change): Only apply fix to joaotavora/eglot#259 if case-fiddling happens on same line.
From the in-code comments: ;; github#259 and github#367: With `capitalize-word' or somesuch, ;; `before-change-functions' always records the whole word's `b-beg' ;; and `b-end'. Similarly, when coalescing two lines into one, ;; `fill-paragraph' they mark the end of the first line up to the end ;; of the second line. In both situations, args received here ;; contradict that information: `beg' and `end' will differ by 1 and ;; will likely only encompass the letter that was capitalized or, in ;; the sentence-joining situation, the replacement of the newline with ;; a space. That's we keep markers _and_ positions so we're able to ;; detect and correct this. We ignore `beg', `len' and ;; `pre-change-len' and send "fuller" information about the region ;; from the markers. I've also experimented with doing this ;; unconditionally but it seems to break when newlines are added. * eglot.el (eglot--after-change): Robustify fix.
M-x fill-paragraph represents some paragraph-fillling changes very summarily. Filling 1 // foo 2 bar Into 1 // foo bar Only makes two changes: a deletion of the "// " and a replacement of a newline with a space character. The second change fooled Eglot's fix for joaotavora/eglot#259, by making a change similar to the one it is made to detect and correct. That fix should taget things that happen on the same line, this not being one of those things. * eglot.el (eglot--after-change): Only apply fix to joaotavora/eglot#259 if case-fiddling happens on same line.
From the in-code comments: ;; github#259 and github#367: With `capitalize-word' or somesuch, ;; `before-change-functions' always records the whole word's `b-beg' ;; and `b-end'. Similarly, when coalescing two lines into one, ;; `fill-paragraph' they mark the end of the first line up to the end ;; of the second line. In both situations, args received here ;; contradict that information: `beg' and `end' will differ by 1 and ;; will likely only encompass the letter that was capitalized or, in ;; the sentence-joining situation, the replacement of the newline with ;; a space. That's we keep markers _and_ positions so we're able to ;; detect and correct this. We ignore `beg', `len' and ;; `pre-change-len' and send "fuller" information about the region ;; from the markers. I've also experimented with doing this ;; unconditionally but it seems to break when newlines are added. * eglot.el (eglot--after-change): Robustify fix.
M-x fill-paragraph represents some paragraph-fillling changes very summarily. Filling 1 // foo 2 bar Into 1 // foo bar Only makes two changes: a deletion of the "// " and a replacement of a newline with a space character. The second change fooled Eglot's fix for #259, by making a change similar to the one it is made to detect and correct. That fix should taget things that happen on the same line, this not being one of those things. * eglot.el (eglot--after-change): Only apply fix to #259 if case-fiddling happens on same line. #367: joaotavora/eglot#367 #259: joaotavora/eglot#259 #259: joaotavora/eglot#259
From the in-code comments: ;; github#259 and github#367: With `capitalize-word' or somesuch, ;; `before-change-functions' always records the whole word's `b-beg' ;; and `b-end'. Similarly, when coalescing two lines into one, ;; `fill-paragraph' they mark the end of the first line up to the end ;; of the second line. In both situations, args received here ;; contradict that information: `beg' and `end' will differ by 1 and ;; will likely only encompass the letter that was capitalized or, in ;; the sentence-joining situation, the replacement of the newline with ;; a space. That's we keep markers _and_ positions so we're able to ;; detect and correct this. We ignore `beg', `len' and ;; `pre-change-len' and send "fuller" information about the region ;; from the markers. I've also experimented with doing this ;; unconditionally but it seems to break when newlines are added. * eglot.el (eglot--after-change): Robustify fix. #367: joaotavora/eglot#367 github#259: joaotavora/eglot#259 github#367: joaotavora/eglot#367
M-x fill-paragraph represents some paragraph-fillling changes very summarily. Filling 1 // foo 2 bar Into 1 // foo bar Only makes two changes: a deletion of the "// " and a replacement of a newline with a space character. The second change fooled Eglot's fix for joaotavora/eglot#259, by making a change similar to the one it is made to detect and correct. That fix should taget things that happen on the same line, this not being one of those things. * eglot.el (eglot--after-change): Only apply fix to joaotavora/eglot#259 if case-fiddling happens on same line. GitHub-reference: fix joaotavora/eglot#367
From the in-code comments: ;; githubhttps://github.com/joaotavora/eglot/issues/259 and githubhttps://github.com/joaotavora/eglot/issues/367: With `capitalize-word' or somesuch, ;; `before-change-functions' always records the whole word's `b-beg' ;; and `b-end'. Similarly, when coalescing two lines into one, ;; `fill-paragraph' they mark the end of the first line up to the end ;; of the second line. In both situations, args received here ;; contradict that information: `beg' and `end' will differ by 1 and ;; will likely only encompass the letter that was capitalized or, in ;; the sentence-joining situation, the replacement of the newline with ;; a space. That's we keep markers _and_ positions so we're able to ;; detect and correct this. We ignore `beg', `len' and ;; `pre-change-len' and send "fuller" information about the region ;; from the markers. I've also experimented with doing this ;; unconditionally but it seems to break when newlines are added. * eglot.el (eglot--after-change): Robustify fix. GitHub-reference: fix joaotavora/eglot#367
Steps to reproduce:
M-q
(c-fill-paragraph)M-q
and we can observe the error lines move downIt feels as if eglot didn't realize the input command happens in comment and doesn't affect code at all. Instead, eglot seems to send comments as code for incremental parsing and generated errors.
The errors can be fixed by reverting the buffer.
The text was updated successfully, but these errors were encountered: