# Emacs-based workflow

**URL:** <https://discourse.julialang.org/t/emacs-based-workflow/19400>\
**Category:** Tooling\
**Tags:** emacs\
**Created:** [January 8, 2019, 10:13pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400 "2019-01-08T22:13:34Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)\
**Post date:** [June 16, 2020, 5:47pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/41 "2020-06-16T17:47:54Z")

</div>

> [@gdkrmr](#):
>
> I have a working version of `lsp-julia` under [https://github.com/gdkrmr/lsp-julia](https://github.com/gdkrmr/lsp-julia). It works fine except for linting and cannot figure out what the problem is. There are a number of github issues and patches to the different programs that have to interface to make a language server work, feel free to investigate yourself.

How can I try it? I suppose that if I just try to install lsp-julia from my .spacemacs file I’m not going to get your version.

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [June 17, 2020, 8:29pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/42 "2020-06-17T20:29:58Z")

</div>

If you want to try it from scratch, follow this gist:  
[https://gist.github.com/gdkrmr/624e423f774768563f30e1bd719579a4](https://gist.github.com/gdkrmr/624e423f774768563f30e1bd719579a4)

The thing is, that you have to apply a small patch to LanguageServer.jl, no idea why this is not necessary from VScode. From Spacemacs you can simply add

```julia
     (lsp-julia :location (recipe :fetcher github
                                  :repo "gdkrmr/lsp-julia"
                                  :files (:defaults "languageserver")))

```

to `dotspacemacs-additional-packages`. And point `lsp-julia-package-dir` to where the patched versions of the julia packages are (see the patch in the gist).

---

<div class="post-metadata">

**Author:** ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)\
**Post date:** [July 1, 2020, 11:12am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/43 "2020-07-01T11:12:37Z")

</div>

Back again.  
As said in a previous comment, I managed to get eglot-jl working. But then I noticed something strange: some packages actually get autocompletion (eg: Flux) but many others doesn’t (VegaLite, GLM, Convex, JuMP…). What could cause this behavior? I tried to precompile them outside emacs, to precompilation inside emacs, but nothing worked

---

<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:** [July 1, 2020, 2:27pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/44 "2020-07-01T14:27:43Z")

</div>

An explanation could be that the SymbolServer hasn’t indexed all dependencies of your project yet (this process can literally take hours in some cases). You know indexing is done when you see something like this in the server output ( in the `*EGLOT (xxx/julia-mode) events*` buffer):

```julia
[ Info: Received new data from Julia Symbol Server.

```

If all dependencies are not indexed, you only have to wait and everything should work ultimately. If indexing is already finished, and autocompletion still does not work for some packages, then I’m not sure what the problem could be…

---

<div class="post-metadata">

**Author:** ![olep](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@olep](https://discourse.julialang.org/u/olep)\
**Post date:** [July 1, 2020, 2:47pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/45 "2020-07-01T14:47:18Z")

</div>

Unfortunately, it’s the second case you mention.  
Now I installed new packages since the first time I did the indexing process, but even packages that were present and even precompiled the first time I installed and ran eglot never obtained completion.  
But do not worry, this is not suck a big problem, most of the main packages I use daily are correctly indexed and get autocompletion. I was wondering if the problem is already known and if I should do something fancy (expecially for freshly installed packages, which I installed after the first indexing)

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [July 1, 2020, 7:38pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/46 "2020-07-01T19:38:25Z")

</div>

I don’t get any autocompletion at all when editing .jmd files in polyglot, with julia-mode and eglot and company all running in the julia sub-buffer.

I realize this is a bit of a weird scenario. But should this be supported?

Steps to reproduce:

1. Put this in a file named foo.jmd and removed the \ character that’s just there to make it possible to see what’s up on this forum…

````julia
hello world,
```julia
x = collec
\```

````

1. Now open this file in emacs, put it in poly-markdown-mode, go to the line that says `x = collec` and see if you indeed wind up in a julia mode sub-buffer… You should. In that buffer, do M-x eglot to enable eglot, and M-x company-mode to enable autocompletion… observe that it doesn’t do any of the cool stuff shown on the eglot-jl page. At least not for me.

NOTE: I still get help in the minibuffer… but I don’t get autocomplete menus

---

<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:** [July 1, 2020, 9:07pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/47 "2020-07-01T21:07:45Z")

</div>

I can reproduce. A (very) short investigation seems to indicate that when the julia sub-buffer is created by polymode, the company back-end is not set up in the same way as for a “normal” julia-mode buffer.

I haven’t managed to correctly configure company, though, so I’m not sure where to go from here…

---

<div class="post-metadata">

**Author:** ![prassee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prassee/32/6605_2.png) [@prassee](https://discourse.julialang.org/u/prassee)\
**Post date:** [July 16, 2020, 5:28am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/48 "2020-07-16T05:28:28Z")

</div>

Hi I moved to eglot-jl from lsp-julia. Installed using `use-package eglot-jl` and did `eglot-init-jl` as mentioned in the readme.

With the latest version, I get an issue with jump to definitions i.e I could not navigate to functions defined in other .jl files.

Please let me know if anybody have face this issue before or what I’m missing.

---

<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:** [July 16, 2020, 10:27pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/49 "2020-07-16T22:27:47Z")

</div>

> [@prassee](#):
>
> I could not navigate to functions defined in other .jl files.

Could you please elaborate on the relationship between the files? Files in the same Julia project/package? Several files that are not part of any Julia project but are in the same directory (i.e. the same eglot project)?

---

<div class="post-metadata">

**Author:** ![prassee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prassee/32/6605_2.png) [@prassee](https://discourse.julialang.org/u/prassee)\
**Post date:** [July 17, 2020, 4:36am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/50 "2020-07-17T04:36:55Z")

</div>

I have a `main.jl` and used `include` directive to import other files. I can navigate to symbols and function definitions with in the file but not outside main.jl.  
The exact error / warning message  
`Read error: Is a directory`

_(As a side note, I faced the the same issue in lsp-julia and reported it is still pending)_

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [July 17, 2020, 7:44pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/51 "2020-07-17T19:44:58Z")

</div>

That sounds like an issue that I _think_ has been fixed in the latest release of LanguageServer.jl. Until we get around to bumping that version, you can customize `eglot-jl-language-server-project` to point to a `Project.toml` with the latest release of LanguageServer and SymbolServer installed to see if that fixes it.

---

<div class="post-metadata">

**Author:** ![prassee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prassee/32/6605_2.png) [@prassee](https://discourse.julialang.org/u/prassee)\
**Post date:** [July 18, 2020, 1:09am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/52 "2020-07-18T01:09:36Z")

</div>

> [@non-Jedi](#):
>
> eglot-jl-language-server-project

@non-Jedi can you help me understand about the `eglot-jl-language-server-project` is that a setting in `eglot-jl`.

---

<div class="post-metadata">

**Author:** ![prassee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prassee/32/6605_2.png) [@prassee](https://discourse.julialang.org/u/prassee)\
**Post date:** [July 21, 2020, 6:13am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/53 "2020-07-21T06:13:11Z")

</div>

@non-Jedi somehow I’ve found myself how to set path or project.toml with latest version of languageserver.jl to `eglot-jl-language-server-project` but still the same error.

Its really sad to see emacs not getting any required attention.

---

<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:** [July 22, 2020, 9:49am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/54 "2020-07-22T09:49:54Z")

</div>

> [@prassee](#):
>
> Its really sad to see emacs not getting any required attention.

I’m not sure what warrants this statement. From whom is “emacs not getting any required attention”? From the julia community?

* * *

Anyway, I can confirm that updating `LanguageServer` and `SymbolServer` to their latest versions does not solve the issue. It looks like the problem occurs because in the case of relative file paths, `LanguageServer` replies with URIs such as

```julia
file://foo.jl

```

instead of something like

```julia
file:///absolute/path/to/foo.jl

```

which is what would happen when `include`ing a julia source file with an absolute path. And relative file URIs are parsed by the `url-parse` emacs package as having an host part and no file name (whereas absolute file URIs are parsed as having a filename but no host part).

I’m not sure whether the fix should belong to `eglot.el` or `url-parse.el`, but in any case it does not seem to have much to do with anything related to either `eglot-jl.el` or `LanguageServer` (unless it is somewhat unorthodox to refer to relative file URIs in the LSP protocol, but this seems to be supported by VScode without any problem).

A fix might be provided by monkey-patching `eglot.el` so that file paths in URIs are correctly extracted in all cases:

```elisp
(eval-after-load 'eglot
  '(defun eglot--uri-to-path (uri)
     "Convert URI to a file path."
     (when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
     (let* ((url (url-generic-parse-url (url-unhex-string uri)))
            (retval (concat (url-host url)
                            (url-filename url))))
       (if (eq system-type 'windows-nt) (substring retval 1) retval))))

```

Putting the above snippet in your emacs init file might fix the issue. But beware: this has not been thoroughly tested and might break other unrelated things.

As I said, I’m not sure whether the fix belongs to `eglot.el` or `url-parse.el` (does anyone here have any opinion on this?), but feel free to file an issue on either one of these packages to discuss this topic. If you do, please also feel free to propose the above code as a tentative fix.

I haven’t checked, but if `lsp-julia` (via `lsp-mode`) relies on `url-parse` in the same way that `eglot` does, that might explain why both packages face the same issue. So this might also be an opportunity to make some progress on the issue you seem to have filed with `lsp-julia`.

---

<div class="post-metadata">

**Author:** ![prassee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prassee/32/6605_2.png) [@prassee](https://discourse.julialang.org/u/prassee)\
**Post date:** [July 23, 2020, 1:02am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/55 "2020-07-23T01:02:06Z")

</div>

Thanks for the snippet, I 'm using elgot only for Julia mode. As you suggested I have installed the snippet on emacs init. It takes to references but not in some cases (I’ll try to find out those).

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [July 23, 2020, 1:09am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/56 "2020-07-23T01:09:15Z")

</div>

For reference, the issue I thought had solved this is below. The server should never be replying with relative URIs, so this is a bug in the server. I’ll reopen the issue since it doesn’t seem to have actually been fixed.

[https://github.com/julia-vscode/LanguageServer.jl/issues/660](https://github.com/julia-vscode/LanguageServer.jl/issues/660)

---

<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:** [July 23, 2020, 7:45am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/57 "2020-07-23T07:45:37Z")

</div>

Ah, sorry, it looks like I have been too careless when doing tests: I can now confirm that the latest released `LanguageServer` indeed fixes that.

Should we perhaps release a new version of `eglot-jl` that relies on up-to-date versions of `LanguageServer` and `SymbolServer`?

---

<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:** [July 23, 2020, 8:02am UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/58 "2020-07-23T08:02:45Z")

</div>

@prassee Here is a minimal set of steps to test whether everything is fixed with a newer version of `LanguageServer`:

1. **Create an up-to-date environment.** From a fresh Julia REPL:

```julia
julia> using Pkg

julia> pkg"activate /tmp/eglotTest"
 Activating new environment at `/tmp/eglotTest/Project.toml`

julia> pkg"add LanguageServer SymbolServer"
   Updating registry at `~/.julia/registries/General`
   Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Resolving package versions...
Updating `/tmp/eglotTest/Project.toml`
  [2b0e0bc5] + LanguageServer v3.2.0
  [cf896787] + SymbolServer v5.1.0
Updating `/tmp/eglotTest/Manifest.toml`
  [...]

```

1. **Use this environment in `eglot-jl.el`.** Within emacs, evaluate this before opening your julia source file:

```julia
(setq eglot-jl-language-server-project "/tmp/eglotTest")

```

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [July 23, 2020, 12:38pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/59 "2020-07-23T12:38:31Z")

</div>

> [@ffevotte](#):
>
> Should we perhaps release a new version of `eglot-jl` that relies on up-to-date versions of `LanguageServer` and `SymbolServer` ?

We definitely should. Are you not getting a crash on startup due to [Handle arbitrary values in response to workspace/configuration request · Issue #806 · julia-vscode/LanguageServer.jl · GitHub](https://github.com/julia-vscode/LanguageServer.jl/issues/806) ? That would be only thing I’m concerned about before releasing.

EDIT: nevermind. I think that user merely configured things wrong on the eglot side. Feel free to update the Project.toml/Manifest.toml and tag a new release. 🙂

---

<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:** [July 23, 2020, 4:10pm UTC](https://discourse.julialang.org/t/emacs-based-workflow/19400/60 "2020-07-23T16:10:04Z")

</div>

> [@non-Jedi](#):
>
> Feel free to update the Project.toml/Manifest.toml and tag a new release.

I made a PR; I’m just going to use it a bit more to try and see whether there are regressions. If I (and anyone willing to try this version) don’t find any quirk, I’ll merge this in the coming days…

> <https://github.com/non-Jedi/eglot-jl/pull/16>
>
> \# v2.1.0
> 
> \## Added
> 
> \- \`eglot-jl-language-server-project\` variable allowing t…o customize the Julia environment in which LanguageServer and SymbolServer are found (#13)
> 
> \## Changed
> 
> \- updated \`LanguageServer\` and \`SymbolServer\` to their latest versions.

[Previous page](https://discourse.julialang.org/t/emacs-based-workflow/19400.md?page=2)

[Next page](https://discourse.julialang.org/t/emacs-based-workflow/19400.md?page=4)
