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

Julia LSP not working #669

Closed
uncomfyhalomacro opened this issue Aug 28, 2021 · 61 comments
Closed

Julia LSP not working #669

uncomfyhalomacro opened this issue Aug 28, 2021 · 61 comments
Assignees
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@uncomfyhalomacro
Copy link
Contributor

uncomfyhalomacro commented Aug 28, 2021

Reproduction steps

  1. Open a julia file.
  2. LSP does not work.

Environment

  • Platform: Linux
  • Helix version: v0.4.1-68-g5cee3b63 (master)
~/.cache/helix/helix.log
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <- 
2021-08-28T12:29:40.183 helix_lsp::transport [ERROR] err <-

Is this related to #413 ?

Just to add, I wonder if it actually not start julia because in htop, no julia process is running.

@uncomfyhalomacro uncomfyhalomacro added the C-bug Category: This is a bug label Aug 28, 2021
@kirawi kirawi added the A-language-server Area: Language server client label Aug 28, 2021
@archseer
Copy link
Member

The language server definition is probably wrong, the original implementer couldn't get it working in #413

Make sure you have the required binary in $PATH then try figuring out the correct LSP definition:

language-server = { command = "julia", args = [ "--startup-file=no", "--history-file=no", "-e", "using LanguageServer;using Pkg;import StaticLint;import SymbolServer;env_path = dirname(Pkg.Types.Context().env.project_file);server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, \"\");server.runlinter = true;run(server);" ] }

@archseer
Copy link
Member

I think you also need to have the package installed? https://github.com/julia-vscode/LanguageServer.jl

@uncomfyhalomacro
Copy link
Contributor Author

uncomfyhalomacro commented Aug 28, 2021

I think you also need to have the package installed? https://github.com/julia-vscode/LanguageServer.jl

I already installed it. Just wondering what might be causing the issue from my first post. I will try to take a look then. I will open a PR if I got it working.

@uncomfyhalomacro
Copy link
Contributor Author

untitled.mp4

it seems that julia terminates prematurely and maybe that is why no lsp was detected and the error logs shows just as in the first post of the issue. is it because julia "slow to first plot" problem is causing the issue? and the lsp plugin is trying to communicate to the lsp server but since the lsp server failed to start, nothing happens? im just guessin since i am not sure how the lsp plugin works in helix.

@archseer
Copy link
Member

