diff --git a/lib/ruby_lsp/requests/selection_ranges.rb b/lib/ruby_lsp/requests/selection_ranges.rb index c435850eb..594d121f0 100644 --- a/lib/ruby_lsp/requests/selection_ranges.rb +++ b/lib/ruby_lsp/requests/selection_ranges.rb @@ -20,123 +20,32 @@ module Requests # puts "Hello, world!" # --> Cursor is on this line # end # ``` - class SelectionRanges < BaseRequest + class SelectionRanges extend T::Sig - - NODES_THAT_CAN_BE_PARENTS = T.let( - [ - 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(YARP::Node)], - ) + include Support::Common sig { params(document: Document).void } def initialize(document) - super(document) - + @document = document @ranges = T.let([], T::Array[Support::SelectionRange]) @stack = T.let([], T::Array[Support::SelectionRange]) end - sig { override.returns(T.all(T::Array[Support::SelectionRange], Object)) } + sig { returns(T.all(T::Array[Support::SelectionRange], Object)) } def run - visit(@document.tree) - @ranges.reverse! - end + # [node, parent] + queue = [[@document.tree, nil]] - private + until queue.empty? + node, parent = queue.shift + next unless node - sig { override.params(node: T.nilable(YARP::Node)).void } - def visit(node) - return if node.nil? - - range = if node.is_a?(YARP::InterpolatedStringNode) - create_heredoc_selection_range(node, @stack.last) - else - create_selection_range(node.location, @stack.last) + range = Support::SelectionRange.new(range: range_from_location(node.location), parent: parent) + T.unsafe(queue).unshift(*node.child_nodes.map { |child| [child, range] }) + @ranges.unshift(range) end - @ranges << range - - return if node.child_nodes.empty? - - @stack << range if NODES_THAT_CAN_BE_PARENTS.include?(node.class) - visit_all(node.child_nodes) - @stack.pop if NODES_THAT_CAN_BE_PARENTS.include?(node.class) - end - - sig do - params( - node: YARP::InterpolatedStringNode, - parent: T.nilable(Support::SelectionRange), - ).returns(Support::SelectionRange) - end - def create_heredoc_selection_range(node, parent) - opening_loc = node.opening_loc || node.location - closing_loc = node.closing_loc || node.location - 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) - RubyLsp::Requests::Support::SelectionRange.new( - range: Interface::Range.new( - start: Interface::Position.new( - line: location.start_line - 1, - character: location.start_column, - ), - end: Interface::Position.new( - line: location.end_line - 1, - character: location.end_column, - ), - ), - parent: parent, - ) + @ranges 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 719c515f0..64c5ae8ae 100644 --- a/test/expectations/selection_ranges/array_literal_oneline.exp.json +++ b/test/expectations/selection_ranges/array_literal_oneline.exp.json @@ -38,6 +38,30 @@ "line": 0, "character": 10 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 10 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 10 + } + } + } } } } diff --git a/test/expectations/selection_ranges/begin_rescue_ensure.exp.json b/test/expectations/selection_ranges/begin_rescue_ensure.exp.json index cc0bf74f7..7aa520099 100644 --- a/test/expectations/selection_ranges/begin_rescue_ensure.exp.json +++ b/test/expectations/selection_ranges/begin_rescue_ensure.exp.json @@ -20,8 +20,8 @@ "parent": { "range": { "start": { - "line": 4, - "character": 0 + "line": 5, + "character": 2 }, "end": { "line": 5, @@ -31,7 +31,7 @@ "parent": { "range": { "start": { - "line": 2, + "line": 4, "character": 0 }, "end": { @@ -42,12 +42,48 @@ "parent": { "range": { "start": { - "line": 0, + "line": 2, "character": 0 }, "end": { - "line": 8, - "character": 3 + "line": 5, + "character": 18 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 8, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 8, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 8, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/case_when.exp.json b/test/expectations/selection_ranges/case_when.exp.json index 2779c0f43..59f5ca7fa 100644 --- a/test/expectations/selection_ranges/case_when.exp.json +++ b/test/expectations/selection_ranges/case_when.exp.json @@ -20,8 +20,8 @@ "parent": { "range": { "start": { - "line": 1, - "character": 0 + "line": 2, + "character": 2 }, "end": { "line": 2, @@ -31,12 +31,48 @@ "parent": { "range": { "start": { - "line": 0, + "line": 1, "character": 0 }, "end": { - "line": 5, - "character": 3 + "line": 2, + "character": 13 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/class_declaration.exp.json b/test/expectations/selection_ranges/class_declaration.exp.json index e3f46d592..dd248c486 100644 --- a/test/expectations/selection_ranges/class_declaration.exp.json +++ b/test/expectations/selection_ranges/class_declaration.exp.json @@ -20,23 +20,71 @@ "parent": { "range": { "start": { - "line": 1, - "character": 2 + "line": 2, + "character": 4 }, "end": { - "line": 3, - "character": 5 + "line": 2, + "character": 17 } }, "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 4, - "character": 3 + "line": 3, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + } + } + } } } } diff --git a/test/expectations/selection_ranges/class_declaration_nested.exp.json b/test/expectations/selection_ranges/class_declaration_nested.exp.json index 19b0926d0..d2b5d65ce 100644 --- a/test/expectations/selection_ranges/class_declaration_nested.exp.json +++ b/test/expectations/selection_ranges/class_declaration_nested.exp.json @@ -16,6 +16,30 @@ "line": 2, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } ] diff --git a/test/expectations/selection_ranges/def.exp.json b/test/expectations/selection_ranges/def.exp.json index 12b3cf112..711cc2600 100644 --- a/test/expectations/selection_ranges/def.exp.json +++ b/test/expectations/selection_ranges/def.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 3, - "character": 3 + "line": 2, + "character": 10 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/def_endless.exp.json b/test/expectations/selection_ranges/def_endless.exp.json index 3137c28b0..378a449c0 100644 --- a/test/expectations/selection_ranges/def_endless.exp.json +++ b/test/expectations/selection_ranges/def_endless.exp.json @@ -16,6 +16,30 @@ "line": 2, "character": 12 } + }, + "parent": { + "range": { + "start": { + "line": 2, + "character": 0 + }, + "end": { + "line": 2, + "character": 12 + } + }, + "parent": { + "range": { + "start": { + "line": 2, + "character": 0 + }, + "end": { + "line": 2, + "character": 12 + } + } + } } } ] diff --git a/test/expectations/selection_ranges/def_multiline_params.exp.json b/test/expectations/selection_ranges/def_multiline_params.exp.json index 6169a5a85..fc2f24376 100644 --- a/test/expectations/selection_ranges/def_multiline_params.exp.json +++ b/test/expectations/selection_ranges/def_multiline_params.exp.json @@ -38,6 +38,30 @@ "line": 6, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/def_oneline.exp.json b/test/expectations/selection_ranges/def_oneline.exp.json index 75be59e0f..d083f48ef 100644 --- a/test/expectations/selection_ranges/def_oneline.exp.json +++ b/test/expectations/selection_ranges/def_oneline.exp.json @@ -16,6 +16,30 @@ "line": 0, "character": 12 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 12 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 12 + } + } + } } } ] 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 2c6ee3067..fd0a40e4c 100644 --- a/test/expectations/selection_ranges/def_require_name_parameter.exp.json +++ b/test/expectations/selection_ranges/def_require_name_parameter.exp.json @@ -16,6 +16,30 @@ "line": 1, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 3 + } + } + } } } ] diff --git a/test/expectations/selection_ranges/defs.exp.json b/test/expectations/selection_ranges/defs.exp.json index c3c778e23..91f97fe21 100644 --- a/test/expectations/selection_ranges/defs.exp.json +++ b/test/expectations/selection_ranges/defs.exp.json @@ -16,6 +16,30 @@ "line": 3, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + } + } } } ] diff --git a/test/expectations/selection_ranges/defs_multiline_params.exp.json b/test/expectations/selection_ranges/defs_multiline_params.exp.json index 6169a5a85..fc2f24376 100644 --- a/test/expectations/selection_ranges/defs_multiline_params.exp.json +++ b/test/expectations/selection_ranges/defs_multiline_params.exp.json @@ -38,6 +38,30 @@ "line": 6, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/do_blocks.exp.json b/test/expectations/selection_ranges/do_blocks.exp.json index f398b5a4d..9fc4a33de 100644 --- a/test/expectations/selection_ranges/do_blocks.exp.json +++ b/test/expectations/selection_ranges/do_blocks.exp.json @@ -27,6 +27,30 @@ "line": 2, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/ensure.exp.json b/test/expectations/selection_ranges/ensure.exp.json index 74043124e..b31922fb3 100644 --- a/test/expectations/selection_ranges/ensure.exp.json +++ b/test/expectations/selection_ranges/ensure.exp.json @@ -20,24 +20,60 @@ "parent": { "range": { "start": { - "line": 2, - "character": 0 + "line": 3, + "character": 2 }, "end": { - "line": 4, - "character": 3 + "line": 3, + "character": 15 } }, "parent": { "range": { "start": { - "line": 0, + "line": 2, "character": 0 }, "end": { "line": 4, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + } + } + } } } } diff --git a/test/expectations/selection_ranges/for.exp.json b/test/expectations/selection_ranges/for.exp.json index 230d31b86..70728842b 100644 --- a/test/expectations/selection_ranges/for.exp.json +++ b/test/expectations/selection_ranges/for.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 3 + "line": 1, + "character": 14 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/hash_literal.exp.json b/test/expectations/selection_ranges/hash_literal.exp.json index 086ace4de..4f9dee835 100644 --- a/test/expectations/selection_ranges/hash_literal.exp.json +++ b/test/expectations/selection_ranges/hash_literal.exp.json @@ -49,6 +49,30 @@ "line": 3, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + } + } } } } diff --git a/test/expectations/selection_ranges/hash_literal_oneline.exp.json b/test/expectations/selection_ranges/hash_literal_oneline.exp.json index 29dd4d676..d4fb75b04 100644 --- a/test/expectations/selection_ranges/hash_literal_oneline.exp.json +++ b/test/expectations/selection_ranges/hash_literal_oneline.exp.json @@ -49,6 +49,30 @@ "line": 0, "character": 18 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 18 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 18 + } + } + } } } } diff --git a/test/expectations/selection_ranges/heredoc.exp.json b/test/expectations/selection_ranges/heredoc.exp.json index cef498415..90ec832ed 100644 --- a/test/expectations/selection_ranges/heredoc.exp.json +++ b/test/expectations/selection_ranges/heredoc.exp.json @@ -20,12 +20,60 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 13 }, "end": { - "line": 2, - "character": 0 + "line": 1, + "character": 18 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 11 + }, + "end": { + "line": 1, + "character": 19 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 10 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 10 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 10 + } + } + } + } } } } diff --git a/test/expectations/selection_ranges/if.exp.json b/test/expectations/selection_ranges/if.exp.json index 55959a702..2fc50f3ed 100644 --- a/test/expectations/selection_ranges/if.exp.json +++ b/test/expectations/selection_ranges/if.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 3 + "line": 1, + "character": 15 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/if_elsif_else.exp.json b/test/expectations/selection_ranges/if_elsif_else.exp.json index 9fff145dc..946984673 100644 --- a/test/expectations/selection_ranges/if_elsif_else.exp.json +++ b/test/expectations/selection_ranges/if_elsif_else.exp.json @@ -20,18 +20,18 @@ "parent": { "range": { "start": { - "line": 4, - "character": 0 + "line": 5, + "character": 2 }, "end": { - "line": 6, - "character": 3 + "line": 5, + "character": 11 } }, "parent": { "range": { "start": { - "line": 2, + "line": 4, "character": 0 }, "end": { @@ -42,13 +42,49 @@ "parent": { "range": { "start": { - "line": 0, + "line": 2, "character": 0 }, "end": { "line": 6, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + } + } + } } } } 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 9a8759bc9..add2e1a7c 100644 --- a/test/expectations/selection_ranges/if_elsif_else_empty.exp.json +++ b/test/expectations/selection_ranges/if_elsif_else_empty.exp.json @@ -38,6 +38,30 @@ "line": 3, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/lambdas.exp.json b/test/expectations/selection_ranges/lambdas.exp.json index 9eebe8a5b..3f8e8af1f 100644 --- a/test/expectations/selection_ranges/lambdas.exp.json +++ b/test/expectations/selection_ranges/lambdas.exp.json @@ -20,24 +20,60 @@ "parent": { "range": { "start": { - "line": 0, - "character": 7 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 1 + "line": 1, + "character": 11 } }, "parent": { "range": { "start": { "line": 0, - "character": 0 + "character": 7 }, "end": { "line": 2, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + } + } + } } } } diff --git a/test/expectations/selection_ranges/module_declaration.exp.json b/test/expectations/selection_ranges/module_declaration.exp.json index 39c5b32b4..70fcb17c2 100644 --- a/test/expectations/selection_ranges/module_declaration.exp.json +++ b/test/expectations/selection_ranges/module_declaration.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 6, - "character": 3 + "line": 5, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 6, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/multiline_arrays.exp.json b/test/expectations/selection_ranges/multiline_arrays.exp.json index 3df1b740c..d2e3bdf8f 100644 --- a/test/expectations/selection_ranges/multiline_arrays.exp.json +++ b/test/expectations/selection_ranges/multiline_arrays.exp.json @@ -38,6 +38,30 @@ "line": 3, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + } + } } } } diff --git a/test/expectations/selection_ranges/multiline_block.exp.json b/test/expectations/selection_ranges/multiline_block.exp.json index 679c237e4..2339a6090 100644 --- a/test/expectations/selection_ranges/multiline_block.exp.json +++ b/test/expectations/selection_ranges/multiline_block.exp.json @@ -27,6 +27,30 @@ "line": 2, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + } + } } } } diff --git a/test/expectations/selection_ranges/multiline_invocation.exp.json b/test/expectations/selection_ranges/multiline_invocation.exp.json index ae75d49af..548afc4e1 100644 --- a/test/expectations/selection_ranges/multiline_invocation.exp.json +++ b/test/expectations/selection_ranges/multiline_invocation.exp.json @@ -60,6 +60,30 @@ "line": 3, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + } + } } } } diff --git a/test/expectations/selection_ranges/nested_invocation.exp.json b/test/expectations/selection_ranges/nested_invocation.exp.json index 64770cbf1..b70c82518 100644 --- a/test/expectations/selection_ranges/nested_invocation.exp.json +++ b/test/expectations/selection_ranges/nested_invocation.exp.json @@ -60,6 +60,30 @@ "line": 5, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 1 + } + } + } } } } 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 39443a858..7c8f06ae9 100644 --- a/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json +++ b/test/expectations/selection_ranges/nested_invocation_no_parenthesis.exp.json @@ -60,6 +60,30 @@ "line": 3, "character": 1 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 3, + "character": 1 + } + } + } } } } diff --git a/test/expectations/selection_ranges/pattern_matching.exp.json b/test/expectations/selection_ranges/pattern_matching.exp.json index 897b10012..4fc31185b 100644 --- a/test/expectations/selection_ranges/pattern_matching.exp.json +++ b/test/expectations/selection_ranges/pattern_matching.exp.json @@ -20,8 +20,8 @@ "parent": { "range": { "start": { - "line": 1, - "character": 0 + "line": 2, + "character": 2 }, "end": { "line": 2, @@ -31,12 +31,48 @@ "parent": { "range": { "start": { - "line": 0, + "line": 1, "character": 0 }, "end": { - "line": 5, - "character": 3 + "line": 2, + "character": 10 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 5, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/rescue_multiple.exp.json b/test/expectations/selection_ranges/rescue_multiple.exp.json index c8b35faa7..4cfc275a5 100644 --- a/test/expectations/selection_ranges/rescue_multiple.exp.json +++ b/test/expectations/selection_ranges/rescue_multiple.exp.json @@ -38,6 +38,30 @@ "line": 2, "character": 3 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/sclass.exp.json b/test/expectations/selection_ranges/sclass.exp.json index c93480f6e..35a8a8ee8 100644 --- a/test/expectations/selection_ranges/sclass.exp.json +++ b/test/expectations/selection_ranges/sclass.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 4, - "character": 3 + "line": 3, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/string_concat.exp.json b/test/expectations/selection_ranges/string_concat.exp.json index 5ddb824bf..4e6c9a5ac 100644 --- a/test/expectations/selection_ranges/string_concat.exp.json +++ b/test/expectations/selection_ranges/string_concat.exp.json @@ -38,6 +38,30 @@ "line": 2, "character": 7 } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 7 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 7 + } + } + } } } } diff --git a/test/expectations/selection_ranges/unless.exp.json b/test/expectations/selection_ranges/unless.exp.json index e61319355..6fa9b969c 100644 --- a/test/expectations/selection_ranges/unless.exp.json +++ b/test/expectations/selection_ranges/unless.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 3 + "line": 1, + "character": 13 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/until.exp.json b/test/expectations/selection_ranges/until.exp.json index 230d31b86..70728842b 100644 --- a/test/expectations/selection_ranges/until.exp.json +++ b/test/expectations/selection_ranges/until.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 3 + "line": 1, + "character": 14 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/expectations/selection_ranges/while.exp.json b/test/expectations/selection_ranges/while.exp.json index 230d31b86..70728842b 100644 --- a/test/expectations/selection_ranges/while.exp.json +++ b/test/expectations/selection_ranges/while.exp.json @@ -20,12 +20,48 @@ "parent": { "range": { "start": { - "line": 0, - "character": 0 + "line": 1, + "character": 2 }, "end": { - "line": 2, - "character": 3 + "line": 1, + "character": 14 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 3 + } + } + } } } } diff --git a/test/integration_test.rb b/test/integration_test.rb index 0bd2f9823..89f31cdbd 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -305,8 +305,8 @@ def test_selection_ranges ) assert_equal( - { range: { start: { line: 0, character: 0 }, end: { line: 1, character: 3 } } }, - response[:result].first, + { start: { line: 0, character: 0 }, end: { line: 1, character: 3 } }, + response[:result].first[:range], ) end