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

lsp-julia crash on Julia v1.4 #20

Closed
yzcj105 opened this issue Apr 7, 2020 · 21 comments · Fixed by #32
Closed

lsp-julia crash on Julia v1.4 #20

yzcj105 opened this issue Apr 7, 2020 · 21 comments · Fixed by #32

Comments

@yzcj105
Copy link

yzcj105 commented Apr 7, 2020

According to suggestion

I've tried two versions of LanguageServer, v.2.0.0 and v 1.0.0 both failed.

ERROR: MethodError: Cannot `convert` an object of type Dict{Any,Any} to an object of type Function
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T at essentials.jl:171
Stacktrace:
 [1] convert(::Type{Union{Nothing, Function}}, ::Dict{Any,Any}) at ./some.jl:34
 [2] LanguageServer.JSONRPCEndpoints.JSONRPCEndpoint(::Base.PipeEndpoint, ::Base.PipeEndpoint, ::Dict{Any,Any}) at /Users/jchen/.julia/packages/LanguageServer/wMPrf/src/jsonrpcendpoint.jl:19
 [3] LanguageServerInstance(::Base.PipeEndpoint, ::Base.PipeEndpoint, ::Bool, ::String, ::String, ::Dict{Any,Any}) at /Users/jchen/.julia/packages/LanguageServer/wMPrf/src/languageserverinstance.jl:59
 [4] top-level scope at none:1

Process julia-ls stderr finished
@AlexLewandowski
Copy link

lsp-julia is currently not functioning with LanguageServer#v2.0.0. Furthermore, there was a change in Julia 1.4 that breaks compatability with the older LanguageServer#v1.0.0 and SymbolServer#v1.0.1. If you try to run LanguageServer#v1.0.0 on Julia 1.4 it complains that is_stdlib() is not defined or something.

@ashiklom
Copy link

ashiklom commented Apr 8, 2020

FWIW, I think this revision to SymbolServer/src/symbols.jl makes lsp-julia work with Julia 1.4.

@AlexLewandowski
Copy link

AlexLewandowski commented Apr 8, 2020

To get the language server working on Julia v1.0 and v1.4 you can use the following patch for SymbolServer courtesy of @ashiklom. I merely removed the !is_stdlib call since it was causing issues on Julia v1.0.