Yeah I assume it's a similar crash to the original issue. You can use hx -v to increase the log level then check the LSP output in ~/.cache/helix/helix.log (I think that's the path, you can confirm under hx -h) to see what's going on. Post the whole log, if it's a timeout it should be visible in there (it'll time out after two seconds).

I think the problem is with the command that's getting executed though.

@archseer
Copy link
Member

Ah so looking at the first post there's nothing reported after the "<- err"? That's weird, it would mean that we're getting a bunch of blank lines from the LSP.

@uncomfyhalomacro
Copy link
Contributor Author

uncomfyhalomacro commented Aug 29, 2021

I think the problem is with the command that's getting executed though.

my current LSP configuration is based of nvim-lspconfig's julials, so I am sure I am doing it right in languages.toml:

[[language]]
name = "julia"
scope = "source.julia"
injection-regex = "julia"
file-types = ["jl"]
roots = []
comment-token = "#"
language-server = { command = "julia", args = ["--startup-file=no", "--history-file=no", "-e","'using LanguageServer;popfirst!(LOAD_PATH);depot_path = get(ENV, \"JULIA_DEPOT_PATH\", \"\");project_path = let; dirname(something(Base.load_path_expand((p = get(ENV, \"JULIA_PROJECT\", nothing); p === nothing ? nothing : isempty(p) ? nothing : p)), Base.current_project(), get(Base.load_path(), 1, nothing), Base.load_path_expand(\"@v#.#\"),)); end; @info \"Running language server\" VERSION pwd() project_path depot_path; server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path); server.runlinter = true; run(server)'"] }

indent = { tab-width = 2, unit = "  " }

Ah so looking at the first post there's nothing reported after the "<- err"? That's weird, it would mean that we're getting a bunch of blank lines from the LSP.

Using the working command for the julia lsp and then running helix -vvv helloworld.jl seems to give the similar logs.

~/.cache/helix/helix.log
2021-08-29T10:47:54.342 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2021-08-29T10:47:54.342 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2021-08-29T10:47:54.342 mio::poll [TRACE] registering event source with poller: token=Token(3), interests=READABLE | WRITABLE
2021-08-29T10:47:54.342 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":54196,"rootUri":null},"id":0}
2021-08-29T10:47:55.170 helix_lsp::transport [ERROR] err <- ERROR: syntax: invalid character literal

2021-08-29T10:47:55.171 helix_lsp::transport [ERROR] err <- Stacktrace:

2021-08-29T10:47:55.171 helix_lsp::transport [ERROR] err <-  [1] top-level scope

2021-08-29T10:47:55.292 helix_lsp::transport [ERROR] err <-    @ none:1

2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err: <- Other(missing content length)
2021-08-29T10:47:55.303 mio::poll [TRACE] deregistering event source from poller
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 
2021-08-29T10:47:55.303 helix_lsp::transport [ERROR] err <- 

@uncomfyhalomacro
Copy link
Contributor Author

image
This is what it looks like in htop when julia runs before it terminates in just one second. I don't know what is causing the termination of the julia process..

@archseer
Copy link
Member

There's an error in your output:

err <- ERROR: syntax: invalid character literal

Not sure if that's because of the LSP arguments or because of the initialize command.

@uncomfyhalomacro
Copy link
Contributor Author

There's an error in your output:

err <- ERROR: syntax: invalid character literal

Not sure if that's because of the LSP arguments or because of the initialize command.

probably you are right on the arguments of the initialize command for the lsp but because of the verbosity of the arguments, i edited the toml file to launch a script

[[language]]
name = "julia"
scope = "source.julia"
injection-regex = "julia"
file-types = ["jl"]
roots = []
comment-token = "#"
#language-server = { command = "julia", args = ["--startup-file=no", "--history-file=no", "-q", "-e",''''using LanguageServer;popfirst!(LOAD_PATH);depot_path = get(ENV, "JULIA_DEPOT_PATH", "");project_path = let; dirname(something(Base.load_path_expand((p = get(ENV, "JULIA_PROJECT", nothing); p === nothing ? nothing : isempty(p) ? nothing : p)), Base.current_project(), get(Base.load_path(), 1, nothing), Base.load_path_expand("@v#.#"),)); end; @info "Running language server" VERSION pwd() project_path depot_path; server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path); server.runlinter = true; run(server)''''] }

language-server = { command = "julia", args = ["--startup-file=no", "--history-file=no", "/home/uncomfy/test.jl"] }

indent = { tab-width = 2, unit = "  " }

The script in $HOME/test.jl:

using LanguageServer; popfirst!(LOAD_PATH);depot_path = get(ENV,"JULIA_DEPOT_PATH", ""); project_path=let;dirname(something(Base.load_path_expand((p=get(ENV,"JULIA_PROJECT",nothing);p === nothing ? nothing : isempty(p) ? nothing : p)), Base.current_project(), get(Base.load_path(), 1, nothing), Base.load_path_expand("@v#.#")),); end; @info "Running language server" VERSION pwd() project_path depot_path; server=LanguageServer.LanguageServerInstance(stdin,stdout,project_path,depot_path); server.runlinter = true; run(server)

Syntax error is gone but problem persists.

~/.cache/helix/helix.log
2021-08-29T11:18:44.129 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2021-08-29T11:18:44.129 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2021-08-29T11:18:44.129 mio::poll [TRACE] registering event source with poller: token=Token(3), interests=READABLE | WRITABLE
2021-08-29T11:18:44.129 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":65730,"rootUri":null},"id":0}
2021-08-29T11:18:45.944 helix_lsp::transport [ERROR] err: <- IO(Custom { kind: Other, error: "Failed to parse header" })
2021-08-29T11:18:45.944 mio::poll [TRACE] deregistering event source from poller
2021-08-29T11:18:46.130 mio::poll [TRACE] deregistering event source from poller
2021-08-29T11:18:46.130 mio::poll [TRACE] registering event source with poller: token=Token(16777218), interests=READABLE | WRITABLE
2021-08-29T11:18:46.130 mio::poll [TRACE] registering event source with poller: token=Token(16777217), interests=READABLE | WRITABLE
2021-08-29T11:18:46.130 mio::poll [TRACE] registering event source with poller: token=Token(0), interests=READABLE
2021-08-29T11:18:46.130 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.142 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.143 helix_lsp::transport [ERROR] err <- 
2021-08-29T11:18:46.143 helix_lsp::transport [ERROR] err <- 

@uncomfyhalomacro
Copy link
Contributor Author

it'll time out after two seconds

is this for the lsp plugin of helix? julia's LanguageServer.jl usually starts at least 2 to 10 seconds in my experience (even a minute or more depending on the project). this is because of the "slow time to first plot" of julia that is also applicable to almost all packages. Not sure if this is relevant though.

@archseer
Copy link
Member

It seems to be an error before we even hit the timeout.

I pushed a commit with some more logging (7eff905) can you build from master, try again and give me the hx -v -v log output again?

@uncomfyhalomacro
Copy link
Contributor Author

Thanks for the assistance. It seems there is new stuff in the logs:

~/.cache/helix/helix.log
2021-08-29T12:16:35.578 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":78545,"rootUri":null},"id":0}
2021-08-29T12:16:37.446 helix_lsp::transport [DEBUG] <- header ┌ Info: Running language server
2021-08-29T12:16:37.446 helix_lsp::transport [DEBUG] <- header │   VERSION = v"1.7.0-beta3.0"
2021-08-29T12:16:37.446 helix_lsp::transport [ERROR] err: <- Other(Failed to parse header: "│   VERSION = v\"1.7.0-beta3.0\"")
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 
2021-08-29T12:16:37.593 helix_lsp::transport [ERROR] err <- 

I have a guess that it is receiving the output of @info macro when LanguageServer runs but not sure. This is what it looks like when running the script alone:

$ julia test.jl
┌ Info: Running language server
│   VERSION = v"1.7.0-beta3.0"pwd() = "/home/uncomfy"
│   project_path = "/home/uncomfy/.julia/environments/v1.7"
└   depot_path = ""
[ Info: Couldn't retrieve cache file for FuzzyCompletions.
[ Info: Couldn't retrieve cache file for LibSSH2_jll.
[ Info: Couldn't retrieve cache file for MbedTLS_jll.
┌ Warning: LibSSH2_jll not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192
┌ Warning: MbedTLS_jll not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192
┌ Warning: FuzzyCompletions not stored on disc
└ @ SymbolServer ~/.julia/packages/SymbolServer/rrlGM/src/SymbolServer.jl:192
[ Info: Received new data from Julia Symbol Server.

@archseer
Copy link
Member

Oh yeah, definitely get rid of the @info line in the command: @info "Running language server" VERSION pwd() project_path depot_path; all of this will completely trip things up since it's not JSONRPC, as per spec.

Here's how the kakoune definition looks like:
https://github.com/julia-vscode/LanguageServer.jl/wiki/Kakoune#specify-the-julia-language-server

(or here https://github.com/kak-lsp/kak-lsp/blob/35c4be891ede4d9a0985c8294399fb0e8c9d8c79/kak-lsp.toml#L152)

There seems to be further logging into stdout though so I'm checking how this is handled in other clients.

@archseer
Copy link
Member

If it still breaks I'll probably add a workaround in the client (I assume [ Info: Received new data from Julia Symbol Server. will still break)

@VarLad
Copy link
Contributor

VarLad commented Aug 29, 2021

@archseer After trying a few things, I think its a problem on the helix side of LSP implementation

@archseer
Copy link
Member

archseer commented Aug 29, 2021

@archseer After trying a few things, I think its a problem on the helix side of LSP implementation

It would be useful if you provided logs after applying the changes above and/or explained what you tried. From what I can tell the Julia LSP doesn't conform to the spec and mixes in logging output with RPC messages. We can work around this, but it really should be fixed in the server.

@VarLad
Copy link
Contributor

VarLad commented Aug 29, 2021

The errors I got are same as @uncomfyhalomacro

I'll be filing an issue on the LanguageServer.jl side of things though

Here: julia-vscode/LanguageServer.jl#982

@archseer
Copy link
Member

Pushed a workaround: 847d1fa

@uncomfyhalomacro
Copy link
Contributor Author

Update

First attempt

Configuration on language.toml:

[[language]]
name = "julia"
scope = "source.julia"
injection-regex = "julia"
file-types = ["jl"]
roots = []
comment-token = "#"
language-server = { command = "julia", args = ["--startup-file=no", "--history-file=no", "-q", "-e", "'using LanguageServer;popfirst!(LOAD_PATH);depot_path = get(ENV, \"JULIA_DEPOT_PATH\", \"\");project_path = let; dirname(something(Base.load_path_expand((p = get(ENV, \"JULIA_PROJECT\", nothing); p === nothing ? nothing : isempty(p) ? nothing : p)), Base.current_project(), get(Base.load_path(), 1, nothing), Base.load_path_expand(\"@v#.#\"),)); end; server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path); server.runlinter = true; run(server)'"] }

indent = { tab-width = 2, unit = "  " }

It is valid TOML format though no matter how I check it

image

Helix Logs:

~/.cache/helix/helix.log

2021-08-29T17:26:11.150 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":140204,"rootUri":null},"id":0}
2021-08-29T17:26:11.994 helix_lsp::transport [ERROR] err <- ERROR: syntax: invalid character literal

2021-08-29T17:26:11.994 helix_lsp::transport [ERROR] err <- Stacktrace:

2021-08-29T17:26:11.994 helix_lsp::transport [ERROR] err <-  [1] top-level scope

2021-08-29T17:26:12.048 helix_lsp::transport [ERROR] err <-    @ none:1

2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err: <- Other(missing content length)
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:26:12.060 helix_lsp::transport [ERROR] err <- 

Second attempt

Configuration in language.toml:

[[language]]
name = "julia"
scope = "source.julia"
injection-regex = "julia"
file-types = ["jl"]
roots = []
comment-token = "#"
language-server = { command = "julia", args = ["--startup-file=no", "--history-file=no", "--quiet", "/home/uncomfy/julialsp.jl"] }

indent = { tab-width = 2, unit = "  " }

Using a script instead because I have no other ways to find out what is causing the syntax error.

Helix Logs
~/.cache/helix/helix.log

2021-08-29T17:40:48.504 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":145443,"rootUri":null},"id":0}
2021-08-29T17:40:50.519 helix_lsp::transport [ERROR] err: <- Other(missing content length)
2021-08-29T17:40:50.519 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:40:50.520 helix_lsp::transport [ERROR] err <- 

Both attempts have problems, the second one is weird, because julia process dies. Maybe because of the timeout, it may have not let julia start the process completely.

@uncomfyhalomacro
Copy link
Contributor Author

Pushed a workaround: 847d1fa

oh nice, going to try this one. thanks again. sorry for the bother

@archseer
Copy link
Member

I think the problem with the first command is likely the quoting around that last parameter, it might work if you remove the single quotes '. These should be automatically added by helix when executing the command.

@archseer
Copy link
Member

Try defining it like this:

language-server = { command = "julia", args = [
        "--startup-file=no",
        "--history-file=no",
        "--quiet",
        "-e",
        """
                using LanguageServer;
                using Pkg;
                import StaticLint;
                import SymbolServer;
                env_path = dirname(Pkg.Types.Context().env.project_file);

                server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, "");
                server.runlinter = true;
                run(server);
        """,
        ] }

@uncomfyhalomacro
Copy link
Contributor Author

uncomfyhalomacro commented Aug 29, 2021

I think the problem with the first command is likely the quoting around that last parameter, it might work if you remove the single quotes '. These should be automatically added by helix when executing the command.

That fixed the syntax literal problem. Thanks! 😃

2021-08-29T17:56:53.727 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":155984,"rootUri":null},"id":0}
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err: <- Other(missing content length)
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 
2021-08-29T17:56:55.745 helix_lsp::transport [ERROR] err <- 

Now it looks like the second attempt from before. I used the latest master btw with your changes 847d1fa. Hmm seems julia process still terminates prematurely.

@archseer
Copy link
Member

Can you do it with -vvv? I'd like to see the raw lines we receive

@uncomfyhalomacro
Copy link
Contributor Author

With hx -vvv ~/helloworld.jl, the log looks like this:

2021-08-29T18:03:12.292 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
2021-08-29T18:03:12.292 mio::poll [TRACE] registering event source with poller: token=Token(2), interests=READABLE | WRITABLE
2021-08-29T18:03:12.292 mio::poll [TRACE] registering event source with poller: token=Token(3), interests=READABLE | WRITABLE
2021-08-29T18:03:12.292 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]}},"window":{"workDoneProgress":true}},"processId":156555,"rootUri":null},"id":0}
2021-08-29T18:03:14.294 mio::poll [TRACE] deregistering event source from poller
2021-08-29T18:03:14.294 mio::poll [TRACE] registering event source with poller: token=Token(4), interests=READABLE | WRITABLE
2021-08-29T18:03:14.294 mio::poll [TRACE] registering event source with poller: token=Token(16777217), interests=READABLE | WRITABLE
2021-08-29T18:03:14.294 mio::poll [TRACE] registering event source with poller: token=Token(0), interests=READABLE
2021-08-29T18:03:14.294 mio::poll [TRACE] registering event source with poller: token=Token(1), interests=READABLE
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err: <- Other(missing content length)
2021-08-29T18:03:14.311 mio::poll [TRACE] deregistering event source from poller
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 
2021-08-29T18:03:14.311 helix_lsp::transport [ERROR] err <- 

@archseer
Copy link
Member

I'll set up julia and do some tests tomorrow morning, been meaning to tweak the highlight definitions for it a bit anyway. Is it enough for me to just add a test.jl file or do I need a specific project structure?

@archseer
Copy link
Member

archseer commented Sep 3, 2021

It doesn't because indents.toml wasn't defined. Someone needs to go and list all the scopes that are considered indents.

@VarLad
Copy link
Contributor

VarLad commented Sep 3, 2021

Can we use something like the LSP for auto-formatting? Julia has a formatter too.
But I guess auto-formatting for large files would be bad that way
I'll see if I can write a indents.toml (looks easy enough to write one)

@archseer
Copy link
Member

archseer commented Sep 3, 2021

We auto format via the LSP on save for certain languages, if the Julia formatter is good enough we could enable it:

auto-format = true

@uncomfyhalomacro
Copy link
Contributor Author

With RUST_BACKTRACE=1 :
backtrace-1.log

With RUST_BACKTRACE=full :
backtrace-full.log

@archseer
Copy link
Member

archseer commented Sep 4, 2021

How is the LSP so slow :D I thought Julia was a fast language. You might want to experiment with a longer timeout here (try 60s)

timeout(Duration::from_secs(20), rx.recv())

@uncomfyhalomacro
Copy link
Contributor Author

