-
Notifications
You must be signed in to change notification settings - Fork 90
Emacs
Adam B edited this page Apr 14, 2019
·
14 revisions
It is possible to use the Julia LanguageServer in Emacs using the lsp-mode
and the lsp-julia
packages. See the README of lsp-julia
to get it working. It also might be helpful to look at this discourse post from @ffevotte to get an idea of the capabilities available.
The following is my (@non-Jedi) config for using LanguageServer.jl
with eglot. I haven't tested it much, and there may be weirdness/dragons here I'm not aware of, but you can base your own config on it if interested. Let me know in the discourse thread if you have trouble getting this working.
(require 'cl-generic)
(defcustom julia-default-depot ""
"The default depot path, used if `JULIA_DEPOT_PATH' is unset"
:type 'string
:group 'julia-config)
(defcustom julia-default-environment "~/.julia/environment/v1.1"
"The default julia environment"
:type 'string
:group 'julia-config)
(defun julia/get-depot-path ()
(or (getenv "JULIA_DEPOT_PATH") julia-default-depot))
;; Make project.el aware of Julia projects
(defun julia/project-try (dir)
(let ((root (or (locate-dominating-file dir "JuliaProject.toml")
(locate-dominating-file dir "Project.toml"))))
(and root (cons 'julia root))))
(add-hook 'project-find-functions 'julia/project-try)
(cl-defmethod project-roots ((project (head julia)))
(list (cdr project)))
(defun julia/get-environment (dir)
(if dir (or (locate-dominating-file dir "JuliaProject.toml")
(locate-dominating-file dir "Project.toml")
(expand-file-name julia-default-environment))
(expand-file-name julia-default-environment)))
;; Setup eglot with julia
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
;; function instead of strings to find project dir at runtime
'(julia-mode . (lambda (interactive)
`("julia"
,(expand-file-name
"~/.emacs.d/lisp/eglot-julia/eglot.jl")
,(julia/get-environment (buffer-file-name))
,(julia/get-depot-path))))))
(add-hook 'julia-mode-hook 'eglot-ensure)
~/.emacs.d/lisp/eglot-julia/eglot.jl
is just:
import Pkg
Pkg.activate(@__DIR__)
using LanguageServer, Sockets, SymbolServer
server = LanguageServer.LanguageServerInstance(stdin, stdout, false,
ARGS[1], ARGS[2], Dict())
server.runlinter = true
run(server)
with the following Project.toml
:
[deps]
LanguageServer = "2b0e0bc5-e4fd-59b4-8912-456d1b03d8d7"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
SymbolServer = "cf896787-08d5-524d-9de7-132aaa0cb996"