gdkrmr / lsp-julia

MIT License
70 stars 19 forks source link

Julia Language Server Crashes in Julia 1.3 Series #19

Closed omidmnz closed 4 years ago

omidmnz commented 4 years ago

I get a log very similar to the one in this and this julia-vscode issues. They seem to have shipped a fix in an alpha release, but I couldn't find the relevant commits.

I am using Julia 1.31, LanguageServer v1.0.0, and SymbolServer v1.0.1.

gdkrmr commented 4 years ago

I have noticed, too, I guess we have to wait until the LanguageServer devs put out a new release, I don't think we should include alpha/beta releases of LanguageServer.jl. Meanwhile you can just use an older version of Julia as the LanguageServer process.

omidmnz commented 4 years ago

Thanks. I'm gonna try that as a workaround for now.

fleimgruber commented 4 years ago

A new release of LanguageServer.jl has arrived: https://github.com/julia-vscode/LanguageServer.jl/releases/tag/v2.0.0

Gijs-Koot commented 4 years ago

For me the 2.0.0 version of LanguageServer broke julia-lsp with the following error

ERROR: MethodError: Cannot `convert` an object of type Dict{Any,Any} to an object of type Function

I fixed it by downgrading the LanguageServer package back to v1.0.0.

gdkrmr commented 4 years ago

As said before, I am waiting for the new release of the vscode plugin to update the julia libraries. If you are super unpatient, you could prepare a PR :+1:

gdkrmr commented 4 years ago

I just checked, the vscode extension got released, I am quite busy at the moment, but I will be on it.

Gijs-Koot commented 4 years ago

Dear Guido, sorry to seem unpatient but I was just trying to be helpful, no hurries from me! Thanks a lot for the work you put into this. I would like at some point to be able to help you out, but I'm not very experienced with Elisp, just happy to get it to work at the moment.

gdkrmr commented 4 years ago

I have upgraded all the julia packages to the versions specified in by julia-vscode v0.14.12 and I get the same error. I have tried with julia 1.2 and 1.3.

bcgv commented 4 years ago

Hello, I got it to work by redefining lsp-julia--rls-command to take into account changes in LanguageServer.LanguageServerInstance.

  (eval-after-load 'lsp-julia
    '(defun lsp-julia--rls-command ()
       "The command to lauch the Julia Language Server."
       `(,lsp-julia-command
         ,@lsp-julia-flags
         ,(concat "-e using LanguageServer, Sockets, SymbolServer;"
                  " server = LanguageServer.LanguageServerInstance("
                  " stdin, stdout, true,"
                  " \"" (lsp-julia--get-root) "\","
                  " \"" (lsp-julia--get-depot-path) "\");"
                  " server.runlinter = true;"
                  " run(server);"))))
  )

I also set the variable lsp-folding-range-limit because of a bug if it is left unset.

  (setq lsp-folding-range-limit 100)

And I set lsp-julia-flags to use a local LanguageServer.jl because I had to made some changes there also.

  (setq lsp-julia-flags '("--startup-file=no" "--history-file=no"))

The (small) changes that were required in LanguageServer.jl are in this branch. I am new to the Github process so I'm all ears on how to proceed from there. Cheers.

gdkrmr commented 4 years ago

Thanks for this. I am aware of the different way LanguageServerInstance has to be used. There was just another release for the vscode plugin and they updated the packaged LanguageServer.jl from v1 to v2, so I guess things are still very unstable on their side. I will try if the new combination of Julia packages is working now.

gdkrmr commented 4 years ago

@bcgv: I have tried your fix (you can find it here) and it stops LanguageServer.jl from crashing, it shows documentation of symbols, but doesn't show any problems with the code. E.g. a function like

function a(b)
    @show c
    wbvorn: qpwor
    return x
en

doesn't show a single "Missing reference" warning.

AlexLewandowski commented 4 years ago

doesn't show a single "Missing reference" warning.

In addition, the formatter is not found.

bcgv commented 4 years ago

It seems to be due to the workspace and linter configuration. If I comment out the lines in the function here to something like that :

function publish_diagnostics(doc::Document, server)
#    if server.runlinter && server.symbol_store_ready && is_workspace_file(doc)
        publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, doc.diagnostics)
#    else
#        publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, Diagnostic[])
#    end
    JSONRPCEndpoints.send_notification(server.jr_endpoint, "textDocument/publishDiagnostics", publishDiagnosticsParams)
end

Then it works. Somehow server.runlinter is set to false at one point, and for some files is_workspace_file(doc) also returns false.

PS: by working I mean it provides the "missing reference" warnings but at one points it fails due to another bug.

AlexLewandowski commented 4 years ago

Is this an issue with LanguageServer.jl or lsp-julia, and should an issue be opened?

gdkrmr commented 4 years ago

There have been a couple of new pre-releases of vscode-julia, I will have to check if it got fixed.

AlexLewandowski commented 4 years ago

Unfortunately, it seems that my languageserver (which I installed manually at v1.0.0) is not picking up local modules. To get this working, I tried to use the currently bundled languager server, which crashes.

The fork by @gdkrmr fixes this, but no longer displays error messages and other linting features. Many changes were made in v2.0.0 of languageserver, and neither is_workspace_file(doc) or server.runlinter gets set to true for publish_diagnostics to properly work.

I cannot get the fix suggested by @bcgv to work, since the server crashes with

ERROR: MethodError: no method matching LanguageServer.DiagnosticRelatedInformation(::Nothing)

Does anyone have any leads on how to fix this? From a quick experiment, everything works fine in VScode, and it doesn't seem like lsp-julia does anything that could affect this.

Edit: I dug around a little more and I identified two (potential?) issues.

The first is that the r.params.capabilities.workspace.workspaceFolders is set to true and r.params.workspaceFolders is set to missing. So, server.workspaceFolders is never set and is_workspace_file(doc) is evaluated to false.

The second issue is a newly added function request_julia_config which toggles server.runlinter. I cannot even begin to understand what it is doing, but as far as I can see it is the only thing toggling server.runlinter.

Edit2: It turns out the fix for imported user modules is only two lines (see here if interested). So I am back to running a manually installed v1.0.0 language server.

gdkrmr commented 4 years ago

I have merged the PR of @AlexLewandowski (thank you for that!) and have updated the readme, I would like to tag a new version, please test current master. Sadly julia 1.0 doesn't work with this anymore, but I guess we will have to live with this.