How is the LSP so slow :D I thought Julia was a fast language. You might want to experiment with a longer timeout here (try 60s)

timeout(Duration::from_secs(20), rx.recv())

Julia is fast but still, the "slow time to first plot" problem is a pain. I think I can try to change the commands to run it with a compiled sysimage of the server. If that works, i might add an instruction for it either in the wiki or somewhere. I will test that first and then that longer time out thingy.

@archseer
Copy link
Member

archseer commented Sep 4, 2021

@uncomfyhalomacro
Copy link
Contributor Author

uncomfyhalomacro commented Sep 5, 2021

Good morning. I tested it with both a compiled sysimage with timeout of 20 seconds with the following TOML configuration

language-server = { command = "julia", args = [
        "--startup-file=no",
        "--history-file=no",
        "--sysimage=/home/uncomfy/julialsp.so",
        "--sysimage-native-code=yes",
        "--quiet",
        "--eval",
        """
                using LanguageServer;
                popfirst!(LOAD_PATH);
                depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
                project_path = let
                    dirname(something(
                        Base.load_path_expand((
                            p = get(ENV, "JULIA_PROJECT", nothing);
                            p === nothing ? nothing : isempty(p) ? nothing : p
                        )),
                        Base.current_project(),
                        get(Base.load_path(), 1, nothing),
                        Base.load_path_expand("@v#.#"),
                    ))
                end;
                server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
                server.runlinter = true;
                run(server);
        """,
        ] }

