erlang-ls / erlang_ls

The Erlang Language Server
https://erlang-ls.github.io/
Apache License 2.0
628 stars 136 forks source link

Sublime Text 3's LSP exits with code 127 #783

Closed aaronlelevier closed 4 years ago

aaronlelevier commented 4 years ago

Describe the bug I am getting an exit code of 127 when trying to run Erlang-LS with LSP.

I tried following the configuration advise in #565 as I thought that it might be the same issue, but I couldn't get around the error.

I'm not sure if this is related to Erlang-LS or Sublime Text LSP, but I thought that I could start asking here.

I googled the error and it says here that the error is:

Exit code 127 means job's command can not be found or executed

I checked my erlang_ls executable, and it looks fine:

aaron@ ~/Documents/github/erlang_ls ((HEAD detached at 0.4.1))
$ pwd
/Users/aaron/Documents/github/erlang_ls
aaron@ ~/Documents/github/erlang_ls ((HEAD detached at 0.4.1))
$ ls -la _build/default/bin/erlang_ls 
-rwxr-xr-x  1 aaron  staff  2465517 Sep 12 10:03 _build/default/bin/erlang_ls

To Reproduce Here are the logs from Sublime Text:

​```
plugins loaded
LSP: global configs ['rls=False', 'rlang=False', 'elixir-ls=False', 'haskell-ide-engine=False', 'dart=False', 'polymer-ide=False', 'erlang-ls=True', 'flow=False', 'vscode-css=False', 'sorbet=False', 'phpls=False', 'golsp=False', 'sourcekit-lsp=False', 'reason=False', 'cquery=False', 'rust-analyzer=False', 'gopls=False', 'jdtls=False', 'bashls=False', 'ruby=False', 'intelephense-ls=False', 'javascript-typescript-langserver=False', 'typescript-language-server=False', 'clangd=False', 'lsp-tsserver=False', 'pyls=False', 'ocaml=False']
LSP: group 0 view /Users/aaron/Documents/erlang/dta/erlang_ls.config
LSP: window 4 starting 1 initial views
Package Control: Skipping automatic upgrade, last run at 2020-09-12 10:33:54, next run at 2020-09-12 11:33:54 or after
LSP: window 4 requests erlang-ls for /Users/aaron/Documents/erlang/dta/apps/chromag/src/chromag.erl
LSP: starting ['/Users/aaron/Documents/github/erlang_ls/_build/default/bin/erlang_ls', '--transport', 'stdio']
LSP:LSP: process 48240 stdout ended (still alive)
LSP: process 48240 exited with code 127
LSP: transport failed
 window 4 added session erlang-ls
LSP: LSP stream logger stopped.
​```

erlang_ls.config

otp_path: "/usr/local/Cellar/erlang/23.0.2/lib/erlang"
deps_dirs:
  - "_build/default/lib/*"
  - "_build/test/lib/*"
include_dirs:
  - "include"
  - "_build/default/lib"
  - "_build/test/lib"

LSP.sublime-settings

{
  "clients":
    {
      "erlang-ls":
        {
          "command"   : [
            "/Users/aaron/Documents/github/erlang_ls/_build/default/bin/erlang_ls",
            "--transport", "stdio"
          ],
          "enabled"   : true,
          "languageId": "erlang",
          "scopes"    : [ "source.erlang" ],
          "syntaxes"  : ["Packages/Erlang/Erlang.sublime-syntax"]
        }
    },
  // Allow up to 30 secs to `erlang_ls` to respond to `initialize`
  // (it requires less, but just to be on the safe side)
  "initialize_timeout": 30,

  // Show verbose debug messages in the sublime console.
  "log_debug": true,
  "log_server": true,
  "log_stderr": true,
  "log_payloads": true
}

Expected behavior To be able to use Erlang-LS with Sublime Text 3 LSP.

Actual behavior Can't use Erlang-LS with Sublime Text 3 LSP.

Context

This is for an open source hobby project of mine. I'm trying to Erlang better. I created a branch for this here if that helps.

aaronlelevier commented 4 years ago

I found this issue in Sublime Text LSP issues: https://github.com/sublimelsp/LSP/issues/1137

Maybe it's related. I am going to read it and check.

robertoaloi commented 4 years ago

Ok, let us know if you realize they are two occurrences of the same issue.

aaronlelevier commented 4 years ago

I am not sure to be honest. When I run the last command in the linked LSP issue, it seems to work. I get this:

aaron@ ~/Documents/github/erlang_ls ((HEAD detached at 0.4.1))
$ erlang_ls --version  
Version: 0.4.1
aaronlelevier commented 4 years ago

The issue is due to my local environment.

When I ran shutil.which("erlang_ls") before, I would get no output, and Erlang-LS had didn't start because of the path issue.

But now on another machine I get the following, and Erlang-LS is working as expected.

>>> import shutil
>>> shutil.which("erlang_ls")
'/usr/local/bin/erlang_ls'
aaronlelevier commented 4 years ago

It was due to a path issue with SublimeText. This package fixed it for me on my original machine: https://github.com/int3h/SublimeFixMacPath

robertoaloi commented 4 years ago

Glad to hear that you found a solution. I'm going to add the above as hints for the Sublime section in erlang-ls.github.io.

robertoaloi commented 4 years ago

@aaronlelevier Also, looking at your config file, you were using an absolute path:

 "/Users/aaron/Documents/github/erlang_ls/_build/default/bin/erlang_ls"

Maybe it was Erlang itself not to be in the path? I'm not a Sublime Text user. Is there a terminal I can open from Sublime to verify the "path" from Sublime perspective?

robertoaloi commented 4 years ago

Updated docs: https://github.com/erlang-ls/erlang-ls.github.io/pull/24

aaronlelevier commented 4 years ago

Thank you for submitting https://github.com/erlang-ls/erlang-ls.github.io/pull/24. That will help other Sublime Text users I think.

About my absolute path above, yes that is correct. The path was not on the Erlang code path, so it didn't work.

Okay, I see in https://github.com/erlang-ls/erlang-ls.github.io/pull/24 your notes on toggling the Show Console. From the Menu Bar its under View > Show Console

With the open Sublime Text console, which is a Python terminal, I then ran commands like this to inspect the path:

import shutil
shutil.which("erlang_ls")

import os
os.environ["PATH"]

Maybe one other thing to include that helped me is the Sublime Text auto-save package. I didn't know if Erlang-LS was working until I saw that it's triggered on save, which Sublime Text only has an option to do this on file close or file blur, so the auto-save package does this every 1 second, so you get the Erlang-LS feedback a lot easier. Here's the link:

https://github.com/jamesfzhang/auto-save