@@ -83,7 +83,7 @@ InlineCompletionItem objects"
83
83
; ; Any event outside of the map, cancel and use it
84
84
(define-key map [t] #'lsp-inline-completion-cancel-with-input )
85
85
map)
86
- " Keymap active when showing inline code suggestions" )
86
+ " Keymap active when showing inline code suggestions. " )
87
87
88
88
(defface lsp-inline-completion-overlay-face
89
89
'((t :inherit shadow ))
@@ -92,13 +92,13 @@ InlineCompletionItem objects"
92
92
93
93
; ; Local Buffer State
94
94
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. " )
99
99
100
100
(defcustom lsp-before-inline-completion-hook nil
101
- " Hooks run before starting code suggestions"
101
+ " Hooks run before starting code suggestions. "
102
102
:type 'hook
103
103
:group 'lsp-mode )
104
104
@@ -107,14 +107,14 @@ InlineCompletionItem objects"
107
107
:type 'hook
108
108
:group 'lsp-mode )
109
109
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. "
113
113
:type 'hook
114
114
:group 'lsp-mode )
115
115
116
116
(defcustom lsp-inline-completion-cancelled-hook nil
117
- " Hooks executed after cancelling the completion UI"
117
+ " Hooks executed after cancelling the completion UI. "
118
118
:type 'hook
119
119
:group 'lsp-mode )
120
120
@@ -144,14 +144,14 @@ text range that was updated by the completion"
144
144
(overlay-buffer lsp-inline-completion--overlay)))
145
145
146
146
(defun lsp-inline-completion--clear-overlay ()
147
- " Hide the suggestion overlay"
147
+ " Hide the suggestion overlay. "
148
148
(when (lsp-inline-completion--overlay-visible)
149
149
(delete-overlay lsp-inline-completion--overlay))
150
150
(setq lsp-inline-completion--overlay nil ))
151
151
152
152
153
153
(defun lsp-inline-completion--get-overlay (beg end )
154
- " Build the suggestions overlay"
154
+ " Build the suggestions overlay. "
155
155
(when (overlayp lsp-inline-completion--overlay)
156
156
(lsp-inline-completion--clear-overlay))
157
157
@@ -163,7 +163,7 @@ text range that was updated by the completion"
163
163
164
164
165
165
(defun lsp-inline-completion--show-keys ()
166
- " Shows active keymap hints in the minibuffer"
166
+ " Shows active keymap hints in the minibuffer. "
167
167
168
168
(unless (and lsp-inline-completion--items
169
169
(numberp lsp-inline-completion--current))
@@ -190,7 +190,7 @@ text range that was updated by the completion"
190
190
" /" ))))))))
191
191
192
192
(defun lsp-inline-completion-show-overlay ()
193
- " Makes the suggestion overlay visible"
193
+ " Makes the suggestion overlay visible. "
194
194
(unless (and lsp-inline-completion--items
195
195
(numberp lsp-inline-completion--current))
196
196
(error " No completions to show " ))
@@ -202,40 +202,36 @@ text range that was updated by the completion"
202
202
(-let* ((suggestion
203
203
(elt lsp-inline-completion--items
204
204
lsp-inline-completion--current))
205
- ((&InlineCompletionItem? :insert-text :range? ) suggestion)
206
- ((&RangeToPoint :start :end ) range?)
205
+ ((&InlineCompletionItem? :insert-text :range? (&RangeToPoint :start :end )) suggestion)
207
206
(start-point (or start (point )))
208
207
(showing-at-eol (save-excursion
209
208
(goto-char start-point)
210
- (eolp )))
209
+ (and ( not ( bolp )) ( eolp ) )))
211
210
(beg (if showing-at-eol (1- start-point) start-point))
212
211
(end-point (or end (1+ beg)))
213
212
(text (cond
214
213
((lsp-markup-content? insert-text) (lsp:markup-content-value insert-text))
215
214
(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 )))
219
218
(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))))
223
219
display-str after-str target-position)
224
220
225
221
(goto-char beg)
226
222
227
- (put-text-property 0 (length propertizedText ) 'cursor t propertizedText )
223
+ (put-text-property 0 (length propertized-text ) 'cursor t propertized-text )
228
224
229
- (if completion-is-substr
225
+ (if (string-prefix-p
226
+ (buffer-substring-no-properties beg lsp-inline-completion--start-point)
227
+ text)
230
228
(progn
231
229
; ; 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 ))
234
232
(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 ))
239
235
(setq target-position beg))
240
236
241
237
(overlay-put ov 'display display-str)
@@ -248,10 +244,7 @@ text range that was updated by the completion"
248
244
249
245
(defun lsp-inline-completion--insert-sugestion (text kind start end command? )
250
246
(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)
255
248
(when text-insert-start
256
249
(goto-char text-insert-start))
257
250
@@ -278,15 +271,11 @@ text range that was updated by the completion"
278
271
(when command?
279
272
(lsp--execute-command command?) )
280
273
281
- (if completion-is-substr
282
- (goto-char lsp-inline-completion--start-point)
283
- (goto-char text-insert-start))
284
-
285
274
; ; 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)))
287
276
288
277
(defun lsp-inline-completion-accept ()
289
- " Accepts the current suggestion"
278
+ " Accepts the current suggestion. "
290
279
(interactive )
291
280
(unless (lsp-inline-completion--overlay-visible)
292
281
(error " Not showing suggestions " ))
@@ -319,7 +308,7 @@ text range that was updated by the completion"
319
308
0 )))))
320
309
321
310
(defun lsp-inline-completion-cancel ()
322
- " Close the suggestion overlay"
311
+ " Close the suggestion overlay. "
323
312
(interactive )
324
313
(when (lsp-inline-completion--overlay-visible)
325
314
@@ -331,7 +320,7 @@ text range that was updated by the completion"
331
320
(run-hooks 'lsp-inline-completion-cancelled-hook )))
332
321
333
322
(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. "
335
324
(interactive (list last-input-event current-prefix-arg))
336
325
337
326
(lsp-inline-completion-cancel)
@@ -343,7 +332,7 @@ text range that was updated by the completion"
343
332
(call-interactively command))))
344
333
345
334
(defun lsp-inline-completion-next ()
346
- " Display the next inline completion"
335
+ " Display the next inline completion. "
347
336
(interactive )
348
337
(unless (lsp-inline-completion--overlay-visible)
349
338
(error " Not showing suggestions " ))
@@ -354,7 +343,7 @@ text range that was updated by the completion"
354
343
(lsp-inline-completion-show-overlay))
355
344
356
345
(defun lsp-inline-completion-prev ()
357
- " Display the previous inline completion"
346
+ " Display the previous inline completion. "
358
347
(interactive )
359
348
(unless (lsp-inline-completion--overlay-visible)
360
349
(error " Not showing suggestions " ))
@@ -366,7 +355,7 @@ text range that was updated by the completion"
366
355
367
356
;;;### autoload
368
357
(defun lsp-inline-completion-display (&optional implicit )
369
- " Displays the inline completions overlay"
358
+ " Displays the inline completions overlay. "
370
359
(interactive )
371
360
372
361
(unless implicit
@@ -389,7 +378,7 @@ text range that was updated by the completion"
389
378
; ; Clean up
390
379
(unless implicit
391
380
(lsp--spinner-stop)))
392
- (t (lsp--error " Couldnot fetch completions: %s" err))))
381
+ (t (lsp--error " Could not fetch completions: %s" err))))
393
382
394
383
395
384
; ; Inline Completion Mode
@@ -402,18 +391,18 @@ text range that was updated by the completion"
402
391
403
392
(defcustom lsp-inline-completion-idle-delay 2
404
393
" 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. "
406
395
:type 'number
407
396
:group 'lsp-mode
408
397
:package-version '(lsp-mode . " 9.0.1" ))
409
398
410
399
(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. "
412
401
:type '(repeat function)
413
402
:group 'lsp-mode )
414
403
415
404
(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. " )
417
406
418
407
;;;### autoload
419
408
(define-minor-mode lsp-inline-completion-mode
@@ -473,11 +462,11 @@ lsp-inline-completion-mode is active"
473
462
(declare-function company-manual-begin " ext:company" )
474
463
(defvar company--begin-inhibit-commands )
475
464
(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. "
477
466
:type 'boolean
478
467
:group 'lsp-mode )
479
468
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. " )
481
470
482
471
(defun lsp-inline-completion--company-save-state-and-hide ()
483
472
(setq lsp-inline-completion--showing-company
@@ -497,7 +486,7 @@ lsp-inline-completion-mode is active"
497
486
498
487
;;;### autoload
499
488
(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. "
501
490
:lighter nil
502
491
(cond
503
492
((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"
520
509
(delq #'lsp-inline-completion--company-active-p lsp-inline-completion-inhibit-predicates)))))
521
510
522
511
(provide 'lsp-inline-completion )
512
+ ; ;; lsp-inline-completion.el ends here
0 commit comments