# Emacs + lsp mode

**URL:** <https://discourse.julialang.org/t/emacs-lsp-mode/53427>\
**Category:** Tooling\
**Tags:** emacs\
**Created:** [January 16, 2021, 8:48am UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427 "2021-01-16T08:48:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://discourse.julialang.org/u/dean)\
**Post date:** [January 16, 2021, 8:48am UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/1 "2021-01-16T08:48:49Z")

</div>

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

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.

```julia
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!

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [January 17, 2021, 10:13pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/2 "2021-01-17T22:13:21Z")

</div>

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](https://discourse.julialang.org/t/emacs-based-workflow/19400)? 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`.

---

<div class="post-metadata">

**Author:** ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://discourse.julialang.org/u/dean)\
**Post date:** [January 17, 2021, 10:21pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/3 "2021-01-17T22:21:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [January 17, 2021, 10:57pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/4 "2021-01-17T22:57:16Z")

</div>

Here’s my whole setup:

```julia
(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.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [January 19, 2021, 12:48pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/5 "2021-01-19T12:48:48Z")

</div>

> [@dfdx](#):
>
> I _think_ `eglot-jl` covered installation and management of LanguageServer.jl itself

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`:

```julia
(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))

```

---

<div class="post-metadata">

**Author:** ![nsquare](https://avatars.discourse-cdn.com/v4/letter/n/779978/32.png) [@nsquare](https://discourse.julialang.org/u/nsquare)\
**Post date:** [May 7, 2021, 2:19pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/6 "2021-05-07T14:19:54Z")

</div>

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:

```julia
(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](https://tecosaur.github.io/emacs-config/config.html#julia).

---

<div class="post-metadata">

**Author:** ![Anil\_Joshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anil_joshi/32/7869_2.png) [@Anil\_Joshi](https://discourse.julialang.org/u/Anil_Joshi)\
**Post date:** [June 5, 2021, 11:31pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/7 "2021-06-05T23:31:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![George9000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george9000/32/23619_2.png) [@George9000](https://discourse.julialang.org/u/George9000)\
**Post date:** [August 6, 2021, 11:11pm UTC](https://discourse.julialang.org/t/emacs-lsp-mode/53427/8 "2021-08-06T23:11:27Z")

</div>

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.