. It currently works. If not using sysimage, it will fail because timeout already happened so i need to increase it to at least 10 seconds (currently 60 just to make sure). There is something wrong with executing :gi or finding implementation sometimes but overall it kinda works. Is it fine to open a PR? The script for the LSP server should be reworked because of these julia-vscode/LanguageServer.jl#750 (comment) & julia-vscode/SymbolServer.jl#155. there is no need to import SymbolServer.

@ym-han
Copy link

ym-han commented Sep 7, 2021

Good morning. I tested it with both a compiled sysimage with timeout of 20 seconds with the following TOML configuration

language-server = { command = "julia", args = [
        "--startup-file=no",
        "--history-file=no",
        "--sysimage=/home/uncomfy/julialsp.so",
        "--sysimage-native-code=yes",
        "--quiet",
        "--eval",
        """
                using LanguageServer;
                popfirst!(LOAD_PATH);
                depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
                project_path = let
                    dirname(something(
                        Base.load_path_expand((
                            p = get(ENV, "JULIA_PROJECT", nothing);
                            p === nothing ? nothing : isempty(p) ? nothing : p
                        )),
                        Base.current_project(),
                        get(Base.load_path(), 1, nothing),
                        Base.load_path_expand("@v#.#"),
                    ))
                end;
                server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
                server.runlinter = true;
                run(server);
        """,
        ] }

