leona / helix-gpt

Code assistant language server for Helix with support for Copilot/OpenAI/Codeium/Ollama
MIT License
285 stars 19 forks source link

[BUG] failed to initialize language server: request 0 timed out #49

Open xaverhimmelsbach opened 3 months ago

xaverhimmelsbach commented 3 months ago

device info Apple M2 Pro

helix-editor version helix 23.10 (1d1806c8)

helix-gpt version 0.31

Describe the bug The initialization request from Helix times out when opening a file for which helix-gpt is configured to run. helix-gpt waits in src/models/lsp.ts in line 207 for Chunks from. Bun.stdin.stream() but nothing ever arrives. I checked this by logging the chunkText.

If I start helix-gpt manually with

echo "Hello Helix-GPT" | bun run /Users/xaver.himmelsbach/Development/helix-gpt/src/app.ts --logFile /Users/xaver.himmelsbach/gpt.log

the input is read from stdin:

APP 2024-03-19T16:45:21.209Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:45:21.213Z --> Hello Helix-GPT

APP 2024-03-19T16:45:21.214Z --> failed to parse line:| failed to parse | Hello Helix-GPT

helix-gpt logs Most of the time, helix-gpt justs prints the triggerCharacters and receives nothing more. Sometimes, when repeatedly executing :lsp-restart in Helix, an initialization request comes through, but that still doesn't seem to be handled correctly.

These logs show the request showing up after repeatedly calling :lsp-restart:

APP 2024-03-19T16:48:07.090Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:49:41.674Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:50:33.410Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:51:46.195Z --> triggerCharacters: | ["{","("," "]

APP 2024-03-19T16:51:49.266Z --> Content-Length: 2016

{"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}

APP 2024-03-19T16:51:49.267Z --> received request: | {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}

APP 2024-03-19T16:51:49.267Z --> sent request | {"jsonrpc":"2.0","method":"initialize","id":0,"result":{"capabilities":{"codeActionProvider":true,"executeCommandProvider":{"commands":["resolveDiagnostics","generateDocs","improveCode","refactorFromComment","writeTest"]},"completionProvider":{"resolveProvider":false,"triggerCharacters":["{","("," "]},"textDocumentSync":{"change":1,"openClose":true}}}}

APP 2024-03-19T16:51:49.311Z --> triggerCharacters: | ["{","("," "]

helix logs Helix seems to send the initialization request and times out after 10 seconds (default LSP timeout). Increasing the timeout in languages.toml just led to longer waiting times.

2024-03-19T17:50:33.362 helix_lsp::transport [INFO] gpt -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"positionEncodings":["utf-8","utf-32","utf-16"]},"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"isPreferredSupport":true,"resolveSupport":{"properties":["edit","command"]}},"completion":{"completionItem":{"deprecatedSupport":true,"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"inlayHint":{"dynamicRegistration":false},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"versionSupport":true},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":true},"signatureHelp":{"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown"],"parameterInformation":{"labelOffsetSupport":true}}}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":false},"executeCommand":{"dynamicRegistration":false},"fileOperations":{"didRename":true,"willRename":true},"inlayHint":{"refreshSupport":false},"symbol":{"dynamicRegistration":false},"workspaceEdit":{"documentChanges":true,"failureHandling":"abort","normalizesLineEndings":false,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"helix","version":"23.10 (1d1806c8)"},"processId":23053,"rootPath":"/Users/xaver.himmelsbach/Development/cruise-cruised","rootUri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised","workspaceFolders":[{"name":"cruise-cruised","uri":"file:///Users/xaver.himmelsbach/Development/cruise-cruised"}]},"id":0}
2024-03-19T17:50:53.365 helix_lsp [ERROR] failed to initialize language server: request 0 timed out
nkobber commented 3 months ago

I face the same issue

My helix logs also shows

helix_lsp [ERROR] failed to initialize language server: request 0 timed out

I tried both using bun, and built my own executable using bun build. Same results for both.

My config (with the path edited and api key redacted):

[language-server.gpt]
command = "bun"
args = ["run", "/path/to/helix-gpt", "--handler", "copilot", "--copilotApiKey", "redacted"]

[[language]]
name = "go"
language-servers = [
  "gopls",
  "gpt"
]
justinlovinger commented 3 months ago

I am getting the same issue on NixOS using Codeium.

justinlovinger commented 3 months ago

I resolved this issue by going back to version 0.28. It seems 0.31 is simply broken.

sigmaSd commented 3 months ago

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

nkobber commented 3 months ago

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

Thanks @sigmaSd. I got it working using deno and your fork.

xaverhimmelsbach commented 3 months ago

Its a bug in bun, either use an old version, or use my deno fork https://github.com/sigmaSd/helix-gpt

Obviously the best thing is to find whats the issue exactly to report it to the bun devs

Works flawlessly, thank you so much! I'm closing this issue for now, hopefully bun will fix this error. Otherwise @sigmaSd have you thought about opening a PR for deno support?

sigmaSd commented 3 months ago

I opened a PR already https://github.com/leona/helix-gpt/pull/45 but then I thought maybe its too many changes and its better kept as a fork, obviously if @leona is interested I can reopen it

justinlovinger commented 3 months ago

