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:, path:, name:, test_command:, type:) ⇒ 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:, path:, name:, test_command:, type:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 64 def create_code_lens(node, title:, command_name:, path:, name:, test_command:, type:) range = range_from_syntax_tree_node(node) arguments = [ path, name, test_command, { start_line: node.location.start_line - 1, start_column: node.location.start_column, end_line: node.location.end_line - 1, end_column: node.location.end_column, }, ] Interface::CodeLens.new( range: range, command: Interface::Command.new( title: title, command: command_name, arguments: arguments, ), data: { type: type }, ) end |
#full_constant_name(node) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 26 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
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 11 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
45 46 47 48 49 50 51 |
# File 'lib/ruby_lsp/requests/support/common.rb', line 45 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 |