Module: RubyLsp::Requests::Support::Common
- Extended by:
- T::Sig
- Included in:
- Listener, BaseRequest
- Defined in:
- lib/ruby_lsp/requests/support/common.rb
Instance Method Summary collapse
- #create_code_lens(node, title:, command_name:, arguments:, data:) ⇒ Object
- #full_constant_name(node) ⇒ Object
- #range_from_syntax_tree_node(node) ⇒ Object
- #visible?(node, range) ⇒ Boolean
Instance Method Details
#create_code_lens(node, title:, command_name:, arguments:, data:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 64 def create_code_lens(node, title:, command_name:, arguments:, data:) range = range_from_syntax_tree_node(node) Interface::CodeLens.new( range: range, command: Interface::Command.new( title: title, command: command_name, arguments: arguments, ), data: data, ) end |
#full_constant_name(node) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 28 def full_constant_name(node) name = +node.constant.value constant = T.let(node, SyntaxTree::Node) while constant.is_a?(SyntaxTree::ConstPathRef) constant = constant.parent case constant when SyntaxTree::ConstPathRef name.prepend("#{constant.constant.value}::") when SyntaxTree::VarRef name.prepend("#{constant.value.value}::") end end name end |
#range_from_syntax_tree_node(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 13 def range_from_syntax_tree_node(node) loc = node.location Interface::Range.new( start: Interface::Position.new( line: loc.start_line - 1, character: loc.start_column, ), end: Interface::Position.new(line: loc.end_line - 1, character: loc.end_column), ) end |
#visible?(node, range) ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 47 def visible?(node, range) return true if range.nil? return false if node.nil? loc = node.location range.cover?(loc.start_line - 1) && range.cover?(loc.end_line - 1) end |