@@ -83,7 +83,7 @@ InlineCompletionItem objects"
8383 ; ; Any event outside of the map, cancel and use it
8484 (define-key map [t] #'lsp-inline-completion-cancel-with-input )
8585 map)
86- " Keymap active when showing inline code suggestions" )
86+ " Keymap active when showing inline code suggestions. " )
8787
8888(defface lsp-inline-completion-overlay-face
8989 '((t :inherit shadow ))
@@ -92,13 +92,13 @@ InlineCompletionItem objects"
9292
9393; ; Local Buffer State
9494
95- (defvar-local lsp-inline-completion--items nil " The completions provided by the server" )
96- (defvar-local lsp-inline-completion--current nil " The current suggestion to be displayed" )
97- (defvar-local lsp-inline-completion--overlay nil " The overlay displaying code suggestions" )
98- (defvar-local lsp-inline-completion--start-point nil " The point where the completion started" )
95+ (defvar-local lsp-inline-completion--items nil " The completions provided by the server. " )
96+ (defvar-local lsp-inline-completion--current nil " The current suggestion to be displayed. " )
97+ (defvar-local lsp-inline-completion--overlay nil " The overlay displaying code suggestions. " )
98+ (defvar-local lsp-inline-completion--start-point nil " The point where the completion started. " )
9999
100100(defcustom lsp-before-inline-completion-hook nil
101- " Hooks run before starting code suggestions"
101+ " Hooks run before starting code suggestions. "
102102 :type 'hook
103103 :group 'lsp-mode )
104104
@@ -107,14 +107,14 @@ InlineCompletionItem objects"
107107 :type 'hook
108108 :group 'lsp-mode )
109109
110- (defcustom lsp-inline-completion-accepted-hook nil
111- " Hooks executed after accepting a code suggestion. The hooks receive the
112- text range that was updated by the completion"
110+ (defcustom lsp-inline-completion-accepted-functions nil
111+ " Functions executed after accepting a code suggestion.
112+ The functions receive the text range that was updated by the completion. "
113113 :type 'hook
114114 :group 'lsp-mode )
115115
116116(defcustom lsp-inline-completion-cancelled-hook nil
117- " Hooks executed after cancelling the completion UI"
117+ " Hooks executed after cancelling the completion UI. "
118118 :type 'hook
119119 :group 'lsp-mode )
120120
@@ -144,14 +144,14 @@ text range that was updated by the completion"
144144 (overlay-buffer lsp-inline-completion--overlay)))
145145
146146(defun lsp-inline-completion--clear-overlay ()
147- " Hide the suggestion overlay"
147+ " Hide the suggestion overlay. "
148148 (when (lsp-inline-completion--overlay-visible)
149149 (delete-overlay lsp-inline-completion--overlay))
150150 (setq lsp-inline-completion--overlay nil ))
151151
152152
153153(defun lsp-inline-completion--get-overlay (beg end )
154- " Build the suggestions overlay"
154+ " Build the suggestions overlay. "
155155 (when (overlayp lsp-inline-completion--overlay)
156156 (lsp-inline-completion--clear-overlay))
157157
@@ -163,7 +163,7 @@ text range that was updated by the completion"
163163
164164
165165(defun lsp-inline-completion--show-keys ()
166- " Shows active keymap hints in the minibuffer"
166+ " Shows active keymap hints in the minibuffer. "
167167
168168 (unless (and lsp-inline-completion--items
169169 (numberp lsp-inline-completion--current))
@@ -190,7 +190,7 @@ text range that was updated by the completion"
190190 " /" ))))))))
191191
192192(defun lsp-inline-completion-show-overlay ()
193- " Makes the suggestion overlay visible"
193+ " Makes the suggestion overlay visible. "
194194 (unless (and lsp-inline-completion--items
195195 (numberp lsp-inline-completion--current))
196196 (error " No completions to show " ))
@@ -202,40 +202,36 @@ text range that was updated by the completion"
202202 (-let* ((suggestion
203203 (elt lsp-inline-completion--items
204204 lsp-inline-completion--current))
205- ((&InlineCompletionItem? :insert-text :range? ) suggestion)
206- ((&RangeToPoint :start :end ) range?)
205+ ((&InlineCompletionItem? :insert-text :range? (&RangeToPoint :start :end )) suggestion)
207206 (start-point (or start (point )))
208207 (showing-at-eol (save-excursion
209208 (goto-char start-point)
210- (eolp )))
209+ (and ( not ( bolp )) ( eolp ) )))
211210 (beg (if showing-at-eol (1- start-point) start-point))
212211 (end-point (or end (1+ beg)))
213212 (text (cond
214213 ((lsp-markup-content? insert-text) (lsp:markup-content-value insert-text))
215214 (t insert-text)))
216- (propertizedText (concat
217- (buffer-substring beg start-point)
218- (propertize text 'face 'lsp-inline-completion-overlay-face )))
215+ (propertized-text (concat
216+ (buffer-substring beg start-point)
217+ (propertize text 'face 'lsp-inline-completion-overlay-face )))
219218 (ov (lsp-inline-completion--get-overlay beg end-point))
220- (completion-is-substr (string-equal
221- (buffer-substring beg lsp-inline-completion--start-point)
222- (substring propertizedText 0 (- lsp-inline-completion--start-point beg))))
223219 display-str after-str target-position)
224220
225221 (goto-char beg)
226222
227- (put-text-property 0 (length propertizedText ) 'cursor t propertizedText )
223+ (put-text-property 0 (length propertized-text ) 'cursor t propertized-text )
228224
229- (if completion-is-substr
225+ (if (string-prefix-p
226+ (buffer-substring-no-properties beg lsp-inline-completion--start-point)
227+ text)
230228 (progn
231229 ; ; Show the prefix as `display'
232- (setq display-str (substring propertizedText 0 (- lsp-inline-completion--start-point beg)))
233- (setq after-str (substring propertizedText (- lsp-inline-completion--start-point beg) nil ))
230+ (setq display-str (substring propertized-text 0 (- lsp-inline-completion--start-point beg)))
231+ (setq after-str (substring propertized-text (- lsp-inline-completion--start-point beg) nil ))
234232 (setq target-position lsp-inline-completion--start-point))
235-
236-
237- (setq display-str (substring propertizedText 0 1 ))
238- (setq after-str (substring propertizedText 1 ))
233+ (setq display-str (substring propertized-text 0 1 ))
234+ (setq after-str (substring propertized-text 1 ))
239235 (setq target-position beg))
240236
241237 (overlay-put ov 'display display-str)
@@ -248,10 +244,7 @@ text range that was updated by the completion"
248244
249245(defun lsp-inline-completion--insert-sugestion (text kind start end command? )
250246 (let* ((text-insert-start (or start lsp-inline-completion--start-point))
251- text-insert-end
252- (completion-is-substr (string-equal
253- (buffer-substring text-insert-start lsp-inline-completion--start-point)
254- (substring text 0 (- lsp-inline-completion--start-point text-insert-start)))))
247+ text-insert-end)
255248 (when text-insert-start
256249 (goto-char text-insert-start))
257250
@@ -278,15 +271,11 @@ text range that was updated by the completion"
278271 (when command?
279272 (lsp--execute-command command?) )
280273
281- (if completion-is-substr
282- (goto-char lsp-inline-completion--start-point)
283- (goto-char text-insert-start))
284-
285274 ; ; hooks
286- (run-hook-with-args-until-failure 'lsp-inline-completion-accepted-hook text text-insert-start text-insert-end)))
275+ (run-hook-with-args 'lsp-inline-completion-accepted-functions text text-insert-start text-insert-end)))
287276
288277(defun lsp-inline-completion-accept ()
289- " Accepts the current suggestion"
278+ " Accepts the current suggestion. "
290279 (interactive )
291280 (unless (lsp-inline-completion--overlay-visible)
292281 (error " Not showing suggestions " ))
@@ -319,7 +308,7 @@ text range that was updated by the completion"
319308 0 )))))
320309
321310(defun lsp-inline-completion-cancel ()
322- " Close the suggestion overlay"
311+ " Close the suggestion overlay. "
323312 (interactive )
324313 (when (lsp-inline-completion--overlay-visible)
325314
@@ -331,7 +320,7 @@ text range that was updated by the completion"
331320 (run-hooks 'lsp-inline-completion-cancelled-hook )))
332321
333322(defun lsp-inline-completion-cancel-with-input (event &optional arg )
334- " Cancel the inline completion and executes whatever event was received"
323+ " Cancel the inline completion and executes whatever event was received. "
335324 (interactive (list last-input-event current-prefix-arg))
336325
337326 (lsp-inline-completion-cancel)
@@ -343,7 +332,7 @@ text range that was updated by the completion"
343332 (call-interactively command))))
344333
345334(defun lsp-inline-completion-next ()
346- " Display the next inline completion"
335+ " Display the next inline completion. "
347336 (interactive )
348337 (unless (lsp-inline-completion--overlay-visible)
349338 (error " Not showing suggestions " ))
@@ -354,7 +343,7 @@ text range that was updated by the completion"
354343 (lsp-inline-completion-show-overlay))
355344
356345(defun lsp-inline-completion-prev ()
357- " Display the previous inline completion"
346+ " Display the previous inline completion. "
358347 (interactive )
359348 (unless (lsp-inline-completion--overlay-visible)
360349 (error " Not showing suggestions " ))
@@ -366,7 +355,7 @@ text range that was updated by the completion"
366355
367356;;;### autoload
368357(defun lsp-inline-completion-display (&optional implicit )
369- " Displays the inline completions overlay"
358+ " Displays the inline completions overlay. "
370359 (interactive )
371360
372361 (unless implicit
@@ -389,7 +378,7 @@ text range that was updated by the completion"
389378 ; ; Clean up
390379 (unless implicit
391380 (lsp--spinner-stop)))
392- (t (lsp--error " Couldnot fetch completions: %s" err))))
381+ (t (lsp--error " Could not fetch completions: %s" err))))
393382
394383
395384; ; Inline Completion Mode
@@ -402,18 +391,18 @@ text range that was updated by the completion"
402391
403392(defcustom lsp-inline-completion-idle-delay 2
404393 " The number of seconds before trying to fetch inline completions, when
405- lsp-inline-completion-mode is active"
394+ lsp-inline-completion-mode is active. "
406395 :type 'number
407396 :group 'lsp-mode
408397 :package-version '(lsp-mode . " 9.0.1" ))
409398
410399(defcustom lsp-inline-completion-inhibit-predicates nil
411- " When a function of this list returns non nil, lsp-inline-completion-mode will not show the completion"
400+ " When a function of this list returns non nil, lsp-inline-completion-mode will not show the completion. "
412401 :type '(repeat function)
413402 :group 'lsp-mode )
414403
415404(defvar-local lsp-inline-completion--idle-timer nil
416- " The idle timer used by lsp-inline-completion-mode" )
405+ " The idle timer used by lsp-inline-completion-mode. " )
417406
418407;;;### autoload
419408(define-minor-mode lsp-inline-completion-mode
@@ -473,11 +462,11 @@ lsp-inline-completion-mode is active"
473462(declare-function company-manual-begin " ext:company" )
474463(defvar company--begin-inhibit-commands )
475464(defcustom lsp-inline-completion-mode-inhibit-when-company-active t
476- " If the inline completion mode should avoid calling completions when company is active"
465+ " If the inline completion mode should avoid calling completions when company is active. "
477466 :type 'boolean
478467 :group 'lsp-mode )
479468
480- (defvar-local lsp-inline-completion--showing-company nil " If company was active when the tooltip is shown" )
469+ (defvar-local lsp-inline-completion--showing-company nil " If company was active when the tooltip is shown. " )
481470
482471(defun lsp-inline-completion--company-save-state-and-hide ()
483472 (setq lsp-inline-completion--showing-company
@@ -497,7 +486,7 @@ lsp-inline-completion-mode is active"
497486
498487;;;### autoload
499488(define-minor-mode lsp-inline-completion-company-integration-mode
500- " Minor mode to be used when company mode is active with lsp-inline-completion-mode"
489+ " Minor mode to be used when company mode is active with lsp-inline-completion-mode. "
501490 :lighter nil
502491 (cond
503492 ((and lsp-inline-completion-company-integration-mode lsp--buffer-workspaces (bound-and-true-p company-mode))
@@ -520,3 +509,4 @@ lsp-inline-completion-mode is active"
520509 (delq #'lsp-inline-completion--company-active-p lsp-inline-completion-inhibit-predicates)))))
521510
522511(provide 'lsp-inline-completion )
512+ ; ;; lsp-inline-completion.el ends here
0 commit comments