Emacs + lsp mode

Hello guys!
Been following this discourse for the last two weeks and got a lot of nice tips ! :slight_smile:

So Juno is great, as well as VS code, but I am into Emacs and I would really like to make it work.

I am having problem with settings up Emacs to use Julia.

Using Doom Emacs, I have the line (julia +lsp) enabled in my init.el file.
In my packages.el I added (package! lsp-julia) line. In my REPL I did install LanguageServer.jl.

The problem:
Every time I start edit my Julia source files, the julia-ls is starting and after a couple of seconds crashes.

LSP :: Guessed project root is ~/Documents/Julia
LSP :: Connected to [julia-ls:273531 status:starting].
LSP :: julia-ls has exited (exited abnormally with code 1)

The Julia language server asks me if I want to restart it and if I agree then it repeats this behavior.

Does someone know what can be the problem? Alternatively, can someone tell me how to view the logs?

Thanks in advance!

1 Like

Are you looking specifically for lsp-mode support or just a way to with with Julia from Emacs? Did you see the long thread about Emacs-based workflow? Based on that thread, I set up Emacs with julia-mode, julia-repl and eglot-jl, and I feel pretty comfortable so far. I believe other folks here can provide more useful setups, but not necessary directly based on lsp-mode.

Hey there!
For your question, I am looking for Julia lsp support. I have it in Python,C++ and Java and it works like a charm. Syntax highlighting I already get from the julia-mode that is preinstalled in Doom Emacs. So only the auto completion etc is missing.

About the thread, thanks I’ll definitely check it out!

Would you be able to share with me your configs? I am new to emacs-lisp and that would help!

Here’s my whole setup:

(require 'julia-mode)
(require 'julia-repl)
(add-hook 'julia-mode-hook 'julia-repl-mode)
(add-hook 'julia-mode-hook 'eglot-jl-init)
(add-hook 'julia-mode-hook 'eglot-ensure)
;; key bindings are arbitrary, ignore if you are ok with the defaults
(add-hook 'julia-mode-hook
	  '(lambda ()
	     (local-set-key (kbd "C-d") 'julia-repl-send-line)
	     (local-set-key (kbd "C-c C-c") 'julia-repl-send-buffer)))

;; this caused a timeout error with the default settings
(setq eglot-connect-timeout 300)

;; see Julia manual for the detailed description of this var
(setenv "JULIA_NUM_THREADS" "4")

I think eglot-jl covered installation and management of LanguageServer.jl itself, but I remember I had to spend some time testing different options. I never worked with lsp-mode directly though (currently it’s not installed on my machine), so can’t provide any info on it.

2 Likes

Yes, eglot-jl comes with a Julia environment that it instantiates in order to get the right versions of LanguageServer and SymbolServer. Regular users shouldn’t have to worry about that; simply be aware that the first use of eglot-jl will entail an additional latency in order to actually download and install the required Julia packages.

FWIW, my Julia-related emacs config is basically the same as @dfdx’s one, but based on use-package:

(use-package eglot-jl
  :ensure t
  :defer  t)

(use-package julia-mode
  :ensure t
  :interpreter ("julia" . julia-mode)

  :config
  (add-hook 'julia-mode-hook 'eglot-jl-init)
  (add-hook 'julia-mode-hook 'eglot-ensure))
1 Like

Hi!

I know this topic is 4-months old, but I ran into the exact same issue myself, and found a workaround that does not require eglot. So I am posting here in the hope it can be helpful to someone!

I am using Doom Emacs. I enabled lsp and (julia +lsp) in init.el. I did not install LanguageServer.jl in a Julia REPL.

In my config.el, I added the following lines:

(after! julia-mode
  (add-hook! 'julia-mode-hook
    (setq-local lsp-enable-folding t
                lsp-folding-range-limit 100)))

Everything is working now! The first time you open a Julia file is a bit slow, as lsp-julia needs to install LanguageServer.

For reference, I found this solution here.

1 Like

I moved to doom emacs myself sans evil. Very happy with it.

I followed your directions on doom emacs. While this worked, I found the combo of lsp and flycheck, which was required by lsp to be more distracting than helpful. Flycheck would flag the source with lots of squiggles, endless, inconsequential linting. If I cleared the errors, they would all come back if I typed something new. If flycheck was toggled off, lsp would complain. Finally, I just removed lsp from my init and config completely and enjoyed a far calmer interface. lsp works better in VS Code.