elixir-tools / credo-language-server

LSP implementation for Credo.
MIT License
96 stars 11 forks source link

Standalone usage with neoVim and CoC #7

Closed bigardone closed 1 year ago

bigardone commented 1 year ago

Hello! First of all thank you for developing this great LS 🙌🏼

I'm a nvim user, but I use CoC for language server support rather than nvim's built in lsp. To use custom language servers with CoC, you can do it manually by adding something like this to its config file:

{
  ...

  "languageserver": {
    "credoLS": {
      "command": "~/projects/elixir/credo-ls/bin/credo-language-server",
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ]
    },
    "elixirLS": {
      "command": "~/projects/elixir/elixir-ls/release/language_server.sh",
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ]
    },
   ....
}

However, credo-language-server does not seem to work. When I check its output I get the following:

warning: found quoted keyword "bandit" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:2:4

warning: found quoted keyword "bunt" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:3:4

warning: found quoted keyword "castore" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:4:4

warning: found quoted keyword "certifi" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:5:4

warning: found quoted keyword "cldr_utils" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:6:4

warning: found quoted keyword "connection" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:7:4

warning: found quoted keyword "credo" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:8:4

warning: found quoted keyword "db_connection" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:9:4

warning: found quoted keyword "decimal" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:10:4

warning: found quoted keyword "digital_token" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:11:4

warning: found quoted keyword "ecto" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:12:4

warning: found quoted keyword "ecto_sql" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:13:4

warning: found quoted keyword "esbuild" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:14:4

warning: found quoted keyword "ex_cldr" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:15:4

warning: found quoted keyword "ex_cldr_calendars" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:16:4

warning: found quoted keyword "ex_cldr_currencies" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:17:4

warning: found quoted keyword "ex_cldr_dates_times" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:18:4

warning: found quoted keyword "ex_cldr_numbers" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:19:4

warning: found quoted keyword "expo" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:20:4

warning: found quoted keyword "file_system" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:21:4

warning: found quoted keyword "floki" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:22:4

warning: found quoted keyword "gettext" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:23:4

warning: found quoted keyword "hackney" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:24:4

warning: found quoted keyword "hpax" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:25:4

warning: found quoted keyword "idna" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:26:4

warning: found quoted keyword "jason" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:27:4

warning: found quoted keyword "logger_file_backend" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:28:4

warning: found quoted keyword "metrics" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:29:4

warning: found quoted keyword "mime" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:30:4

warning: found quoted keyword "mimerl" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:31:4

warning: found quoted keyword "money" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:32:4

warning: found quoted keyword "parse_trans" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:33:4

warning: found quoted keyword "phoenix" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:34:4

warning: found quoted keyword "phoenix_html" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:35:4

warning: found quoted keyword "phoenix_live_reload" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:36:4

warning: found quoted keyword "phoenix_live_view" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:37:4

warning: found quoted keyword "phoenix_pubsub" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:38:4

warning: found quoted keyword "phoenix_template" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:39:4

warning: found quoted keyword "plug" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:40:4

warning: found quoted keyword "plug_crypto" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:41:4

warning: found quoted keyword "postgrex" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:42:4

warning: found quoted keyword "scrivener" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:43:4

warning: found quoted keyword "scrivener_ecto" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:44:4

warning: found quoted keyword "ssl_verify_fun" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:45:4

warning: found quoted keyword "tailwind" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:46:4

warning: found quoted keyword "telemetry" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:48:4

warning: found quoted keyword "telemetry_metrics" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:49:4

warning: found quoted keyword "telemetry_poller" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:50:4

warning: found quoted keyword "tesla" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:51:4

warning: found quoted keyword "thousand_island" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:52:4

warning: found quoted keyword "unicode_util_compat" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:53:4

warning: found quoted keyword "websock" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:54:4

warning: found quoted keyword "websock_adapter" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of ASCII letters, numbers, and underscores and not beginning with a number do not require quotes
  mix.lock:55:4

However CoC does not show any credo warnings like the language server does while using it with elixir-tools.nvim. Is it possible to use it this way?

Thanks in advance

mhanberg commented 1 year ago

So those warnings shouldn't be a problem. Unrelated consequence.

Does the project you are trying it with use credo itself?

