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 crashing with MethodError on FoldingRangeClientCapabilities #35

Closed
TimQuelch opened this issue Sep 25, 2020 · 13 comments
Closed

LSP crashing with MethodError on FoldingRangeClientCapabilities #35

TimQuelch opened this issue Sep 25, 2020 · 13 comments

Comments

@TimQuelch
Copy link

The server seems to be crashing soon after starting. It seems to always be crashing on the function LanguageServer.FoldingRangeClientCapabilities. Not quite sure how to go about debugging this issue

The stderr log is below

Process julia-ls stderr finished
ERROR: [ Info: Indexing Ipopt...
MethodError: no method matching LanguageServer.FoldingRangeClientCapabilities(::Nothing)
Closest candidates are:
  LanguageServer.FoldingRangeClientCapabilities(::Any, !Matched::Any, !Matched::Any) at /home/timquelch/.julia/packages/LanguageServer/y1ebo/src/protocol/features.jl:217
  LanguageServer.FoldingRangeClientCapabilities(; dynamicRegistration, rangeLimit, lineFoldingOnly) at /home/timquelch/.julia/packages/JSONRPC/1Kq3H/src/interface_def.jl:50
  LanguageServer.FoldingRangeClientCapabilities(!Matched::Union{Missing, Bool}, !Matched::Union{Missing, Int64}, !Matched::Union{Missing, Bool}) at /home/timquelch/.julia/packages/LanguageServer/y1ebo/src/protocol/features.jl:217
  ...
Stacktrace:
 [1] LanguageServer.TextDocumentClientCapabilities(::Dict{String,Any}) at /home/timquelch/.julia/packages/JSONRPC/1Kq3H/src/interface_def.jl:56
 [2] LanguageServer.ClientCapabilities(::Dict{String,Any}) at /home/timquelch/.julia/packages/JSONRPC/1Kq3H/src/interface_def.jl:56
 [3] LanguageServer.InitializeParams(::Dict{String,Any}) at /home/timquelch/.julia/packages/LanguageServer/y1ebo/src/protocol/initialize.jl:111
 [4] dispatch_msg(::JSONRPC.JSONRPCEndpoint, ::JSONRPC.MsgDispatcher, ::Dict{String,Any}) at /home/timquelch/.julia/packages/JSONRPC/1Kq3H/src/typed.jl:64
 [5] run(::LanguageServerInstance) at /home/timquelch/.julia/packages/LanguageServer/y1ebo/src/languageserverinstance.jl:308
 [6] top-level scope at none:1
@gdkrmr
Copy link
Owner

gdkrmr commented Sep 25, 2020

Did you see #23 (comment)?

@TimQuelch
Copy link
Author

Going by some of the suggestions in that thread, I managed getting it to work by setting lsp-enable-folding to t. This is using the bundled language server.

@lunik1
Copy link

lunik1 commented Nov 1, 2020

I have the same issue on Doom emacs. The (setq lsp-enable-folding t) fix worked for me, but the version of lsp-mode is pinned at emacs-lsp/lsp-mode@fb4c35c so emacs-lsp/lsp-mode#1595 did not fix the issue (or it has since regressed).

@roiholtzman
Copy link

roiholtzman commented Mar 19, 2021

I have the same issue.
I added (setq lsp-enable-folding t)

Now I get the following error:

ERROR: MethodError: no method matching Union{Int64, String}(::String)
Stacktrace:
 [1] LanguageServer.InitializeParams(::Dict{String,Any}) at /Users/roiholtzman/.julia/packages/LanguageServer/y1ebo/src/protocol/initialize.jl:111
 [2] dispatch_msg(::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint,Base.PipeEndpoint}, ::JSONRPC.MsgDispatcher, ::Dict{String,Any}) at /Users/roiholtzman/.julia/packages/JSONRPC/xbAlZ/src/typed.jl:64
 [3] run(::LanguageServerInstance) at /Users/roiholtzman/.julia/packages/LanguageServer/y1ebo/src/languageserverinstance.jl:308
 [4] top-level scope at none:1

Process julia-ls stderr finished

my configuration is

(setq lsp-julia-package-dir nil)
(setq lsp-julia-default-environment "~/.julia/environments/v1.5")
(setq lsp-enable-folding t)

hlissner added a commit to doomemacs/doomemacs that referenced this issue May 11, 2021
@beamiter
Copy link

beamiter commented Jun 2, 2021

This works for me, thanks a lot!!!

@gdkrmr gdkrmr closed this as completed Jun 2, 2021
peterhoeg pushed a commit to peterhoeg/doomemacs that referenced this issue Aug 2, 2021
@ulysses4ever
Copy link

