Skip to content

Commit

Permalink
lsp-inline-completion: cleanup autoload to make it loads correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kiennq authored Dec 2, 2024
1 parent 57ea512 commit c3be413
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
1 change: 1 addition & 0 deletions lsp-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
(define-obsolete-variable-alias 'lsp-enable-completion-at-point
'lsp-completion-enable "lsp-mode 7.0.1")

;;;###autoload
(defcustom lsp-completion-enable t
"Enable `completion-at-point' integration."
:type 'boolean
Expand Down
36 changes: 3 additions & 33 deletions lsp-inline-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,7 @@

;;; Code:

(require 'lsp-protocol)
(require 'dash)
(require 'cl-lib)
(require 'fringe)

(if (version< emacs-version "29.1")
;; Undo macro probably introduced in 29.1
(defmacro lsp-inline-completion--with-undo-amalgamate (&rest body)
"Like `progn' but perform BODY with amalgamated undo barriers.
This allows multiple operations to be undone in a single step.
When undo is disabled this behaves like `progn'."
(declare (indent 0) (debug t))
(let ((handle (make-symbol "--change-group-handle--")))
`(let ((,handle (prepare-change-group))
;; Don't truncate any undo data in the middle of this,
;; otherwise Emacs might truncate part of the resulting
;; undo step: we want to mimic the behavior we'd get if the
;; undo-boundaries were never added in the first place.
(undo-outer-limit nil)
(undo-limit most-positive-fixnum)
(undo-strong-limit most-positive-fixnum))
(unwind-protect
(progn
(activate-change-group ,handle)
,@body)
(progn
(accept-change-group ,handle)
(undo-amalgamate-change-group ,handle))))))
(defalias 'lsp-inline-completion--with-undo-amalgamate 'with-undo-amalgamate))
(require 'lsp-mode)

(defun lsp-inline-completion--params (implicit &optional identifier position)
"Returns a InlineCompletionParams instance"
Expand Down Expand Up @@ -91,7 +62,6 @@ InlineCompletionItem objects"

;;;;;; Default UI -- overlay

;;;###autoload
(defvar lsp-inline-completion-active-map
(let ((map (make-sparse-keymap)))
;; accept
Expand All @@ -115,7 +85,6 @@ InlineCompletionItem objects"
map)
"Keymap active when showing inline code suggestions")

;;;###autoload
(defface lsp-inline-completion-overlay-face
'((t :inherit shadow))
"Face for the inline code suggestions overlay."
Expand Down Expand Up @@ -334,7 +303,7 @@ text range that was updated by the completion"

(with-no-warnings
;; Compiler does not believes this macro is defined
(lsp-inline-completion--with-undo-amalgamate
(lsp-with-undo-amalgamate
(lsp-inline-completion--insert-sugestion text kind start end command?)))))

(defun lsp-inline-completion-accept-on-click (event)
Expand Down Expand Up @@ -422,6 +391,7 @@ text range that was updated by the completion"


;; Inline Completion Mode
;;;###autoload
(defcustom lsp-inline-completion-enable t
"If non-nil it will enable inline completions on idle."
:type 'boolean
Expand Down
35 changes: 27 additions & 8 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,6 @@ If this is set to nil, `eldoc' will show only the symbol information."
:type 'boolean
:group 'lsp-mode)

(define-obsolete-variable-alias 'lsp-enable-completion-at-point
'lsp-completion-enable "lsp-mode 7.0.1")

(defcustom lsp-completion-enable t
"Enable `completion-at-point' integration."
:type 'boolean
:group 'lsp-completion)

(defcustom lsp-enable-symbol-highlighting t
"Highlight references of the symbol at point."
:type 'boolean
Expand Down Expand Up @@ -1408,6 +1400,33 @@ Symlinks are not followed."
(s-prefix? (concat (lsp-f-canonical path-a) (f-path-separator))
(lsp-f-canonical path-b))))

;; compat
(if (version< emacs-version "29.1")
;; Undo macro probably introduced in 29.1
(defmacro lsp-with-undo-amalgamate (&rest body)
"Like `progn' but perform BODY with amalgamated undo barriers.

This allows multiple operations to be undone in a single step.
When undo is disabled this behaves like `progn'."
(declare (indent 0) (debug t))
(let ((handle (make-symbol "--change-group-handle--")))
`(let ((,handle (prepare-change-group))
;; Don't truncate any undo data in the middle of this,
;; otherwise Emacs might truncate part of the resulting
;; undo step: we want to mimic the behavior we'd get if the
;; undo-boundaries were never added in the first place.
(undo-outer-limit nil)
(undo-limit most-positive-fixnum)
(undo-strong-limit most-positive-fixnum))
(unwind-protect
(progn
(activate-change-group ,handle)
,@body)
(progn
(accept-change-group ,handle)
(undo-amalgamate-change-group ,handle))))))
(defalias 'lsp-with-undo-amalgamate 'with-undo-amalgamate))

(defun lsp--merge-results (results method)
"Merge RESULTS by filtering the empty hash-tables and merging
the lists according to METHOD."
Expand Down

0 comments on commit c3be413

Please sign in to comment.