mhanberg commented 1 year ago

Also, make sure you have pulled down the latest changes. I made a change to the bin script last night.

mhanberg commented 1 year ago

One thing that elixir-tools extensions do is only start the LSP if the mix.exs file has credo in it (they just do a simple search for {:credo,).

bigardone commented 1 year ago

👋🏼 All my projects include credo as a dependency, and I'm running credo's LS latest version. I'll try to figure out the issue over the weekend. 🙌🏼

mhanberg commented 1 year ago

Please try starting credo in a terminal with ~/projects/elixir/credo-ls/bin/credo-language-server --port 9000 (from your project root directory) and then change your config to

{
  ...

  "languageserver": {
    "credoLS": {
      "host": "127.0.0.1",
      "port": 9000,
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ]
    },
    "elixirLS": {
      "command": "~/projects/elixir/elixir-ls/release/language_server.sh",
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ]
    },
   ....
}

and please let me know what is the output in the terminal running after opening an elixir file

bigardone commented 1 year ago

That seems to work 🎉

image

Do we have to start it always manually?

mhanberg commented 1 year ago

No, I just wanted to make sure that it wasn't spitting out any weird errors and starting it manually with a port makes it easier to see that.

According to that, it should work with your originally config.

Do you mind reverting to your original config and trying again?

bigardone commented 1 year ago

It's finally working 🎉 This did the trick:

    "credoLS": {
      "command": "~/projects/elixir/credo-ls/bin/credo-language-server",
      "args": [
        "--port",
        "9000",
        "--stdio"
      ],
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ]
    },

Thanks for the help 🙌🏼

mhanberg commented 1 year ago

you don't need to pass the --port 9000 arg if you are going to use --stdio.

I think the original problem was that I was thinking that if you passed no args, it defaulted to --stdio behavior, but I actually changed that and made one of them required.

There should have been more errors in your lsp log, but i'm not sure how coc works so it must work differently.

glad its working tho!

bigardone commented 1 year ago

you don't need to pass the --port 9000 arg if you are going to use --stdio.

Working like a charm! Thanks again for the help 🙌🏼

bigardone commented 1 year ago

👋🏼 @mhanberg After upgrading to 0.1.1 and forth, I'm not able to run the server using CoC again. Do I need to change anything in the custom LS configuration? Here's the error:

** (RuntimeError) no shell process input given for yes?/2
    (mix 1.14.5) lib/mix/shell/process.ex:148: Mix.Shell.Process.yes?/2
    (mix 1.14.5) lib/mix/tasks/deps.compile.ex:256: Mix.Tasks.Deps.Compile.handle_rebar_not_found/1
    (mix 1.14.5) lib/mix/tasks/deps.compile.ex:218: Mix.Tasks.Deps.Compile.do_rebar3/2
    (mix 1.14.5) lib/mix/tasks/deps.compile.ex:96: anonymous fn/4 in Mix.Tasks.Deps.Compile.compile/2
    (elixir 1.14.5) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    (mix 1.14.5) lib/mix/tasks/deps.compile.ex:80: Mix.Tasks.Deps.Compile.compile/2
    (mix 1.14.5) lib/mix/tasks/deps.loadpaths.ex:84: Mix.Tasks.Deps.Loadpaths.deps_check/2
    (mix 1.14.5) lib/mix/tasks/deps.loadpaths.ex:43: Mix.Tasks.Deps.Loadpaths.run/1
[Error - 07:48:22.845] ~/projects/elixir/credo-ls/bin/credo-language-server exited with code: 1
[Error - 07:48:22.845] Connection to server got closed. Server will not be restarted.
[Error - 07:48:22.845] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

And this is the config working until 0.1.1:

    "credoLS": {
      "command": "~/projects/elixir/credo-ls/bin/credo-language-server",
      "args": [
        "--stdio"
      ],
      "filetypes": [
        "elixir",
        "eelixir",
        "heex"
      ],
      "rootPatterns": [
        "mix.exs"
      ],
    },
mhanberg commented 1 year ago

Can you try with the latest version and let me know.

bigardone commented 1 year ago

Sure, I'm currently running 0.1.3 from the main branch, and it is throwing that error. 🙌🏼