@@ -89,7 +89,7 @@ for a new workspace."
89
89
:group 'lsp-mode )
90
90
91
91
;;;### autoload
92
- (defcustom lsp-document-sync-method 'full
92
+ (defcustom lsp-document-sync-method nil
93
93
" How to sync the document with the language server."
94
94
:type '(choice (const :tag " Documents should not be synced at all." 'none )
95
95
(const :tag " Documents are synced by always sending the full content of the document." 'full )
@@ -437,6 +437,7 @@ disappearing, unset all the variables related to it."
437
437
(add-hook 'completion-at-point-functions #'lsp-completion-at-point ))
438
438
439
439
; ; Make sure the hook is local (last param) otherwise we see all changes for all buffers
440
+ (add-hook 'before-change-functions #'lsp-before-change nil t )
440
441
(add-hook 'after-change-functions #'lsp-on-change nil t )
441
442
(lsp--set-sync-method))
442
443
@@ -581,6 +582,15 @@ interface Range {
581
582
; ; ,"end" :{"line":7,"character":0}}
582
583
; ; ,"rangeLength":7
583
584
; ; ,"text":""}
585
+ ; ;
586
+ ; ; Adding text:
587
+ ; ; lsp-before-change:(start,end)=(33,33)
588
+ ; ; lsp-on-change:(start,end,length)=(33,34,0)
589
+ ; ;
590
+ ; ; Deleting text:
591
+ ; ; lsp-before-change:(start,end)=(19,27)
592
+ ; ; lsp-on-change:(start,end,length)=(19,19,8)
593
+
584
594
(if (eq length 0 )
585
595
; ; Adding something, work from start only
586
596
`(:range ,(lsp--range (lsp--point-to-position start)
@@ -676,6 +686,37 @@ to a text document."
676
686
; ; (message "lsp--push-change entered")
677
687
(setq lsp--changes (vconcat lsp--changes `(, change-event ))))
678
688
689
+ (defvar-local lsp--before-change-vals nil
690
+ " Store the positions from the `lsp-before-change' function
691
+ call, for validation and use in the `lsp-on-change' function." )
692
+ (defun lsp-before-change (start end )
693
+ " Executed before a file is changed.
694
+ Added to `before-change-functions' "
695
+ ; ; Note:
696
+ ; ;
697
+ ; ; This variable holds a list of functions to call when Emacs is about to
698
+ ; ; modify a buffer. Each function gets two arguments, the beginning and end of
699
+ ; ; the region that is about to change, represented as integers. The buffer
700
+ ; ; that is about to change is always the current buffer when the function is
701
+ ; ; called.
702
+ ; ;
703
+ ; ; WARNING:
704
+ ; ;
705
+ ; ; Do not expect the before-change hooks and the after-change hooks be called
706
+ ; ; in balanced pairs around each buffer change. Also don't expect the
707
+ ; ; before-change hooks to be called for every chunk of text Emacs is about to
708
+ ; ; delete. These hooks are provided on the assumption that Lisp programs will
709
+ ; ; use either before- or the after-change hooks, but not both, and the
710
+ ; ; boundaries of the region where the changes happen might include more than
711
+ ; ; just the actual changed text, or even lump together several changes done
712
+ ; ; piecemeal.
713
+ (message " lsp-before-change:(start,end)=(%s ,%s ) " start end)
714
+ (setq lsp--before-change-vals
715
+ `(:start start
716
+ :end end
717
+ :start-pos ,(lsp--point-to-position start)
718
+ :end-pos ,(lsp--point-to-position end))))
719
+
679
720
(defun lsp-on-change (start end length )
680
721
" Executed when a file is changed.
681
722
Added to `after-change-functions' "
@@ -693,7 +734,7 @@ to a text document."
693
734
; ;
694
735
; ; So (47 54 0) means add 7 chars starting at pos 47
695
736
; ; So (47 47 7) means delete 7 chars starting at pos 47
696
- ; ; (message "lsp-on-change:(start,end,length)=(%s,%s,%s)" start end length)
737
+ (message " lsp-on-change:(start,end,length)=(%s ,%s ,%s ) " start end length )
697
738
(lsp--flush-other-workspace-changes)
698
739
(when (and lsp--cur-workspace
699
740
(not (or (eq lsp--server-sync-method 'none )
0 commit comments