Skip to content

Commit

Permalink
Merge branch 'pr-9'
Browse files Browse the repository at this point in the history
  • Loading branch information
non-Jedi committed May 14, 2020
2 parents 9f126d0 + 10f8fee commit 9d48245
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ To work around this issue, you can:
1. Set =eglot-connect-timeout= to a very high value.
- Progress of the SymbolServer can be monitored in the =*EGLOT
(ProjectName/julia-mode) stderr*= buffer.
2. Run the following:
2. Run the following, from your project directory:

#+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/ 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: 2 additions & 16 deletions eglot-jl.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

;; Copyright (C) 2019 Adam Beckmeyer

;; Version: 1.2.0
;; Version: 2.0.0
;; Author: Adam Beckmeyer <adam_git@thebeckmeyers.xyz>
;; Maintainer: Adam Beckmeyer <adam_git@thebeckmeyers.xyz>
;; URL: https://github.com/non-Jedi/eglot-jl
Expand Down Expand Up @@ -52,22 +52,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"
"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 @@ -85,7 +71,7 @@ Otherwise returns nil"
,@eglot-jl-julia-flags
,(concat "--project=" eglot-jl-base)
,(expand-file-name "eglot-jl.jl" eglot-jl-base)
,(eglot-jl--env (buffer-file-name))
,(file-name-directory (buffer-file-name))
,eglot-jl-depot))

;;;###autoload
Expand Down
23 changes: 22 additions & 1 deletion eglot-jl.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Usage:
# julia --project=path/to/eglot-jl path/to/eglot-jl/eglot-jl.jl [SOURCE_PATH] [DEPOT_PATH]

# Get the source path. In order of increasing priority:
# - default value: pwd()
# - command-line: ARGS[1]
src_path = length(ARGS) >= 1 ? ARGS[1] : pwd()

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

# Get the project environment from the source path
project_path = something(Base.current_project(src_path), Base.load_path_expand(LOAD_PATH[2])) |> dirname

# Make sure that we only load packages from this environment specifically.
empty!(LOAD_PATH)
push!(LOAD_PATH, "@")
Expand All @@ -9,5 +29,6 @@ Pkg.instantiate()

using LanguageServer, SymbolServer

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

0 comments on commit 9d48245

Please sign in to comment.