Skip to content

Commit 63f21e1

Browse files
committed
Send changes immediately instead of queueing them
For incremental change mode, all the changes in a `textDocument/didChange` message are interpreted as applying to the same version of a particular document. But each emacs change corresponds to the state of the document when the change happens. So harmonise the expectations by sending each change in its own message. closes emacs-lsp#112
1 parent 80160e7 commit 63f21e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lsp-methods.el

+9-2
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,22 @@ to a text document."
802802
;;
803803
;; So (47 54 0) means add 7 chars starting at pos 47
804804
;; So (47 47 7) means delete 7 chars starting at pos 47
805-
;; (message "lsp-on-change:(start,end,length)=(%s,%s,%s)" start end length)
805+
;; (message "lsp-on-change:(start,end,length)=(%s,%s,%s)" start end length)
806806
(lsp--flush-other-workspace-changes)
807807
(when (and lsp--cur-workspace
808808
(not (or (eq lsp--server-sync-method 'none)
809809
(eq lsp--server-sync-method nil))))
810810
(setq lsp--has-changes t)
811811
(lsp--rem-idle-timer)
812812
(when (eq lsp--server-sync-method 'incremental)
813-
(lsp--push-change (lsp--text-document-content-change-event start end length)))
813+
;; (lsp--push-change (lsp--text-document-content-change-event start end length)))
814+
815+
;; Each change needs to be wrt to the current doc, so send immediately.
816+
;; Otherwise we need to adjust the coordinates of the new change according
817+
;; to the cumulative changes already queued.
818+
(progn
819+
(lsp--push-change (lsp--text-document-content-change-event start end length))
820+
(lsp--send-changes lsp--cur-workspace)))
814821
(if (lsp--workspace-change-timer-disabled lsp--cur-workspace)
815822
(lsp--send-changes lsp--cur-workspace)
816823
(lsp--set-idle-timer lsp--cur-workspace))))

0 commit comments

Comments
 (0)