sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.65k stars 182 forks source link

erlang-ls crashes with exit code 127 and no log #1137

Closed eproxus closed 4 years ago

eproxus commented 4 years ago

OS and language server

How you installed LSP (Package Control or from git?)

Package Control

Minimal reproduction steps

  1. Enable erlang-ls

Log

LSP.sublime-settings ``` // Settings in here override those in "LSP/LSP.sublime-settings", { "diagnostics_highlight_style": "box", "auto_show_diagnostics_panel_level": 0, "show_diagnostics_count_in_view_status": true, "show_code_actions_bulb": true, "log_server": true, "log_debug": true, "log_stderr": true, // "log_payloads": true, "clients": { "erlang-ls": { "command" : [ "erlang_ls", "--transport", "stdio", "--log-level", "debug"], "enabled": true, }, "lsp-json": { "enabled": false }, }, } ```
Sublime Console ``` LSP: "syntaxes" is deprecated, use "document_selector" instead. The document_selector for ['Packages/JavaScript/JSON.sublime-syntax', 'Packages/JSON/JSON.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Build System/Sublime Text Build System.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Color Scheme/Sublime Text Color Scheme.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Commands/Sublime Text Commands.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Completions/Sublime Text Completions.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Keymap/Sublime Text Keymap.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Macro/Sublime Text Macro.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Menu/Sublime Text Menu.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Mousemap/Sublime Text Mousemap.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Project/Sublime Text Project.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Settings/Sublime Text Settings.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Theme/Sublime Text Theme.sublime-syntax'] was deduced to "source.json" LSP: global configs ['lsp-json=False', 'rls=False', 'elixir-ls=False', 'javascript-typescript-langserver=False', 'rlang=False', 'clangd=False', 'lsp-tsserver=False', 'pyls=False', 'jdtls=False', 'golsp=False', 'dart=False', 'rust-analyzer=False', 'gopls=False', 'polymer-ide=False', 'cquery=False', 'ruby=False', 'sourcekit-lsp=False', 'erlang-ls=True', 'phpls=False', 'vscode-css=False', 'ocaml=False', 'sorbet=False', 'typescript-language-server=False', 'haskell-ide-engine=False', 'intelephense-ls=False', 'reason=False', 'flow=False', 'bashls=False'] LSP: group 0 view /Users/user/Project/src/my_project.app.src LSP: group 1 view /Users/user/Project/src/my_project_days.erl LSP: group 2 view /Users/user/Project/src/my_project_balance.erl LSP: window 8 starting 3 initial views LSP: window 8 requests erlang-ls for /Users/user/Project/src/my_project_days.erl LSP: starting ['erlang_ls', '--transport', 'stdio'] in /Users/user/Project LSP: window 8 added session erlang-ls LSP: scheduling for delayed open, session erlang-ls not ready: /Users/user/Project/src/my_project.app.src LSP: scheduling for delayed open, session erlang-ls not ready: /Users/user/Project/src/my_project_balance.erl .neovintageousrc file loaded LSP: window 8 requests erlang-ls for /Users/user/Project/src/my_project_days.erl LSP: starting ['erlang_ls', '--transport', 'stdio'] in /Users/user/Project LSP: window 8 added session erlang-ls LSP: stopped erlang-ls exit code 127 LSP: stopped erlang-ls exit code 127 LSP: clients for window 8 unloaded ```
LSP Log Panel ``` :: --> erlang-ls initialize(1): {'rootPath': '/Users/user/Project', 'workspaceFolders': [{'name': 'my_project', 'uri': 'file:///Users/user/Project'}], 'rootUri': 'file:///Users/user/Project', 'processId': 53236, 'initializationOptions': {}, 'capabilities': {'experimental': {}, 'textDocument': {'implementation': {'dynamicRegistration': True, 'linkSupport': True}, 'signatureHelp': {'signatureInformation': {'documentationFormat': ['markdown', 'plaintext'], 'parameterInformation': {'labelOffsetSupport': True}}, 'dynamicRegistration': True}, 'declaration': {'dynamicRegistration': True, 'linkSupport': True}, 'rangeFormatting': {'dynamicRegistration': True}, 'documentHighlight': {'dynamicRegistration': True}, 'typeDefinition': {'dynamicRegistration': True, 'linkSupport': True}, 'codeAction': {'dynamicRegistration': True, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source.organizeImports']}}}, 'hover': {'dynamicRegistration': True, 'contentFormat': ['markdown', 'plaintext']}, 'selectionRange': {'dynamicRegistration': True}, 'publishDiagnostics': {'relatedInformation': True}, 'completion': {'completionItemKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, 'dynamicRegistration': True, 'completionItem': {'snippetSupport': True, 'deprecatedSupport': True, 'tagSupport': {'valueSet': [1]}}}, 'documentSymbol': {'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'dynamicRegistration': True, 'hierarchicalDocumentSymbolSupport': True}, 'references': {'dynamicRegistration': True}, 'rename': {'dynamicRegistration': True}, 'formatting': {'dynamicRegistration': True}, 'synchronization': {'willSave': True, 'dynamicRegistration': True, 'willSaveWaitUntil': True, 'didSave': True}, 'definition': {'dynamicRegistration': True, 'linkSupport': True}, 'colorProvider': {'dynamicRegistration': True}}, 'window': {'workDoneProgress': True}, 'workspace': {'didChangeConfiguration': {'dynamicRegistration': True}, 'workspaceFolders': True, 'symbol': {'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'dynamicRegistration': True}, 'configuration': True, 'executeCommand': {}, 'workspaceEdit': {'documentChanges': True, 'failureHandling': 'abort'}, 'applyEdit': True}}, 'clientInfo': {'name': 'Sublime Text LSP', 'version': '1.0.1'}} ```