. It currently works. If not using sysimage, it will fail because timeout already happened so i need to increase it to at least 10 seconds (currently 60 just to make sure). There is something wrong with executing :gi or finding implementation sometimes but overall it kinda works. Is it fine to open a PR? The script for the LSP server should be reworked because of these julia-vscode/LanguageServer.jl#750 (comment) & julia-vscode/SymbolServer.jl#155. there is no need to import SymbolServer.

@uncomfyhalomacro regardless of whether they want a PR, I'd be interested in getting a hold of whatever scripts you used to make this work. I use Julia myself too, and am interested in trying out Helix.

@VarLad
Copy link
Contributor

VarLad commented Sep 15, 2021

@archseer Any update on this?

@archseer
Copy link
Member

@VarLad I've merged lsp-async-init into master a while ago and it also contains some modifications to the server definition (drops SymbolServer 3cbdc05).

If the sysimage changes can be made in a way all users can benefit from (no hardcoded /home/<user>) then I'm open to accepting that in a PR.

@VarLad
Copy link
Contributor

VarLad commented Sep 16, 2021

@archseer Is there a possibility that you can somehow increase the time or add something like an exception for the Julia LSP when it comes to timeout?
That would be the ideal solution. Making sysimages is a process not many julia users might find ideal

@uncomfyhalomacro
Copy link
Contributor Author

@archseer Hello! I know that this is late but currently Julia LSP is working now. I should close this :D

@uncomfyhalomacro
Copy link
Contributor Author

Thanks again!

@paveloom
Copy link

paveloom commented Apr 20, 2022

So, currently Julia users need to:

  1. Create a sysimage of the LanguageServer package:
pkg> add LanguageServer
pkg> add PackageCompiler
julia> using PackageCompiler
julia> create_sysimage(["LanguageServer"]; sysimage_path="julialsp.so")
  1. Change the default language server command:
# ~/.config/helix/languages.toml
# <...>
[[language]]
name = "julia"
language-server = { command = "julia", args = [
  "--startup-file=no",
  "--history-file=no",
  "--sysimage=/path/to/julialsp.so",
  "--sysimage-native-code=yes",
  "--quiet",
  "--eval",
  """
  using LanguageServer;
  popfirst!(LOAD_PATH);
  depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
  project_path = let
      dirname(something(
          Base.load_path_expand((
              p = get(ENV, "JULIA_PROJECT", nothing);
              p === nothing ? nothing : isempty(p) ? nothing : p
          )),
          Base.current_project(),
          get(Base.load_path(), 1, nothing),
          Base.load_path_expand("@v#.#"),
      ))
  end;
  server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
  server.runlinter = true;
  run(server);
  """,
] }

Also, no Tab completions for writing Unicode characters easily.

@uncomfyhalomacro
Copy link
Contributor Author

So, currently Julia users need to:

1. Create a sysimage of the `LanguageServer` package:
pkg> add LanguageServer
pkg> add PackageCompiler
julia> using PackageCompiler
julia> create_sysimage(["LanguageServer"]; sysimage_path="julialsp.so")
2. Change the default language server command:
# ~/.config/helix/languages.toml
# <...>
[[language]]
name = "julia"
language-server = { command = "julia", args = [
  "--startup-file=no",
  "--history-file=no",
  "--sysimage=/path/to/julialsp.so",
  "--sysimage-native-code=yes",
  "--quiet",
  "--eval",
  """
  using LanguageServer;
  popfirst!(LOAD_PATH);
  depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
  project_path = let
      dirname(something(
          Base.load_path_expand((
              p = get(ENV, "JULIA_PROJECT", nothing);
              p === nothing ? nothing : isempty(p) ? nothing : p
          )),
          Base.current_project(),
          get(Base.load_path(), 1, nothing),
          Base.load_path_expand("@v#.#"),
      ))
  end;
  server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
  server.runlinter = true;
  run(server);
  """,
] }

