elixir-lsp / elixir-ls

A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol"
https://elixir-lsp.github.io/elixir-ls/
Apache License 2.0
1.5k stars 196 forks source link

Repeatedly crashing when installing dependencies #1033

Closed John-Goff closed 11 months ago

John-Goff commented 11 months ago

Precheck

Environment

Current behavior

When opening ElixirLS, it repeatedly crashes when trying to install dependencies. If I restart it continually, it eventually works, but requires over a dozen restarts to work properly.

*lsp-log* buffer contents:

Started ElixirLS v0.17.10
Running in /Users/johngoff/Repos/HiredHippo
ElixirLS built with elixir "1.14.3" on OTP "25"
Running on elixir "1.14.3 (compiled with Erlang/OTP 25)" on OTP "25"
Protocols are not consolidated
Elixir sources not found (checking in /home/build/elixir). Code navigation to Elixir modules disabled.
Received client configuration via workspace/configuration
%{"dialyzerEnabled" => true, "dialyzerFormat" => "dialyxir_long", "enableTestLenses" => true, "fetchDeps" => false, "mixEnv" => "test", "projectDir" => "server", "signatureAfterComplete" => true, "suggestSpecs" => true}
DETS databases will be rebuilt
Client does not support workspace/didChangeConfiguration dynamic registration
Registering for workspace/didChangeWatchedFiles notifications
Starting build with MIX_ENV: test MIX_TARGET: host
Loaded DETS databases in 9ms
client/registerCapability succeeded
Received workspace/didChangeConfiguration
Received client configuration via workspace/didChangeConfiguration
%{"dialyzerEnabled" => true, "dialyzerFormat" => "dialyxir_long", "enableTestLenses" => true, "fetchDeps" => false, "mixEnv" => "test", "projectDir" => "server", "signatureAfterComplete" => true, "suggestSpecs" => true}
DETS databases will be rebuilt
Unable to reload project: cwd "/Users/johngoff/Repos/HiredHippo/server/deps/yaml_elixir" is not project dir /Users/johngoff/Repos/HiredHippo/server
warning: String.strip/1 is deprecated. Use String.trim/1 instead
  /Users/johngoff/Repos/HiredHippo/server/deps/poison/mix.exs:4: Poison.Mixfile

Stopping hired_hippo
Unloading hired_hippo
==> file_system
Compiling 7 files (.ex)
Generated file_system app
===> Analyzing applications...
===> Compiling telemetry_poller
==> gen_stage
Compiling 10 files (.ex)

The line Unable to reload project: cwd "/Users/johngoff/Repos/HiredHippo/server/deps/yaml_elixir" is not project dir /Users/johngoff/Repos/HiredHippo/server will change the dependency listed every time that I restart elixir LS.

*elixir-ls::stderr* buffer contents:

Running /Users/johngoff/.config/emacs/.local/etc/lsp/elixir-ls/launch.sh
Preferred shell is fish, launching launch.fish
Looking for ASDF install
ASDF install found in /Users/johngoff/.asdf/asdf.fish, sourcing
Installing ElixirLS release v0.17.10
Running in /Users/johngoff/Repos/HiredHippo
Could not find Hex, which is needed to build dependency true
Shall I install Hex? (if running non-interactively, use "mix local.hex --force")
* creating /Users/johngoff/.asdf/installs/elixir/1.14.3-otp-25/.mix/archives/hex-2.0.6
Install complete
Could not find Hex, which is needed to build dependency true
Shall I install Hex? (if running non-interactively, use "mix local.hex --force")
* creating /Users/johngoff/.asdf/installs/elixir/1.14.3-otp-25/.mix/archives/hex-2.0.6

It seems as though ASDF is not detected? It did prompt me once to install Hex, though it should have been already installed in the asdf location listed.

Relevant contents of the *Messages* buffer:

LSP :: Connected to [elixir-ls:82862/starting /Users/johngoff/Repos/HiredHippo].
LSP :: Sending to process failed with the following error: Process elixir-ls not running: exited abnormally with code 1

