Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let eglot-jl.jl determine the default project path #9

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ To work around this issue, you can:
2. Run the following:

#+begin_src sh
JULIA_LOAD_PATH="@" julia --project=path/to/eglot-jl/ path/to/eglot-jl/eglot-jl.jl path/to/project ""
julia --project path/to/eglot-jl/eglot-jl.jl
#+end_src

The SymbolServer is finished with caching dependencies when it
displays:

#+begin_quote
[ Info: store set
[ Info: Received new data from Julia Symbol Server.
#+end_quote
18 changes: 1 addition & 17 deletions eglot-jl.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,8 @@
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-default-environment "~/.julia/environment/v1.2"
non-Jedi marked this conversation as resolved.
Show resolved Hide resolved
"Path to the Julia environment used if file not in a Julia Project."
:type 'string)

(defconst eglot-jl-base (file-name-directory load-file-name))

(defun eglot-jl--env (dir)
"Find the most relevant Julia Project for a given directory.
If a parent directory to DIR contains a file JuliaProject.toml or
Project.toml, that parent directory is used. If not,
`eglot-jl-default-environment' is used."
(expand-file-name (if dir (or (locate-dominating-file dir "JuliaProject.toml")
(locate-dominating-file dir "Project.toml")
eglot-jl-default-environment)
eglot-jl-default-environment)))

;; Make project.el aware of Julia projects
(defun eglot-jl--project-try (dir)
"Return project instance if DIR is part of a julia project.
Expand All @@ -83,9 +68,8 @@ Otherwise returns nil"
"Return list of strings to be called to start the Julia language server."
`(,eglot-jl-julia-command
,@eglot-jl-julia-flags
,(concat "--project=" eglot-jl-base)
"--project"
non-Jedi marked this conversation as resolved.
Show resolved Hide resolved
,(expand-file-name "eglot-jl.jl" eglot-jl-base)
,(eglot-jl--env (buffer-file-name))
,eglot-jl-depot))

;;;###autoload
Expand Down
26 changes: 23 additions & 3 deletions eglot-jl.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# Make sure that we only load packages from this environment specifically.
# Usage:
# julia --project path/to/eglot-jl/eglot-jl.jl [DEPOT_PATH]

# Get the project environment.
#
# WARNING: this script must be called with the `--project` command-line switch
# for this to work reliably.
project_path = dirname(Base.load_path()[1])
non-Jedi marked this conversation as resolved.
Show resolved Hide resolved
non-Jedi marked this conversation as resolved.
Show resolved Hide resolved

# Get the depot path. In order of increasing priority
# - default value: ""
# - environment: ENV["JULIA_DEPOT_PATH"]
# - command-line: ARGS[1]
depot_path = get(ENV, "JULIA_DEPOT_PATH", "")
if length(ARGS) >= 1
depot_path = ARGS[1]
end

# Make sure that we only load packages from the eglot-jl environment specifically.
import Pkg
Pkg.activate(@__DIR__)
empty!(LOAD_PATH)
push!(LOAD_PATH, "@")

import Pkg
# In julia 1.4 this operation takes under a second. This can be
# crushingly slow in older versions of julia though.
Pkg.instantiate()

using LanguageServer, SymbolServer

server = LanguageServerInstance(stdin, stdout, ARGS[1], ARGS[2])
@info "Running language server" env=Base.load_path()[1] src_path=pwd() project_path depot_path
server = LanguageServerInstance(stdin, stdout, project_path, depot_path)
run(server)