Skip to content

Commit

Permalink
Fix some bytecompiler warnings/gccemacs errors (emacs-lsp#1767)
Browse files Browse the repository at this point in the history
* [Cask] Compile lsp-{protocol, mode}.el first

this exposes ordering issues that might otherwise get masked by other
lsp-*.el files requiring lsp-mode.el before lsp-mode.el itself is
byte-compiled. In its current form, the Cask file will now lead to
lsp-mode.el and lsp-protocol.el being compiled twice, but I don't
believe this causes any issues except for the extra second or so of
compile time.

I'd rather not list all *.el files explicitly; instead, I'd prefer Cask
to ignore duplicate files automatically (or, in an ideal world, to
analyze `require` forms automatically, warn about cycles and otherwise
compile in the correct order).

* Eval-when-compile dash-expand:&lsp-*

this fixes 10 compiler warnings (and actual runtime errors on gccemacs).
Thanks to @yyoncho and @ericdallo for figuring out this issue

* Fix several reference-to-free-variable warnings

this separates a number of defcustoms from the accompanying
logic (lsp-signature in particular), so feel free to drop
this commit if you think it hurts readability

* Fix late macro definitions

lsp-with-current-buffer, lsp-with-filename
  • Loading branch information
sebastiansturm authored Jun 9, 2020
1 parent 21cfcf5 commit ff19e36
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cask
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(source gnu)
(source melpa)
(package-file "lsp-mode.el")
(files "*.el")
(files "lsp-protocol.el" "lsp-mode.el" "*.el")

(development
(depends-on "ert-runner")
Expand Down
115 changes: 59 additions & 56 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,32 @@ They are added to `markdown-code-lang-modes'")
"The face used for code lens overlays."
:group 'lsp-faces)

(defcustom lsp-signature-render-documentation t
"Display signature documentation in `eldoc'."
:type 'boolean
:group 'lsp-mode
:package-version '(lsp-mode . "6.2"))

(defcustom lsp-signature-auto-activate t
"Auto-activate the documentation when "
:type 'boolean
:group 'lsp-mode
:package-version '(lsp-mode . "6.2"))

(defcustom lsp-signature-doc-lines 20
"If number, limit the number of lines to show in the docs."
:type 'number
:group 'lsp-mode
:package-version '(lsp-mode . "6.3"))

(defcustom lsp-signature-function 'lsp-lv-message
"The function used for displaying signature info.
It will be called with one param - the signature info. When
called with nil the signature info must be cleared."
:type 'function
:group 'lsp-mode
:package-version '(lsp-mode . "6.3"))

(defvar-local lsp--lens-overlays nil
"Current lenses.")

Expand Down Expand Up @@ -1027,6 +1053,17 @@ calling `remove-overlays'.")
;; Buffer local variable for storing number of lines.
(defvar lsp--log-lines)

(defvar-local lsp--eldoc-saved-message nil)

(defvar lsp--on-change-timer nil)
(defvar lsp--on-idle-timer nil)

(defvar-local lsp--signature-last nil)
(defvar-local lsp--signature-last-index nil)
(defvar lsp--signature-last-buffer nil)

(defvar-local lsp--virtual-buffer-point-max nil)

(cl-defgeneric lsp-execute-command (server command arguments)
"Ask SERVER to execute COMMAND with ARGUMENTS.")

Expand Down Expand Up @@ -3802,6 +3839,23 @@ in that particular folder."
(lsp--apply-text-edits text-edits)))
changes))))

(defmacro lsp-with-current-buffer (buffer-id &rest body)
(declare (indent 1) (debug t))
`(if-let (wcb (plist-get ,buffer-id :with-current-buffer))
(with-lsp-workspaces (plist-get ,buffer-id :workspaces)
(funcall wcb (lambda () ,@body)))
(with-current-buffer ,buffer-id
,@body)))

(defmacro lsp-with-filename (file &rest body)
"Execute BODY with FILE as a context.
Need to handle the case when FILE indicates virtual buffer."
(declare (indent 1) (debug t))
`(if-let (lsp--virtual-buffer (get-text-property 0 'lsp-virtual-buffer ,file))
(lsp-with-current-buffer lsp--virtual-buffer
,@body)
,@body))

(defun lsp--apply-text-document-edit (edit)
"Apply the TextDocumentEdit object EDIT.
If the file is not being visited by any buffer, it is opened with
Expand Down Expand Up @@ -4176,8 +4230,6 @@ Added to `after-change-functions'."
:type 'hook
:group 'lsp-mode)

(defvar lsp--on-change-timer nil)
(defvar lsp--on-idle-timer nil)

(defun lsp--idle-reschedule (buffer)
(setq lsp--on-idle-timer (run-with-idle-timer
Expand Down Expand Up @@ -4858,15 +4910,6 @@ Others: TRIGGER-CHARS"
(lsp-translate-line (1+ (gethash "line" pos-start)))
(lsp-translate-column (gethash "character" pos-start))))))

(defmacro lsp-with-filename (file &rest body)
"Execute BODY with FILE as a context.
Need to handle the case when FILE indicates virtual buffer."
(declare (indent 1) (debug t))
`(if-let (lsp--virtual-buffer (get-text-property 0 'lsp-virtual-buffer ,file))
(lsp-with-current-buffer lsp--virtual-buffer
,@body)
,@body))

(defun lsp--locations-to-xref-items (locations)
"Return a list of `xref-item' from Location[] or LocationLink[]."
(setq locations (if (sequencep locations)
Expand Down Expand Up @@ -4927,11 +4970,12 @@ If INCLUDE-DECLARATION is non-nil, request the server to include declarations."
(run-hooks 'lsp-eldoc-hook)
eldoc-last-message)

(defun dash-expand:&lsp-wks (key source)
`(,(intern-soft (format "lsp--workspace-%s" (eval key) )) ,source))
(eval-when-compile
(defun dash-expand:&lsp-wks (key source)
`(,(intern-soft (format "lsp--workspace-%s" (eval key) )) ,source))

(defun dash-expand:&lsp-cln (key source)
`(,(intern-soft (format "lsp--client-%s" (eval key) )) ,source))
(defun dash-expand:&lsp-cln (key source)
`(,(intern-soft (format "lsp--client-%s" (eval key) )) ,source)))

(defun lsp--point-on-highlight? ()
(-some? (lambda (overlay)
Expand Down Expand Up @@ -5235,10 +5279,6 @@ RENDER-ALL - nil if only the signature should be rendered."



(defvar-local lsp--signature-last nil)
(defvar-local lsp--signature-last-index nil)
(defvar lsp--signature-last-buffer nil)

(defvar lsp-signature-mode-map
(-doto (make-sparse-keymap)
(define-key (kbd "M-n") #'lsp-signature-next)
Expand All @@ -5253,32 +5293,6 @@ RENDER-ALL - nil if only the signature should be rendered."
:lighter ""
:group 'lsp-mode)

(defcustom lsp-signature-render-documentation t
"Display signature documentation in `eldoc'."
:type 'boolean
:group 'lsp-mode
:package-version '(lsp-mode . "6.2"))

(defcustom lsp-signature-auto-activate t
"Auto-activate the documentation when "
:type 'boolean
:group 'lsp-mode
:package-version '(lsp-mode . "6.2"))

(defcustom lsp-signature-doc-lines 20
"If number, limit the number of lines to show in the docs."
:type 'number
:group 'lsp-mode
:package-version '(lsp-mode . "6.3"))

(defcustom lsp-signature-function 'lsp-lv-message
"The function used for displaying signature info.
It will be called with one param - the signature info. When
called with nil the signature info must be cleared."
:type 'function
:group 'lsp-mode
:package-version '(lsp-mode . "6.3"))

(defun lsp-signature-stop ()
"Stop showing current signature help."
(interactive)
Expand Down Expand Up @@ -5473,7 +5487,6 @@ It will show up only if current point has signature help."
;; hover

(defvar-local lsp--hover-saved-bounds nil)
(defvar-local lsp--eldoc-saved-message nil)

(defun lsp-hover ()
"Display hover info (based on `textDocument/signatureHelp')."
Expand Down Expand Up @@ -6052,14 +6065,6 @@ REFERENCES? t when METHOD returns references."
(or lsp--virtual-buffer
(current-buffer)))

(defmacro lsp-with-current-buffer (buffer-id &rest body)
(declare (indent 1) (debug t))
`(if-let (wcb (plist-get ,buffer-id :with-current-buffer))
(with-lsp-workspaces (plist-get ,buffer-id :workspaces)
(funcall wcb (lambda () ,@body)))
(with-current-buffer ,buffer-id
,@body)))

(defun lsp-buffer-live-p (buffer-id)
(if-let (buffer-live (plist-get buffer-id :buffer-live?))
(funcall buffer-live buffer-id)
Expand Down Expand Up @@ -8257,8 +8262,6 @@ See https://github.com/emacs-lsp/lsp-mode."
lsp--virtual-buffer-point-max)
:text (lsp--buffer-content))))))))

(defvar-local lsp--virtual-buffer-point-max nil)

(defun lsp-virtual-buffer-before-change (start _end)
(when-let (virtual-buffer (-first (lambda (vb)
(lsp-with-current-buffer vb
Expand Down

0 comments on commit ff19e36

Please sign in to comment.