non-Jedi / eglot-jl

Wrapper for using Julia LanguageServer.jl with emacs eglot
Creative Commons Zero v1.0 Universal
61 stars 11 forks source link

How to custom the julia environment passed to eglot-jl #23

Closed Ionizing closed 3 years ago

Ionizing commented 3 years ago

Hi, thanks for your fantastic work on eglot-jl, which may help me a lot on julia coding.

It seemed I came across an issue on the julia environment passed to eglot-jl.

My environments

I've installed julia v1.6 on my machine and

$ ls ~/.julia/environments
v1.0 v1.6

in which v1.0 was created by eglot-jl-init and eglot.

If I directly cd into eglot-jl folder and run julia --project eglot-jl.jl, it said:

$ julia --project eglot-jl.jl
  No Changes to `~/.emacs.d/.local/straight/repos/eglot-jl/Project.toml`
  No Changes to `~/.emacs.d/.local/straight/repos/eglot-jl/Manifest.toml`
[ Info: Environment successfully resolved
┌ Info: Running language server
│   env = "/Users/ionizing/.emacs.d/.local/straight/repos/eglot-jl/Project.toml"
│   src_path = "/Users/ionizing/.emacs.d/.local/straight/repos/eglot-jl"
│   project_path = "/Users/ionizing/.emacs.d/.local/straight/repos/eglot-jl"
└   depot_path = ""
┌ Warning: LibSSH2_jll not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/2m6sg/src/SymbolServer.jl:190
┌ Warning: MbedTLS_jll not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/2m6sg/src/SymbolServer.jl:190
┌ Warning: Zlib_jll not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/2m6sg/src/SymbolServer.jl:190
[ Info: Received new data from Julia Symbol Server.

it seemed the SymbolServer and LanguageServer works well.

Also I am using the latest DoomEmacs with (package! eglot-jl) added to packages.el only.

The issue

However, if I open a julia project, then :eglot-jl-init and :eglot, it complained:

[click to expand] `ERROR: LoadError: ArgumentError: Package LanguageServer not found in current path.` ``` [client-request] (id:1) Tue May 11 21:17:31 2021: (:jsonrpc "2.0" :id 1 :method "initialize" :params (:processId 31148 :rootPath "/Users/ionizing/github/namd.jl/" :rootUri "file:///Users/ionizing/github/namd.jl" :initializationOptions #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :capabilities (:workspace (:applyEdit t :executeCommand (:dynamicRegistration :json-false) :workspaceEdit (:documentChanges :json-false) :didChangeWatchedFiles (:dynamicRegistration t) :symbol (:dynamicRegistration :json-false) :configuration t) :textDocument (:synchronization (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t) :completion (:dynamicRegistration :json-false :completionItem (:snippetSupport t) :contextSupport t) :hover (:dynamicRegistration :json-false :contentFormat ["markdown" "plaintext"]) :signatureHelp (:dynamicRegistration :json-false :signatureInformation (:parameterInformation (:labelOffsetSupport t) :activeParameterSupport t)) :references (:dynamicRegistration :json-false) :definition (:dynamicRegistration :json-false) :declaration (:dynamicRegistration :json-false) :implementation (:dynamicRegistration :json-false) :typeDefinition (:dynamicRegistration :json-false) :documentSymbol (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind (:valueSet [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])) :documentHighlight (:dynamicRegistration :json-false) :codeAction (:dynamicRegistration :json-false :codeActionLiteralSupport (:codeActionKind (:valueSet ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"])) :isPreferredSupport t) :formatting (:dynamicRegistration :json-false) :rangeFormatting (:dynamicRegistration :json-false) :rename (:dynamicRegistration :json-false) :publishDiagnostics (:relatedInformation :json-false)) :experimental #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data ())))) [stderr] nil [stderr] No Changes to `~/.julia/environments/v1.0/Project.toml` [stderr] No Changes to `~/.julia/environments/v1.0/Manifest.toml` [stderr] [ Info: Environment successfully resolved [stderr] nil [stderr] nil [stderr] ERROR: LoadError: ArgumentError: Package LanguageServer not found in current path: [stderr] - Run `import Pkg; Pkg.add("LanguageServer")` to install the LanguageServer package. [stderr] [stderr] Stacktrace: [stderr] Stacktrace: [stderr] nil [stderr] [1] require(into::Module, mod::Symbol) [stderr] [1] require(into::Module, mod::Symbol) [stderr] @ Base ./loading.jl:871 [stderr] in expression starting at /Users/ionizing/.emacs.d/.local/straight/build-28.0.50/eglot-jl/eglot-jl.jl:47 [internal] Tue May 11 21:17:32 2021: (:message "Connection state changed" :change "exited abnormally with code 1\n") ----------b---y---e---b---y---e---------- [stderr] [stderr] [stderr] nil [stderr] nil [stderr] Process EGLOT (namd/julia-mode) stderr finished ```

The Project.toml:

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

The line [stderr] No Changes to '~/.julia/environments/v1.0/Project.toml' means eglot-jl is using v1.0 environment, instead of v1.6, so can I solve this problem by defining the right julia environment within eglot-jl? Also it confuses me that why eglot-jl is using v1.0 environment ...

If more info is required, I'll provide as much as I can.

Looking forward to your reply~

non-Jedi commented 3 years ago

Have you customized the value of eglot-jl-language-server-project? If not could you check the value of that variable? Could you also paste the output of running M-: (eglot-jl--ls-invocation nil)?

Ionizing commented 3 years ago

Thanks for the reply!

I've paste the output according the reply.

Have you customized the value of eglot-jl-language-server-project? If not could you check the value of that variable?

No, the only thing I did about eglot is listed in the follow:

$ rg eglot ~/.doom.d
packages.el
69:(package! eglot-jl)

config.el
182:(setq eglot-jl-default-environment "~/.julia/environments/v1.6") ;; found on julia forum

The value of variable eglot-jl-language-server-project is "~/.julia/environments/v1.0"

Could you also paste the output of running M-: (eglot-jl--ls-invocation nil)?

("julia" "--startup-file=no" "--project=~/.julia/environments/v1.0" "/Users/ionizing/.doom.d/.local/straight/build-28.0.50/eglot-jl/eglot-jl.jl" "/Users/ionizing/github/namd.jl/src/" "")
Ionizing commented 3 years ago

It seems eglot works well if eglot-jl-language-server-project is set to "~/.julia/environments/v1.6" manually.

I am curious about why that variable is set to v1.0 environment by default... 🤔🤔

ffevotte commented 3 years ago

This is strange, because eglot-jl should set this variable automatically to the correct default value.

What do you see when running: M-xcustomize-variableRETeglot-jl-language-server-projectRET

You should get something like this

Eglot Jl Language Server Project: /Users/ionizing/.doom.d/.local/straight/build-28.0.50/eglot-jl/
   [State] : STANDARD.

   Julia project to run language server from.
   The project should have LanguageServer and SymbolServer packages
   available.
Groups: Eglot Jl

Note in particular the customization state. If it is not is listed as "STANDARD" (like above), try clicking the State button and the Erase customization entry in the menu.


Anyway, the correct value for this variable should be something like /Users/ionizing/.doom.d/.local/straight/build-28.0.50/eglot-jl/ and not ~/.julia/environments/v1.6

Ionizing commented 3 years ago

Thanks for the reply! @ffevotte

You should get something like this

Here is what I get without customized eglot-jl-language-server-project:

image

It's interesting that it is CHANGED outside Customize. It seems I have to set it to (setq eglot-jl-language-server-project "/Users/ionizing/.emacs.d/.local/straight/repos/eglot-jl").

By the way, would it be possible that someone adds the documentation of customizable variables of eglot-jl to something like FAQ in README? It may help the ones in trouble save a lot of time. Anyway, I appreciate your patient replies.

Ionizing commented 3 years ago

It seems that manually (setq eglot-jl-language-server-project "/Users/ionizing/.emacs.d/.local/straight/repos/eglot-jl") is a workaround for this issue. It should be the time close this issue.

Thanks for your help!

non-Jedi commented 3 years ago

This "bug" is intentionally caused by doom: https://github.com/hlissner/doom-emacs/blob/ea3adb0e72a4c4baa88c6704678edf813757130e/modules/lang/julia/config.el#L97 :/