diff --git a/src/symbols.jl b/src/symbols.jl
index f74f85c..6ec77cf 100644
--- a/src/symbols.jl
+++ b/src/symbols.jl
@@ -207,13 +207,20 @@ function cache_package(c::Pkg.Types.Context, uuid::UUID, depot::Dict, env_path =
         end
     end
 
+    pkgpath = try
+        LoadingBay.eval(:(import $(Symbol(pe_name))))
+        LoadingBay.eval(:(joinpath(dirname(pathof($(Symbol(pe_name)))), "..")))
+    catch err
+        return nothing
+    end
+
     # Dependencies
     for pkg in deps(pe)
         if path(pe) isa String
             env_path = path(pe)
             Pkg.API.activate(env_path)
-        elseif !is_stdlib(c, uuid) && ((Pkg.API.dir(pe_name) isa String) && !isempty(Pkg.API.dir(pe_name)))
-            env_path = Pkg.API.dir(pe_name)
+        elseif ((pkgpath isa String) && !isempty(pkgpath))
+            env_path = pkgpath
             Pkg.API.activate(env_path)
         end
         cache_package(c, packageuuid(pkg), depot, env_path)

Note: I am unsure what side-effects this change may have.

@ashiklom
Copy link

ashiklom commented Apr 9, 2020

You can git checkout the above version of SymbolServer here. It generally works for me, though I haven't tested it extensively.

@yzcj105
Copy link
Author

yzcj105 commented Apr 9, 2020

There are some other problems when trying to compile the package.

(@v1.4) pkg> test LanguageServer
    Testing LanguageServer
Status `/private/var/folders/hj/82yq6m691qq66m31k9x5j74w00015f/T/jl_jN87V1/Manifest.toml`
  [00ebfdb7] CSTParser v1.1.1
  [ffa9a821] DocumentFormat v1.1.1
  [48062228] FilePathsBase v0.7.0
  [682c06a0] JSON v0.21.0
  [2b0e0bc5] LanguageServer v1.0.0 #v1.0.0 (https://github.com/julia-vscode/LanguageServer.jl.git)
  [69de0a69] Parsers v1.0.1
  [b3cc710f] StaticLint v1.0.2
  [cf896787] SymbolServer v1.0.1 #julia-14-fixes (https://github.com/ashiklom/SymbolServer.jl)
  [0796e94c] Tokenize v0.5.8
  [30578b45] URIParser v0.4.0
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8ba89e20] Distributed
  [b77e0a4c] InteractiveUtils
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [44cfe95a] Pkg
  [de0858da] Printf
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA
  [9e88b42a] Serialization
  [6462fe0b] Sockets
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
applytextdocumentchanges: Error During Test at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/test_document.jl:53
  Got exception outside of a @test
  MethodError: Cannot `convert` an object of type Nothing to an object of type LanguageServer.Range
  Closest candidates are:
    convert(::Type{T}, !Matched::T) where T at essentials.jl:171
    LanguageServer.Range(::Any, !Matched::Any) at /Users/jchen/.julia/packages/LanguageServer/wMPrf/src/protocol/basic.jl:10
  Stacktrace:
   [1] convert(::Type{Union{Missing, LanguageServer.Range}}, ::Nothing) at ./missing.jl:69
   [2] LanguageServer.TextDocumentContentChangeEvent(::Nothing, ::Nothing, ::String) at /Users/jchen/.julia/packages/LanguageServer/wMPrf/src/protocol/document.jl:45
   [3] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/test_document.jl:59
   [4] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1113
   [5] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/test_document.jl:54
   [6] include(::String) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [7] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:7
   [8] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1113
   [9] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:7
   [10] include(::String) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [11] top-level scope at none:6
   [12] eval(::Module, ::Any) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [13] exec_options(::Base.JLOptions) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [14] _start() at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?

LanguageServer: Error During Test at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:5
  Got exception outside of a @test
  LoadError: UndefVarError: write_transport_layer not defined
  Stacktrace:
   [1] getproperty(::Module, ::Symbol) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [2] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/test_communication.jl:97
   [3] include(::String) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [4] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:8
   [5] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1113
   [6] top-level scope at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:7
   [7] include(::String) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [8] top-level scope at none:6
   [9] eval(::Module, ::Any) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [10] exec_options(::Base.JLOptions) at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
   [11] _start() at /Applications/Julia-1.4.app/Contents/Resources/julia/lib/julia/sys.dylib:?
  in expression starting at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/test_communication.jl:96

Test Summary:              | Pass  Error  Broken  Total
LanguageServer             |   21      2       1     24
  applytextdocumentchanges |           1              1
ERROR: LoadError: Some tests did not pass: 21 passed, 0 failed, 2 errored, 1 broken.
in expression starting at /Users/jchen/.julia/packages/LanguageServer/XXTJb/test/runtests.jl:5
ERROR: Package LanguageServer errored during testing

@gdkrmr
Copy link
Owner

gdkrmr commented Apr 18, 2020

