eglot:有diagnostics信息的buffer, revert-buffer后diagnostics消失

Emacs -Q 下涉及到太多包不知怎样测试。麻烦哪位使用eglot的帮忙测试下。

服务器是会推送diagnostics信息的。已经在js(typescript-language-server)和python(pyright-langserver)下复现。

GNU Emacs 29.1 (build 1, x86_64-w64-mingw32) of 2023-09-17

可能跟flymake有关,执行一下flymake-start试试。

执行 flymake-start 有的。请教 flymake-start 应加在哪个地方?

可以用下面这段代码试试。但说起来正常编辑代码的时候,你这个问题的影响其实也不会很大,因为在编辑代码或者保存buffer的时候,flymake会调用flymake-start。

(add-hook 'flymake-mode-hook
                      (lambda () (run-with-idle-timer flymake-no-changes-timeout t #'flymake-start)))

有影响的。出现这种情况后,正在编辑时服务器会发来诊断信息,但就是不会实时提示。要等保存时才会有。

我对flymake也不很熟,不确定你这个跟配置有关还是flymake本身的问题导致的。

上面那段加hook的代码应该能缓解一下这个问题,你可以试试,或者再研究下flymake看有没有更好的方法。

好的,谢谢。也许是flymake不会像 vscode 那样实时显示服务器推送来的诊断信息。

原先我还怀疑是服务器推送了空的信息引起的。下面这个 revert-buffer 的日志,有一行 diagnostics 是[]

[client-notification] Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :method "textDocument/didClose" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py")))
[client-notification] Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py" :version 0 :languageId "python-ts" :text "a=23\nif=a\n")))
[client-request] (id:9) Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :id 9 :method "textDocument/inlayHint" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py")
           :range
           (:start
            (:line 0 :character 0)
            :end
            (:line 2 :character 0))))
[server-notification] Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
          (:uri "file:///d%3A/msys64/home/hh/test/a.py" :diagnostics
                []))
[server-notification] Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
          (:uri "file:///d%3A/msys64/home/hh/test/a.py" :version 0 :diagnostics
                [(:range
                  (:start
                   (:line 1 :character 2)
                   :end
                   (:line 1 :character 3))
                  :message "Expected expression" :severity 1 :source "Pyright")
                 (:range
                  (:start
                   (:line 1 :character 4)
                   :end
                   (:line 2 :character 0))
                  :message "Expected \":\"" :severity 1 :source "Pyright")]))
[server-reply] (id:9) Sat Dec  2 16:50:15 2023:
(:jsonrpc "2.0" :id 9 :result nil)
[client-request] (id:10) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 10 :method "textDocument/signatureHelp" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py")
           :position
           (:line 1 :character 4)))
[client-request] (id:11) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 11 :method "textDocument/hover" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py")
           :position
           (:line 1 :character 4)))
[client-request] (id:12) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 12 :method "textDocument/documentHighlight" :params
          (:textDocument
           (:uri "file:///d%3A/msys64/home/hh/test/a.py")
           :position
           (:line 1 :character 4)))
[server-reply] (id:10) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 10 :result nil)
[server-reply] (id:11) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 11 :result nil)
[server-reply] (id:12) Sat Dec  2 16:50:16 2023:
(:jsonrpc "2.0" :id 12 :result nil)

eglot + pyright + flymake 复现成功,revert 之后需修改再保存一次才能重新显示,是不是和 flymake 设置为“保存时检查”后遇到的问题:需要重复保存两次才能提示正确的检查结果 - #3,来自 Roife 这个相关