From 71c81dd54c56f427e2ff8469e5aa53c0e9cfbe1f Mon Sep 17 00:00:00 2001 From: Rodrigo Kassick Date: Mon, 25 Nov 2024 11:17:41 -0300 Subject: [PATCH] chore: avoid linter errors --- lsp-inline-completion.el | 16 +++++++++----- lsp-mode.el | 46 ++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/lsp-inline-completion.el b/lsp-inline-completion.el index 56ba0e5e7e2..dcf366ffe69 100644 --- a/lsp-inline-completion.el +++ b/lsp-inline-completion.el @@ -95,7 +95,8 @@ ;;;###autoload (defface lsp-inline-completion-overlay-face '((t :inherit shadow)) - "Face for the inline code suggestions overlay.") + "Face for the inline code suggestions overlay." + :group 'lsp-mode) ;; Local Buffer State @@ -106,20 +107,24 @@ (defcustom lsp-before-inline-completion-hook nil "Hooks run before starting code suggestions" - :type 'hook) + :type 'hook + :group 'lsp-mode) (defcustom lsp-after-inline-completion-hook nil "Hooks executed after asking for code suggestions." - :type 'hook) + :type 'hook + :group 'lsp-mode) ;; TODO: Add parameters to the hooks! (defcustom lsp-inline-completion-accepted-hook nil "Hooks executed after accepting a code suggestion." - :type 'hook) + :type 'hook + :group 'lsp-mode) (defcustom lsp-inline-completion-shown-hook nil "Hooks executed after showing a suggestion." - :type 'hook) + :type 'hook + :group 'lsp-mode) (defsubst lsp-inline-completion--overlay-visible () "Return whether the `overlay' is avaiable." @@ -276,6 +281,7 @@ ;; hooks (run-hook-with-args-until-failure 'lsp-inline-completion-accepted-hook text text-insert-start text-insert-end))) +;;;###autoload (defun lsp-inline-completion-cancel () "Close the suggestion overlay" (interactive) diff --git a/lsp-mode.el b/lsp-mode.el index f3e47ab87f5..0a284321b20 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -68,6 +68,8 @@ (declare-function yas-expand-snippet "ext:yasnippet") (declare-function dap-mode "ext:dap-mode") (declare-function dap-auto-configure-mode "ext:dap-mode") +(declare-function lsp-inline-completion-display "lsp-inline-completion" (&optional implicit)) +(declare-function lsp-inline-completion-cancel "lsp-inline-completion") (defvar yas-inhibit-overlay-modification-protection) (defvar yas-indent-line) @@ -3693,6 +3695,19 @@ and expand the capabilities section" :group 'lsp-mode :package-version '(lsp-mode . "9.0.0")) +(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 + :group 'lsp-mode + :package-version '(lsp-mode . "9.0.1")) + (defun lsp--uninitialize-workspace () "Cleanup buffer state. When a workspace is shut down, by request or from just @@ -9944,30 +9959,9 @@ string." ;; 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 @@ -9982,6 +9976,16 @@ lsp-inline-completion-mode is active" (remove-hook 'lsp-on-change-hook #'lsp-inline-completion--after-change t)))) +(defun lsp-inline-completion--after-change (&rest _) + (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)))) + ;;;###autoload