Also, no Tab completions for writing Unicode characters easily.

seems like we have the same idea. I do hope in the future that helix will have the ability to create envs like how kakoune does it e.g. $kak_buffile and the LSP client can receive it so anyone can do this:

https://github.com/kak-lsp/kak-lsp/blob/52197dde1a1c5e997a3ad989a8dfdd8017056a3b/kak-lsp.toml#L155-L189

@shaul-pollak
Copy link

any idea how I can use absolute paths in the config file?
This is required when pointing to the languageserver compiled sysimage

Thanks!

@ChrHorn
Copy link
Contributor

ChrHorn commented Aug 7, 2022

any idea how I can use absolute paths in the config file? This is required when pointing to the languageserver compiled sysimage

Thanks!

Absolute paths should just work.

Note that if you are facing the timeout issue, you can also fix it by increasing the max timeout in your languages.toml:

[[language]]
name = "julia"
...
language-server.timeout = 60 # default 20

@shaul-pollak
Copy link

shaul-pollak commented Aug 7, 2022

hmmm... weird

I compiled a sysimage at ~/.julia/sysimages/julialsp.so
This is my config:

[[language]]
name = "julia"
language-server = { command = "julia", args = [
"--startup-file=no",
"--history-file=no",
"--sysimage=~/.julia/sysimages/julialsp.so",
"--sysimage-native-code=yes",
"--quiet",
"--eval",
"""
using LanguageServer;
popfirst!(LOAD_PATH);
depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
project_path = let
dirname(something(
Base.load_path_expand((
p = get(ENV, "JULIA_PROJECT", nothing);
p === nothing ? nothing : isempty(p) ? nothing : p
)),
Base.current_project(),
get(Base.load_path(), 1, nothing),
Base.load_path_expand("@v#.#"),
))
end;
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
""",
] }

and i'm getting this error:
2022-08-07T17:02:27.293 helix_lsp::transport [ERROR] err <- "ERROR: could not load library "/myhomedir/.config/helix/~/.julia/sysimages/julialsp.so"\n"
2022-08-07T17:02:27.293 helix_lsp::transport [ERROR] err <- "/myhomedir/.config/helix/~/.julia/sysimages/julialsp.so: cannot open shared object file: No such file or directory\n"

This happens when i try to edit a julia file in ~/.config/helix

if I edit a julia file from my home dir, everything works fine, as one would expect from a relative path

@shaul-pollak
Copy link

got it to work by using -J instead of --sysimage

@ChrHorn
Copy link
Contributor

ChrHorn commented Aug 7, 2022

This part is not really needed:

"""
using LanguageServer;
popfirst!(LOAD_PATH);
depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
project_path = let
dirname(something(
Base.load_path_expand((
p = get(ENV, "JULIA_PROJECT", nothing);
p === nothing ? nothing : isempty(p) ? nothing : p
)),
Base.current_project(),
get(Base.load_path(), 1, nothing),
Base.load_path_expand("@v#.#"),
))
end;
server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
server.runlinter = true;
run(server);
"""

This should do the same:

"using LanguageServer; runserver()"

@jcbritobr
Copy link

There are any tutorials to setup julia in helix? This seems confuse a lot.

@uncomfyhalomacro
Copy link
Contributor Author

There are any tutorials to setup julia in helix? This seems confuse a lot.

I will write a short post soon on how to set it up :)

@uncomfyhalomacro
Copy link
Contributor Author

There are any tutorials to setup julia in helix? This seems confuse a lot.

https://uncomfyhalomacro.pl/blog/14/

@luiswirth
Copy link

the link of @uncomfyhalomacro is unfortunatly dead :(
Are there any other guides to setting this up?

@luiswirth
Copy link

I created a new issue #10759

@2639-unofficial
Copy link

2639-unofficial commented May 14, 2024

I've found the wiki page from julia-vscode/LanguageServer to be quite useful.

@uncomfyhalomacro
Copy link
Contributor Author

the link of @uncomfyhalomacro is unfortunatly dead :(
Are there any other guides to setting this up?

Oh it was archived in my blog. i also think that i was the one that added on the wiki. you can still see the archive from my website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests