Skip to content

Commit

Permalink
Add instructions for neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
catlee authored Jul 21, 2023
1 parent 4a254c4 commit fadcca7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions EDITORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ new H2 header in this file containing the instructions. -->

- [Emacs LSP Mode](https://emacs-lsp.github.io/lsp-mode/page/lsp-ruby-lsp/)
- [Emacs Eglot](#Emacs-Eglot)
- [Neovim LSP](#Neovim-LSP)

## Emacs Eglot

Expand All @@ -19,3 +20,60 @@ put that in your init file:
```

When you run `eglot` command it will run `ruby-lsp` process for you.

## Neovim LSP
The [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/ruby_ls.lua)
plugin has support for Ruby LSP.

Ruby LSP only supports pull diagnostics, and neovim versions prior to v0.10.0-dev-695+g58f948614 only support [publishDiagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics).
Additional setup is required to enable diagnostics from Ruby LSP to appear in neovim.

```lua
-- textDocument/diagnostic support until 0.10.0 is released
_timers = {}
local function setup_diagnostics(client, buffer)
if require("vim.lsp.diagnostic")._enable then
return
end

local diagnostic_handler = function()
local params = vim.lsp.util.make_text_document_params(buffer)
client.request("textDocument/diagnostic", { textDocument = params }, function(err, result)
if err then
local err_msg = string.format("diagnostics error - %s", vim.inspect(err))
vim.lsp.log.error(err_msg)
end
if not result then
return
end
vim.lsp.diagnostic.on_publish_diagnostics(
nil,
vim.tbl_extend("keep", params, { diagnostics = result.items }),
{ client_id = client.id }
)
end)
end

diagnostic_handler() -- to request diagnostics on buffer when first attaching

vim.api.nvim_buf_attach(buffer, false, {
on_lines = function()
if _timers[buffer] then
vim.fn.timer_stop(_timers[buffer])
end
_timers[buffer] = vim.fn.timer_start(200, diagnostic_handler)
end,
on_detach = function()
if _timers[buffer] then
vim.fn.timer_stop(_timers[buffer])
end
end,
})
end

require("lspconfig").ruby_ls.setup({
on_attach = function(client, buffer)
setup_diagnostics(client, buffer)
end,
})
```

0 comments on commit fadcca7

Please sign in to comment.