diff --git a/README.org b/README.org index 554fa7c..eff2573 100644 --- a/README.org +++ b/README.org @@ -27,15 +27,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 diff --git a/eglot-jl.el b/eglot-jl.el index 490ae09..daa249d 100644 --- a/eglot-jl.el +++ b/eglot-jl.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2019 Adam Beckmeyer -;; Version: 1.2.0 +;; Version: 2.0.0 ;; Author: Adam Beckmeyer ;; Maintainer: Adam Beckmeyer ;; URL: https://github.com/non-Jedi/eglot-jl @@ -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. @@ -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 diff --git a/eglot-jl.jl b/eglot-jl.jl index 754899f..da6af7f 100644 --- a/eglot-jl.jl +++ b/eglot-jl.jl @@ -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, "@") @@ -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)