Skip to content

Commit

Permalink
feat: provide a minor mode for auto activating inline completions
Browse files Browse the repository at this point in the history
  • Loading branch information
kassick committed Nov 25, 2024
1 parent 2b9d47d commit 5ee78c1
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4274,6 +4274,10 @@ yet."
(lsp-feature? "textDocument/inlayHint"))
(lsp-inlay-hints-mode))

(when (and lsp-inline-completion-enable
(lsp-feature? "textDocument/inlineCompletion"))
(lsp-inline-completion-mode))

(when (and lsp-enable-dap-auto-configure
(functionp 'dap-mode))
(dap-auto-configure-mode 1)))
Expand Down Expand Up @@ -5430,9 +5434,9 @@ If EXCLUDE-DECLARATION is non-nil, request the server to include declarations."
(lsp-help-mode)
(with-help-window lsp-help-buf-name
(insert
(mapconcat 'string-trim-right
(split-string (lsp--render-on-hover-content contents t) "\n")
"\n"))))
(mapconcat 'string-trim-right
(split-string (lsp--render-on-hover-content contents t) "\n")
"\n"))))
(run-mode-hooks)))
(lsp--info "No content at point."))))

Expand Down Expand Up @@ -9938,6 +9942,46 @@ string."
(setf window-scroll-functions
(delete #'lsp--update-inlay-hints-scroll-function window-scroll-functions)))))


;; Inline Completions
(defcustom lsp-inline-completion-enable t
"If non-nil it will enable inline completions on idle."
:type 'boolean
:group 'lsp-mode
:package-version '(lsp-mode . "9.0.1"))

(defcustom lsp-inline-completion-idle-delay 2
"The number of seconds before trying to fetch inline completions, when
lsp-inline-completion-mode is active"
:type 'number)

(defvar-local lsp-inline-completion--idle-timer nil
"The idle timer used by lsp-inline-completion-mode")

(defun lsp-inline-completion--after-change (&rest args)
(when (and lsp-inline-completion-mode lsp--buffer-workspaces)
(when lsp-inline-completion--idle-timer
(cancel-timer lsp-inline-completion--idle-timer))
(setq lsp-inline-completion--idle-timer
(run-with-timer lsp-inline-completion-idle-delay
nil
#'lsp-inline-completion-display
'implicit))))

(define-minor-mode lsp-inline-completion-mode
"Mode automatically displaying inline completions."
:lighter nil
(cond
((and lsp-inline-completion-mode lsp--buffer-workspaces)
(add-hook 'lsp-on-change-hook #'lsp-inline-completion--after-change nil t))
(t
(when lsp-inline-completion--idle-timer
(cancel-timer lsp-inline-completion--idle-timer))

(lsp-inline-completion-cancel)

(remove-hook 'lsp-on-change-hook #'lsp-inline-completion--after-change t))))



;;;###autoload
Expand Down

0 comments on commit 5ee78c1

Please sign in to comment.