I narrowed the issue down to between Bun version 1.0.29, exclusive, and 1.0.35, inclusive.

adriangalilea commented 3 months ago

I think this issue should stay open for visibility while there's no warning on the README Thank you @sigmaSd

EDIT: what are version 0.30 and 0.31? there's no release logs and no changes in files as far as I can see

EDIT2: @justinlovinger

I resolved this issue by going back to version 0.28. I had no luck running 0.28 either, not sure what I'm doing wrong at this point.

pheepa commented 3 months ago

0.28 broken for me either

pheepa commented 3 months ago
[language-server.gpt]
command = "deno"
args = ["run", "--allow-env", "--allow-net",  "/usr/local/bin/helix-gpt-0.31.js",
 "--logFile",  "/Users/f.abapoov/gpt.log", "--handler", "copilot"]

Am I doing it right? deno installed with brew but nothing works

sigmaSd commented 3 months ago

@pheepa

pheepa commented 3 months ago

I was not sure how to do it, did not find releases in your fork

I can just clone repo and refer to src/app.ts instead of /usr/local/bin/helix-gpt-0.31.js?

sigmaSd commented 3 months ago

Yes or if you want to use the easiest way you can just deno run url_to_app.js for example deno run --allow-net --allow-env https://raw.githubusercontent.com/sigmaSd/helix-gpt/421f4ef14a7d23d102bfec3cba24899cbbeda682/src/app.ts will run the current latest commit on my fork

sigmaSd commented 3 months ago

I updated the usage instruction to make it simpler

**Usage:**

The fork have tags that follows upstream but with `-deno` suffix, for example `0.31-deno`

To run with deno

deno run --allow-env --allow-net https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts  --handler codeium` # make sure to use the latest deno tag

To compile to a standalone executable

deno compile --output helix-gpt --no-check --allow-env --allow-net https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts # make sure to use the latest deno tag
adriangalilea commented 3 months ago

@sigmaSd

Thanks, but, what do I put on the languages.toml with your fork then?

sigmaSd commented 3 months ago
[language-server.gpt]
command = "deno"
args = ["run", "--allow-net","--allow-env", "https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts"]
# HANDLER can be set to openai/copilot/codeium
environment = { HANDLER= "codeium" }
adriangalilea commented 3 months ago

Managed to make it work, thank you, it doesn't feel right to be executing a remote file with --allow-net tho, any thoughts on that?

pheepa commented 3 months ago

I just cloned and refered to helix-gpt/src/app.ts, everything works

sigmaSd commented 3 months ago

Managed to make it work, thank you, it doesn't feel right to be executing a remote file with --allow-net tho, any thoughts on that?

My arguments

tldr deno only uses net and env permission but no read/write/ffi/run, I think this is secure

adriangalilea commented 3 months ago
  • the remote module is cached locally by deno on first access

I guess it'll eventually retrieve it again, right?

  • the net permission is needed to speak with the ai apis (codeium/openai ,etc)

I personally did this for copilot: --allow-net=api.github.com,copilot-proxy.githubusercontent.com,api.githubcopilot.com

  • there is no read or write permission!, only net and env, I can't imagine you can do many things with it

Well, you never know, just check the xz drama lately.

tldr deno only uses net and env permission but no read/write/ffi/run, I think this is secure

Just to be sure I did:

deno compile --output helix-gpt --no-check --allow-env --allow-net=api.github.com,copilot-proxy.githubusercontent.com,api.githubcopilot.com https://raw.githubusercontent.com/sigmaSd/helix-gpt/0.31-deno/src/app.ts

Then move that to /bin sudo mv helix-gpt /usr/local/bin/helix-gpt

And then on languages.toml

 [language-server.gpt]
command = "helix-gpt"
environment = { HANDLER= "copilot", COPILOT_API_KEY="***"}

So with this approach I'm not executing a remote file and only has the net permission for what it needs.

Out of curiosity, is it easy to see what changes on your fork from main somehow?

Regardless, thank you again.

sigmaSd commented 3 months ago

https://github.com/leona/helix-gpt/compare/master...sigmaSd:helix-gpt:deno

sstubbs commented 2 months ago

Hi, this is such an awesome project. Makes helix so much better. The nix package is also giving me this issue. Would be great if @leona could give an idea of whether we should use the fork or if there is another option. The fork with deno is working for me in the interim.

justinlovinger commented 2 months ago

Hi, this is such an awesome project. Makes helix so much better. The nix package is also giving me this issue. Would be great if @leona could give an idea of whether we should use the fork or if there is another option. The fork with deno is working for me in the interim.

For Nixpkgs, you can pin bun to a working version. This is what I did using Flakes,

helix-gpt = nixpkgs-unstable.legacyPackages.${system}.helix-gpt.override {
  bun = inputs.nixpkgs-working-bun.legacyPackages.${system}.bun;
};

where inputs.nixpkgs-working-bun is nixpkgs-working-bun.url = "github:nixos/nixpkgs/9e58aca561e18f5197029926db8dbde1738a2ff5";. You can do the similar without Flakes if you are not using them.

sbrow commented 1 month ago

@justinlovinger You're a lifesaver!

hacktivista commented 1 month ago

Isn't there any workaround for this? where can I find more info about the bug on bun?