Skip to content

Commit

Permalink
Add lsp-flush-delayed-changes-before-next-message option
Browse files Browse the repository at this point in the history
Some LSP clients spam the server with message, such as
"textDocument/codeAction" requests on every keystroke, so if we require
synchronizing the delayed changes before the next LSP message, it looses
its meaning: In most cases the next cursor movement comes right after a
change, so `lsp--send-no-wait` forces the change notification out before
it sends the codeAction request.

Let the users of the slow LSP servers that depend on this change
notification throttling customize this behavior to choose their own
tradeoff.
  • Loading branch information
necto committed Jul 28, 2024
1 parent 5298775 commit 6081d06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Added a new optional ~:action-filter~ argument when defining LSP clients that allows code action requests to be modified before they are sent to the server. This is used by the Haskell language server client to work around an ~lsp-mode~ parsing quirk that incorrectly sends ~null~ values instead of ~false~ in code action requests.
* Add support for C# via the [[https://github.com/dotnet/roslyn/tree/main/src/LanguageServer][Roslyn language server]].
* Add basic support for [[https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics][pull diagnostics]] requests.
* Add ~lsp-flush-delayed-changes-before-next-message~ customization point to enforce throttling document change notifications.

** 9.0.0
* Add language server config for QML (Qt Modeling Language) using qmlls.
Expand Down
17 changes: 14 additions & 3 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -6743,13 +6743,24 @@ textDocument/didOpen for the new file."

(advice-add 'set-visited-file-name :around #'lsp--on-set-visited-file-name)

(defvar lsp--flushing-delayed-changes nil)
(defcustom lsp-flush-delayed-changes-before-next-message t
"If non-nil send the document changes update before sending other messages.

If nil, and `lsp-debounce-full-sync-notifications' is non-nil,
change notifications will be throttled by
`lsp-debounce-full-sync-notifications-interval' regardless of
other messages."
:group 'lsp-mode
:type 'boolean)

(defvar lsp--not-flushing-delayed-changes t)

(defun lsp--send-no-wait (message proc)
"Send MESSAGE to PROC without waiting for further output."

(unless lsp--flushing-delayed-changes
(let ((lsp--flushing-delayed-changes t))
(when (and lsp--not-flushing-delayed-changes
lsp-flush-delayed-changes-before-next-message)
(let ((lsp--not-flushing-delayed-changes nil))
(lsp--flush-delayed-changes)))
(lsp-process-send proc message))

Expand Down

0 comments on commit 6081d06

Please sign in to comment.