LSP :: elixir-ls:82862 initialized successfully in folders: (/Users/johngoff/Repos/HiredHippo)
LSP :: Unable to reload project: cwd "/Users/johngoff/Repos/HiredHippo/server/deps/combine" is not project dir /Users/johngoff/Repos/HiredHippo/server
LSP :: elixir-ls has exited (exited abnormally with code 1)
Server elixir-ls:82862 exited (check corresponding stderr buffer for details). Do you want to restart it? (y or n) n

I do not have a reproduction (yet), but some more details that may be relevant:

Expected behavior

Dependencies should install without crashing the server.

lukaszsamson commented 11 months ago

Can you attach initalize request sent by your client? I'm interested in rootUri property. Please describe your project structure. Where is your mix.exs located? Is it in server/mix.exs?

I suspect race conditions issue when ElixirLS tries to clean and rebuild the project. I noticed similar behaviour in tests on elixir <= 1.14. It may be already fixed on the master branch.

John-Goff commented 11 months ago

Yes, it's a monorepo structure with the elixir code living in server. There is no mix.exs in the root directory, only in server. Here's the initialize request:

[Trace - 01:46:51 pm] Sending request 'initialize - (2918)'.
Params: {
  "processId": 12850,
  "rootPath": "/Users/johngoff/Repos/HiredHippo",
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 29.1 (build 2, aarch64-apple-darwin22.6.0, NS appkit-2299.70 Version 13.5.2 (Build 22G91))\n of 2023-11-19"
  },
  "rootUri": "file:///Users/johngoff/Repos/HiredHippo",
  "capabilities": {
    "general": {
      "positionEncodings": ["utf-32", "utf-16"]
    },
    "workspace": {
      "workspaceEdit": {
        "documentChanges": true,
        "resourceOperations": ["create", "rename", "delete"]
      },
      "applyEdit": 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]
        }
      },
      "executeCommand": {
        "dynamicRegistration": false
      },
      "didChangeWatchedFiles": {
        "dynamicRegistration": true
      },
      "workspaceFolders": true,
      "configuration": true,
      "codeLens": {
        "refreshSupport": true
      },
      "fileOperations": {
        "didCreate": false,
        "willCreate": false,
        "didRename": true,
        "willRename": true,
        "didDelete": false,
        "willDelete": false
      }
    },
    "textDocument": {
      "declaration": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "definition": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "references": {
        "dynamicRegistration": true
      },
      "implementation": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "typeDefinition": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "synchronization": {
        "willSave": true,
        "didSave": true,
        "willSaveWaitUntil": true
      },
      "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]
        },
        "hierarchicalDocumentSymbolSupport": true
      },
      "formatting": {
        "dynamicRegistration": true
      },
      "rangeFormatting": {
        "dynamicRegistration": true
      },
      "onTypeFormatting": {
        "dynamicRegistration": true
      },
      "rename": {
        "dynamicRegistration": true,
        "prepareSupport": true
      },
      "codeAction": {
        "dynamicRegistration": true,
        "isPreferredSupport": true,
        "codeActionLiteralSupport": {
          "codeActionKind": {
            "valueSet": [
              "",
              "quickfix",
              "refactor",
              "refactor.extract",
              "refactor.inline",
              "refactor.rewrite",
              "source",
              "source.organizeImports"
            ]
          }
        },
        "resolveSupport": {
          "properties": ["edit", "command"]
        },
        "dataSupport": true
      },
      "completion": {
        "completionItem": {
          "snippetSupport": true,
          "documentationFormat": ["markdown", "plaintext"],
          "resolveAdditionalTextEditsSupport": true,
          "insertReplaceSupport": true,
          "deprecatedSupport": true,
          "resolveSupport": {
            "properties": ["documentation", "detail", "additionalTextEdits", "command"]
          },
          "insertTextModeSupport": {
            "valueSet": [1, 2]
          }
        },
        "contextSupport": true,
        "dynamicRegistration": true
      },
      "signatureHelp": {
        "signatureInformation": {
          "parameterInformation": {
            "labelOffsetSupport": true
          }
        },
        "dynamicRegistration": true
      },
      "documentLink": {
        "dynamicRegistration": true,
        "tooltipSupport": true
      },
      "hover": {
        "contentFormat": ["markdown", "plaintext"],
        "dynamicRegistration": true
      },
      "selectionRange": {
        "dynamicRegistration": true
      },
      "callHierarchy": {
        "dynamicRegistration": false
      },
      "typeHierarchy": {
        "dynamicRegistration": true
      },
      "publishDiagnostics": {
        "relatedInformation": true,
        "tagSupport": {
          "valueSet": [1, 2]
        },
        "versionSupport": true
      },
      "linkedEditingRange": {
        "dynamicRegistration": true
      }
    },
    "window": {
      "workDoneProgress": true,
      "showDocument": {
        "support": true
      }
    }
  },
  "initializationOptions": null,
  "workDoneToken": "1"
}
sreecodeslayer commented 11 months ago

