emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.8k stars 893 forks source link

Symbol’s value as variable is void: lsp-lens #2905

Closed stuart-little closed 3 years ago

stuart-little commented 3 years ago

Thank you for the bug report

Bug description

I am starting a newly-built emacs 27.2.50 (cloned from the source) with lsp-mode version 20210530.1518 (the latest I can find with package-list-packages).

Steps to reproduce

Start emacs 27 with the following init file:

;; emacs package repositories
(require 'package)
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/") 
                          ("gnu" . "http://elpa.gnu.org/packages/")
                          ;;("marmalade" . "http://marmalade-repo.org/packages/")
              ("melpa" . "https://melpa.org/packages/")))
;; adds repository for org mode
(require 'package)                                                                                    
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)

;;;; package installs

;; use-package
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

(use-package lsp-mode :ensure t)

The error I receive:

Error (use-package): lsp-mode/:catch: Symbol’s value\ as variable is void: lsp-lens

That error goes away if I comment out the very last line,

(use-package lsp-mode :ensure t)

Expected behavior

No such error.

Which Language Server did you use?

None of those, as far as I can tell (see the init file above).

OS

Linux

Error callstack

If I load the init file manually (by eval-ing (load <path-to-file>)) I get the following trace:

Debugger entered--Lisp error: (void-variable lsp-lens)
  byte-code("\301\10!\210\302\300!\207" [lsp-lens lsp-consistency-check provide] 2)
  require(lsp-lens)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312DD\313\314\315\316\317&\7\210\306\320\310\311\321DD\322\314\315\316\317&\7\210..." [require dash lsp-lens lsp-dart-protocol lsp-dart-dap lsp-dart-test-support custom-declare-variable lsp-dart-main-code-lens funcall function #f(compiled-function () #<bytecode 0x15938a335471>) "Enable the main code lens overlays." :type boolean :group lsp-dart lsp-dart-test-code-lens #f(compiled-function () #<bytecode 0x15938a335481>) "Enable the test code lens overlays." custom-declare-face lsp-dart-code-lens-separator ((t :height 0.3)) "The face used for separate test code lens overlays..."] 8)
  require(lsp-dart-code-lens)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\210\300\310!\210\300\311!\210\300\312!\210\300\313!\210\300\314!\210\300\315..." [require f dash lsp-mode lsp-dart-protocol lsp-dart-utils lsp-dart-closing-labels lsp-dart-dap lsp-dart-test-support lsp-dart-test-output lsp-dart-test-tree lsp-dart-code-lens lsp-dart-outline lsp-dart-flutter-fringe-colors lsp-dart-flutter-widget-guide lsp-dart-commands custom-declare-group lsp-dart nil "LSP support for Dart, using dart analysis server." :prefix "lsp-dart-" :group applications :link (url-link :tag "GitHub" "https://github.com/emacs-lsp/lsp-dart") custom-declare-variable lsp-dart-server-command funcall function #f(compiled-function () #<bytecode 0x15938a476849>) "The analysis_server executable to use." :type (repeat string) lsp-dart-extra-library-directories #f(compiled-function () #<bytecode 0x15938a476859>) "List of directories which will be considered to be..." :risky t (repeat string) lsp-dart-only-analyze-projects-with-open-files #f(compiled-function () #<bytecode 0x15938a476869>) "Analyze project root of open files even if not usi..." boolean lsp-dart-suggest-from-unimported-libraries #f(compiled-function () #<bytecode 0x15938a476879>) "Import suggestions happens only for non imported s..." lsp-dart-enable-sdk-formatter #f(compiled-function () #<bytecode 0x15938a476889>) "When to enable server formmating." ...] 10)
  require(lsp-dart)
  (lambda nil (require 'lsp-dart))()
  eval-after-load-helper("$HOME/.emacs.d/elpa/lsp-mode-20210530....")
  run-hook-with-args(eval-after-load-helper "$HOME/.emacs.d/elpa/lsp-mode-20210530....")
  do-after-load-evaluation("$HOME/.emacs.d/elpa/lsp-mode-20210530....")
  require(lsp-mode nil t)
  (not (require 'lsp-mode nil t))
  (if (not (require 'lsp-mode nil t)) (display-warning 'use-package (format "Cannot load %s" 'lsp-mode) :error))
  (condition-case err (if (not (require 'lsp-mode nil t)) (display-warning 'use-package (format "Cannot load %s" 'lsp-mode) :error)) ((debug error) (funcall use-package--warning1 :catch err)))
  eval-buffer(#<buffer  *load*> nil "$HOME/.em-lsp" nil t)  ; Reading at buffer position 765
  load-with-code-conversion("$HOME/.em-lsp" "$HOME/.em-lsp" nil nil)
  load("~/.em-lsp")
  eval((load "~/.em-lsp") t)
  eval-expression((load "~/.em-lsp") nil nil 127)
  funcall-interactively(eval-expression (load "~/.em-lsp") nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)


### Anything else?

_No response_
ericdallo commented 3 years ago

Thanks for the report, It seems related with lsp-dart, I'll take a look

ericdallo commented 3 years ago

@yyoncho I'm not sure that error is related with the warnings changes on lsp-dart, doesn't that is related to wrong byte-compiled packages? Or do we need to change anything on lsp-dart after the lsp-consistency-check merge?

yyoncho commented 3 years ago

We need to add (require 'lsp-mode) at the top of the file (and theck if other files in the repo had that too). The issue is that in some cases lsp-lens.el might be byte-compiled without lsp-mode.el being loaded.

stuart-little commented 3 years ago

Well, I won't pretend I understand what sort of subtle out-of-order-compilation magic took place here, but for what it's worth, this made the error go away:

yyoncho commented 3 years ago

Ok, I got it... There isn't really something we can do here. This is package.el limitation. The issue is that lsp-lens.el is bytecompiled against old lsp-mode.el. FTR the proper way to upgrade any emacs package is to delete the package, restart emacs and then install it.

stuart-little commented 3 years ago

OK, well, I suppose I can live with this sort of sporadic breakage then.. I'd seen glimpses of it before: on other systems, also running emacs 27.2.50 (compiled in the same fashion from source), I

For some reason things happened in a different order on this system, and the error lingered. Anyway, package.el is very useful in telling me I have such and such a list of packages to upgrade, upgrading them automatically, etc. I suppose one just has to deal with the fallout every one in a while (this is a rare occurrence..).

Anyway, thanks! I at least know what to do in the future.