I can start and run erlang_ls manually from the Sublime console:

>>> os.environ['PATH']
'/Users/user/.asdf/shims:/Users/user/.asdf/bin:/Users/user/.local/bin:/Users/user/.cache/rebar3/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/user/Code/go/bin:/Users/user/.cargo/bin'
>>> subprocess.run(['erlang_ls', '--version', '--log-level', 'debug'], capture_output=True)
CompletedProcess(args=['erlang_ls', '--version', '--log-level', 'debug'], returncode=1, stdout=b'Version: 0.4.1\n', stderr=b'')
>>> subprocess.run(['erlang_ls', '--transport', 'stdio', '--log-level', 'debug'], capture_output=True)
CompletedProcess(args=['erlang_ls', '--transport', 'stdio', '--log-level', 'debug'], returncode=1, stdout=b'', stderr=b'')

(erlang_ls resides in /Users/user/.local/bin)

If I run erlang_ls this way I it returns exit code 1 and I get log output in /Users/user/Library/Logs/erlang_ls/MacOS/*.log.

However, when LSP tries to start the server I get this:

Screenshot 2020-06-17 at 14 17 57

If I configure LSP to use exactly the flags I use manually above, I still get no logs. That and the error code 127 leads me to belive LSP is failing to start erlang_ls at all, but I can't figure out why since there are no logs anywhere (either from LSP or from erlang_ls). The only thing "logged" is the LSP Log Panel output above.

rwols commented 4 years ago

It’s a bit suspicious that two erlang-ls processes are started. Can you perhaps check if things are working when you have a single group in the window?

eproxus commented 4 years ago

@rwols Good observation. If I reduce the window to one group only and then restart Sublime Text (version 4074 btw) I still see two entries in the log and the same error.

Sublime Console ``` LSP: "syntaxes" is deprecated, use "document_selector" instead. The document_selector for ['Packages/JavaScript/JSON.sublime-syntax', 'Packages/JSON/JSON.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Build System/Sublime Text Build System.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Color Scheme/Sublime Text Color Scheme.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Commands/Sublime Text Commands.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Completions/Sublime Text Completions.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Keymap/Sublime Text Keymap.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Macro/Sublime Text Macro.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Menu/Sublime Text Menu.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Mousemap/Sublime Text Mousemap.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Project/Sublime Text Project.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Settings/Sublime Text Settings.sublime-syntax', 'Packages/PackageDev/Package/Sublime Text Theme/Sublime Text Theme.sublime-syntax'] was deduced to "source.json" LSP: global configs ['lsp-json=False', 'clangd=False', 'javascript-typescript-langserver=False', 'flow=False', 'sorbet=False', 'golsp=False', 'sourcekit-lsp=False', 'elixir-ls=False', 'rlang=False', 'jdtls=False', 'polymer-ide=False', 'haskell-ide-engine=False', 'typescript-language-server=False', 'dart=False', 'vscode-css=False', 'intelephense-ls=False', 'ruby=False', 'pyls=False', 'ocaml=False', 'reason=False', 'cquery=False', 'phpls=False', 'erlang-ls=True', 'rls=False', 'gopls=False', 'bashls=False', 'rust-analyzer=False', 'lsp-tsserver=False'] LSP: group 0 view /Users/user/Project/src/my_project.app.src LSP: window 2 starting 1 initial views LSP: window 2 requests erlang-ls for /Users/user/Project/src/my_project.app.src LSP: starting ['erlang_ls', '--transport', 'stdio', '--log-level', 'debug'] in /Users/user/Project LSP: window 2 added session erlang-ls .neovintageousrc file loaded LSP: window 2 requests erlang-ls for /Users/user/Project/src/my_project.app.src LSP: starting ['erlang_ls', '--transport', 'stdio', '--log-level', 'debug'] in /Users/user/Project LSP: window 2 added session erlang-ls LSP: stopped erlang-ls exit code 127 LSP: stopped erlang-ls exit code 127 LSP: clients for window 2 unloaded ```

If two were indeed started, I would also expect one of them to succeed if they were fighting for port numbers or similar (they're not since they run in stdio mode).

rwols commented 4 years ago

Can you run this in the ST console:

import shutil; shutil.which(“erlang_ls”)

It should print the full path to the executable.

eproxus commented 4 years ago
>>> import shutil; shutil.which("erlang_ls")
'/Users/user/.local/bin/erlang_ls'
rwols commented 4 years ago

If you restart ST with a single view open, does one process get started (instead of two)?

rwols commented 4 years ago

I compiled erlang_ls and it seems to be working on my end (Ubuntu 20.04) (checking whether a language server works by opening its own git repo is always handy :) )

:: --> erlang-ls initialize(1): {'initializationOptions': {}, 'capabilities': {'window': {'workDoneProgress': True}, 'workspace': {'configuration': True, 'symbol': {'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'dynamicRegistration': True}, 'executeCommand': {}, 'applyEdit': True, 'workspaceFolders': True, 'workspaceEdit': {'failureHandling': 'abort', 'documentChanges': True}, 'didChangeConfiguration': {'dynamicRegistration': True}}, 'experimental': {}, 'textDocument': {'hover': {'dynamicRegistration': True, 'contentFormat': ['markdown', 'plaintext']}, 'references': {'dynamicRegistration': True}, 'definition': {'linkSupport': True, 'dynamicRegistration': True}, 'documentSymbol': {'hierarchicalDocumentSymbolSupport': True, 'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, 'dynamicRegistration': True}, 'publishDiagnostics': {'relatedInformation': True}, 'documentHighlight': {'dynamicRegistration': True}, 'codeAction': {'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source.organizeImports']}}, 'dynamicRegistration': True}, 'implementation': {'linkSupport': True, 'dynamicRegistration': True}, 'colorProvider': {'dynamicRegistration': True}, 'completion': {'completionItem': {'tagSupport': {'valueSet': [1]}, 'snippetSupport': True, 'deprecatedSupport': True}, 'dynamicRegistration': True, 'completionItemKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}}, 'synchronization': {'willSave': True, 'dynamicRegistration': True, 'willSaveWaitUntil': True, 'didSave': True}, 'signatureHelp': {'signatureInformation': {'parameterInformation': {'labelOffsetSupport': True}, 'documentationFormat': ['markdown', 'plaintext']}, 'dynamicRegistration': True}, 'rename': {'dynamicRegistration': True}, 'typeDefinition': {'linkSupport': True, 'dynamicRegistration': True}, 'declaration': {'linkSupport': True, 'dynamicRegistration': True}, 'rangeFormatting': {'dynamicRegistration': True}, 'selectionRange': {'dynamicRegistration': True}, 'formatting': {'dynamicRegistration': True}}}, 'rootPath': '/home/raoul/Documents/Programming/erlang_ls', 'clientInfo': {'name': 'Sublime Text LSP', 'version': '1.0.1'}, 'workspaceFolders': [{'name': 'erlang_ls', 'uri': 'file:///home/raoul/Documents/Programming/erlang_ls'}], 'processId': 28842, 'rootUri': 'file:///home/raoul/Documents/Programming/erlang_ls'}
:: <<< erlang-ls 1: {'capabilities': {'codeActionProvider': True, 'documentHighlightProvider': True, 'completionProvider': {'resolveProvider': False, 'triggerCharacters': [':', '#', '?', '.']}, 'executeCommandProvider': {'commands': ['28881:replace-lines', '28881:server-info', '28881:ct-run-test', '28881:show-behaviour-usages']}, 'documentFormattingProvider': True, 'foldingRangeProvider': True, 'hoverProvider': True, 'referencesProvider': True, 'workspaceSymbolProvider': True, 'textDocumentSync': {'openClose': True, 'save': {'includeText': True}, 'change': 1}, 'codeLensProvider': {'resolveProvider': False}, 'documentRangeFormattingProvider': False, 'documentSymbolProvider': True, 'implementationProvider': True, 'definitionProvider': True}}
::  -> erlang-ls initialized: {}
::  -> erlang-ls textDocument/didOpen
::  -> erlang-ls textDocument/didOpen
:: <-  erlang-ls window/showMessage: {'type': 3, 'message': 'Erlang LS (in erlang_ls), version: 0.4.1+build.1165.ref596e0fb'}
:: <-- erlang-ls window/workDoneProgress/create(1): {'token': 'b0e1c343-17d1-441c-9142-fdf0ced36410'}
:: >>> erlang-ls 1: None

The 127 status code seems to suggest that some binary somewhere is missing as that status code is used by sh to denote a missing binary. But it may be a red herring.

Trying again with

        "erlang-ls": {
            "command": [
                "erlang_ls",
                "--transport",
                "stdio",
                "--log-level",
                "debug"
            ],
            "enabled": true
        },

Also works here. Multiple views open also works.

eproxus commented 4 years ago

So I did get this error in the terminal some times (haven't figured out why, seems to be related to my Erlang version set by asdf somehow...):

erlang_ls --version                                                                                                                                                                                                                                                                                                                                                                                                                  0s
escript: exception error: undefined function erlang_ls:main/1
  in function  escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1
  in call from init:do_boot/3

What is odd (or perhaps a missing feature?) is that LSP doesn't report this error in the log, which would have made debugging so much easier.

eproxus commented 4 years ago

So, to conclude. erlang-ls crashed because of some weird mismatch between Erlang version used to compile it and the Erlang version used to run it set globally by asdf (I think, at least). Consider this a feature request to print the output of failed language servers to the log so they can be debugged in case they don't start properly.