elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
395 stars 29 forks source link

{:error, :already_present} #181

Closed coop closed 8 months ago

coop commented 8 months ago

I am using Lunar Vim to bootstrap neovim. I am using their 1.3 branch (latest).

My config is copy pasted from this repo.

When I open an elixir file for the first time I see an error:

image

When I look at :LspInfo I see errors like:

[WARN][2023-11-07 23:19:45] ...lsp/handlers.lua:487 "** (MatchError) no match of right hand side value: {:error, :already_present}\n    lib/language_server/cli.ex:20: ElixirLS.LanguageServer.CLI.main/0\n    nofile:1: (file)\n    (stdlib 5.1.1) erl_eval.erl:750: :erl_eval.do_apply/7\n    (elixir 1.15.7) lib/code.ex:543: Code.validated_eval_string/3"

And

[WARN][2023-11-07 23:20:23] ...lsp/handlers.lua:487 "[NextLS] Unexpected compiler response: {:error, %{message: \"Can't continue due to errors on dependencies\", __struct__: Mix.Error, __exception__: true, mix: 1}}"

This app's .tool-versions:

❯ cat .tool-versions                 
erlang 26.1.2
elixir 1.15.7-otp-26

If I ignore the error formatting on save and :ElixirFromPipe etc are there and work so maybe these errors don't matter?

mhanberg commented 8 months ago
coop commented 8 months ago

Do you want to use Elixir LS or Next LS? You have them both enabled in your config (if you copy pasted the code you linked exactly), but you probably only want one

I did wonder about that but the first example had them both on so I assumed it was "ok" and they'd work it out between themselves.

The Next LS error means that you need to run mix deps.get and then restart your editor.

I don't know if this is a lunar vim thing or not but I'm still getting the issue even after mix deps.get and restarting. I've also cleaned out the lunarvim cache, elixir-tools.nvim cache, uninstalled next-ls and reinstalled next-ls to try and get rid of the problem but it still persists.

My config is now:

lvim.plugins = {
    {
        "vim-test/vim-test",
        config = function()
          vim.g["test#strategy"] = "kitty"
        end,
    },
    { "duggiefresh/vim-easydir" },
    { "tpope/vim-eunuch" },
    {
        "elixir-tools/elixir-tools.nvim",
        version = "*",
        event = { "BufReadPre", "BufNewFile" },
        config = function()
          local elixir = require("elixir")

          elixir.setup {
              nextls = { enable = true },
              elixirls = {
                  enable = false,
              }
          }
        end,
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
    },
}

I have also noticed that NextLS is marked as autostart false but it seems to kick in when editing an elixir file. I assume that is how it works - just different to what I had before.

image

I'm also still seeing the error:

[WARN][2023-11-08 08:43:32] ...lsp/handlers.lua:487 "** (MatchError) no match of right hand side value: {:error, :already_present}\n    lib/language_server/cli.ex:20: ElixirLS.LanguageServer.CLI.main/0\n    nofile:1: (file)\n    (stdlib 5.1.1) erl_eval.erl:750: :erl_eval.do_apply/7\n    (elixir 1.15.7) lib/code.ex:543: Code.validated_eval_string/3"

even with everything disabled. If there is a better place to discuss this let me know :)

coop commented 8 months ago

I just realised the last few lines of that screenshot say that elixirls is there. I guess it is being triggered from somewhere. Let me see if I can find out where.

coop commented 8 months ago

Ok ok I see what is happening. FYI for anyone else reading about lunarvim integration you need to add "elixirls" to the list of skipped servers in the lvim config (the lvim docs cover this):

vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "elixirls" })

After this there are no more errors. autostart is still set to false but it's working so I assume it isn't an issue.

mhanberg commented 8 months ago

you should also disable credo language server, as Next LS supports credo out of the box. so add a credo = {enable = false} along side the elixirls = {enable = false}

I have also noticed that NextLS is marked as autostart false but it seems to kick in when editing an elixir file. I assume that is how it works - just different to what I had before.

autostart is an lspconfig thing. elixir-tools.nvim does not use lspconfig as a dependency, but the way that :LspInfo works, Next LS still shows up in the window. so you can ignore that.

I just realised the last few lines of that screenshot say that elixirls is there. I guess it is being triggered from somewhere. Let me see if I can find out where.

Yes, either lunarvim has some elixir default there, or you have it configured somewhere in your config. You can tell that it is not from elixir-tools.nvim because the cmd is elixir-ls and not ~/.cache/elixir-tools.nvim/...`


EDIT: You replied before I hit send, but for posterity I'm going to send this anyway, even tho you seemed to have everything taken care of.

I would still disable credo language server though

mhanberg commented 8 months ago

FYI for anyone else reading about lunarvim integration you need to add "elixirls" to the list of skipped servers in the lvim config (the lvim docs cover this):

I'm going to update the docs to mention this. Thanks for figuring that out!

coop commented 8 months ago

You replied before I hit send, but for posterity I'm going to send this anyway, even tho you seemed to have everything taken care of.

Yes sorry - too excited. Everything seems to be working correctly now.

I would still disable credo language server though

I have updated this.

I'm going to update the docs to mention this. Thanks for figuring that out!

No problems and than you for the software!

mhanberg commented 8 months ago

Happy hacking! Please come back if you have any other issues