emacs-lsp / lsp-metals

lsp-mode :heart: metals
https://emacs-lsp.github.io/lsp-metals
GNU General Public License v3.0
58 stars 33 forks source link

Upon the installation, issues with connecting to server/debug messages on opening .scala files first time pers session #54

Closed limar63 closed 3 years ago

limar63 commented 3 years ago

My current emacs version is 27.2, OS is Ubuntu 20.04,Java version is 11.0.11.

I was following the official guide of installing metals on emacs, did a little change from the course at the start (I first installed required packages/dependencies through M-x package-list-packages and only then did what was going on on the guide, but from my understanding, it shouldn't matter. My current init.el file contains the code related to lsp-mode:

;; Install use-package if not already installed
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)

;; Enable defer and ensure by default for use-package
;; Keep auto-save/backup files separate from source code:  https://github.com/scalameta/metals/issues/1027
(setq use-package-always-defer t
      use-package-always-ensure t
      backup-directory-alist `((".*" . ,temporary-file-directory))
      auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))

;; Enable scala-mode for highlighting, indentation and motion commands
(use-package scala-mode
  :interpreter
    ("scala" . scala-mode))

;; Enable sbt mode for executing sbt commands
(use-package sbt-mode
  :commands sbt-start sbt-command
  :config
  ;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
  ;; allows using SPACE when in the minibuffer
  (substitute-key-definition
   'minibuffer-complete-word
   'self-insert-command
   minibuffer-local-completion-map)
   ;; sbt-supershell kills sbt-mode:  https://github.com/hvesalai/emacs-sbt-mode/issues/152
   (setq sbt:program-options '("-Dsbt.supershell=false"))
)

;; Enable nice rendering of diagnostics like compile errors.
(use-package flycheck
  :init (global-flycheck-mode))

(use-package lsp-mode
  ;; Optional - enable lsp-mode automatically in scala files
  :hook  (scala-mode . lsp)
         (lsp-mode . lsp-lens-mode)
  :config
  ;; Uncomment following section if you would like to tune lsp-mode performance according to
  ;; https://emacs-lsp.github.io/lsp-mode/page/performance/
  ;;       (setq gc-cons-threshold 100000000) ;; 100mb
  ;;       (setq read-process-output-max (* 1024 1024)) ;; 1mb
  ;;       (setq lsp-idle-delay 0.500)
  ;;       (setq lsp-log-io nil)
  ;;       (setq lsp-completion-provider :capf)
  (setq lsp-prefer-flymake nil))

;; Add metals backend for lsp-mode
(use-package lsp-metals)

;; Enable nice rendering of documentation on hover
;;   Warning: on some systems this package can reduce your emacs responsiveness significally.
;;   (See: https://emacs-lsp.github.io/lsp-mode/page/performance/)
;;   In that case you have to not only disable this but also remove from the packages since
;;   lsp-mode can activate it automatically.
(use-package lsp-ui)

;; lsp-mode supports snippets, but in order for them to work you need to use yasnippet
;; If you don't want to use snippets set lsp-enable-snippet to nil in your lsp-mode settings
;;   to avoid odd behavior with snippets and indentation
(use-package yasnippet)

;; Use company-capf as a completion provider.
;;
;; To Company-lsp users:
;;   Company-lsp is no longer maintained and has been removed from MELPA.
;;   Please migrate to company-capf.
(use-package company
  :hook (scala-mode . company-mode)
  :config
  (setq lsp-completion-provider :capf))

;; Use the Debug Adapter Protocol for running tests and debugging
(use-package posframe
  ;; Posframe is a pop-up tool that must be manually installed for dap-mode
  )
(use-package dap-mode
  :hook
  (lsp-mode . dap-mode)
  (lsp-mode . dap-ui-mode)
  )

without the first part of adding melpa, since I got it added already. After doing everything and restarting the Emacs, I proceeded with opening .scala file and on open I get a debug message:

Debugger entered--Lisp error: (void-function -compose)                                                                                                                                                     
  -compose(lsp--client-path->uri-fn lsp--workspace-client)                                                                                                                                                 
  lsp--path-to-uri("pathtoemacs/.emacs.d/index.sqlite")                                                                                                                                            
  #f(compiled-function () #<bytecode 0x15566aea7e91>)()                                                                                                                                                    
  funcall(#f(compiled-function () #<bytecode 0x15566aea7e91>))                                                                                                                                             
  eval((funcall #'#f(compiled-function () #<bytecode 0x15566aea7e91>)))                                                                                                                                    
  custom-initialize-reset(lsp-serenata-index-database-uri (funcall #'#f(compiled-function () #<bytecode 0x15566aea7e91>)))                                                                                 
  custom-declare-variable(lsp-serenata-index-database-uri (funcall #'#f(compiled-function () #<bytecode 0x15566aea7e91>)) "The location to store the index database.\nNote tha..." :group lsp-serenata :ty$
  byte-code("\301\302\303\304 \305\306\307!\310\311\312\313&\10!\210\314\315\316\317\320\321\322\323\324\325&\11\210\326\327\330\331\332DD\333\334\335\320\315\324\336&\11\210\326\337\330..." [lsp-intele$
  require(lsp-php nil t)                                                                                                                                                                                   
  #f(compiled-function (package) #<bytecode 0x15566ad2cc81>)(lsp-php)                                                                                                                                      
  mapc(#f(compiled-function (package) #<bytecode 0x15566ad2cc81>) (ccls lsp-actionscript lsp-ada lsp-angular lsp-bash lsp-beancount lsp-clangd lsp-clojure lsp-cmake lsp-crystal lsp-csharp lsp-css lsp-d $
  seq-do(#f(compiled-function (package) #<bytecode 0x15566ad2cc81>) (ccls lsp-actionscript lsp-ada lsp-angular lsp-bash lsp-beancount lsp-clangd lsp-clojure lsp-cmake lsp-crystal lsp-csharp lsp-css lsp-$
  lsp--require-packages()                                                                                                                                                                                  
  lsp()                                                                                                                                                                                                    
  run-hooks(change-major-mode-after-body-hook prog-mode-hook scala-mode-hook)                                                                                                                              
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook scala-mode-hook))                                                                                                                      
  run-mode-hooks(scala-mode-hook)                                                                                                                                                                          
  scala-mode()                                                                                                                                                                                             
  set-auto-mode-0(scala-mode nil)                                                                                                                                                                          
  set-auto-mode()                                                                                                                                                                                          
  normal-mode(t)                                                                                                                                                                                           
  after-find-file(nil t)                                                                                                                                                                                   
  find-file-noselect-1(#<buffer test.scala> "~/Scala/test.scala" nil nil "~/Python_rofli/Scala/test.scala" (5288230 2065))                                                                    
  find-file-noselect("~/Scala/test.scala" nil nil)                                                                                                                          
  ido-file-internal(raise-frame)                                                                                                                                                                           
  ido-find-file()                                                                                                                                                                                          
  funcall-interactively(ido-find-file)                                                                                                                                                                     
  call-interactively(ido-find-file nil nil)                                                                                                                                                                
  command-execute(ido-find-file)   

I can try to open the .scala file again and it will be opened, but upon trying to activate lsp-mode, it will tell [Disabled] and a bunch of other errors about not having a connection to the server. And according to the debug message, I am supposed to have some kind of index.sqlite inside my .emacs.d folder, but I don't have one, and creating one didn't help. I also followed the alternative LSP server listed there, the "Eglot", and it worked fine, but upon switching back to lsp-mode variant, it was still giving the same error. Any idea how to start debugging this mess? I tried to manually install metals, tried shenanigans with a "coursier", nothing helped.

yyoncho commented 3 years ago

this is a well-known issue - you have to upgrade your dash package version(and in general, it is good to update all your packages when you install a new one)..

limar63 commented 3 years ago

this is a well-known issue - you have to upgrade your dash package version(and in general, it is good to update all your packages when you install a new one)..

Hmm, I don't have one installed in my emacs at all, gonna install and check how it will work. It wasn't required to do in installation and it wasn't grabbed as a part of dependencies.

limar63 commented 3 years ago

Yes, it actually worked. Is this common knowledge that 99.9% people using emacs know about dash and I managed to dodge the mention of it, or it is missed in the emacs metals installation guide and should be added to the guide?

yyoncho commented 3 years ago

I don't quite understand the question - on lsp-mode side, we have pinned issue for that problem.

yyoncho commented 3 years ago

https://github.com/emacs-lsp/lsp-mode/issues

limar63 commented 3 years ago

You are right, sorry, I am not that experienced with using public GitHub pages and finding solutions there. And also the error message in emacs debug is very verbose, wasn't sure which part of the error I am supposed to google.

yyoncho commented 3 years ago

No worries. Unfortunately, there is no way to force updating the dependencies due to melpa limitation.

limar63 commented 3 years ago

I will try to contact people supporting the emacs-metals guide section to mention the dash requirement

yyoncho commented 3 years ago

dash version is a requirement and it is automatically installed when you install lsp-mode. The issue here is that you already had old version of dash package and when you install lsp-mode and that version was incompatible with lsp-mode.

limar63 commented 3 years ago

It was mentioned as "available" on package-list-packages, which, if I understand correctly, means that it is not installed, not that it is not updated, or I am wrong?

yyoncho commented 3 years ago

dash is present 2 times in package-list-packages on my side - from elpa and melpa, one of them will be in state available.