Happening recently on one of my project as well, using elixir-ls through https://github.com/sublimelsp/LSP-elixir and there was release bumping the version to support latest elixir-ls v0.17.10

lsp-elixir: Received workspace/didChangeConfiguration
lsp-elixir: Received client configuration via workspace/didChangeConfiguration
%{"dialyzerEnabled" => true, "dialyzerFormat" => "dialyxir_long", "dialyzerWarnOpts" => [], "fetchDeps" => true, "mixEnv" => "test", "mixTarget" => nil, "projectDir" => nil}
:: [13:07:25.498] <-  lsp-elixir window/logMessage: {'message': 'client/registerCapability succeeded', 'type': 3}
:: [13:07:25.498] <-  lsp-elixir window/logMessage: {'message': 'Client does not support workspace/didChangeWatchedFiles dynamic registration', 'type': 3}
:: [13:07:25.498] <-  lsp-elixir window/logMessage: {'message': 'Received workspace/didChangeConfiguration', 'type': 3}
:: [13:07:25.498] <-  lsp-elixir window/logMessage: {'message': 'Received client configuration via workspace/didChangeConfiguration\n%{"dialyzerEnabled" => true, "dialyzerFormat" => "dialyxir_long", "dialyzerWarnOpts" => [], "fetchDeps" => true, "mixEnv" => "test", "mixTarget" => nil, "projectDir" => nil}', 'type': 3}
lsp-elixir: Starting build with MIX_ENV: test MIX_TARGET: host
:: [13:07:25.501] <-  lsp-elixir window/logMessage: {'message': 'Starting build with MIX_ENV: test MIX_TARGET: host', 'type': 3}
lsp-elixir: DETS databases will be rebuilt
lsp-elixir: Unable to reload project: cwd "/Users/sreenadh/Projects/app-core/deps/cachex" is not project dir /Users/sreenadh/Projects/app-core
:: [13:07:25.509] <-  lsp-elixir window/logMessage: {'message': 'DETS databases will be rebuilt', 'type': 3}
:: [13:07:25.509] <-  lsp-elixir window/showMessage: {'message': 'Unable to reload project: cwd "/Users/sreenadh/Projects/app-core/deps/cachex" is not project dir /Users/sreenadh/Projects/app-core', 'type': 1}
:: [13:07:25.509] <-  lsp-elixir window/logMessage: {'message': 'Unable to reload project: cwd "/Users/sreenadh/Projects/app-core/deps/cachex" is not project dir /Users/sreenadh/Projects/app-core', 'type': 1}
lsp-elixir: Loaded DETS databases in 26ms
:: [13:07:25.529] <-  lsp-elixir window/logMessage: {'message': 'Loaded DETS databases in 26ms', 'type': 3}

Update

Uninstalled sublime plugin, Removed .elixir_ls/ , _build/ and deps/ completely, and installed plugin back again. Everything works as expected

lukaszsamson commented 11 months ago

Closing this as v0.18 should not have this issue