Skip to content

Commit 27f80a3

Browse files
committed
feat: credo-language-server support
1 parent a24a603 commit 27f80a3

3 files changed

Lines changed: 46 additions & 17 deletions

File tree

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## Features
1010

1111
- [ElixirLS](https://github.com/elixir-lsp/elixir-ls) installation and configuration (uses the Neovim built-in LSP client)
12+
- [credo-language-server](https://github.com/elixir-tools/credo-language-server) integration.
1213
- `:Mix` command with autocomplete
1314
- [vim-projectionist](https://github.com/tpope/vim-projectionist) support
1415

@@ -27,13 +28,13 @@ Requires 0.8
2728
local elixirls = require("elixir.elixirls")
2829

2930
elixir.setup {
31+
credo = {},
3032
elixirls = {
33+
enabled = true,
3134
settings = elixirls.settings {
3235
dialyzerEnabled = false,
3336
enableTestLenses = false,
3437
},
35-
log_level = vim.lsp.protocol.MessageType.Log,
36-
message_level = vim.lsp.protocol.MessageType.Log,
3738
on_attach = function(client, bufnr)
3839
-- whatever keybinds you want, see below for more suggestions
3940
vim.keymap.set("n", "<space>fp", ":ElixirFromPipe<cr>", { buffer = true, noremap = true })
@@ -59,21 +60,38 @@ use({ "elixir-tools/elixir-tools.nvim", requires = { "nvim-lua/plenary.nvim" }})
5960

6061
### Minimal Setup
6162

63+
The minimal setup will configure both ElixirLS and credo-langauge-server.
64+
6265
```lua
6366
require("elixir").setup()
6467
```
6568

69+
ElixirLS and credo-language-server can be disabled by setting the `enabled` flag in the respective options table.
70+
71+
```lua
72+
require("elixir").setup({
73+
credo = {enable = false},
74+
elixirls = {enable = false},
75+
})
76+
```
77+
6678
### Advanced Setup
6779

6880
While the plugin works with a minimal setup, it is much more useful if you add some personal configuration.
6981

70-
Note: Not specifying the `repo`, `branch`, or `tag` options will default to the latest release.
82+
Note: For ElixirLS, not specifying the `repo`, `branch`, or `tag` options will default to the latest release.
7183

7284
```lua
7385
local elixir = require("elixir")
7486
local elixirls = require("elixir.elixirls")
7587

7688
elixir.setup {
89+
credo = {
90+
cmd = "path/to/credo-language-server",
91+
on_attach = function(client, bufnr)
92+
-- custom keybinds
93+
end
94+
},
7795
elixirls = {
7896
-- specify a repository and branch
7997
repo = "mhanberg/elixir-ls", -- defaults to elixir-lsp/elixir-ls
@@ -124,15 +142,15 @@ elixir.setup {
124142

125143
## Features
126144

127-
### Language Server
145+
### ElixirLS
128146

129-
#### Automatic ElixirLS Installation
147+
#### Automatic Installation
130148

131149
When a compatible installation of ELixirLS is not found, you will be prompted to install it. The plugin will download the source code to the `.elixir_ls` directory and compile it using the Elixir and OTP versions used by your current project.
132150

133151
Caveat: This assumes you are developing your project locally (outside of something like Docker) and they will be available.
134152

135-
Caveat: This currently downloads the language server into the `.elixir_ls` directory in your repository, but it does install it into `~/.cache` and will re-use it when needed.
153+
Caveat: This currently downloads the language server into the `.elixir_ls` directory in your repository, but it does install it into `~/.cache` and will re-use it when needed.
136154

137155
![auto-install-elixirls](https://user-images.githubusercontent.com/5523984/160333851-94d448d9-5c80-458c-aa0d-4c81528dde8f.gif)
138156

@@ -181,6 +199,14 @@ You can see the logs for ElixirLS via the output panel. By default opens the buf
181199
:lua require("elixir").open_output_panel({ window = "float" })
182200
```
183201

202+
### credo-language-server
203+
204+
> Note: The credo-language-server integration utilizes `Mix.install/2`, so you must be running Elixir >= 1.12
205+
206+
- Uses your project's Credo version.
207+
- Full project diagnostics
208+
- Code Actions
209+
184210
### Mix
185211

186212
You can run any `mix` command in your project, complete with... autocomplete!
@@ -198,9 +224,3 @@ You can run any `mix` command in your project, complete with... autocomplete!
198224
- Phoenix Controllers
199225
- Phoenix Channels
200226
- Wallaby/Hound Feature tests
201-
202-
### Debugger
203-
204-
TODO: make it work
205-
206-
TODO: gif

lua/elixir/credo/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function M.setup(opts)
2727
vim.lsp.start {
2828
name = "Credo",
2929
-- cmd = vim.lsp.rpc.connect('127.0.0.1', 9000),
30-
cmd = { opts.bin, "--stdio" },
30+
cmd = { opts.cmd, "--stdio" },
3131
settings = {},
3232
root_dir = vim.fs.dirname(file),
3333
on_attach = opts.on_attach or function() end,

lua/elixir/init.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@ M.credo = {}
1515
M.credo.default_bin = vim.fn.fnamemodify(debug.getinfo(1).short_src, ":h")
1616
.. "/../../bin/credo-language-server"
1717

18+
local enabled = function(value)
19+
return value == nil or value == true
20+
end
21+
1822
function M.setup(opts)
1923
opts = opts or {}
2024

21-
if opts.credo and not opts.credo.bin then
22-
opts.credo.bin = M.credo.default_bin
25+
opts.elixirls = opts.elixirls or {}
26+
opts.credo = opts.credo or {}
27+
28+
if not opts.credo.cmd then
29+
opts.credo.cmd = M.credo.default_bin
2330
end
2431

2532
mix.setup()
2633
projectionist.setup()
27-
elixirls.setup(opts.elixirls or {})
28-
if opts.credo then
34+
if enabled(opts.elixirls.enable) then
35+
elixirls.setup(opts.elixirls)
36+
end
37+
if enabled(opts.credo.enable) then
2938
credo.setup(opts.credo)
3039
end
3140
end

0 commit comments

Comments
 (0)