-
Notifications
You must be signed in to change notification settings - Fork 11
/
eglot-jl.el
97 lines (77 loc) · 3.19 KB
/
eglot-jl.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;;; eglot-jl.el --- Julia support for eglot -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Adam Beckmeyer
;; Version: 2.4.0
;; Author: Adam Beckmeyer <adam_git@thebeckmeyers.xyz>
;; Maintainer: Adam Beckmeyer <adam_git@thebeckmeyers.xyz>
;; URL: https://github.com/non-Jedi/eglot-jl
;; Keywords: convenience, languages
;; Package-Requires: ((emacs "25.1") (eglot "1.4") (project "0.8.1") (cl-generic "1.0"))
;; License: CC0
;; This file is not part of GNU Emacs.
;;; License:
;; To the extent possible under law, Adam Beckmeyer has waived all
;; copyright and related or neighboring rights to eglot-jl. This
;; work is published from: United States.
;;; Commentary:
;; This package loads support for the Julia language server into eglot
;; and package.el. This provides IDE-like features for editing
;; julia-mode buffers. After installing this package, to load support
;; for the Julia language server, run eglot-jl-init. After that,
;; running the eglot function in a julia-mode buffer should work
;; properly.
;;; Code:
(require 'cl-generic)
(require 'eglot)
(require 'project)
(defconst eglot-jl-base (file-name-directory load-file-name))
(defgroup eglot-jl nil
"Interaction with LanguageServer.jl LSP server via eglot"
:prefix "eglot-jl-"
:group 'applications)
(defcustom eglot-jl-julia-command "julia"
"Command to run the Julia executable."
:type 'string)
(defcustom eglot-jl-julia-flags nil
"Extra flags to pass to the Julia executable."
:type '(repeat string))
(defcustom eglot-jl-depot ""
"Path or paths (space-separated) to Julia depots.
An empty string uses the default depot for ‘eglot-jl-julia-command’
when the JULIA_DEPOT_PATH environment variable is not set."
:type 'string)
(defcustom eglot-jl-language-server-project eglot-jl-base
"Julia project to run language server from.
The project should have LanguageServer and SymbolServer packages
available."
:type 'string)
;; Make project.el aware of Julia projects
(defun eglot-jl--project-try (dir)
"Return project instance if DIR is part of a julia project.
Otherwise returns nil"
(let ((root (or (locate-dominating-file dir "JuliaProject.toml")
(locate-dominating-file dir "Project.toml"))))
(and root (cons 'julia root))))
(cl-defmethod project-root ((project (head julia)))
(cdr project))
(defun eglot-jl--ls-invocation (_interactive)
"Return list of strings to be called to start the Julia language server."
`(,eglot-jl-julia-command
"--startup-file=no"
,(concat "--project=" eglot-jl-language-server-project)
,@eglot-jl-julia-flags
,(expand-file-name "eglot-jl.jl" eglot-jl-base)
,(file-name-directory (buffer-file-name))
,eglot-jl-depot))
;;;###autoload
(defun eglot-jl-init ()
"Load `eglot-jl' to use eglot with the Julia language server."
(interactive)
(add-hook 'project-find-functions #'eglot-jl--project-try)
(add-to-list 'eglot-server-programs
;; function instead of strings to find project dir at runtime
'(((ess-julia-mode :language-id "julia")
(julia-mode :language-id "julia")
(julia-ts-mode :language-id "julia"))
. eglot-jl--ls-invocation)))
(provide 'eglot-jl)
;;; eglot-jl.el ends here