Skip to content

Add definition on mailbox callbacks #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ module Callbacks
"before_perform",
].freeze

ALL = (MODELS + CONTROLLERS + JOBS).freeze #: Array[String]
MAILBOX = [
"after_processing",
"before_processing",
"around_processing",
].freeze

ALL = (MODELS + CONTROLLERS + JOBS + MAILBOX).freeze #: Array[String]
end
end
end
Expand Down
63 changes: 63 additions & 0 deletions test/ruby_lsp_rails/definition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,69 @@ def baz; end
assert_empty(response)
end

test "recognizes mailbox before_processing callback" do
response = generate_definitions_for_source(<<~RUBY, { line: 1, character: 20 })
class FooMailbox < ApplicationMailbox
before_processing :bar

private
def bar; end
end
RUBY

assert_equal(1, response.size)

response = response.first

assert_equal("file:///fake.rb", response.uri)
assert_equal(4, response.range.start.line)
assert_equal(4, response.range.start.character)
assert_equal(4, response.range.end.line)
assert_equal(16, response.range.end.character)
end

test "recognizes mailbox around_processing callback" do
response = generate_definitions_for_source(<<~RUBY, { line: 1, character: 20 })
class FooMailbox < ApplicationMailbox
around_processing :baz

private
def baz; end
end
RUBY

assert_equal(1, response.size)

response = response.first

assert_equal("file:///fake.rb", response.uri)
assert_equal(4, response.range.start.line)
assert_equal(4, response.range.start.character)
assert_equal(4, response.range.end.line)
assert_equal(16, response.range.end.character)
end

test "recognizes mailbox after_processing callback" do
response = generate_definitions_for_source(<<~RUBY, { line: 1, character: 20 })
class FooMailbox < ApplicationMailbox
after_processing :qux

private
def qux; end
end
RUBY

assert_equal(1, response.size)

response = response.first

assert_equal("file:///fake.rb", response.uri)
assert_equal(4, response.range.start.line)
assert_equal(4, response.range.start.character)
assert_equal(4, response.range.end.line)
assert_equal(16, response.range.end.character)
end

private

def generate_definitions_for_source(source, position)
Expand Down