Skip to content

Commit

Permalink
Merge branch 'main' into fix-handling-of-multibyte-characters
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFounds committed Jun 5, 2024
2 parents 895dff7 + 28978dc commit 052d674
Show file tree
Hide file tree
Showing 109 changed files with 10,041 additions and 6,169 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ updates:
- "patch"
exclude-patterns:
- "prism"
open-pull-requests-limit: 100
- package-ecosystem: "npm"
directory: "vscode/"
schedule:
Expand All @@ -29,6 +30,7 @@ updates:
update-types:
- "minor"
- "patch"
open-pull-requests-limit: 100
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ruby: ["3.0", "3.1", "3.2", "3.3"]
ruby: ["3.1", "3.2", "3.3"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
name: Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
Expand Down Expand Up @@ -86,6 +86,8 @@ jobs:
# We need some Ruby installed for the environment activation tests
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Download shadowenv
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ vscode/dist
vscode/node_modules
vscode/.vscode-test/
vscode/*.vsix
vscode/*.log
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@
]
}
],
"sorbet.highlightUntyped": "everywhere-but-tests"
}
14 changes: 7 additions & 7 deletions ADDONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module RubyLsp
module MyGem
class Addon < ::RubyLsp::Addon
# Performs any activation that needs to happen once when the language server is booted
def activate(message_queue)
def activate(global_state, message_queue)
end

# Performs any cleanup when shutting down the server, like terminating a subprocess
Expand Down Expand Up @@ -131,7 +131,7 @@ following listener implementation.
module RubyLsp
module MyGem
class Addon < ::RubyLsp::Addon
def activate(message_queue)
def activate(global_state, message_queue)
@message_queue = message_queue
@config = SomeConfiguration.new
end
Expand All @@ -143,7 +143,7 @@ module RubyLsp
"Ruby LSP My Gem"
end

def create_hover_listener(response_builder, nesting, index, dispatcher)
def create_hover_listener(response_builder, node_context, index, dispatcher)
# Use the listener factory methods to instantiate listeners with parameters sent by the LSP combined with any
# pre-computed information in the addon. These factory methods are invoked on every request
Hover.new(client, response_builder, @config, dispatcher)
Expand Down Expand Up @@ -249,7 +249,7 @@ interested in using it.
module RubyLsp
module MyGem
class Addon < ::RubyLsp::Addon
def activate(message_queue)
def activate(global_state, message_queue)
@message_queue = message_queue
end

Expand All @@ -259,13 +259,13 @@ module RubyLsp
"Ruby LSP My Gem"
end

def create_hover_listener(response_builder, nesting, index, dispatcher)
MyHoverListener.new(@message_queue, response_builder, nesting, index, dispatcher)
def create_hover_listener(response_builder, node_context, index, dispatcher)
MyHoverListener.new(@message_queue, response_builder, node_context, index, dispatcher)
end
end

class MyHoverListener
def initialize(message_queue, response_builder, nesting, index, dispatcher)
def initialize(message_queue, response_builder, node_context, index, dispatcher)
@message_queue = message_queue

@message_queue << Notification.new(
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ To add a new expectations test runner for a new request handler:

```ruby
require "test_helper"
require "expectations/expectations_test_runner"
require_relative "support/expectations_test_runner"

class MyRequestExpectationsTest < ExpectationsTestRunner
# The first argument is the fully qualified name of the request class
Expand All @@ -83,7 +83,7 @@ example

```ruby
require "test_helper"
require "expectations/expectations_test_runner"
require_relative "support/expectations_test_runner"

class MyRequestExpectationsTest < ExpectationsTestRunner
expectations_tests RubyLsp::Requests::MyRequest, "my_request"
Expand Down
127 changes: 42 additions & 85 deletions EDITORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ Code, use the official [Ruby LSP extension](https://marketplace.visualstudio.com
> Some Ruby LSP features may be unavailable or limited due to incomplete implementations of the Language Server
> Protocol, such as dynamic feature registration, or [file watching](https://github.com/Shopify/ruby-lsp/issues/1456).
If you need to select particular features to enable or disable, see
[`vscode/package.json`](vscode/package.json) for the full list.

<!-- When adding a new editor to the list, either link directly to a website containing the instructions or link to a
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)
- [Neovim LSP](#Neovim)
- [Sublime Text LSP](#sublime-text-lsp)
- [Zed](#zed)
- [RubyMine](#RubyMine)

## Emacs Eglot

Expand All @@ -28,6 +33,8 @@ When you run `eglot` command it will run `ruby-lsp` process for you.

## Neovim

**Note**: Ensure that you are using Neovim 0.10 or newer.

### nvim-lspconfig

The [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/ruby_lsp.lua)
Expand Down Expand Up @@ -61,98 +68,42 @@ mason_lspconfig.setup_handlers {
}
```

### Neovim Limitations
### Additional setup (optional)

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.
`rubyLsp/workspace/dependencies` is a custom method currently supported only in the VS Code plugin.
The following snippet adds `ShowRubyDeps` command to show dependencies in the quickfix list.

```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
local diagnostic_items = {}
if result then
diagnostic_items = result.items
local function add_ruby_deps_command(client, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, "ShowRubyDeps", function(opts)
local params = vim.lsp.util.make_text_document_params()
local showAll = opts.args == "all"

client.request("rubyLsp/workspace/dependencies", params, function(error, result)
if error then
print("Error showing deps: " .. error)
return
end
vim.lsp.diagnostic.on_publish_diagnostics(
nil,
vim.tbl_extend("keep", params, { diagnostics = diagnostic_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])
local qf_list = {}
for _, item in ipairs(result) do
if showAll or item.dependency then
table.insert(qf_list, {
text = string.format("%s (%s) - %s", item.name, item.version, item.dependency),
filename = item.path
})
end
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

-- adds ShowRubyDeps command to show dependencies in the quickfix list.
-- add the `all` argument to show indirect dependencies as well
local function add_ruby_deps_command(client, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, "ShowRubyDeps",
function(opts)

local params = vim.lsp.util.make_text_document_params()

local showAll = opts.args == "all"

client.request("rubyLsp/workspace/dependencies", params,
function(error, result)
if error then
print("Error showing deps: " .. error)
return
end

local qf_list = {}
for _, item in ipairs(result) do
if showAll or item.dependency then
table.insert(qf_list, {
text = string.format("%s (%s) - %s",
item.name,
item.version,
item.dependency),

filename = item.path
})
end
end

vim.fn.setqflist(qf_list)
vim.cmd('copen')
end, bufnr)
end, {nargs = "?", complete = function()
return {"all"}
end})
vim.fn.setqflist(qf_list)
vim.cmd('copen')
end, bufnr)
end,
{nargs = "?", complete = function() return {"all"} end})
end


require("lspconfig").ruby_lsp.setup({
on_attach = function(client, buffer)
setup_diagnostics(client, buffer)
add_ruby_deps_command(client, buffer)
end,
})
Expand Down Expand Up @@ -182,12 +133,18 @@ To configure the Ruby LSP using [LSP for Sublime Text](https://github.com/sublim

Restart LSP or Sublime Text and `ruby-lsp` will automatically activate when opening ruby files.

## Zed (some limitations)
## Zed

[Setting up Ruby LSP](https://github.com/zed-industries/zed/blob/main/docs/src/languages/ruby.md#setting-up-ruby-lsp)

[Zed has added support for Ruby LSP as a alternative language server](https://github.com/zed-industries/zed/pull/11768) in version v0.0.2 of the Ruby extension.

See https://github.com/zed-industries/zed/issues/4834 for discussion of the limitations.

## RubyMine (not yet supported)
## RubyMine

You can use the Ruby LSP with RubyMine (or IntelliJ IDEA Ultimate) through the following plugin.

Note that there might be overlapping functionality when using it with RubyMine, given that the IDE provides similar features as the ones coming from the Ruby LSP.

Although there is overlap between the features provided by RubyMine and Ruby LSP, there may be benefits in using both together. RubyMine has a [LSP API](https://blog.jetbrains.com/ruby/2023/07/the-rubymine-2023-2-beta-updated-ai-assistant-lsp-api-for-plugin-developers-and-more/), so adding support would involve writing a plugin using Kotlin. The [rubymine-sorbet-lsp](https://github.com/simoleone/rubymine-sorbet-lsp) project may be a useful reference for this.
[https://plugins.jetbrains.com/plugin/24413-ruby-lsp](Ruby LSP plugin)
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ group :development do
gem "bundler", "~> 2.5"
gem "debug", "~> 1.9", require: false
gem "minitest-reporters", "~> 1.6"
gem "minitest", "~> 5.22"
gem "mocha", "~> 2.2"
gem "minitest", "~> 5.23"
gem "mocha", "~> 2.3"
gem "psych", "~> 5.1", require: false
gem "rake", "~> 13.2"
gem "rdoc", require: false, github: "Shopify/rdoc", branch: "create_snapper_generator"
Expand All @@ -18,7 +18,7 @@ group :development do
gem "rubocop-rake", "~> 0.6.0", require: false
gem "rubocop-shopify", "~> 2.15", require: false
gem "rubocop-sorbet", "~> 0.8", require: false
gem "rubocop", "~> 1.63"
gem "rubocop", "~> 1.64"
gem "simplecov", require: false
gem "syntax_tree", ">= 6.1.1", "< 7"

Expand Down
Loading

0 comments on commit 052d674

Please sign in to comment.