Skip to content
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

add highlight for do...end blocks #3061

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
19 changes: 18 additions & 1 deletion lib/ruby_lsp/listeners/document_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def initialize(response_builder, target, parent, dispatcher, position)
Prism::RequiredParameterNode, Prism::RestParameterNode
[target, node_value(target)]
when Prism::ModuleNode, Prism::ClassNode, Prism::SingletonClassNode, Prism::DefNode, Prism::CaseNode,
Prism::WhileNode, Prism::UntilNode, Prism::ForNode, Prism::IfNode, Prism::UnlessNode
Prism::WhileNode, Prism::UntilNode, Prism::ForNode, Prism::IfNode, Prism::UnlessNode, Prism::BlockNode,
Prism::LambdaNode
target
end

Expand Down Expand Up @@ -184,6 +185,8 @@ def initialize(response_builder, target, parent, dispatcher, position)
:on_for_node_enter,
:on_if_node_enter,
:on_unless_node_enter,
:on_block_node_enter,
:on_lambda_node_enter,
)
end
end
Expand Down Expand Up @@ -578,6 +581,20 @@ def on_unless_node_enter(node)
add_matching_end_highlights(node.keyword_loc, node.end_keyword_loc)
end

sig { params(node: Prism::BlockNode).void }
def on_block_node_enter(node)
return unless @target.is_a?(Prism::BlockNode)

add_matching_end_highlights(node.opening_loc, node.closing_loc)
end

sig { params(node: Prism::LambdaNode).void }
def on_lambda_node_enter(node)
return unless @target.is_a?(Prism::LambdaNode)

add_matching_end_highlights(node.opening_loc, node.closing_loc)
end

private

sig { params(node: Prism::Node, classes: T::Array[T.class_of(Prism::Node)]).returns(T.nilable(T::Boolean)) }
Expand Down
36 changes: 36 additions & 0 deletions test/expectations/document_highlight/do_blocks.exp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"params": [
{
"line": 0,
"character": 10
}
],
"result": [
{
"range": {
"start": {
"line": 0,
"character": 10
},
"end": {
"line": 0,
"character": 12
}
},
"kind": 1
},
{
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 2,
"character": 3
}
},
"kind": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"params": [
{
"line": 0,
"character": 19
}
],
"result": [
{
"range": {
"start": {
"line": 0,
"character": 18
},
"end": {
"line": 0,
"character": 20
}
},
"kind": 1
},
{
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 2,
"character": 3
}
},
"kind": 1
}
]
}
Loading