Using LanguageServer.jl with eglot in emacs

Opened a PR to fix the issue you filed. If you get a chance to try the PR and see if you still get crashes, that would be awesome.

2 Likes

Thanks a lot! I will give it a try at some point this week.

Thought I will update here that the fix from @non-Jedi solved the issue I was seeing, and it is now incorporated into the master branch of LanguageServer. Thanks for your fixes @non-Jedi !
As of now I am able to get LanguageServer + eglot running properly using LanguageServer#master SymbolServer#master (no need to pin the other dependencies). Also it seems that there are a lot of updates done at LanguageServer.jl so maybe soon it will not be even necessary to pin SymbolServer to master.

As for the lsp-mode vs. eglot question I managed to get both of them working (@gdkrmr was right it is quite smooth now to get lsp-mode working, thanks for your contributions to lsp-julia!). I decided to continue with eglot in the meantime.
The main reason is that with eglot I can get documentation / code completion of functions from other packages outside of Base which the current module is using while I could not get this information with lsp-mode (see also discussion in this issue ).
A possible reason to use lsp-mode instead would be that it is supposedly possible to make it work with TRAMP (haven’t tried), but I personally find the documentation/completion feature more important.

1 Like

Where did you read this? That sounds really cool, tramp was one of the big reasons for me to switch to emacs entirely!

2 Likes

Originally I saw someone mentioning it in some recent reddit discussion about eglot vs. lsp-mode, but it appears also in the lsp-mode README here.

You will have to have the language server running on the remote server, so I don’t know if it fits your use case. Also I don’t know if it will actually work with LanguageServer.jl, but worth trying.

1 Like

LanguageServer.jl eglot integration is now packaged up at https://github.com/non-Jedi/jleglot and I just created a pending PR to melpa at https://github.com/melpa/melpa/pull/6531. Hope it’s helpful to y’all. :slight_smile:

For anyone wondering how I ended up making sure the project was instantiated, I stole a page from the Revise playbook:

try
    @eval using LanguageServer
catch
    @warn "Unable to import LanguageServer. Instantiating project."
    Pkg.instantiate()
    @eval using LanguageServer
end#try
4 Likes

Thanks everyone for all that great work!

I’ll try it on my home computers.

At work, I have to use Windows. On Windows, the Emacs GUI with Julia has about 1 second of input lag per keystroke. Inside a Cygwin terminal, the lag is livable without the GUI (but still not snappy, like the GUI on Linux). Is this likely to work in that sort of environment?

Anyone also know how to set the executable path in Cygwin?
I’ve just been using emacs as an editor with nice keybindings, but I can’t launch the executable, and copy and paste also does not work well from terminal Emacs on Windows. While it is well integrated on Linux, Windows seems to keep a separate copy paste clipboard for Emacs, as well as a separate “what is highlighted”. Meaning anything copied with M/C + W cannot be pasted externally, and anything highlighted within Emacs (eg, using C+SPACE) cannot be copied with C + INSERT. I can point, click, and drag to copy with C+INSERT, but this does not respect Emacs formatting; it’ll copy line numbers, treat 1 line of text as cutting across all vertically oriented windows, etc.
The fact it isn’t ergonomic to copy/paste, nor can I run code directly within Emacs (I don’t know how / can’t set the executable path), means it is hard to run code within the editor.

Also, a more general emacs question: how does it decide how to split the screen?
I have a relatively square monitor, and emacs always defaults to splitting side by side (equivalent to C-x 3), while with ultra-wide monitors, it splits them one above the other (equivalent to C-x 2). So it seems to be using the screen resolution to always make the opposite choice of what I want.
How can I change this default behavior?

Have you tried the linux subsystem for windows?

No, I don’t have admin access and therefore cannot install/activate WSL.

EDIT:
There is a Linux cluster at work. What I normally do is ssh into it, and run emacs (in the Cygwin terminal).
There I can run Julia code, etc.

However, the master branches of many of my repos have been broken for a couple weeks, as I’m overhauling some of the internals. I have avoided updating the cluster, because I still need to get work done, and have therefore been developing the master branches locally.
This is also probably something that could be solved with Julia environments, letting me keep two separate environments on the Linux cluster. Although being able to work locally would be nice as well.

Also, a more general emacs question: how does it decide how to split the screen?
I have a relatively square monitor, and emacs always defaults to splitting side by side (equivalent to C-x 3 ), while with ultra-wide monitors, it splits them one above the other (equivalent to C-x 2 ). So it seems to be using the screen resolution to always make the opposite choice of what I want.
How can I change this default behavior?

I don’t have experience with customizing this but looking at the docs of split-window-sensibly it seems that if you set split-width-threshold to nil and split-height-threshold to 0 it will try to split the window vertically (and the other way around if you want a horizontal split).

1 Like

How did you obtain emacs? Is this from https://www.gnu.org/software/emacs/download.html or installed via cygwin? My experience has been that the perf of programs intalled via cygwin leaves a lot to be desired. What modes are enabled when you see the input lag (M-x describe-mode)?

Just modify the PATH environment variable? Note that within emacs, you can also modify the exec-path variable.

For the clipboard, try setting both select-enable-clipboard and select-enable-primary to t (just a guess on the problem).

1 Like

Hi, how does one use that recipe? I use the included package.el.

You can use straight or quelpa to install a melpa recipe. If you don’t want to use those, you can just download the package and make sure it’s on your load-path. I’m not exactly sure how you get autoloads working with this setup though, so you might just have to require it. Once the pull request to melpa is accepted you’ll be able to install with package-install if you’ve added melpa to package-archives.

1 Like

I cloned the repository, added the following line to my init:

(add-to-list 'load-path "/home/myuser/Desktop/eglot-jl-master/eglot-jl.el")
(require 'eglot-jl)

I get an error and it seems the the problem is in this line
(defconst eglot-jl-base (file-name-directory load-file-name))

Could you toggle-debug-on-error and paste the traceback either here or in a github issue, please?

Nevermind, I had to add the full directory and not just the .el file.

It seems to be working,

  • but it disconnects and reconnects a lot of times,
  • doesn’t seem to understand stuff that is imported with “using
  • and keeps printing:
[eglot] (warning) Server tried to register unsupported capability `workspace/didChangeWorkspaceFolders'

But this are probably LanguageServer.jl and eglot.el issues.

This is normal, although if it prints it more than once, that means that the language server is restarting. And yes, I certainly wouldn’t call the setup stable at the moment. I’ve been in a bit of a crunch lately, so I haven’t even been using it myself as it’s been getting in the way more than helping.

When the server restarts, it would be great if you could capture the events immediately preceding the restart from the eglot events buffer and submit an issue on github. From there I can route it upstream to eglot or LanguageServer.jl as appropriate.

Sure. Thanks for your hard work!

1 Like

Julia eglot support is now available on melpa as eglot-jl.

https://melpa.org/#/eglot-jl

2 Likes