lsp-mode has been patched (emacs-lsp/lsp-mode#1595) and is working for me now with Julia 1.4, please check master on https://github.com/gdkrmr/lsp-julia. It seems that everything works, except linting.

@gdkrmr
Copy link
Owner

gdkrmr commented Apr 27, 2020

I have updated the Julia packages and it still doesn't work for me julia-vscode/LanguageServer.jl#651

@gdkrmr
Copy link
Owner

gdkrmr commented May 11, 2020

It works with Julia 1.4 now (after this patch: julia-vscode/LanguageServer.jl#688) but linting is still broken.

I have asked both at lsp-mode and LanguageServer.jl, both repos' maintainers were very helpful and fixed something, but this didn't make flycheck integration work. So I am really running out of ideas now.

@NightMachinery
Copy link

@gdkrmr Can you put the elisp code for getting julia to work in your repo at https://github.com/gdkrmr/lsp-julia ? BTW, why is vscode not getting affected by these bugs? Their julia mode works like a horse on 1.4.

@gdkrmr
Copy link
Owner

gdkrmr commented May 19, 2020

If you want something that is working at the moment, use the code in this repository with Julia 1.3. If you want to help fixing this issue, you can get instruction how to make https://github.com/gdkrmr/lsp-julia work with Julia 1.4 here: https://gist.github.com/gdkrmr/624e423f774768563f30e1bd719579a4 any help is appreciated!

BTW, why is vscode not getting affected by these bugs? Their julia mode works like a horse on 1.4.

I have no idea, but it seems that other language server clients (e.g. vim and sublime text don't work either). eglot seems to work though.

@smabie
Copy link

smabie commented May 21, 2020

I manually added your patch and deleted the the files under ``~/.julia/compiler/v1.4/` I now get a new error:

ERROR: MethodError: Cannot `convert` an object of type String to an object of type Function
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T at essentials.jl:171
Stacktrace:
 [1] convert(::Type{Union{Nothing, Function}}, ::String) at ./some.jl:34
 [2] LanguageServer.JSONRPCEndpoints.JSONRPCEndpoint(::Base.PipeEndpoint, ::Base.PipeEndpoint, ::String) at /home/sturm/.julia/packages/LanguageServer/mpNvN/src/jsonrpcendpoint.jl:62
 [3] LanguageServerInstance(::Base.PipeEndpoint, ::Base.PipeEndpoint, ::Bool, ::String, ::String, ::Nothing) at /home/sturm/.julia/packages/LanguageServer/mpNvN/src/languageserverinstance.jl:62 (repeats 2 times)
 [4] top-level scope at none:1

Process julia-ls stderr finished

Does anyone know what's going on?

@gdkrmr
Copy link
Owner

gdkrmr commented May 21, 2020

You need to modify LanguageServer.jl. ProgressToken needs a constructor:

ProgressToken(x::ProgressToken) = x

@smabie
Copy link

smabie commented May 21, 2020

Yeah, I tried that, I get the error above. The bundled server that comes with lsp-julia works with 1.3.1 though.

To be clear, adding the constructor fixes the original error. But it seems like there's another problem as well. Oh well, I guess I'll just use 1.3.1 in the meantime.

@ghost
Copy link

ghost commented Jul 9, 2020

@non-Jedi any update on this

@non-Jedi
Copy link
Collaborator

non-Jedi commented Jul 9, 2020

I am uninvolved. Please don't ping me. In general even if I were involved doing so is a bit rude.

@ghost
Copy link

ghost commented Jul 9, 2020

@non-Jedi Thanks .. looks like thats the fate of this project :-(

@gdkrmr
Copy link
Owner

gdkrmr commented Aug 27, 2020

To all the naysayers: I think I fixed the issue.
Please test master from https://github.com/gdkrmr/lsp-julia, please check if it works for you on Julia 1.5 (don't forget to set lsp-julia-default-environment to accordingly, probably "~/.julia/environments/v1.5")

@ashiklom
Copy link

@gdkrmr With Julia 1.5.1, I get the following error on a minimal Julia file:

ERROR: MethodError: no method matching LanguageServer.FoldingRangeClientCapabilities(::Nothing)
Closest candidates are:
  LanguageServer.FoldingRangeClientCapabilities(::Any, !Matched::Any, !Matched::Any) at /Users/ashiklom/.emacs.d/.local/straight/repos/lsp-julia/languageserver/LanguageServer/src/protocol/features.jl:217
  LanguageServer.FoldingRangeClientCapabilities(; dynamicRegistration, rangeLimit, lineFoldingOnly) at /Users/ashiklom/.emacs.d-doom/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:50
  LanguageServer.FoldingRangeClientCapabilities(!Matched::Union{Missing, Bool}, !Matched::Union{Missing, Int64}, !Matched::Union{Missing, Bool}) at /Users/ashiklom/.emacs.d/.local/straight/repos/lsp-julia/languageserver/LanguageServer/src/protocol/features.jl:217
  ...
Stacktrace:
 [1] LanguageServer.TextDocumentClientCapabilities(::Dict{String,Any}) at /Users/ashiklom/.emacs.d-doom/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:56
 [2] LanguageServer.ClientCapabilities(::Dict{String,Any}) at /Users/ashiklom/.emacs.d-doom/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:56
 [3] LanguageServer.InitializeParams(::Dict{String,Any}) at /Users/ashiklom/.emacs.d/.local/straight/repos/lsp-julia/languageserver/LanguageServer/src/protocol/initialize.jl:111
 [4] dispatch_msg(::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint,Base.PipeEndpoint}, ::JSONRPC.MsgDispatcher, ::Dict{String,Any}) at /Users/ashiklom/.emacs.d-doom/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/typed.jl:64
 [5] run(::LanguageServerInstance) at /Users/ashiklom/.emacs.d/.local/straight/repos/lsp-julia/languageserver/LanguageServer/src/languageserverinstance.jl:309
 [6] top-level scope at none:1

Also, for any doom-emacs users (straight.el users?), the default project detection points to the .emacs.d/.local/straight/build directory instead of the .emacs.d/.local/straight/repos directory, but the actual Julia libraries aren't copied over. So I had to add (setq lsp-julia-package-dir "~/.emacs.d/.local/straight/repos/lsp-julia/languageserver") to my config.

@gdkrmr
Copy link
Owner

gdkrmr commented Aug 27, 2020

Have you tried updating again? I made some changes.

I would guess that somehow not the versions that come with the lsp-julia are being used.

@AlexLewandowski
Copy link

AlexLewandowski commented Aug 27, 2020

Also running into this, I included a @warn pathof(LanguageServer) after the using statements in lsp-julia--rls-command and it seems the bundled langaugeserver is being used.

Edit: With (setq lsp-enable-folding t) linting and completion work!

Edit2: @ashiklom, you need to run doom build and it will properly symlink the language server to build.

Edit3: I encountered an error by opening a file outside of a project (e.g. a one-off script in $HOME). After restarting, LSP works fine for that file but if I open yet another file outside of a project I get the error again.

ERROR: KeyError: key "name" not found
Stacktrace:
 [1] getindex at ./dict.jl:467 [inlined]
 [2] LanguageServer.WorkspaceFolder(::Dict{String,Any}) at /home/alex3/.emacs.d/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:56
 [3] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
 [4] _broadcast_getindex at ./broadcast.jl:621 [inlined]
 [5] getindex at ./broadcast.jl:575 [inlined]
 [6] macro expansion at ./broadcast.jl:932 [inlined]
 [7] macro expansion at ./simdloop.jl:77 [inlined]
 [8] copyto! at ./broadcast.jl:931 [inlined]
 [9] copyto! at ./broadcast.jl:886 [inlined]
 [10] copy(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Tuple{Base.OneTo{Int64}},Type{LanguageServer.WorkspaceFolder},Tuple{Array{Any,1}}}) at ./broadcast.jl:862
 [11] materialize at ./broadcast.jl:837 [inlined]
 [12] LanguageServer.WorkspaceFoldersChangeEvent(::Dict{String,Any}) at /home/alex/.emacs.d/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:56
 [13] LanguageServer.DidChangeWorkspaceFoldersParams(::Dict{String,Any}) at /home/alex/.emacs.d/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/interface_def.jl:56
 [14] dispatch_msg(::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint,Base.PipeEndpoint}, ::JSONRPC.MsgDispatcher, ::Dict{String,Any}) at /home/alex/.emacs.d/.local/straight/repos/lsp-julia/languageserver/JSONRPC/src/typed.jl:64
 [15] run(::LanguageServerInstance) at /home/alex/.emacs.d/.local/straight/repos/lsp-julia/languageserver/LanguageServer/src/languageserverinstance.jl:309
 [16] top-level scope at none:1

@gdkrmr
Copy link
Owner

gdkrmr commented Aug 28, 2020

I cannot reproduce the error in Edit3. When opening a file outside of project directory. lsp-mode asks where the root of the new project is and if I say that it is outside of a project, it simply does nothing and if I choose any directory, it just keeps working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants