From 9815467536d32ab9a4b56665b3974fe37eabc09b Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 19:58:38 -0600 Subject: [PATCH 01/10] feat: turn on code lenses in Ruby LSP buffers Neovim 0.12 leaves code lenses off until something enables them, so a new user saw no Run or Debug lenses above their tests. Enable them for the ruby_lsp client on attach, behind a codelens option that defaults to true. Neovim's grx mapping already runs a lens, so the plugin adds no keymap. --- lua/ruby-lsp/config.lua | 2 ++ lua/ruby-lsp/init.lua | 3 +++ tests/config_spec.lua | 4 ++++ tests/init_spec.lua | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/lua/ruby-lsp/config.lua b/lua/ruby-lsp/config.lua index 6f5c846..ad30d69 100644 --- a/lua/ruby-lsp/config.lua +++ b/lua/ruby-lsp/config.lua @@ -31,6 +31,8 @@ local defaults = { auto_start = true, }, + codelens = true, + user_commands = false, } diff --git a/lua/ruby-lsp/init.lua b/lua/ruby-lsp/init.lua index a773102..3e8cff5 100644 --- a/lua/ruby-lsp/init.lua +++ b/lua/ruby-lsp/init.lua @@ -40,6 +40,9 @@ function M.setup(opts) return end -- per buffer, so it runs before the per-client guard below + if config.get().codelens then + vim.lsp.codelens.enable(true, { bufnr = ev.buf, client_id = client.id }) + end if config.get().user_commands then require('ruby-lsp.user_commands').attach(client, ev.buf) end diff --git a/tests/config_spec.lua b/tests/config_spec.lua index 50f7926..4b8bf93 100644 --- a/tests/config_spec.lua +++ b/tests/config_spec.lua @@ -53,6 +53,10 @@ describe('config', function() it('leaves user commands off by default', function() assert.is_false(config.get().user_commands) end) + + it('enables code lenses by default', function() + assert.is_true(config.get().codelens) + end) end) describe('setup', function() diff --git a/tests/init_spec.lua b/tests/init_spec.lua index ba46f88..67583c0 100644 --- a/tests/init_spec.lua +++ b/tests/init_spec.lua @@ -128,4 +128,38 @@ describe('setup', function() vim.lsp.get_client_by_id = original_get vim.api.nvim_buf_delete(buf, { force = true }) end) + + it('enables code lenses for the ruby_lsp client on attach unless turned off', function() + local buf = vim.api.nvim_create_buf(true, false) + local original_get = vim.lsp.get_client_by_id + local original_enable = vim.lsp.codelens.enable + local client = { id = 10, name = 'ruby_lsp', handlers = {}, request = function() end } + local other = { id = 11, name = 'lua_ls', handlers = {}, request = function() end } + vim.lsp.get_client_by_id = function(id) + return id == 10 and client or other + end + local calls = {} + vim.lsp.codelens.enable = function(enable, filter) + table.insert(calls, { enable, filter }) + end + + local function attach(id) + vim.api.nvim_exec_autocmds('LspAttach', { group = 'RubyLsp', buffer = buf, data = { client_id = id } }) + end + + ruby_lsp.setup({ dap = { auto_configure = false } }) + attach(11) + assert.same({}, calls) + attach(10) + assert.same({ { true, { bufnr = buf, client_id = 10 } } }, calls) + + calls = {} + ruby_lsp.setup({ dap = { auto_configure = false }, codelens = false }) + attach(10) + assert.same({}, calls) + + vim.lsp.codelens.enable = original_enable + vim.lsp.get_client_by_id = original_get + vim.api.nvim_buf_delete(buf, { force = true }) + end) end) From 246802e38f7c55793e1b71eb100623ac13108f02 Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 19:58:38 -0600 Subject: [PATCH 02/10] docs: explain code lenses and show a solargraph auto_start example Point users to grx for running a lens and show how to map their own key. Replace the .solargraph.yml example with one that checks Gemfile.lock, which matches how projects usually opt into solargraph. --- README.md | 28 ++++++++++++++++++++++++++-- doc/ruby-lsp.nvim.txt | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 148942a..dbebb75 100644 --- a/README.md +++ b/README.md @@ -59,19 +59,40 @@ Don't lazy-load the plugin. Its `lsp/ruby_lsp.lua` must be on the runtimepath be If you're upgrading and already start Ruby LSP yourself, remove your `vim.lsp.enable("ruby_lsp")` call and your `fullTestDiscovery` setting. Or set `lsp.auto_start = false` and keep your `vim.lsp.enable("ruby_lsp")` call, as long as the plugin still isn't lazy-loaded. +## 🔍 Code Lenses + +The plugin turns on code lenses in buffers Ruby LSP is attached to, so **Run**, **Run In Terminal**, and **Debug** show above your tests. Run the lens on the cursor line with `grx`, Neovim's default mapping for `vim.lsp.codelens.run()`. To use a different key, map it yourself: + +```lua +vim.keymap.set("n", "cl", vim.lsp.codelens.run, { desc = "run code lens" }) +``` + +Set `codelens = false` to leave code lenses to your own config. + ## 🖥️ Ruby LSP Server The plugin configures and starts Ruby LSP for you, in any project with a `Gemfile` or `.git` directory. You don't need nvim-lspconfig or a `ruby_lsp` config of your own. If nvim-lspconfig is installed, its config merges with the plugin's without conflict. Before starting, the plugin checks that `ruby-lsp --version` runs from the project root. If you set `cmd` to a list such as `{ "bundle", "exec", "ruby-lsp" }`, it only checks that the first entry is executable. When the check fails, the server stays off and nothing is shown. Run `:checkhealth ruby-lsp` to see why. -Set `lsp.auto_start` to choose where the server starts. `true` starts it in every Ruby project, and `false` leaves it to you to call `vim.lsp.enable("ruby_lsp")`. A function decides per project. This one skips projects that use solargraph: +Set `lsp.auto_start` to choose where the server starts. `true` starts it in every Ruby project, and `false` leaves it to you to call `vim.lsp.enable("ruby_lsp")`. A function decides per project. + +For example, if some of your projects bundle solargraph and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` lists it: ```lua require("ruby-lsp").setup({ lsp = { auto_start = function(root_dir) - return vim.fn.filereadable(root_dir .. "/.solargraph.yml") == 0 + local lockfile = root_dir .. "/Gemfile.lock" + if vim.fn.filereadable(lockfile) == 0 then + return true + end + for _, line in ipairs(vim.fn.readfile(lockfile)) do + if line:match("^%s+solargraph[%s(]") or line:match("^%s+solargraph$") then + return false + end + end + return true end, }, }) @@ -165,6 +186,9 @@ require("ruby-lsp").setup({ auto_start = true, }, + -- Show code lenses in buffers Ruby LSP is attached to + codelens = true, + -- Add :RubyLsp* user commands to buffers Ruby LSP is attached to user_commands = false, }) diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index f2fd62a..b08a3e4 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -1,5 +1,5 @@ *ruby-lsp.nvim.txt* - For NVIM v0.12.0 Last change: 2026 October 31 + For NVIM v0.12.0 Last change: 2026 November 01 ============================================================================== Table of Contents *ruby-lsp.nvim-table-of-contents* @@ -9,6 +9,7 @@ Table of Contents *ruby-lsp.nvim-table-of-contents* - 📝 Commands |ruby-lsp.nvim-ruby-lsp.nvim-📝-commands| - 📋 Requirements |ruby-lsp.nvim-ruby-lsp.nvim-📋-requirements| - 🛠️ Installation |ruby-lsp.nvim-ruby-lsp.nvim-���-️-installation| + - 🔍 Code Lenses |ruby-lsp.nvim-ruby-lsp.nvim-🔍-code-lenses| - 🖥️ Ruby LSP Server|ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server| - 🧪 Neotest |ruby-lsp.nvim-ruby-lsp.nvim-🧪-neotest| - 🐞 Debugging |ruby-lsp.nvim-ruby-lsp.nvim-🐞-debugging| @@ -118,6 +119,20 @@ If you’re upgrading and already start Ruby LSP yourself, remove your long as the plugin still isn’t lazy-loaded. +П�� CODE LENSES *ruby-lsp.nvim-ruby-lsp.nvim-🔍-code-lenses* + +The plugin turns on code lenses in buffers Ruby LSP is attached to, so **Run**, +**Run In Terminal**, and **Debug** show above your tests. Run the lens on the +cursor line with `grx`, Neovim’s default mapping for +`vim.lsp.codelens.run()`. To use a different key, map it yourself: + +>lua + vim.keymap.set("n", "cl", vim.lsp.codelens.run, { desc = "run code lens" }) +< + +Set `codelens = false` to leave code lenses to your own config. + + П��ϸ� RUBY LSP SERVER *ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server* The plugin configures and starts Ruby LSP for you, in any project with a @@ -133,14 +148,25 @@ ruby-lsp` to see why. Set `lsp.auto_start` to choose where the server starts. `true` starts it in every Ruby project, and `false` leaves it to you to call -`vim.lsp.enable("ruby_lsp")`. A function decides per project. This one skips -projects that use solargraph: +`vim.lsp.enable("ruby_lsp")`. A function decides per project. + +For example, if some of your projects bundle solargraph and you want solargraph +to handle those, skip Ruby LSP when `Gemfile.lock` lists it: >lua require("ruby-lsp").setup({ lsp = { auto_start = function(root_dir) - return vim.fn.filereadable(root_dir .. "/.solargraph.yml") == 0 + local lockfile = root_dir .. "/Gemfile.lock" + if vim.fn.filereadable(lockfile) == 0 then + return true + end + for _, line in ipairs(vim.fn.readfile(lockfile)) do + if line:match("^%s+solargraph[%s(]") or line:match("^%s+solargraph$") then + return false + end + end + return true end, }, }) @@ -253,6 +279,9 @@ These are the defaults. You only need to pass the ones you want to change. auto_start = true, }, + -- Show code lenses in buffers Ruby LSP is attached to + codelens = true, + -- Add :RubyLsp* user commands to buffers Ruby LSP is attached to user_commands = false, }) From d7cf95e73a08992fbbea791b4e79817d21e6c3a9 Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:02:56 -0600 Subject: [PATCH 03/10] fix(docs): keep emoji intact in vimdoc headings panvimdoc uppercases headings byte by byte, and under a UTF-8 locale that rewrote the bytes of each heading's emoji. Run it in the C locale so those bytes pass through unchanged. --- Makefile | 3 ++- doc/ruby-lsp.nvim.txt | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index e325ac2..bdab21e 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ lint: stylua --check lsp/ lua/ tests/ docs: panvimdoc - $(PANVIMDOC_DIR)/panvimdoc.sh \ + # the C locale keeps panvimdoc from mangling emoji when it uppercases headings + LC_ALL=C $(PANVIMDOC_DIR)/panvimdoc.sh \ --project-name ruby-lsp.nvim \ --input-file README.md \ --vim-version "NVIM v0.12.0" \ diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index b08a3e4..fade101 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -8,7 +8,7 @@ Table of Contents *ruby-lsp.nvim-table-of-contents* - 💡 Why |ruby-lsp.nvim-ruby-lsp.nvim-💡-why| - 📝 Commands |ruby-lsp.nvim-ruby-lsp.nvim-📝-commands| - 📋 Requirements |ruby-lsp.nvim-ruby-lsp.nvim-📋-requirements| - - 🛠️ Installation |ruby-lsp.nvim-ruby-lsp.nvim-���-️-installation| + - 🛠️ Installation |ruby-lsp.nvim-ruby-lsp.nvim-🛠️-installation| - 🔍 Code Lenses |ruby-lsp.nvim-ruby-lsp.nvim-🔍-code-lenses| - 🖥️ Ruby LSP Server|ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server| - 🧪 Neotest |ruby-lsp.nvim-ruby-lsp.nvim-🧪-neotest| @@ -29,7 +29,7 @@ this plugin they actually do something: run through neotest with nvim-dap . -П�� WHY *ruby-lsp.nvim-ruby-lsp.nvim-💡-why* +💡 WHY *ruby-lsp.nvim-ruby-lsp.nvim-💡-why* Ruby LSP’s code lenses call client-side commands like `rubyLsp.runTest` and `rubyLsp.debugTest`. VS Code’s Ruby LSP extension implements them, but Neovim @@ -41,7 +41,7 @@ neotest adapter and an rdbg debug adapter that use Ruby LSP to find and run your tests. -П�� COMMANDS *ruby-lsp.nvim-ruby-lsp.nvim-📝-commands* +📝 COMMANDS *ruby-lsp.nvim-ruby-lsp.nvim-📝-commands* ----------------------------------------------------------------------- Command What it does @@ -82,7 +82,7 @@ attached to: the buffer in the quickfix list ----------------------------------------------------------------------- -П�� REQUIREMENTS *ruby-lsp.nvim-ruby-lsp.nvim-📋-requirements* +📋 REQUIREMENTS *ruby-lsp.nvim-ruby-lsp.nvim-📋-requirements* - Neovim >= 0.12 - Ruby LSP >= 0.23.0, installed with `gem install ruby-lsp`. With a Ruby version manager, install it once for each Ruby version you use. @@ -96,7 +96,7 @@ OPTIONAL ~ - ruby-lsp-rspec in your Gemfile for RSpec projects. Minitest works out of the box. -П��ϸ� INSTALLATION *ruby-lsp.nvim-ruby-lsp.nvim-���-️-installation* +🛠️ INSTALLATION *ruby-lsp.nvim-ruby-lsp.nvim-🛠️-installation* With lazy.nvim : @@ -119,7 +119,7 @@ If you’re upgrading and already start Ruby LSP yourself, remove your long as the plugin still isn’t lazy-loaded. -П�� CODE LENSES *ruby-lsp.nvim-ruby-lsp.nvim-🔍-code-lenses* +🔍 CODE LENSES *ruby-lsp.nvim-ruby-lsp.nvim-🔍-code-lenses* The plugin turns on code lenses in buffers Ruby LSP is attached to, so **Run**, **Run In Terminal**, and **Debug** show above your tests. Run the lens on the @@ -133,7 +133,7 @@ cursor line with `grx`, Neovim’s default mapping for Set `codelens = false` to leave code lenses to your own config. -П��ϸ� RUBY LSP SERVER *ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server* +🖥️ RUBY LSP SERVER *ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server* The plugin configures and starts Ruby LSP for you, in any project with a `Gemfile` or `.git` directory. You don’t need nvim-lspconfig or a `ruby_lsp` @@ -188,7 +188,7 @@ If you override `root_dir`, your function replaces the plugin’s start checks, including `lsp.auto_start` and the check that `ruby-lsp` runs. -П�� NEOTEST *ruby-lsp.nvim-ruby-lsp.nvim-🧪-neotest* +🧪 NEOTEST *ruby-lsp.nvim-ruby-lsp.nvim-🧪-neotest* The neotest adapter finds tests with Ruby LSP and runs the commands Ruby LSP resolves for them, so it works the same for Minitest and RSpec, in Rails apps @@ -207,7 +207,7 @@ results show up in neotest’s signs, summary, and output. **Run In Terminal** always uses a terminal. -П�� DEBUGGING *ruby-lsp.nvim-ruby-lsp.nvim-🐞-debugging* +🐞 DEBUGGING *ruby-lsp.nvim-ruby-lsp.nvim-🐞-debugging* When nvim-dap is installed, the plugin registers a `ruby` debug adapter that starts your tests under rdbg. The **Debug** code lens uses it, and the plugin @@ -231,7 +231,7 @@ adapter is already registered under the `dap.adapter` name, since they depend on its own adapter. -š�ϸ� OPTIONS *ruby-lsp.nvim-ruby-lsp.nvim-⚙️-options* +⚙️ OPTIONS *ruby-lsp.nvim-ruby-lsp.nvim-⚙️-options* These are the defaults. You only need to pass the ones you want to change. @@ -288,7 +288,7 @@ These are the defaults. You only need to pass the ones you want to change. < -П�� HEALTH CHECK *ruby-lsp.nvim-ruby-lsp.nvim-🩺-health-check* +🩺 HEALTH CHECK *ruby-lsp.nvim-ruby-lsp.nvim-🩺-health-check* > :checkhealth ruby-lsp @@ -299,7 +299,7 @@ It reports whether `ruby-lsp` runs from the current project, the the plugin can use. -П�� DEVELOPMENT *ruby-lsp.nvim-ruby-lsp.nvim-🔧-development* +🔧 DEVELOPMENT *ruby-lsp.nvim-ruby-lsp.nvim-🔧-development* One-time setup to enable the local git hooks: @@ -318,7 +318,7 @@ requires pandoc . < -П�� ACKNOWLEDGEMENTS *ruby-lsp.nvim-ruby-lsp.nvim-🙏-acknowledgements* +🙏 ACKNOWLEDGEMENTS *ruby-lsp.nvim-ruby-lsp.nvim-🙏-acknowledgements* Thank you to the Ruby LSP team for such a great tool. This isn’t an official Ruby LSP project, just my work to make From 7f26224741cef0628fd044f954f5caa771ea8cf7 Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:02:56 -0600 Subject: [PATCH 04/10] docs: show turning off auto_start before the per-project function --- README.md | 22 +++++++++++++++++++--- doc/ruby-lsp.nvim.txt | 35 +++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dbebb75..1a91d84 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,23 @@ The plugin configures and starts Ruby LSP for you, in any project with a `Gemfil Before starting, the plugin checks that `ruby-lsp --version` runs from the project root. If you set `cmd` to a list such as `{ "bundle", "exec", "ruby-lsp" }`, it only checks that the first entry is executable. When the check fails, the server stays off and nothing is shown. Run `:checkhealth ruby-lsp` to see why. -Set `lsp.auto_start` to choose where the server starts. `true` starts it in every Ruby project, and `false` leaves it to you to call `vim.lsp.enable("ruby_lsp")`. A function decides per project. +### Starting the server yourself -For example, if some of your projects bundle solargraph and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` lists it: +By default the server starts in every Ruby project. To start it yourself instead, turn off `auto_start` and enable it when you want it: + +```lua +require("ruby-lsp").setup({ + lsp = { + auto_start = false, + }, +}) + +vim.lsp.enable("ruby_lsp") +``` + +### Choosing projects (optional) + +`auto_start` also takes a function that receives the project root and returns whether to start there. For example, if some of your projects bundle solargraph and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` lists it: ```lua require("ruby-lsp").setup({ @@ -98,7 +112,9 @@ require("ruby-lsp").setup({ }) ``` -To customize the server, use `after/lsp/ruby_lsp.lua` or `vim.lsp.config("ruby_lsp", { ... })`. Your settings merge on top of the plugin's: +### Customizing the server + +Use `after/lsp/ruby_lsp.lua` or `vim.lsp.config("ruby_lsp", { ... })`. Your settings merge on top of the plugin's: ```lua vim.lsp.config("ruby_lsp", { diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index fade101..5958c7c 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -146,12 +146,29 @@ project root. If you set `cmd` to a list such as `{ "bundle", "exec", check fails, the server stays off and nothing is shown. Run `:checkhealth ruby-lsp` to see why. -Set `lsp.auto_start` to choose where the server starts. `true` starts it in -every Ruby project, and `false` leaves it to you to call -`vim.lsp.enable("ruby_lsp")`. A function decides per project. -For example, if some of your projects bundle solargraph and you want solargraph -to handle those, skip Ruby LSP when `Gemfile.lock` lists it: +STARTING THE SERVER YOURSELF ~ + +By default the server starts in every Ruby project. To start it yourself +instead, turn off `auto_start` and enable it when you want it: + +>lua + require("ruby-lsp").setup({ + lsp = { + auto_start = false, + }, + }) + + vim.lsp.enable("ruby_lsp") +< + + +CHOOSING PROJECTS (OPTIONAL) ~ + +`auto_start` also takes a function that receives the project root and returns +whether to start there. For example, if some of your projects bundle solargraph +and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` +lists it: >lua require("ruby-lsp").setup({ @@ -172,9 +189,11 @@ to handle those, skip Ruby LSP when `Gemfile.lock` lists it: }) < -To customize the server, use `after/lsp/ruby_lsp.lua` or -`vim.lsp.config("ruby_lsp", { ... })`. Your settings merge on top of the -plugin’s: + +CUSTOMIZING THE SERVER ~ + +Use `after/lsp/ruby_lsp.lua` or `vim.lsp.config("ruby_lsp", { ... })`. Your +settings merge on top of the plugin’s: >lua vim.lsp.config("ruby_lsp", { From 2eb7eb8d099648f1cb0817d18b590e22fb1387cc Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:03:22 -0600 Subject: [PATCH 05/10] docs: name the Ruby LSP server in the auto_start sections --- README.md | 10 +++++----- doc/ruby-lsp.nvim.txt | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1a91d84..5cf0dda 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,9 @@ The plugin configures and starts Ruby LSP for you, in any project with a `Gemfil Before starting, the plugin checks that `ruby-lsp --version` runs from the project root. If you set `cmd` to a list such as `{ "bundle", "exec", "ruby-lsp" }`, it only checks that the first entry is executable. When the check fails, the server stays off and nothing is shown. Run `:checkhealth ruby-lsp` to see why. -### Starting the server yourself +### Starting the Ruby LSP server yourself -By default the server starts in every Ruby project. To start it yourself instead, turn off `auto_start` and enable it when you want it: +By default the plugin starts the Ruby LSP server in every Ruby project. To start the server yourself instead, set `lsp.auto_start = false` and call `vim.lsp.enable("ruby_lsp")` when you want it: ```lua require("ruby-lsp").setup({ @@ -89,9 +89,9 @@ require("ruby-lsp").setup({ vim.lsp.enable("ruby_lsp") ``` -### Choosing projects (optional) +### Choosing which projects start the Ruby LSP server (optional) -`auto_start` also takes a function that receives the project root and returns whether to start there. For example, if some of your projects bundle solargraph and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` lists it: +`lsp.auto_start` also takes a function. It receives the project root and returns whether to start the Ruby LSP server there. For example, if some of your projects bundle solargraph and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` lists it: ```lua require("ruby-lsp").setup({ @@ -112,7 +112,7 @@ require("ruby-lsp").setup({ }) ``` -### Customizing the server +### Customizing the Ruby LSP server Use `after/lsp/ruby_lsp.lua` or `vim.lsp.config("ruby_lsp", { ... })`. Your settings merge on top of the plugin's: diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index 5958c7c..529551f 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -147,10 +147,11 @@ check fails, the server stays off and nothing is shown. Run `:checkhealth ruby-lsp` to see why. -STARTING THE SERVER YOURSELF ~ +STARTING THE RUBY LSP SERVER YOURSELF ~ -By default the server starts in every Ruby project. To start it yourself -instead, turn off `auto_start` and enable it when you want it: +By default the plugin starts the Ruby LSP server in every Ruby project. To +start the server yourself instead, set `lsp.auto_start = false` and call +`vim.lsp.enable("ruby_lsp")` when you want it: >lua require("ruby-lsp").setup({ @@ -163,12 +164,12 @@ instead, turn off `auto_start` and enable it when you want it: < -CHOOSING PROJECTS (OPTIONAL) ~ +CHOOSING WHICH PROJECTS START THE RUBY LSP SERVER (OPTIONAL) ~ -`auto_start` also takes a function that receives the project root and returns -whether to start there. For example, if some of your projects bundle solargraph -and you want solargraph to handle those, skip Ruby LSP when `Gemfile.lock` -lists it: +`lsp.auto_start` also takes a function. It receives the project root and +returns whether to start the Ruby LSP server there. For example, if some of +your projects bundle solargraph and you want solargraph to handle those, skip +Ruby LSP when `Gemfile.lock` lists it: >lua require("ruby-lsp").setup({ @@ -190,7 +191,7 @@ lists it: < -CUSTOMIZING THE SERVER ~ +CUSTOMIZING THE RUBY LSP SERVER ~ Use `after/lsp/ruby_lsp.lua` or `vim.lsp.config("ruby_lsp", { ... })`. Your settings merge on top of the plugin’s: From a084dd08a67b7022117e31ec3a63063208731c8f Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:06:17 -0600 Subject: [PATCH 06/10] test: share setup across the attach tests The attach tests each built their own buffer and fake clients and restored their stubs at the end of the test body. The two older ones did not stub vim.lsp.codelens.enable, so once code lenses were on by default they called the real API with a fake client and failed. Move the buffer, the fake clients, and the get_client_by_id, codelens.enable, and $/progress stubs into before_each and after_each, so every attach test gets them and a failed assertion cannot leak a stub into later tests. --- tests/init_spec.lua | 159 ++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 87 deletions(-) diff --git a/tests/init_spec.lua b/tests/init_spec.lua index 67583c0..ac08877 100644 --- a/tests/init_spec.lua +++ b/tests/init_spec.lua @@ -69,97 +69,82 @@ describe('setup', function() assert.is_false(c.reuse_client(client, other)) end) - it('adds user commands on attach only when enabled', function() - local buf = vim.api.nvim_create_buf(true, false) - local original_get = vim.lsp.get_client_by_id - local client = { id = 7, name = 'ruby_lsp', handlers = {}, request = function() end } - local other = { id = 8, name = 'lua_ls', handlers = {}, request = function() end } - vim.lsp.get_client_by_id = function(id) - return id == 7 and client or other - end - - local function attach(id) - vim.api.nvim_exec_autocmds('LspAttach', { - group = 'RubyLsp', - buffer = buf, - data = { client_id = id }, - }) - end - - ruby_lsp.setup({ dap = { auto_configure = false } }) - attach(7) - assert.is_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) - - ruby_lsp.setup({ dap = { auto_configure = false }, user_commands = true }) - attach(8) - assert.is_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) - attach(7) - assert.is_not_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) - - vim.lsp.get_client_by_id = original_get - vim.api.nvim_buf_delete(buf, { force = true }) - end) - - it('drops null values from progress notifications on attach', function() - local buf = vim.api.nvim_create_buf(true, false) - local original_get = vim.lsp.get_client_by_id - local original_progress = vim.lsp.handlers['$/progress'] - local client = { id = 9, name = 'ruby_lsp', handlers = {}, request = function() end } - vim.lsp.get_client_by_id = function() - return client - end - local received - vim.lsp.handlers['$/progress'] = function(_, result) - received = result - end - - ruby_lsp.setup({ dap = { auto_configure = false } }) - vim.api.nvim_exec_autocmds('LspAttach', { group = 'RubyLsp', buffer = buf, data = { client_id = 9 } }) - client.handlers['$/progress']( - nil, - { token = 't', value = { kind = 'report', message = vim.NIL, percentage = vim.NIL } }, - {}, - {} - ) - - assert.same({ token = 't', value = { kind = 'report' } }, received) - - vim.lsp.handlers['$/progress'] = original_progress - vim.lsp.get_client_by_id = original_get - vim.api.nvim_buf_delete(buf, { force = true }) - end) - - it('enables code lenses for the ruby_lsp client on attach unless turned off', function() - local buf = vim.api.nvim_create_buf(true, false) - local original_get = vim.lsp.get_client_by_id - local original_enable = vim.lsp.codelens.enable - local client = { id = 10, name = 'ruby_lsp', handlers = {}, request = function() end } - local other = { id = 11, name = 'lua_ls', handlers = {}, request = function() end } - vim.lsp.get_client_by_id = function(id) - return id == 10 and client or other - end - local calls = {} - vim.lsp.codelens.enable = function(enable, filter) - table.insert(calls, { enable, filter }) - end + describe('on attach', function() + local buf, clients, codelens_calls, originals local function attach(id) vim.api.nvim_exec_autocmds('LspAttach', { group = 'RubyLsp', buffer = buf, data = { client_id = id } }) end - ruby_lsp.setup({ dap = { auto_configure = false } }) - attach(11) - assert.same({}, calls) - attach(10) - assert.same({ { true, { bufnr = buf, client_id = 10 } } }, calls) - - calls = {} - ruby_lsp.setup({ dap = { auto_configure = false }, codelens = false }) - attach(10) - assert.same({}, calls) - - vim.lsp.codelens.enable = original_enable - vim.lsp.get_client_by_id = original_get - vim.api.nvim_buf_delete(buf, { force = true }) + before_each(function() + buf = vim.api.nvim_create_buf(true, false) + clients = { + [1] = { id = 1, name = 'ruby_lsp', handlers = {}, request = function() end }, + [2] = { id = 2, name = 'lua_ls', handlers = {}, request = function() end }, + } + codelens_calls = {} + originals = { + get_client_by_id = vim.lsp.get_client_by_id, + codelens_enable = vim.lsp.codelens.enable, + progress = vim.lsp.handlers['$/progress'], + } + vim.lsp.get_client_by_id = function(id) + return clients[id] + end + vim.lsp.codelens.enable = function(enable, filter) + table.insert(codelens_calls, { enable, filter }) + end + end) + + after_each(function() + vim.lsp.get_client_by_id = originals.get_client_by_id + vim.lsp.codelens.enable = originals.codelens_enable + vim.lsp.handlers['$/progress'] = originals.progress + vim.api.nvim_buf_delete(buf, { force = true }) + end) + + it('adds user commands only when enabled', function() + ruby_lsp.setup({ dap = { auto_configure = false } }) + attach(1) + assert.is_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) + + ruby_lsp.setup({ dap = { auto_configure = false }, user_commands = true }) + attach(2) + assert.is_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) + attach(1) + assert.is_not_nil(vim.api.nvim_buf_get_commands(buf, {}).RubyLspShowDependencies) + end) + + it('drops null values from progress notifications', function() + local received + vim.lsp.handlers['$/progress'] = function(_, result) + received = result + end + + ruby_lsp.setup({ dap = { auto_configure = false } }) + attach(1) + clients[1].handlers['$/progress']( + nil, + { token = 't', value = { kind = 'report', message = vim.NIL, percentage = vim.NIL } }, + {}, + {} + ) + + assert.same({ token = 't', value = { kind = 'report' } }, received) + end) + + it('enables code lenses for the ruby_lsp client', function() + ruby_lsp.setup({ dap = { auto_configure = false } }) + attach(2) + assert.same({}, codelens_calls) + attach(1) + assert.same({ { true, { bufnr = buf, client_id = 1 } } }, codelens_calls) + end) + + it('leaves code lenses alone when turned off', function() + ruby_lsp.setup({ dap = { auto_configure = false }, codelens = false }) + attach(1) + assert.same({}, codelens_calls) + end) end) end) From e2c5080784953b9758c093e213a06dc0ed320f4c Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:06:17 -0600 Subject: [PATCH 07/10] refactor: read config once on attach and shorten the solargraph example --- README.md | 9 +++------ doc/ruby-lsp.nvim.txt | 9 +++------ lua/ruby-lsp/init.lua | 5 +++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5cf0dda..2b4e3df 100644 --- a/README.md +++ b/README.md @@ -101,12 +101,9 @@ require("ruby-lsp").setup({ if vim.fn.filereadable(lockfile) == 0 then return true end - for _, line in ipairs(vim.fn.readfile(lockfile)) do - if line:match("^%s+solargraph[%s(]") or line:match("^%s+solargraph$") then - return false - end - end - return true + return not vim.iter(vim.fn.readfile(lockfile)):any(function(line) + return line:match("^%s+solargraph%f[^%w_-]") ~= nil + end) end, }, }) diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index 529551f..0a1d73d 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -179,12 +179,9 @@ Ruby LSP when `Gemfile.lock` lists it: if vim.fn.filereadable(lockfile) == 0 then return true end - for _, line in ipairs(vim.fn.readfile(lockfile)) do - if line:match("^%s+solargraph[%s(]") or line:match("^%s+solargraph$") then - return false - end - end - return true + return not vim.iter(vim.fn.readfile(lockfile)):any(function(line) + return line:match("^%s+solargraph%f[^%w_-]") ~= nil + end) end, }, }) diff --git a/lua/ruby-lsp/init.lua b/lua/ruby-lsp/init.lua index 3e8cff5..55e781c 100644 --- a/lua/ruby-lsp/init.lua +++ b/lua/ruby-lsp/init.lua @@ -40,10 +40,11 @@ function M.setup(opts) return end -- per buffer, so it runs before the per-client guard below - if config.get().codelens then + local cfg = config.get() + if cfg.codelens then vim.lsp.codelens.enable(true, { bufnr = ev.buf, client_id = client.id }) end - if config.get().user_commands then + if cfg.user_commands then require('ruby-lsp.user_commands').attach(client, ev.buf) end if client._ruby_lsp_nvim_attached then From 868922c93fdf84ab52290502d98ead4b6792893b Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:09:07 -0600 Subject: [PATCH 08/10] fix: enable code lenses per buffer, not per client With client_id in the filter, Neovim records the enable flag on the client instead of the buffer. is_enabled({ bufnr }) then reports false, so toggling lenses off in a buffer did nothing. When the client stopped or restarted, the lenses stayed behind and the next edit raised an assertion in codelens.lua. Scope the call to the buffer, and test it through the real API so the spec checks what a user observes. --- README.md | 2 +- doc/ruby-lsp.nvim.txt | 4 +++- lua/ruby-lsp/init.lua | 4 +++- tests/init_spec.lua | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2b4e3df..3621eb5 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ The plugin turns on code lenses in buffers Ruby LSP is attached to, so **Run**, vim.keymap.set("n", "cl", vim.lsp.codelens.run, { desc = "run code lens" }) ``` -Set `codelens = false` to leave code lenses to your own config. +Set `codelens = false` to leave code lenses to your own config. With it on, the plugin enables code lenses for every server attached to a Ruby buffer, which overrides a global `vim.lsp.codelens.enable(false)` there. ## 🖥️ Ruby LSP Server diff --git a/doc/ruby-lsp.nvim.txt b/doc/ruby-lsp.nvim.txt index 0a1d73d..51e4e3d 100644 --- a/doc/ruby-lsp.nvim.txt +++ b/doc/ruby-lsp.nvim.txt @@ -130,7 +130,9 @@ cursor line with `grx`, Neovim’s default mapping for vim.keymap.set("n", "cl", vim.lsp.codelens.run, { desc = "run code lens" }) < -Set `codelens = false` to leave code lenses to your own config. +Set `codelens = false` to leave code lenses to your own config. With it on, the +plugin enables code lenses for every server attached to a Ruby buffer, which +overrides a global `vim.lsp.codelens.enable(false)` there. 🖥️ RUBY LSP SERVER *ruby-lsp.nvim-ruby-lsp.nvim-🖥️-ruby-lsp-server* diff --git a/lua/ruby-lsp/init.lua b/lua/ruby-lsp/init.lua index 55e781c..e985fd1 100644 --- a/lua/ruby-lsp/init.lua +++ b/lua/ruby-lsp/init.lua @@ -41,8 +41,10 @@ function M.setup(opts) end -- per buffer, so it runs before the per-client guard below local cfg = config.get() + -- scoped to the buffer only: with client_id, Neovim records the flag on the + -- client, so is_enabled({ bufnr }) is false and the lenses outlive the client if cfg.codelens then - vim.lsp.codelens.enable(true, { bufnr = ev.buf, client_id = client.id }) + vim.lsp.codelens.enable(true, { bufnr = ev.buf }) end if cfg.user_commands then require('ruby-lsp.user_commands').attach(client, ev.buf) diff --git a/tests/init_spec.lua b/tests/init_spec.lua index ac08877..82ddf13 100644 --- a/tests/init_spec.lua +++ b/tests/init_spec.lua @@ -133,12 +133,14 @@ describe('setup', function() assert.same({ token = 't', value = { kind = 'report' } }, received) end) - it('enables code lenses for the ruby_lsp client', function() + it('enables code lenses in buffers the ruby_lsp client attaches to', function() + -- the real API, so the test checks what a user can observe + vim.lsp.codelens.enable = originals.codelens_enable ruby_lsp.setup({ dap = { auto_configure = false } }) attach(2) - assert.same({}, codelens_calls) + assert.is_false(vim.lsp.codelens.is_enabled({ bufnr = buf })) attach(1) - assert.same({ { true, { bufnr = buf, client_id = 1 } } }, codelens_calls) + assert.is_true(vim.lsp.codelens.is_enabled({ bufnr = buf })) end) it('leaves code lenses alone when turned off', function() From de63d6e43faf591531df992198ce50b1e0dbbabb Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:09:08 -0600 Subject: [PATCH 09/10] chore: stop make docs from echoing the locale comment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bdab21e..1ef6a82 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ panvimdoc: lint: stylua --check lsp/ lua/ tests/ +# the C locale keeps panvimdoc from mangling emoji when it uppercases headings docs: panvimdoc - # the C locale keeps panvimdoc from mangling emoji when it uppercases headings LC_ALL=C $(PANVIMDOC_DIR)/panvimdoc.sh \ --project-name ruby-lsp.nvim \ --input-file README.md \ From 7f203f49707dc84cc6574deb02a8036dd6806ee6 Mon Sep 17 00:00:00 2001 From: Wassim Metallaoui Date: Sun, 1 Nov 2026 20:09:08 -0600 Subject: [PATCH 10/10] feat: report the codelens setting in checkhealth --- lua/ruby-lsp/health.lua | 1 + tests/health_spec.lua | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lua/ruby-lsp/health.lua b/lua/ruby-lsp/health.lua index 23a758a..b384872 100644 --- a/lua/ruby-lsp/health.lua +++ b/lua/ruby-lsp/health.lua @@ -72,6 +72,7 @@ local function check_install(root) else vim.health.info('auto_start: ' .. (auto_start and 'on' or 'off')) end + vim.health.info('codelens: ' .. (config.get().codelens and 'on' or 'off')) if bundles_ruby_lsp(root) then vim.health.warn('ruby-lsp is in ' .. root .. '/Gemfile.lock', { diff --git a/tests/health_spec.lua b/tests/health_spec.lua index 4e701d7..26d80d8 100644 --- a/tests/health_spec.lua +++ b/tests/health_spec.lua @@ -162,6 +162,16 @@ describe('health', function() assert.truthy(find('info', 'auto_start: function')) end) + it('reports the codelens setting', function() + health.check() + assert.truthy(find('info', 'codelens: on')) + + reports = {} + config.setup({ codelens = false }) + health.check() + assert.truthy(find('info', 'codelens: off')) + end) + it('places the checks after the Neovim version check', function() health.check()