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

ELX_ELIXIR_OPTS not loaded when starting dap server #1120

Open
nicklayb opened this issue Sep 27, 2024 · 4 comments
Open

ELX_ELIXIR_OPTS not loaded when starting dap server #1120

nicklayb opened this issue Sep 27, 2024 · 4 comments

Comments

@nicklayb
Copy link

nicklayb commented Sep 27, 2024

Precheck

  • Do a quick search and make sure the issue has not yet been reported Have seen nothing
  • Do not use the issues tracker for guidance, questions or support (try Elixir Forum, Stack Overflow, Slack, etc. instead) Got no answer
  • If using a client other than VS Code, please try VSCode's "ElixirLS: Elixir support and debugger" extension. Does it reproduce your failure? I don't know I don't have vscode

Environment

  • Elixir & Erlang versions (elixir --version): 1.16.0 OTP 26
  • Elixir Language Server version: 0.23.0
  • Operating system: macOS Sequoia
  • Editor or IDE name (e.g. Emacs/VSCode): neovim (With Astronvim)
  • Editor Plugin/LSP Client name and version: nvim-dap

Current behavior

Unable to start the dap adapter with ELS_ELIXIR_OPTS. I have this configuration:

        local dap = require('dap')
        local elixir_ls_debugger = vim.fn.exepath "elixir-ls-debugger"
        dap.adapters.mix_task = {
          type = "executable",
          command = elixir_ls_debugger,
        }

        dap.configurations.elixir = {
          {
            type = "mix_task",
            name = "phoenix server",
            task = "phx.server",
            request = "launch",
            projectDir = "${workspaceFolder}",
            exitAfterTaskReturns = false,
            debugAutoInterpretAllModules = false,
            env = {
              ELS_ELIXIR_OPTS = "--name elixirls@localhost --cookie elixirls"
            }
          }
        }

And added the following to application.ex

    IO.puts("""
    #{Node.self()}
    #{Node.get_cookie()}
    #{System.get_env("ELS_ELIXIR_OPTS")}
    """)

When starting the debugger it outputs

nonode@nohost
nocookie
--name elixirls@localhost --cookie elixirls

Expected behavior

I would expect my dap environment to have the node name elixirls@localhost with cookie elixirls and that application.ex would log

elixirls@localhost
elixirls
--name elixirls@localhost --cookie elixirls
@lukaszsamson
Copy link
Collaborator

I tried reproducing it with an empty mix project in VSCode

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "mix (Default task)",
      "request": "launch",
      "task": "run",
      "taskArgs": ["lib/dap_env.ex"],
      "projectDir": "${workspaceRoot}",
      "env": {
        "ELS_ELIXIR_OPTS": "--name elixirls@localhost --cookie elixirls"
      },
      "exitAfterTaskReturns": false
    }
  ]
}

lib/dap_env.ex

defmodule DapEnv do
  def hello do
    IO.puts("hello")
    IO.puts("""
    #{Node.self()}
    #{Node.get_cookie()}
    #{System.get_env("ELS_ELIXIR_OPTS")}
    """)
    :world
  end
end

DapEnv.hello()

and I'm seeing this output

hello
elixirls@localhost
elixirls
--name elixirls@localhost --cookie elixirls

@lukaszsamson
Copy link
Collaborator

I also tried a new phoenix project and a launch config identical to yours @nicklayb

mix phx.new dap_env_phx

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "phoenix server",
      "request": "launch",
      "task": "phx.server",
      "projectDir": "${workspaceRoot}",
      "env": {
        "ELS_ELIXIR_OPTS": "--name elixirls@localhost --cookie elixirls"
      },
      "exitAfterTaskReturns": false,
      "debugAutoInterpretAllModules": false
    }
  ]
}

lib/dap_env_ph/application.ex

defmodule DapEnvPhx.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    IO.puts("""
    #{Node.self()}
    #{Node.get_cookie()}
    #{System.get_env("ELS_ELIXIR_OPTS")}
    """)

    children = [
      DapEnvPhxWeb.Telemetry,
      ...

and once again it worked as expected

Generated dap_env_phx app
Running mix phx.server
elixirls@localhost
elixirls
--name elixirls@localhost --cookie elixirls

[info] Running DapEnvPhxWeb.Endpoint with Bandit 1.5.7 at 127.0.0.1:4000 (http)

Do you have a repo that reproduces it?

@nicklayb
Copy link
Author

Not really, it's in my neovim's plugin config (what I sent in the original post), anyway I can better trouble shoot it?

@lukaszsamson
Copy link
Collaborator

  1. Try in a minimal project like I did. Surely the env is set but something is preventing node start.
  2. Check if ordinary iex --name elixirls@localhost --cookie elixirls -S mix phx.server works with your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants