From 8be1661d7e0254918ba69ca62eec190f0b529707 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Wed, 30 Aug 2023 13:26:37 -0400 Subject: [PATCH] Migrate Selection Range request to YARP --- lib/ruby_lsp/requests/base_request.rb | 2 +- lib/ruby_lsp/requests/selection_ranges.rb | 105 +++++++++++------- .../requests/support/selection_range.rb | 9 +- .../array_literal_oneline.exp.json | 6 +- .../begin_rescue_ensure.exp.json | 32 ++---- .../selection_ranges/case_when.exp.json | 24 +--- .../class_declaration.exp.json | 30 ++--- .../class_declaration_nested.exp.json | 2 +- .../selection_ranges/def.exp.json | 22 +--- .../selection_ranges/def_endless.exp.json | 2 +- .../def_multiline_params.exp.json | 8 +- .../selection_ranges/def_oneline.exp.json | 2 +- .../def_require_name_parameter.exp.json | 2 +- .../selection_ranges/defs.exp.json | 2 +- .../defs_multiline_params.exp.json | 8 +- .../selection_ranges/do_blocks.exp.json | 20 +--- .../selection_ranges/ensure.exp.json | 26 ++--- .../selection_ranges/for.exp.json | 22 +--- .../selection_ranges/hash_literal.exp.json | 26 +++-- .../hash_literal_oneline.exp.json | 22 +++- .../selection_ranges/heredoc.exp.json | 4 +- .../expectations/selection_ranges/if.exp.json | 22 +--- .../selection_ranges/if_elsif_else.exp.json | 30 ++--- .../if_elsif_else_empty.exp.json | 24 +--- .../selection_ranges/lambdas.exp.json | 26 ++--- .../module_declaration.exp.json | 4 +- .../multiline_arrays.exp.json | 6 +- .../selection_ranges/multiline_block.exp.json | 20 +--- .../multiline_invocation.exp.json | 46 +++++++- .../nested_invocation.exp.json | 42 +++++-- .../nested_invocation_no_parenthesis.exp.json | 38 +++++-- .../pattern_matching.exp.json | 24 +--- .../selection_ranges/rescue_multiple.exp.json | 22 +--- .../selection_ranges/sclass.exp.json | 4 +- .../selection_ranges/string_concat.exp.json | 24 +--- .../selection_ranges/unless.exp.json | 22 +--- .../selection_ranges/until.exp.json | 22 +--- .../selection_ranges/while.exp.json | 22 +--- .../selection_ranges_expectations_test.rb | 2 +- 39 files changed, 347 insertions(+), 429 deletions(-) diff --git a/lib/ruby_lsp/requests/base_request.rb b/lib/ruby_lsp/requests/base_request.rb index e05535e5e3..cbd9796b90 100644 --- a/lib/ruby_lsp/requests/base_request.rb +++ b/lib/ruby_lsp/requests/base_request.rb @@ -23,7 +23,7 @@ def run; end # Syntax Tree implements `visit_all` using `map` instead of `each` for users who want to use the pattern # `result = visitor.visit(tree)`. However, we don't use that pattern and should avoid producing a new array for # every single node visited - sig { params(nodes: T::Array[T.nilable(SyntaxTree::Node)]).void } + sig { params(nodes: T::Array[T.nilable(YARP::Node)]).void } def visit_all(nodes) nodes.each { |node| visit(node) } end diff --git a/lib/ruby_lsp/requests/selection_ranges.rb b/lib/ruby_lsp/requests/selection_ranges.rb index dea4765f35..fcd0f14ac2 100644 --- a/lib/ruby_lsp/requests/selection_ranges.rb +++ b/lib/ruby_lsp/requests/selection_ranges.rb @@ -25,41 +25,37 @@ class SelectionRanges < BaseRequest NODES_THAT_CAN_BE_PARENTS = T.let( [ - SyntaxTree::Assign, - SyntaxTree::ArrayLiteral, - SyntaxTree::Begin, - SyntaxTree::BlockNode, - SyntaxTree::CallNode, - SyntaxTree::Case, - SyntaxTree::ClassDeclaration, - SyntaxTree::Command, - SyntaxTree::DefNode, - SyntaxTree::Elsif, - SyntaxTree::Else, - SyntaxTree::EmbDoc, - SyntaxTree::Ensure, - SyntaxTree::For, - SyntaxTree::HashLiteral, - SyntaxTree::Heredoc, - SyntaxTree::HeredocBeg, - SyntaxTree::HshPtn, - SyntaxTree::IfNode, - SyntaxTree::In, - SyntaxTree::Lambda, - SyntaxTree::MethodAddBlock, - SyntaxTree::ModuleDeclaration, - SyntaxTree::Params, - SyntaxTree::Rescue, - SyntaxTree::RescueEx, - SyntaxTree::StringConcat, - SyntaxTree::StringLiteral, - SyntaxTree::UnlessNode, - SyntaxTree::UntilNode, - SyntaxTree::VCall, - SyntaxTree::When, - SyntaxTree::WhileNode, + YARP::ArgumentsNode, + YARP::ArrayNode, + YARP::AssocNode, + YARP::BeginNode, + YARP::BlockNode, + YARP::CallNode, + YARP::CaseNode, + YARP::ClassNode, + YARP::DefNode, + YARP::ElseNode, + YARP::EnsureNode, + YARP::ForNode, + YARP::HashNode, + YARP::HashPatternNode, + YARP::IfNode, + YARP::InNode, + YARP::InterpolatedStringNode, + YARP::KeywordHashNode, + YARP::LambdaNode, + YARP::LocalVariableWriteNode, + YARP::ModuleNode, + YARP::ParametersNode, + YARP::RescueNode, + YARP::StringConcatNode, + YARP::StringNode, + YARP::UnlessNode, + YARP::UntilNode, + YARP::WhenNode, + YARP::WhileNode, ].freeze, - T::Array[T.class_of(SyntaxTree::Node)], + T::Array[T.class_of(YARP::Node)], ) sig { params(document: Document).void } @@ -72,19 +68,23 @@ def initialize(document) sig { override.returns(T.all(T::Array[Support::SelectionRange], Object)) } def run - visit(@document.tree) if @document.parsed? + visit(@document.tree) @ranges.reverse! end private - sig { override.params(node: T.nilable(SyntaxTree::Node)).void } + sig { override.params(node: T.nilable(YARP::Node)).void } def visit(node) return if node.nil? - range = create_selection_range(node.location, @stack.last) - + range = if node.is_a?(YARP::InterpolatedStringNode) + create_heredoc_selection_range(node, @stack.last) + else + create_selection_range(node.location, @stack.last) + end @ranges << range + return if node.child_nodes.empty? @stack << range if NODES_THAT_CAN_BE_PARENTS.include?(node.class) @@ -94,11 +94,36 @@ def visit(node) sig do params( - location: SyntaxTree::Location, + node: YARP::InterpolatedStringNode, + parent: T.nilable(Support::SelectionRange), + ).returns(Support::SelectionRange) + end + def create_heredoc_selection_range(node, parent) + opening_loc = node.opening_loc + closing_loc = node.closing_loc + + RubyLsp::Requests::Support::SelectionRange.new( + range: Interface::Range.new( + start: Interface::Position.new( + line: opening_loc.start_line - 1, + character: opening_loc.start_column, + ), + end: Interface::Position.new( + line: closing_loc.end_line - 1, + character: closing_loc.end_column, + ), + ), + parent: parent, + ) + end + + sig do + params( + location: YARP::Location, parent: T.nilable(Support::SelectionRange), ).returns(Support::SelectionRange) end - def create_selection_range(location, parent = nil) + def create_selection_range(location, parent) RubyLsp::Requests::Support::SelectionRange.new( range: Interface::Range.new( start: Interface::Position.new( diff --git a/lib/ruby_lsp/requests/support/selection_range.rb b/lib/ruby_lsp/requests/support/selection_range.rb index 4474c94211..8e0b59cace 100644 --- a/lib/ruby_lsp/requests/support/selection_range.rb +++ b/lib/ruby_lsp/requests/support/selection_range.rb @@ -9,10 +9,11 @@ class SelectionRange < Interface::SelectionRange sig { params(position: Document::PositionShape).returns(T::Boolean) } def cover?(position) - line_range = (range.start.line..range.end.line) - character_range = (range.start.character..range.end.character) - - line_range.cover?(position[:line]) && character_range.cover?(position[:character]) + start_covered = range.start.line < position[:line] || + (range.start.line == position[:line] && range.start.character <= position[:character]) + end_covered = range.end.line > position[:line] || + (range.end.line == position[:line] && range.end.character >= position[:character]) + start_covered && end_covered end end end diff --git a/test/expectations/selection_ranges/array_literal_oneline.exp.json b/test/expectations/selection_ranges/array_literal_oneline.exp.json index 719c515f04..a166ce482d 100644 --- a/test/expectations/selection_ranges/array_literal_oneline.exp.json +++ b/test/expectations/selection_ranges/array_literal_oneline.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 0, - "character": 6 + "character": 5 } }, "parent": { @@ -25,7 +25,7 @@ }, "end": { "line": 0, - "character": 10 + "character": 9 } }, "parent": { @@ -36,7 +36,7 @@ }, "end": { "line": 0, - "character": 10 + "character": 9 } } } diff --git a/test/expectations/selection_ranges/begin_rescue_ensure.exp.json b/test/expectations/selection_ranges/begin_rescue_ensure.exp.json index 11ac4944d4..023124658c 100644 --- a/test/expectations/selection_ranges/begin_rescue_ensure.exp.json +++ b/test/expectations/selection_ranges/begin_rescue_ensure.exp.json @@ -14,52 +14,40 @@ }, "end": { "line": 5, - "character": 6 + "character": 17 } }, "parent": { "range": { "start": { - "line": 5, - "character": 2 + "line": 4, + "character": 0 }, "end": { "line": 5, - "character": 18 + "character": 17 } }, "parent": { "range": { "start": { - "line": 4, + "line": 2, "character": 0 }, "end": { - "line": 6, - "character": 0 + "line": 5, + "character": 17 } }, "parent": { "range": { "start": { - "line": 2, + "line": 0, "character": 0 }, "end": { - "line": 6, - "character": 0 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 8, - "character": 3 - } + "line": 8, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/case_when.exp.json b/test/expectations/selection_ranges/case_when.exp.json index 56c396f1cc..af23a6a0d2 100644 --- a/test/expectations/selection_ranges/case_when.exp.json +++ b/test/expectations/selection_ranges/case_when.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 2, - "character": 6 + "character": 12 } }, "parent": { "range": { "start": { - "line": 2, - "character": 2 + "line": 1, + "character": 0 }, "end": { "line": 2, - "character": 13 + "character": 12 } }, "parent": { "range": { "start": { - "line": 1, + "line": 0, "character": 0 }, "end": { "line": 5, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 5, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/class_declaration.exp.json b/test/expectations/selection_ranges/class_declaration.exp.json index f6478d841f..278ff8b84b 100644 --- a/test/expectations/selection_ranges/class_declaration.exp.json +++ b/test/expectations/selection_ranges/class_declaration.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 2, - "character": 8 + "character": 16 } }, "parent": { "range": { "start": { - "line": 2, - "character": 4 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 17 + "line": 3, + "character": 4 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 3, - "character": 5 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 4, - "character": 3 - } + "line": 4, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/class_declaration_nested.exp.json b/test/expectations/selection_ranges/class_declaration_nested.exp.json index 19b0926d08..dd413b5586 100644 --- a/test/expectations/selection_ranges/class_declaration_nested.exp.json +++ b/test/expectations/selection_ranges/class_declaration_nested.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 2, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/def.exp.json b/test/expectations/selection_ranges/def.exp.json index 87d3465f42..60db6b682f 100644 --- a/test/expectations/selection_ranges/def.exp.json +++ b/test/expectations/selection_ranges/def.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 3 + "character": 6 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 7 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 3, - "character": 3 - } + "line": 3, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/def_endless.exp.json b/test/expectations/selection_ranges/def_endless.exp.json index 3137c28b00..de2dfd84ea 100644 --- a/test/expectations/selection_ranges/def_endless.exp.json +++ b/test/expectations/selection_ranges/def_endless.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 2, - "character": 12 + "character": 11 } } } diff --git a/test/expectations/selection_ranges/def_multiline_params.exp.json b/test/expectations/selection_ranges/def_multiline_params.exp.json index d3a13aae13..58f1daa489 100644 --- a/test/expectations/selection_ranges/def_multiline_params.exp.json +++ b/test/expectations/selection_ranges/def_multiline_params.exp.json @@ -14,18 +14,18 @@ }, "end": { "line": 1, - "character": 3 + "character": 2 } }, "parent": { "range": { "start": { "line": 1, - "character": 8 + "character": 2 }, "end": { "line": 2, - "character": 0 + "character": 2 } }, "parent": { @@ -36,7 +36,7 @@ }, "end": { "line": 6, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/def_oneline.exp.json b/test/expectations/selection_ranges/def_oneline.exp.json index 75be59e0f9..d279b3d7e1 100644 --- a/test/expectations/selection_ranges/def_oneline.exp.json +++ b/test/expectations/selection_ranges/def_oneline.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 0, - "character": 12 + "character": 11 } } } diff --git a/test/expectations/selection_ranges/def_require_name_parameter.exp.json b/test/expectations/selection_ranges/def_require_name_parameter.exp.json index 2c6ee30673..d4c78002bb 100644 --- a/test/expectations/selection_ranges/def_require_name_parameter.exp.json +++ b/test/expectations/selection_ranges/def_require_name_parameter.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 1, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/defs.exp.json b/test/expectations/selection_ranges/defs.exp.json index c3c778e234..2e6af85a70 100644 --- a/test/expectations/selection_ranges/defs.exp.json +++ b/test/expectations/selection_ranges/defs.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 3, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/defs_multiline_params.exp.json b/test/expectations/selection_ranges/defs_multiline_params.exp.json index b43b7b98b0..58f1daa489 100644 --- a/test/expectations/selection_ranges/defs_multiline_params.exp.json +++ b/test/expectations/selection_ranges/defs_multiline_params.exp.json @@ -14,18 +14,18 @@ }, "end": { "line": 1, - "character": 3 + "character": 2 } }, "parent": { "range": { "start": { "line": 1, - "character": 13 + "character": 2 }, "end": { "line": 2, - "character": 0 + "character": 2 } }, "parent": { @@ -36,7 +36,7 @@ }, "end": { "line": 6, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/do_blocks.exp.json b/test/expectations/selection_ranges/do_blocks.exp.json index 73d55244c6..8a40c840da 100644 --- a/test/expectations/selection_ranges/do_blocks.exp.json +++ b/test/expectations/selection_ranges/do_blocks.exp.json @@ -13,31 +13,19 @@ "character": 10 }, "end": { - "line": 0, - "character": 12 + "line": 2, + "character": 2 } }, "parent": { "range": { "start": { "line": 0, - "character": 10 + "character": 0 }, "end": { "line": 2, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/ensure.exp.json b/test/expectations/selection_ranges/ensure.exp.json index 106be9eb65..53e7e693b0 100644 --- a/test/expectations/selection_ranges/ensure.exp.json +++ b/test/expectations/selection_ranges/ensure.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 3, - "character": 6 + "character": 14 } }, "parent": { "range": { "start": { - "line": 3, - "character": 2 + "line": 2, + "character": 0 }, "end": { - "line": 3, - "character": 15 + "line": 4, + "character": 2 } }, "parent": { "range": { "start": { - "line": 2, + "line": 0, "character": 0 }, "end": { "line": 4, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 4, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/for.exp.json b/test/expectations/selection_ranges/for.exp.json index 5e89d1f535..8d81e19c1c 100644 --- a/test/expectations/selection_ranges/for.exp.json +++ b/test/expectations/selection_ranges/for.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 6 + "character": 13 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 14 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "line": 2, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/hash_literal.exp.json b/test/expectations/selection_ranges/hash_literal.exp.json index 8c1b421492..f5d6678d4c 100644 --- a/test/expectations/selection_ranges/hash_literal.exp.json +++ b/test/expectations/selection_ranges/hash_literal.exp.json @@ -14,29 +14,41 @@ }, "end": { "line": 1, - "character": 4 + "character": 3 } }, "parent": { "range": { "start": { - "line": 0, - "character": 4 + "line": 1, + "character": 2 }, "end": { - "line": 3, - "character": 1 + "line": 1, + "character": 5 } }, "parent": { "range": { "start": { "line": 0, - "character": 0 + "character": 4 }, "end": { "line": 3, - "character": 1 + "character": 0 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } } } } diff --git a/test/expectations/selection_ranges/hash_literal_oneline.exp.json b/test/expectations/selection_ranges/hash_literal_oneline.exp.json index 49d8f27d47..dc4018f0bc 100644 --- a/test/expectations/selection_ranges/hash_literal_oneline.exp.json +++ b/test/expectations/selection_ranges/hash_literal_oneline.exp.json @@ -14,29 +14,41 @@ }, "end": { "line": 0, - "character": 8 + "character": 7 } }, "parent": { "range": { "start": { "line": 0, - "character": 4 + "character": 6 }, "end": { "line": 0, - "character": 18 + "character": 9 } }, "parent": { "range": { "start": { "line": 0, - "character": 0 + "character": 4 }, "end": { "line": 0, - "character": 18 + "character": 17 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 17 + } } } } diff --git a/test/expectations/selection_ranges/heredoc.exp.json b/test/expectations/selection_ranges/heredoc.exp.json index 63f0acc7cc..1a6b1ab998 100644 --- a/test/expectations/selection_ranges/heredoc.exp.json +++ b/test/expectations/selection_ranges/heredoc.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 1, - "character": 18 + "character": 17 } }, "parent": { @@ -25,7 +25,7 @@ }, "end": { "line": 2, - "character": 8 + "character": 7 } } } diff --git a/test/expectations/selection_ranges/if.exp.json b/test/expectations/selection_ranges/if.exp.json index 4df47d4c1f..eadca142ae 100644 --- a/test/expectations/selection_ranges/if.exp.json +++ b/test/expectations/selection_ranges/if.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 6 + "character": 14 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 15 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "line": 2, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/if_elsif_else.exp.json b/test/expectations/selection_ranges/if_elsif_else.exp.json index 447b5d4047..42a30c8648 100644 --- a/test/expectations/selection_ranges/if_elsif_else.exp.json +++ b/test/expectations/selection_ranges/if_elsif_else.exp.json @@ -14,52 +14,40 @@ }, "end": { "line": 5, - "character": 6 + "character": 10 } }, "parent": { "range": { "start": { - "line": 5, - "character": 2 + "line": 4, + "character": 0 }, "end": { - "line": 5, - "character": 11 + "line": 6, + "character": 2 } }, "parent": { "range": { "start": { - "line": 4, + "line": 2, "character": 0 }, "end": { "line": 6, - "character": 3 + "character": 2 } }, "parent": { "range": { "start": { - "line": 2, + "line": 0, "character": 0 }, "end": { "line": 6, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 6, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/if_elsif_else_empty.exp.json b/test/expectations/selection_ranges/if_elsif_else_empty.exp.json index 4248368341..26edff6d81 100644 --- a/test/expectations/selection_ranges/if_elsif_else_empty.exp.json +++ b/test/expectations/selection_ranges/if_elsif_else_empty.exp.json @@ -13,42 +13,30 @@ "character": 0 }, "end": { - "line": 2, - "character": 4 + "line": 3, + "character": 2 } }, "parent": { "range": { "start": { - "line": 2, + "line": 1, "character": 0 }, "end": { "line": 3, - "character": 3 + "character": 2 } }, "parent": { "range": { "start": { - "line": 1, + "line": 0, "character": 0 }, "end": { "line": 3, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 3, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/lambdas.exp.json b/test/expectations/selection_ranges/lambdas.exp.json index 4e2cf89856..c73cb59294 100644 --- a/test/expectations/selection_ranges/lambdas.exp.json +++ b/test/expectations/selection_ranges/lambdas.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 1, - "character": 6 + "character": 10 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 7 }, "end": { - "line": 1, - "character": 11 + "line": 2, + "character": 0 } }, "parent": { "range": { "start": { "line": 0, - "character": 7 + "character": 0 }, "end": { "line": 2, - "character": 1 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 1 - } + "character": 0 } } } diff --git a/test/expectations/selection_ranges/module_declaration.exp.json b/test/expectations/selection_ranges/module_declaration.exp.json index 39c5b32b4a..19cd79bdce 100644 --- a/test/expectations/selection_ranges/module_declaration.exp.json +++ b/test/expectations/selection_ranges/module_declaration.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 2, - "character": 5 + "character": 4 } }, "parent": { @@ -25,7 +25,7 @@ }, "end": { "line": 6, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/multiline_arrays.exp.json b/test/expectations/selection_ranges/multiline_arrays.exp.json index 3df1b740c8..545f5b40b2 100644 --- a/test/expectations/selection_ranges/multiline_arrays.exp.json +++ b/test/expectations/selection_ranges/multiline_arrays.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 1, - "character": 3 + "character": 2 } }, "parent": { @@ -25,7 +25,7 @@ }, "end": { "line": 3, - "character": 1 + "character": 0 } }, "parent": { @@ -36,7 +36,7 @@ }, "end": { "line": 3, - "character": 1 + "character": 0 } } } diff --git a/test/expectations/selection_ranges/multiline_block.exp.json b/test/expectations/selection_ranges/multiline_block.exp.json index f3a1c04fc7..6887fc8f03 100644 --- a/test/expectations/selection_ranges/multiline_block.exp.json +++ b/test/expectations/selection_ranges/multiline_block.exp.json @@ -13,31 +13,19 @@ "character": 10 }, "end": { - "line": 0, - "character": 11 + "line": 2, + "character": 0 } }, "parent": { "range": { "start": { "line": 0, - "character": 10 + "character": 0 }, "end": { "line": 2, - "character": 1 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 1 - } + "character": 0 } } } diff --git a/test/expectations/selection_ranges/multiline_invocation.exp.json b/test/expectations/selection_ranges/multiline_invocation.exp.json index f4c981f5c9..ad836ad530 100644 --- a/test/expectations/selection_ranges/multiline_invocation.exp.json +++ b/test/expectations/selection_ranges/multiline_invocation.exp.json @@ -14,18 +14,54 @@ }, "end": { "line": 1, - "character": 4 + "character": 3 } }, "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 3, - "character": 1 + "line": 1, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 2, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 2, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + } + } } } } diff --git a/test/expectations/selection_ranges/nested_invocation.exp.json b/test/expectations/selection_ranges/nested_invocation.exp.json index 3bda680418..e77f598155 100644 --- a/test/expectations/selection_ranges/nested_invocation.exp.json +++ b/test/expectations/selection_ranges/nested_invocation.exp.json @@ -14,29 +14,53 @@ }, "end": { "line": 2, - "character": 5 + "character": 4 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 2, + "character": 4 }, "end": { - "line": 4, - "character": 3 + "line": 3, + "character": 4 } }, "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 5, - "character": 1 + "line": 4, + "character": 2 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 4, + "character": 2 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 0 + } + } } } } diff --git a/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json b/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json index fe00c4769f..570fd41a31 100644 --- a/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json +++ b/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json @@ -14,29 +14,53 @@ }, "end": { "line": 2, - "character": 5 + "character": 4 } }, "parent": { "range": { "start": { "line": 1, - "character": 2 + "character": 21 }, "end": { "line": 2, - "character": 5 + "character": 4 } }, "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 3, - "character": 1 + "line": 2, + "character": 4 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 2, + "character": 4 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + } } } } diff --git a/test/expectations/selection_ranges/pattern_matching.exp.json b/test/expectations/selection_ranges/pattern_matching.exp.json index 7e009e32b8..d1e852d83c 100644 --- a/test/expectations/selection_ranges/pattern_matching.exp.json +++ b/test/expectations/selection_ranges/pattern_matching.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 2, - "character": 6 + "character": 9 } }, "parent": { "range": { "start": { - "line": 2, - "character": 2 + "line": 1, + "character": 0 }, "end": { "line": 2, - "character": 10 + "character": 9 } }, "parent": { "range": { "start": { - "line": 1, + "line": 0, "character": 0 }, "end": { "line": 5, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 5, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/rescue_multiple.exp.json b/test/expectations/selection_ranges/rescue_multiple.exp.json index e7d3882b04..7e6bc10c73 100644 --- a/test/expectations/selection_ranges/rescue_multiple.exp.json +++ b/test/expectations/selection_ranges/rescue_multiple.exp.json @@ -14,41 +14,29 @@ }, "end": { "line": 1, - "character": 16 + "character": 15 } }, "parent": { "range": { "start": { "line": 1, - "character": 7 + "character": 0 }, "end": { "line": 1, - "character": 36 + "character": 35 } }, "parent": { "range": { "start": { - "line": 1, + "line": 0, "character": 0 }, "end": { "line": 2, - "character": 3 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "character": 2 } } } diff --git a/test/expectations/selection_ranges/sclass.exp.json b/test/expectations/selection_ranges/sclass.exp.json index c93480f6e1..33587cfda2 100644 --- a/test/expectations/selection_ranges/sclass.exp.json +++ b/test/expectations/selection_ranges/sclass.exp.json @@ -14,7 +14,7 @@ }, "end": { "line": 3, - "character": 5 + "character": 4 } }, "parent": { @@ -25,7 +25,7 @@ }, "end": { "line": 4, - "character": 3 + "character": 2 } } } diff --git a/test/expectations/selection_ranges/string_concat.exp.json b/test/expectations/selection_ranges/string_concat.exp.json index 1b80532498..667d2e79e0 100644 --- a/test/expectations/selection_ranges/string_concat.exp.json +++ b/test/expectations/selection_ranges/string_concat.exp.json @@ -10,7 +10,7 @@ "range": { "start": { "line": 1, - "character": 3 + "character": 2 }, "end": { "line": 1, @@ -20,12 +20,12 @@ "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { "line": 1, - "character": 7 + "character": 6 } }, "parent": { @@ -35,20 +35,8 @@ "character": 0 }, "end": { - "line": 1, - "character": 7 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 7 - } + "line": 2, + "character": 6 } } } diff --git a/test/expectations/selection_ranges/unless.exp.json b/test/expectations/selection_ranges/unless.exp.json index 099748ff1d..54fd0f7c5e 100644 --- a/test/expectations/selection_ranges/unless.exp.json +++ b/test/expectations/selection_ranges/unless.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 6 + "character": 12 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 13 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "line": 2, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/until.exp.json b/test/expectations/selection_ranges/until.exp.json index 5e89d1f535..8d81e19c1c 100644 --- a/test/expectations/selection_ranges/until.exp.json +++ b/test/expectations/selection_ranges/until.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 6 + "character": 13 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 14 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "line": 2, + "character": 2 } } } diff --git a/test/expectations/selection_ranges/while.exp.json b/test/expectations/selection_ranges/while.exp.json index 5e89d1f535..8d81e19c1c 100644 --- a/test/expectations/selection_ranges/while.exp.json +++ b/test/expectations/selection_ranges/while.exp.json @@ -14,30 +14,18 @@ }, "end": { "line": 1, - "character": 6 + "character": 13 } }, "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 0, + "character": 0 }, "end": { - "line": 1, - "character": 14 - } - }, - "parent": { - "range": { - "start": { - "line": 0, - "character": 0 - }, - "end": { - "line": 2, - "character": 3 - } + "line": 2, + "character": 2 } } } diff --git a/test/requests/selection_ranges_expectations_test.rb b/test/requests/selection_ranges_expectations_test.rb index 38538b7988..4a9e580568 100644 --- a/test/requests/selection_ranges_expectations_test.rb +++ b/test/requests/selection_ranges_expectations_test.rb @@ -5,7 +5,7 @@ require "expectations/expectations_test_runner" class SelectionRangesExpectationsTest < ExpectationsTestRunner - # expectations_tests RubyLsp::Requests::SelectionRanges, "selection_ranges" + expectations_tests RubyLsp::Requests::SelectionRanges, "selection_ranges" def run_expectations(source) document = RubyLsp::Document.new(source: source, version: 1, uri: URI("file:///fake.rb"))