emacs-lsp / lsp-treemacs

lsp-mode :heart: treemacs
GNU General Public License v3.0
393 stars 46 forks source link

Error when calling dap-ui-locals: (void-variable lsp-treemacs-generic-root) #145

Closed bastianbeischer closed 1 year ago

bastianbeischer commented 1 year ago

I am using latest treemacs from melpa. Backtrace:

Debugger entered--Lisp error: (void-variable lsp-treemacs-generic-root)
  lsp-treemacs-render(((:label "Nothing to display..." :key "foo" :icon :empty)) " Locals " 1 "*dap-ui-locals*")
  dap-ui-locals()
  funcall-interactively(dap-ui-locals)
  #<subr call-interactively>(dap-ui-locals record nil)
  call-interactively@ido-cr+-record-current-command(#<subr call-interactively> dap-ui-locals record nil)
  apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (dap-ui-locals record nil))
  call-interactively(dap-ui-locals record nil)
  command-execute(dap-ui-locals record)
  execute-extended-command(nil "dap-ui-locals" nil)
  funcall-interactively(execute-extended-command nil "dap-ui-locals" nil)
  #<subr call-interactively>(execute-extended-command nil nil)
  call-interactively@ido-cr+-record-current-command(#<subr call-interactively> execute-extended-command nil nil)
  apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (execute-extended-command nil nil))
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
yyoncho commented 1 year ago

@bastianbeischer can you test after deleting elpa dir, restarting emacs, and installing the packages again? You may also test with M-x lsp-start-plain

bastianbeischer commented 1 year ago

Thanks, reinstalling made a difference, but now I get a different error:

Debugger entered--Lisp error: (wrong-type-argument listp lsp-treemacs-generic-root)
  treemacs--find-custom-node((lsp-treemacs-generic-root "foo"))
  treemacs-find-node((lsp-treemacs-generic-root "foo"))
  treemacs--async-update-part-complete((lsp-treemacs-generic-root "foo") (lsp-treemacs-generic-root "foo") nil)
  #f(compiled-function (items) #<bytecode -0x4d491a752017148>)(nil)
  #f(compiled-function (&optional btn item callback) #<bytecode -0xd8ad6eb77d4b63a>)(#<marker (moves after insertion) at 15 in *dap-ui-locals*> (:label "Nothing to display..." :key "foo" :icon :empty) #f(compiled-function (items) #<bytecode -0x4d491a752017148>))
  treemacs-update-async-node((lsp-treemacs-generic-root "foo"))
  treemacs-expand-extension-node(0)
  treemacs--do-expand-variadic-parent(#<marker at 1 in *dap-ui-locals*> #s(treemacs-extension :name lsp-treemacs-generic-root :closed-state #f(compiled-function () #<bytecode 0x1dc015a07f494>) :open-state #f(compiled-function () #<bytecode 0x1dc015a07e954>) :closed-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :open-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :children #f(compiled-function (&optional btn item) #<bytecode -0xd2451dd26651068>) :key #f(compiled-function (&optional btn item) #<bytecode -0xd2451dc875178a8>) :label #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :more-properties #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :child-type #f(compiled-function () #<bytecode 0x1dc01634677d4>) :variadic? t :async? nil :entry-point? t) 1)
  treemacs--variadic-extension-entry-render(#s(treemacs-extension :name lsp-treemacs-generic-root :closed-state #f(compiled-function () #<bytecode 0x1dc015a07f494>) :open-state #f(compiled-function () #<bytecode 0x1dc015a07e954>) :closed-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :open-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :children #f(compiled-function (&optional btn item) #<bytecode -0xd2451dd26651068>) :key #f(compiled-function (&optional btn item) #<bytecode -0xd2451dc875178a8>) :label #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :more-properties #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :child-type #f(compiled-function () #<bytecode 0x1dc01634677d4>) :variadic? t :async? nil :entry-point? t) 1)
  treemacs--render-extension(#s(treemacs-extension :name lsp-treemacs-generic-root :closed-state #f(compiled-function () #<bytecode 0x1dc015a07f494>) :open-state #f(compiled-function () #<bytecode 0x1dc015a07e954>) :closed-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :open-icon #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :children #f(compiled-function (&optional btn item) #<bytecode -0xd2451dd26651068>) :key #f(compiled-function (&optional btn item) #<bytecode -0xd2451dc875178a8>) :label #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :more-properties #f(compiled-function (&optional btn item) #<bytecode -0xd2451df39e58928>) :child-type #f(compiled-function () #<bytecode 0x1dc01634677d4>) :variadic? t :async? nil :entry-point? t) 1)
  lsp-treemacs-render(((:label "Nothing to display..." :key "foo" :icon :empty)) " Locals " 1 "*dap-ui-locals*")
  dap-ui-locals()
...
bastianbeischer commented 1 year ago

Also saw something about "invalid function lsp-treemacs-wcb-unless-killed", I think this went away when I changed lsp-treemacs-wcb-unless-killed from defmacro to defun.

jcaw commented 1 year ago

I'm also getting this issue - I'm on commit #2894e6d. It works if I quote the symbol:

https://github.com/emacs-lsp/lsp-treemacs/blob/2894e6dec583eaa77037627e9d8c3bc89cf7273d/lsp-treemacs-generic.el#L133

-   (treemacs-initialize lsp-treemacs-generic-root
+   (treemacs-initialize 'lsp-treemacs-generic-root
yyoncho commented 1 year ago

@jcaw that is because your treemacs is out of date.

jcaw commented 1 year ago

Ah yeah, I see, this seems to be the commit that changed things:

https://github.com/Alexander-Miller/treemacs/commit/20765acd38e00faa46a72b9a2cf63a7b451c6850

I'm not sure which repo treemacs is being installed from (I'm running Doom Emacs), but it's pulling the commit before this one.

bastianbeischer commented 1 year ago

Here is a backtrace without byte compilation

Debugger entered--Lisp error: (wrong-type-argument listp lsp-treemacs-generic-root)
  cdr(lsp-treemacs-generic-root)
  (if (cdr goto-path) (progn (setq manual-parts (cons (-last-item goto-path) manual-parts)) (setq goto-path (-butlast goto-path))) (setq goto-path (car goto-path)))
  (if (or (null dom-node) (null (treemacs-dom-node->position dom-node))) (if (cdr goto-path) (progn (setq manual-parts (cons (-last-item goto-path) manual-parts)) (setq goto-path (-butlast goto-path))) (setq goto-path (car goto-path))) (setq continue nil))
  (while continue (setq dom-node (treemacs-find-in-dom goto-path)) (if (or (null dom-node) (null (treemacs-dom-node->position dom-node))) (if (cdr goto-path) (progn (setq manual-parts (cons (-last-item goto-path) manual-parts)) (setq goto-path (-butlast goto-path))) (setq goto-path (car goto-path))) (setq continue nil)))
  (let* ((continue t)) (while continue (setq dom-node (treemacs-find-in-dom goto-path)) (if (or (null dom-node) (null (treemacs-dom-node->position dom-node))) (if (cdr goto-path) (progn (setq manual-parts (cons (-last-item goto-path) manual-parts)) (setq goto-path (-butlast goto-path))) (setq goto-path (car goto-path))) (setq continue nil))))
  (let* ((start (point)) (goto-path (if (listp path) (copy-sequence path) (list path))) (manual-parts nil) (dom-node nil)) (let* ((continue t)) (while continue (setq dom-node (treemacs-find-in-dom goto-path)) (if (or (null dom-node) (null (treemacs-dom-node->position dom-node))) (if (cdr goto-path) (progn (setq manual-parts (cons ... manual-parts)) (setq goto-path (-butlast goto-path))) (setq goto-path (car goto-path))) (setq continue nil)))) (let* ((btn (treemacs-dom-node->position dom-node)) (search-result (if manual-parts (catch '--cl-block-search-- (if (memq ... treemacs--closed-node-states) (progn ... ...)) (while manual-parts (let ... ... ... ... ...)) btn) (goto-char btn)))) (if (eq 'follow-failed search-result) (prog1 nil (goto-char start)) (treemacs-dom-node->set-position! (treemacs-find-in-dom path) search-result) search-result)))
  treemacs--find-custom-node((lsp-treemacs-generic-root "my_project"))
  (cond ((stringp path) (if (and (eq t treemacs--in-this-buffer) (file-exists-p path)) (progn (treemacs-find-file-node path project)))) ((or (symbolp path) (symbolp (car path)) (stringp (car path))) (treemacs--find-custom-node path)) (t (error "Path type did not match: %S" path)))
  (let ((path path)) (cond ((stringp path) (if (and (eq t treemacs--in-this-buffer) (file-exists-p path)) (progn (treemacs-find-file-node path project)))) ((or (symbolp path) (symbolp (car path)) (stringp (car path))) (treemacs--find-custom-node path)) (t (error "Path type did not match: %S" path))))
  (save-excursion (let ((path path)) (cond ((stringp path) (if (and (eq t treemacs--in-this-buffer) (file-exists-p path)) (progn (treemacs-find-file-node path project)))) ((or (symbolp path) (symbolp (car path)) (stringp (car path))) (treemacs--find-custom-node path)) (t (error "Path type did not match: %S" path)))))
  treemacs-find-node((lsp-treemacs-generic-root "my_project"))
  (let* ((button (treemacs-find-node updated-path))) (put-text-property (or (previous-single-property-change (1+ button) 'button) (point-min)) (or (next-single-property-change button 'button) (point-max)) :busy nil))
  (let (buffer-read-only) (treemacs-update-node top-path) (let* ((button (treemacs-find-node updated-path))) (put-text-property (or (previous-single-property-change (1+ button) 'button) (point-min)) (or (next-single-property-change button 'button) (point-max)) :busy nil)))
  (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* ((button (treemacs-find-node updated-path))) (put-text-property (or (previous-single-property-change (1+ button) 'button) (point-min)) (or (next-single-property-change button 'button) (point-max)) :busy nil))))
  (progn (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* ((button (treemacs-find-node updated-path))) (put-text-property (or (previous-single-property-change (1+ button) 'button) (point-min)) (or (next-single-property-change button 'button) (point-max)) :busy nil)))))
  (if it (progn (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* ((button (treemacs-find-node updated-path))) (put-text-property (or (previous-single-property-change ... ...) (point-min)) (or (next-single-property-change button ...) (point-max)) :busy nil))))))
  (let ((it (treemacs-get-local-buffer))) (if it (progn (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* ((button ...)) (put-text-property (or ... ...) (or ... ...) :busy nil)))))))
  (progn (let ((it (treemacs-get-local-buffer))) (if it (progn (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* (...) (put-text-property ... ... :busy nil))))))))
  (if (= 0 count) (progn (let ((it (treemacs-get-local-buffer))) (if it (progn (save-current-buffer (set-buffer it) (let (buffer-read-only) (treemacs-update-node top-path) (let* ... ...))))))))
  (let* ((count (let* ((v treemacs--async-update-count) (v top-path)) (puthash v (- (gethash v v nil) 1) v)))) (if (= 0 count) (progn (let ((it (treemacs-get-local-buffer))) (if it (progn (save-current-buffer (set-buffer it) (let ... ... ...))))))))
  treemacs--async-update-part-complete((lsp-treemacs-generic-root "my_project") ...
  (closure ((children-fn closure (t) (&optional btn item callback) (ignore btn item callback) ...
  funcall((closure ((children-fn closure (t) (&optional btn item callback) (ignore btn item callback)...
  (save-current-buffer (set-buffer buffer) (funcall callback (lsp-treemacs-filter-if-needed result)))
  (with-current-buffer buffer (funcall callback (lsp-treemacs-filter-if-needed result)))
  (progn (with-current-buffer buffer (funcall callback (lsp-treemacs-filter-if-needed result))))
  (if (buffer-live-p (get-buffer buffer)) (progn (with-current-buffer buffer (funcall callback (lsp-treemacs-filter-if-needed result)))))
  (when (buffer-live-p (get-buffer buffer)) (with-current-buffer buffer (funcall callback (lsp-treemacs-filter-if-needed result))))
  (lsp-treemacs-wcb-unless-killed buffer (funcall callback (lsp-treemacs-filter-if-needed result)))
yyoncho commented 1 year ago

@bastianbeischer is this with lsp-start-plain? Because it still seems to me that you are running some odd version of the packages.

jcaw commented 1 year ago

I see the issue for me - Doom has treemacs pinned to a version using the old interface, while it has lsp-treemacs pinned to for lsp-treemacs, it's downloading a newer version. I've opened a PR to fix it.

bastianbeischer commented 1 year ago

@yyoncho Yes this is reproducible with lsp-start-plain. Steps:

1) M-x lsp-start-plain 2) Open a python file (see below) 3) Set a breakpoint 4) M-: (require 'dap-python) 5) M-x customize-variable dap-python-debugger -> debugpy 6) M-x treemacs (<- it does not happen without this step) 7) M-x dap-debug -> Python run file (buffer) 8) In sessions buffer open the current session, expand as far as possible and try to jump the current point of execution (double click on current line)

I guess step 5 is not strictly needed, but I have debugpy instead of ptvsd here, so...

Any simple python file will do, example:

#!/usr/bin/env python

import sys

print("hello")
print(sys.argv)
bastianbeischer commented 1 year ago

@yyoncho Any ideas on this one? Can you reproduce it with the recipe above?

yyoncho commented 1 year ago

I haven't had the time. But based on the description this is for treemacs repo.

yyoncho commented 1 year ago

IOW the order of using treemacs API should not break treemacs.

gsilverstein commented 1 year ago

I see the issue for me - Doom has treemacs pinned to a version using the old interface, while ~it has lsp-treemacs pinned to~ for lsp-treemacs, it's downloading a newer version. I've opened a PR to fix it.

@jcaw did doom ever make this alteration? I seem to have the same problem. As a work around did you just remove the pins in modules/ui/treemacs/packages.el?

gsilverstein commented 1 year ago

Found his PR for those looking to do this on their own for now: https://github.com/doomemacs/doomemacs/pull/6887 thank you for this @jcaw

Alexander-Miller commented 1 year ago

Debugger entered--Lisp error: (wrong-type-argument listp lsp-treemacs-generic-root)

I tackled the error over at https://github.com/Alexander-Miller/treemacs/issues/990. This issue should be fixed now if your treemacs version is up-to-date.