Not sure why this issue was closed, as (setq lsp-enable-folding t) seems like a mere workaround instead of a fix (what if I don't want to enable folding?). On the Julia's LSP server issue tracker, people say it's due to a violation of the LSP from the client side, in particular, at some point the client sends null instead of undefined. I guess, one reason to close this is that it's probably lsp-mode's fault (maybe something to do with foldingRange being initialized in a different manner than everything else?).

@chw90
Copy link

chw90 commented Apr 18, 2022

I'm still having this exact issue using most recent Doom Emacs as well as most recent Julia 1.7.2.

[ Info: Received new data from Julia Symbol Server.
ERROR: MethodError: no method matching LanguageServer.FoldingRangeClientCapabilities(::Nothing)
Closest candidates are:
  LanguageServer.FoldingRangeClientCapabilities(::Any, !Matched::Any, !Matched::Any) at ~/.julia/packages/LanguageServer/NWirc/src/protocol/features.jl:217
  LanguageServer.FoldingRangeClientCapabilities(; dynamicRegistration, rangeLimit, lineFoldingOnly) at ~/.julia/packages/JSONRPC/P0G1p/src/interface_def.jl:58
  LanguageServer.FoldingRangeClientCapabilities(!Matched::Dict) at ~/.julia/packages/JSONRPC/P0G1p/src/interface_def.jl:63
  ...
Stacktrace:
 [1] LanguageServer.TextDocumentClientCapabilities(dict::Dict{String, Any})
   @ LanguageServer ~/.julia/packages/JSONRPC/P0G1p/src/interface_def.jl:64
 [2] LanguageServer.ClientCapabilities(dict::Dict{String, Any})
   @ LanguageServer ~/.julia/packages/JSONRPC/P0G1p/src/interface_def.jl:64
 [3] LanguageServer.InitializeParams(dict::Dict{String, Any})
   @ LanguageServer ~/.julia/packages/LanguageServer/NWirc/src/protocol/initialize.jl:116
 [4] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ JSONRPC ~/.julia/packages/JSONRPC/P0G1p/src/typed.jl:65
 [5] run(server::LanguageServerInstance)
   @ LanguageServer ~/.julia/packages/LanguageServer/NWirc/src/languageserverinstance.jl:365
 [6] top-level scope
   @ none:1

Process julia-ls stderr finished

I tried removing and readding +lsp to the julia module in Doom Emacs, which effectively reinstalls, but to no avail. I noted that I have no environments folder in ~/.julia/. The existence of this folder seems to be implied by

  (unless lsp-julia-default-environment
    (setq lsp-julia-default-environment
          (or (car (last (doom-glob "~/.julia/environments/v*")))
              "~/.julia/environments/v1.6")))

in ~/.emacs.d/modules/lang/julia/config.el. Should a corresponding environment not be created after installing lsp-julia when opening a .jl file for the first time?

@gdkrmr
Copy link
Owner

gdkrmr commented Apr 19, 2022

I have no environments folder in ~/.julia/.

Where are your default environments then? Have you tried changing lsp-julia-default-environment?

@chw90
Copy link

chw90 commented Apr 19, 2022

I think there was no environment at all since I did a fresh install of Julia, removing the old ~/.julia folder, and then reinstalled lsp-julia through Doom emacs, hoping it would do the setup.

I have in the meantime installed LanguageServer manually into the default environment using Pkg (which is v1.7) now.

(@v1.7) pkg> add LanguageServer
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.7/Project.toml`
  No Changes to `~/.julia/environments/v1.7/Manifest.toml`

I don't think changing lsp-julia-default-environment is needed, it's value is correctly set to .julia/environments/v1.7 now.

I've found a way to make it work now, it seems: On a freshly launched Emacs, open any .jl file and let it crash. Close the file, open it again, wait... get julia-ls:7080 initialized sucessfully in folders: ..., enjoy.

@devmotion
Copy link

I've found a way to make it work now, it seems: On a freshly launched Emacs, open any .jl file and let it crash. Close the file, open it again, wait... get julia-ls:7080 initialized sucessfully in folders: ..., enjoy.

I experienced the same crashes (using Doom Emacs with a standard config) and I could also "fix" them by closing and reopening the file.

Doom Emacs implements the originally proposed workaround in https://github.com/doomemacs/doomemacs/blob/bc32e2ec4c51c04da13db3523b19141bcb5883ba/modules/lang/julia/config.el#L85-L88 but for me it was not sufficient (it seems the hook might be applied too late?). Adding

(after! julia-mode
  (when (featurep! :lang julia +lsp)
    (unless (featurep! :tools lsp +eglot)
      (setq-hook! 'julia-mode-hook
        lsp-enable-folding t
        lsp-folding-range-limit 100)
      (add-hook 'julia-mode-local-vars-hook #'lsp! 'append))))

to config.el, similar to the config for scala-mode, seemed to fix the problems - at least I could not reproduce the crashes anymore.

However, I agree with @ulysses4ever: Even if the workaround could be applied successfully, it's still a workaround that does not fix the underlying problem. According to the LS.jl developers it's a bug in lsp-mode. I'm not familiar with the code in lsp-mode and I'm a complete beginner when it comes to lisp programming but I just followed @ulysses4ever's suggestion and tried to change the definition in https://github.com/emacs-lsp/lsp-mode/blob/c44cd787a9164df683ac21ece2c05d21cb3deda7/lsp-mode.el#L3537-L3542 such that it matches other conditional capabilities such as https://github.com/emacs-lsp/lsp-mode/blob/c44cd787a9164df683ac21ece2c05d21cb3deda7/lsp-mode.el#L3474 and https://github.com/emacs-lsp/lsp-mode/blob/c44cd787a9164df683ac21ece2c05d21cb3deda7/lsp-mode.el#L3477-L3481. It seems this actually worked and emacs-lsp/lsp-mode@master...devmotion:lsp-mode:dw/fix_foldingrange was sufficient to fix the crashes.

@ulysses4ever
Copy link

@devmotion this sounds great! By any chance, could you open a pull request against lsp-mode?

@devmotion
Copy link

I opened a PR: emacs-lsp/lsp-mode#3593

@devmotion
Copy link

The PR was merged, so you can test it by updating lsp-mode. I still haven't observed any crashes after updating (and removing the workaround).

hlissner added a commit to doomemacs/doomemacs that referenced this issue Jul 4, 2022
emacs-lsp/lsp-mode@6b6afc00deec -> emacs-lsp/lsp-mode@3fa645c0397b
joaotavora/eglot@e835996e1661 -> joaotavora/eglot@bd970be047ab

- There are multiple issues in the lsp-mode
  repo (emacs-lsp/lsp-mode#2722), lsp-julia repo (gdkrmr/lsp-julia#23
  and gdkrmr/lsp-julia#35), and the LanguageServer.jl
  repo (julia-vscode/LanguageServer.jl#844) about crashes of the Julia
  LSP with lsp-mode due to errors caused by the folding capabilities
  announced by the client. One can work around these issues by enabling
  folding (see gdkrmr/lsp-julia#23) but that is only a hack and does not
  fix the underlying issue. The problem is caused by a violation of the
  LSP specs in lsp-mode which was fixed in emacs-lsp/lsp-mode#3593. The
  PR updates lsp-mode to the latest commit on the master branch which
  contains this fix (and some other unrelated fixes, CI passes
  successfully again), and hence the workaround for lsp-julia can be
  removed.

Ref: emacs-lsp/lsp-mode#3593
Ref: emacs-lsp/lsp-mode#2722
Ref: gdkrmr/lsp-julia#35
Ref: gdkrmr/lsp-julia#23
Ref: julia-vscode/LanguageServer.jl#844
Close: #6516
Co-authored-by: devmotion <devmotion@users.noreply.github.com>
maikol-solis pushed a commit to maikol-solis/doomemacs that referenced this issue Aug 1, 2022
emacs-lsp/lsp-mode@6b6afc00deec -> emacs-lsp/lsp-mode@3fa645c0397b
joaotavora/eglot@e835996e1661 -> joaotavora/eglot@bd970be047ab

- There are multiple issues in the lsp-mode
  repo (emacs-lsp/lsp-mode#2722), lsp-julia repo (gdkrmr/lsp-julia#23
  and gdkrmr/lsp-julia#35), and the LanguageServer.jl
  repo (julia-vscode/LanguageServer.jl#844) about crashes of the Julia
  LSP with lsp-mode due to errors caused by the folding capabilities
  announced by the client. One can work around these issues by enabling
  folding (see gdkrmr/lsp-julia#23) but that is only a hack and does not
  fix the underlying issue. The problem is caused by a violation of the
  LSP specs in lsp-mode which was fixed in emacs-lsp/lsp-mode#3593. The
  PR updates lsp-mode to the latest commit on the master branch which
  contains this fix (and some other unrelated fixes, CI passes
  successfully again), and hence the workaround for lsp-julia can be
  removed.

Ref: emacs-lsp/lsp-mode#3593
Ref: emacs-lsp/lsp-mode#2722
Ref: gdkrmr/lsp-julia#35
Ref: gdkrmr/lsp-julia#23
Ref: julia-vscode/LanguageServer.jl#844
Close: doomemacs#6516
Co-authored-by: devmotion <devmotion@users.noreply.github.com>
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

No branches or pull requests

8 participants