Skip to content

Commit

Permalink
Use the language server gem folding ranges class
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Mar 23, 2022
1 parent c6ca8d2 commit 23beeca
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions lib/ruby/lsp/requests/folding_ranges.rb
Expand Up @@ -20,34 +20,20 @@ def run

case node
when SyntaxTree::Def
@ranges << CodeRange.new(node.location, "region")
location = node.location

@ranges << LanguageServer::Protocol::Interface::FoldingRange.new(
start_line: location.start_line - 1,
end_line: location.end_line - 1,
kind: "region"
)
else
@queue.unshift(*node.child_nodes.compact)
end
end

@ranges
end

class CodeRange
KINDS = ["comment", "imports", "region"].freeze

def initialize(location, kind)
raise ArgumentError, "Invalid folding range kind: #{kind}" unless KINDS.include?(kind)

@start_line = location.start_line - 1
@end_line = location.end_line - 1
@kind = kind
end

def to_json(*)
{
startLine: @start_line,
endLine: @end_line,
kind: @kind,
}.to_json
end
end
end
end
end
Expand Down

0 comments on commit 23beeca

Please sign in to comment.