Lsp-mode: Error: Wrong type argument: lsp--workspace, nil

Created on 10 May 2018  路  31Comments  路  Source: emacs-lsp/lsp-mode

When I in JS source code file enable lsp-mode, company-lsp. I got this error:

Company: backend company-lsp error "Wrong type argument: lsp--workspace, nil" with args (prefix)

Here is my config

(use-package lsp-mode
  :ensure t
  :defer t
  :preface (setq lsp-enable-flycheck nil
                 lsp-enable-indentation nil
                 lsp-highlight-symbol-at-point nil)
  :init (add-hook 'prog-mode-hook #'lsp-mode))

(use-package lsp-ui
  :ensure t
  :init (add-hook 'lsp-after-open-hook #'lsp-ui-mode))

(use-package company-lsp
  :ensure t
  :init (push 'company-lsp company-backends)
  :config
  (setq company-lsp-enable-recompletion t
        company-lsp-enable-snippet t
        company-lsp-cache-candidates t
        company-lsp-async t)
  )

Most helpful comment

@stardiviner your lsp-javascript-typescript configuration seems to be off:

https://github.com/emacs-lsp/lsp-javascript

 (require 'lsp-javascript-typescript)
 (add-hook 'js-mode-hook #'lsp-javascript-typescript-enable)
 (add-hook 'typescript-mode-hook #'lsp-javascript-typescript-enable) ;; for typescript support
 (add-hook 'js3-mode-hook #'lsp-javascript-typescript-enable) ;; for js3-mode support
 (add-hook 'rjsx-mode #'lsp-javascript-typescript-enable) ;; for rjsx-mode support

All 31 comments

Which language server do you use? Did you call the lsp-{language}-enable in the buffer you are trying to

:init (add-hook 'prog-mode-hook #'lsp-mode)

you could delete that line, lsp-{language}-enable will take care of that.

I use lsp-javascript-typescript.
edit file index.js in a JS project which initialized with npm init.
I execute lsp-javascript-typescript-enable in JS source code file. still got this error. I have javascript-typescript-langserver installed with npm.
Here is the stacktrace after enabled debug on error:

Debugger entered--Lisp error: (wrong-type-argument lsp--workspace nil)
  signal(wrong-type-argument (lsp--workspace nil))
  company-lsp(prefix)
  apply(company-lsp prefix)
  company-call-backend-raw(prefix)
  apply(company-call-backend-raw prefix)
  company--force-sync(company-call-backend-raw (prefix) company-lsp)
  company-call-backend(prefix)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer index.js> #<window 6 on index.js> 75 3)
  apply(company-idle-begin (#<buffer index.js> #<window 6 on index.js> 75 3))
  timer-event-handler([t 23284 10732 386215 nil company-idle-begin (#<buffer index.js> #<window 6 on index.js> 75 3) nil 388999])

Have you tried updating the company-lsp package?

I updated company-lsp before. Use latest version on MELPA. I tried again. It works now. Don't know what caused this problem. Thanks for your help @vibhavp .

@stardiviner I am encountering the exact same error. Any idea on what the error may have been? Did you change something in your init.el? Care to post a dump of which packages you have installed, along with any relevant configs?

Would be mostly appreciated!

@jonasws what language server do you use? I usually get that error when the language server has crashed/failed to start. You may check whether the LSP server process is up and running.

I am using the javascript-typescript-langserver language server. FYI I am using the react layer from Spacemacs where this error occurs. I will check out how the actual language server process is doing.

I tried digging into the details of the langserver itself, without any luck. Does the langserver have to be fired up on a particular port? Isn't this supposed to be handled "automatically"?

I'm getting this error whenever I quit emacs after using LSP

I get the error whenever I reach some point in the code that is eligible for completion.

@jonasws you may check whether the external process(LSP server) is running from your task manager. At this point LSP mode does not handle server crashed event gracefully(https://github.com/emacs-lsp/lsp-mode/issues/285) so if your server has crashed/not started you will get that error.

Weird, I got this problem again! and here is the traceback:

Debugger entered--Lisp error: (wrong-type-argument lsp--workspace nil)
  signal(wrong-type-argument (lsp--workspace nil))
  company-lsp(prefix)
  apply(company-lsp prefix)
  company--force-sync(company-lsp (prefix) company-lsp)
  company--multi-backend-adapter((company-lsp :with company-yasnippet) prefix)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer *Org Src My JavaScript Language Syntax Reference.org[ js ]*> #<window 8 on *Org Src My JavaScript Language Syntax Reference.org[ js ]*> 50 43)
  apply(company-idle-begin (#<buffer *Org Src My JavaScript Language Syntax Reference.org[ js ]*> #<window 8 on *Org Src My JavaScript Language Syntax Reference.org[ js ]*> 50 43))
  timer-event-handler([t 23327 35142 311121 nil company-idle-begin (#<buffer *Org Src My JavaScript Language Syntax Reference.org[ js ]*> #<window 8 on *Org Src My JavaScript Language Syntax Reference.org[ js ]*> 50 43) nil 362999])

And the external language lsp-javascript-typescript is not started at all.

Here is my config:

(use-package lsp-mode
  :ensure t
  :preface (setq lsp-enable-flycheck nil
                 lsp-enable-indentation nil
                 lsp-highlight-symbol-at-point nil)
  )

(use-package lsp-ui
  :ensure t
  :init (add-hook 'lsp-after-open-hook #'lsp-ui-mode)
  :config
  (setq lsp-ui-doc-enable nil
        lsp-ui-doc-header t
        lsp-ui-doc-include-signature t
        ;; lsp-ui-doc-position 'at-point
        )
  )

(use-package company-lsp
  :ensure t
  :init
  (defun my:company-lsp-enable ()
    (my-company-add-backend-locally 'company-lsp))
  (add-hook 'lsp-mode-hook #'my:company-lsp-enable)
  :config
  (setq company-lsp-enable-recompletion t
        company-lsp-enable-snippet t
        company-lsp-cache-candidates t
        company-lsp-async t)
  )

(use-package lsp-javascript-typescript
  :ensure t
  :init (require 'lsp-javascript-typescript)
  (add-hook 'js-mode-hook #'lsp-mode)
  (add-hook 'typescript-mode-hook #'lsp-mode) ; for typescript support
  (add-hook 'js3-mode-hook #'lsp-mode) ; for js3-mode support
  (add-hook 'rjsx-mode #'lsp-mode) ; for rjsx-mode support
  )

After a simple Edebug on company-lsp, error occurs on (lsp--capability "completionProvider").

@stardiviner your lsp-javascript-typescript configuration seems to be off:

https://github.com/emacs-lsp/lsp-javascript

 (require 'lsp-javascript-typescript)
 (add-hook 'js-mode-hook #'lsp-javascript-typescript-enable)
 (add-hook 'typescript-mode-hook #'lsp-javascript-typescript-enable) ;; for typescript support
 (add-hook 'js3-mode-hook #'lsp-javascript-typescript-enable) ;; for js3-mode support
 (add-hook 'rjsx-mode #'lsp-javascript-typescript-enable) ;; for rjsx-mode support

Thanks. Seems my config is deprecated for a long time.

I am having the same issue with spacemacs. How can I fix it?

@pavilion which LSP server do you use? Can you paste your configuration?

Hi @yyoncho
This is my
~/.emacs.d/layers/+tools/lsp/
https://gist.github.com/pavilion/ed0b024054fea3c73a501b9e51d28a49

@pavilion this is not the part I am interested in but only the configuration of LSP UI. Do you have more lsp related stuff (or spacemacs layers?).

Maybe you are interested in this?

Yes, which language server do you use? Do you call lsp-{language}-enable?

Sorry, I actually attached you the wrong gitst. Should be this one.

And this is the issue I submitted for spacemacs
https://github.com/syl20bnr/spacemacs/issues/11015

I still have not found the fix... did you have any luck? @yyoncho

The exception is usually caused by the failure in the LSP server(usually server misconfiguration). Can you check the content of the err buffer?

@yyoncho
I basically get this
Package iswitchb is obsolete!
Company: An error occurred in auto-begin Company: backend company-lsp error "Wrong type argument: lsp--workspace, nil" with args (prefix)

There should be *{language} stderr* buffer.

  1. Check whether the language server you are trying to run is started.
  2. Try to manually configure the LSP instead of using the layer - as I mentioned few times in this thread, probably the LSP server has died. The instructions are located here https://github.com/emacs-lsp/lsp-javascript . You have to find out why the LSP server is not starting.

There is a PR related to this in spacemacs which works fine right out of the box. I have merged it with the latest develop.

I get this error in php-mode buffers, using felixbecker/php-language-server, as of today (updating to the melpa version 20181211.1641); typescript/javascript works fine. The language server is up and running. I'm not using spacemacs. Emacs is 26.1. I removed the old configuration stuff; ui-peek and sideline work, hover does not. Did I miss something converting the configuration?

After the configuration-changes, I have left

  (require 'lsp)
  (require 'lsp-clients)
  (require 'lsp-ui)
  (setq lsp-prefer-flymake nil)
  (add-hook 'prog-mode-hook 'lsp)

  (flycheck-define-generic-checker 'lsp-php-ui
    "A syntax checker using the Language Server Protocol (RLS)
    provided by lsp-mode.
    See https://github.com/emacs-lsp/lsp-mode."
    :start #'lsp-ui-sideline--flycheck
    :modes '(php-mode) ; Need a default mode
    :predicate (lambda () lsp-mode)
    :error-explainer (lambda (e) (flycheck-error-message e))
    :next-checkers '((warning . php)))

This usually indicates stale bytecode - can reinstall all lsp components(lsp-ui, company-lsp, lsp-mode) restart emacs and if the issue persists post your errorstack( call toggle-debug-on-error to collect it)?

Thanks a lot, that was indeed the case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sid-kap picture sid-kap  路  5Comments

MaskRay picture MaskRay  路  5Comments

kmdouglass picture kmdouglass  路  3Comments

yyoncho picture yyoncho  路  5Comments

cprussin picture cprussin  路  3Comments