@@ -407,6 +407,21 @@ lsp-inline-completion-mode is active."
407407(defvar-local lsp-inline-completion--idle-timer nil
408408 " The idle timer used by lsp-inline-completion-mode." )
409409
410+ (defvar-local lsp-inline-completion--inhibit-idle-timer nil
411+ " Flag to indicate we do not want the timer to show inline completions. Reset on change." )
412+
413+ ;;;### autoload
414+ (defun lsp-inline-completion-inhibit-idle-completions ()
415+ (setq lsp-inline-completion--inhibit-idle-timer t ))
416+
417+ ;;;### autoload
418+ (defun lsp-inline-completion-uninhibit-idle-completions ()
419+ (setq lsp-inline-completion--inhibit-idle-timer nil ))
420+
421+ ;;;### autoload
422+ (defun lsp-inline-completion-is-inhibited ()
423+ lsp-inline-completion--inhibit-idle-timer)
424+
410425;;;### autoload
411426(defun lsp-inline-completion-cancel-timer ()
412427 " Cancels the completion idle timer, if set"
@@ -420,19 +435,31 @@ lsp-inline-completion-mode is active."
420435 :lighter nil
421436 (cond
422437 ((and lsp-inline-completion-mode lsp--buffer-workspaces)
438+ (add-hook 'after-change-functions #'lsp-inline-completion--uninhibit-on-change nil t )
423439 (add-hook 'lsp-on-change-hook #'lsp-inline-completion--after-change nil t ))
424440
425441 (t
426442 (lsp-inline-completion-cancel-timer)
427443
428444 (lsp-inline-completion-cancel)
429445
446+ (remove-hook 'after-change-functions #'lsp-inline-completion--uninhibit-on-change t )
430447 (remove-hook 'lsp-on-change-hook #'lsp-inline-completion--after-change t ))))
431448
449+ (defun lsp-inline-completion--uninhibit-on-change (&rest _ )
450+ " Resets the uninhibit flag. "
451+
452+ ; ; Must be done in after-change-functions instead of lsp-on-change-hook,
453+ ; ; because LSP's hook happens after lsp-idle-delay. If the user calls some
454+ ; ; function that sets the inhibit flag to t *before* the idle delay, we may
455+ ; ; end up overriding the flag."
456+ (lsp-inline-completion-uninhibit-idle-completions))
457+
432458(defun lsp-inline-completion--maybe-display (original-buffer original-point )
433459 ; ; This is executed on an idle timer -- ensure state did not change before
434460 ; ; displaying
435- (when (and (buffer-live-p original-buffer)
461+ (when (and (not (lsp-inline-completion-is-inhibited))
462+ (buffer-live-p original-buffer)
436463 (eq (current-buffer ) original-buffer)
437464 (eq (point ) original-point)
438465 (--none? (funcall it) lsp-inline-completion-inhibit-predicates))
@@ -463,6 +490,7 @@ lsp-inline-completion-mode is active."
463490 (when (and lsp-inline-completion-enable
464491 (lsp-feature? " textDocument/inlineCompletion" ))
465492 (lsp-inline-completion-mode))))
493+
466494
467495; ; Company default integration
468496
0 commit comments