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.81k stars 894 forks source link

Volar integration triggers "wrong type `stringp nil`" #3261

Open gagbo opened 2 years ago

gagbo commented 2 years ago

Thank you for the bug report

Bug description

starting lsp in a buffer where (lsp-workspace-root) is nil prevents the correct server from starting even if unrelated to volar

Steps to reproduce

I had the issue in a Rust buffer, it would take time to find the precise scenario though. But for the sake of it:

1) open a .rs file in a Rust workspace

Expected behavior

rust-analyzer starts

Which Language Server did you use?

rust-analyzer in lsp-rust (or lsp-rustic, forgot the exact name)

OS

Linux

Error callstack

;; Using Doom (unpinned)
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  f-absolute\?(nil)
  f-relative\?(nil)
  f-join(nil ".volarrc")
  lsp-volar--activate-p("/path/to/src/sr..." rustic-mode)
  lsp--matching-clients\?(#s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode -0x35f8f43cc3eefb2>) :test\? #f(compiled-function () #<bytecode 0x1eaa8c21904628f>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x26bc7e3> :request-handlers #<hash-table equal 0/65 0x26bc909> :response-handlers #<hash-table eql 0/65 0x26bc929> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x26bc949> :action-handlers #<hash-table equal 0/65 0x276e68f> :major-modes nil :activation-fn lsp-volar--activate-p :priority 0 :server-id volar-api :multi-root nil :initialization-options #f(compiled-function () #<bytecode 0x771b9290c0c3199>) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn #f(compiled-function (workspace) #<bytecode 0x7686d4704167dcf>) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x276e6af> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x1730d047a8cabba3>) :download-in-progress? nil :buffers nil :synchronize-sections nil))
  apply(lsp--matching-clients\? #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode -0x35f8f43cc3eefb2>) :test\? #f(compiled-function () #<bytecode 0x1eaa8c21904628f>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x26bc7e3> :request-handlers #<hash-table equal 0/65 0x26bc909> :response-handlers #<hash-table eql 0/65 0x26bc929> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x26bc949> :action-handlers #<hash-table equal 0/65 0x276e68f> :major-modes nil :activation-fn lsp-volar--activate-p :priority 0 :server-id volar-api :multi-root nil :initialization-options #f(compiled-function () #<bytecode 0x771b9290c0c3199>) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn #f(compiled-function (workspace) #<bytecode 0x7686d4704167dcf>) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x276e6af> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x1730d047a8cabba3>) :download-in-progress? nil :buffers nil :synchronize-sections nil))
  #f(compiled-function (&rest args) #<bytecode -0xe4b882a66059af3>)(#s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode -0x35f8f43cc3eefb2>) :test\? #f(compiled-function () #<bytecode 0x1eaa8c21904628f>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x26bc7e3> :request-handlers #<hash-table equal 0/65 0x26bc909> :response-handlers #<hash-table eql 0/65 0x26bc929> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x26bc949> :action-handlers #<hash-table equal 0/65 0x276e68f> :major-modes nil :activation-fn lsp-volar--activate-p :priority 0 :server-id volar-api :multi-root nil :initialization-options #f(compiled-function () #<bytecode 0x771b9290c0c3199>) :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn #f(compiled-function (workspace) #<bytecode 0x7686d4704167dcf>) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x276e6af> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x1730d047a8cabba3>) :download-in-progress? nil :buffers nil :synchronize-sections nil))
  -filter(#f(compiled-function (&rest args) #<bytecode -0xe4b882a66059af3>) (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  lsp--filter-clients(#f(compiled-function (&rest args) #<bytecode -0xe4b882a66059af3>))
  (or (lsp--filter-clients (-andfn #'lsp--matching-clients\? #'lsp--server-binary-present\?)) (not (memq +lsp-prompt-to-install-server '(nil quiet))))
  (if (or (lsp--filter-clients (-andfn #'lsp--matching-clients\? #'lsp--server-binary-present\?)) (not (memq +lsp-prompt-to-install-server '(nil quiet)))) (apply fn args) (let ((doom-debug-p (or doom-debug-p (not (eq +lsp-prompt-to-install-server 'quiet))))) (doom-shut-up-a #'lsp--info "No language server available for %S" major-mode)))
  (progn (require 'lsp-mode) (lsp--require-packages) (if (or (lsp--filter-clients (-andfn #'lsp--matching-clients\? #'lsp--server-binary-present\?)) (not (memq +lsp-prompt-to-install-server '(nil quiet)))) (apply fn args) (let ((doom-debug-p (or doom-debug-p (not (eq +lsp-prompt-to-install-server ...))))) (doom-shut-up-a #'lsp--info "No language server available for %S" major-mode))))
  (if (buffer-file-name) (progn (require 'lsp-mode) (lsp--require-packages) (if (or (lsp--filter-clients (-andfn #'lsp--matching-clients\? #'lsp--server-binary-present\?)) (not (memq +lsp-prompt-to-install-server '(nil quiet)))) (apply fn args) (let ((doom-debug-p (or doom-debug-p (not ...)))) (doom-shut-up-a #'lsp--info "No language server available for %S" major-mode)))))
  +lsp-dont-prompt-to-install-servers-maybe-a(#<subr lsp> nil)
  apply(+lsp-dont-prompt-to-install-servers-maybe-a #<subr lsp> nil)
  lsp(nil)
  #<subr funcall-interactively>(lsp nil)
  apply(#<subr funcall-interactively> (lsp nil))
  funcall-interactively(lsp nil)

Anything else?

Basically, why is this call not guarded with (and (lsp-workspace-root) ...) like the others ?

https://github.com/emacs-lsp/lsp-mode/blob/4f675e21595cfc24e3d5412c842990fd1f358418/clients/lsp-volar.el#L66

gagbo commented 2 years ago

It doesn't do it all the time though, so there might either be a race-condition between various Doom hooks, or just a cache that I have for some projects that prevent me from hitting that problematic line.

So it might be solely a Doom issue, I'm still curious about why this line mentionned in the OP isn't treated as the others

yyoncho commented 2 years ago

I am reverting the PR until we get the fix in.