solargraph 0.59.0.dev.1 → 0.59.0.dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +4 -1
  3. data/.github/workflows/rspec.yml +3 -14
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +32 -5
  6. data/.rubocop_todo.yml +37 -931
  7. data/CHANGELOG.md +7 -1
  8. data/Gemfile +3 -1
  9. data/Rakefile +25 -23
  10. data/bin/solargraph +2 -1
  11. data/lib/solargraph/api_map/index.rb +5 -11
  12. data/lib/solargraph/api_map/source_to_yard.rb +9 -8
  13. data/lib/solargraph/api_map/store.rb +22 -20
  14. data/lib/solargraph/api_map.rb +50 -37
  15. data/lib/solargraph/bench.rb +44 -45
  16. data/lib/solargraph/complex_type/type_methods.rb +12 -15
  17. data/lib/solargraph/complex_type/unique_type.rb +54 -43
  18. data/lib/solargraph/complex_type.rb +69 -61
  19. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
  20. data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
  21. data/lib/solargraph/convention/data_definition.rb +1 -1
  22. data/lib/solargraph/convention/gemfile.rb +15 -15
  23. data/lib/solargraph/convention/gemspec.rb +23 -23
  24. data/lib/solargraph/convention/rakefile.rb +17 -17
  25. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
  26. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
  27. data/lib/solargraph/convention/struct_definition.rb +3 -3
  28. data/lib/solargraph/convention.rb +78 -78
  29. data/lib/solargraph/converters/dd.rb +19 -17
  30. data/lib/solargraph/converters/dl.rb +17 -15
  31. data/lib/solargraph/converters/dt.rb +17 -15
  32. data/lib/solargraph/converters/misc.rb +3 -1
  33. data/lib/solargraph/diagnostics/rubocop.rb +10 -10
  34. data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
  35. data/lib/solargraph/diagnostics/type_check.rb +10 -10
  36. data/lib/solargraph/diagnostics/update_errors.rb +37 -41
  37. data/lib/solargraph/doc_map.rb +9 -10
  38. data/lib/solargraph/equality.rb +3 -3
  39. data/lib/solargraph/gem_pins.rb +7 -5
  40. data/lib/solargraph/language_server/error_codes.rb +20 -20
  41. data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
  42. data/lib/solargraph/language_server/host/dispatch.rb +2 -3
  43. data/lib/solargraph/language_server/host/message_worker.rb +2 -2
  44. data/lib/solargraph/language_server/host/sources.rb +1 -1
  45. data/lib/solargraph/language_server/host.rb +24 -21
  46. data/lib/solargraph/language_server/message/base.rb +97 -97
  47. data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
  48. data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
  49. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
  50. data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
  51. data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
  52. data/lib/solargraph/language_server/message/extended/search.rb +20 -20
  53. data/lib/solargraph/language_server/message/initialize.rb +197 -191
  54. data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
  55. data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
  56. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
  57. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
  58. data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
  59. data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
  60. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
  61. data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
  62. data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
  63. data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
  64. data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
  65. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
  66. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
  67. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
  68. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
  69. data/lib/solargraph/language_server/message.rb +94 -94
  70. data/lib/solargraph/language_server/request.rb +29 -27
  71. data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
  72. data/lib/solargraph/language_server/uri_helpers.rb +49 -49
  73. data/lib/solargraph/library.rb +28 -33
  74. data/lib/solargraph/location.rb +10 -12
  75. data/lib/solargraph/logging.rb +4 -4
  76. data/lib/solargraph/page.rb +92 -92
  77. data/lib/solargraph/parser/comment_ripper.rb +12 -4
  78. data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -42
  79. data/lib/solargraph/parser/node_processor/base.rb +4 -4
  80. data/lib/solargraph/parser/node_processor.rb +1 -1
  81. data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -4
  82. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
  83. data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
  84. data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
  85. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
  86. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -1
  87. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
  88. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
  89. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
  90. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
  91. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
  92. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
  93. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
  94. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
  95. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
  96. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
  97. data/lib/solargraph/parser/parser_gem.rb +14 -12
  98. data/lib/solargraph/parser/snippet.rb +2 -0
  99. data/lib/solargraph/parser.rb +25 -23
  100. data/lib/solargraph/pin/base.rb +78 -64
  101. data/lib/solargraph/pin/base_variable.rb +28 -71
  102. data/lib/solargraph/pin/block.rb +3 -2
  103. data/lib/solargraph/pin/breakable.rb +2 -0
  104. data/lib/solargraph/pin/callable.rb +23 -26
  105. data/lib/solargraph/pin/closure.rb +5 -4
  106. data/lib/solargraph/pin/common.rb +5 -2
  107. data/lib/solargraph/pin/compound_statement.rb +3 -3
  108. data/lib/solargraph/pin/constant.rb +43 -45
  109. data/lib/solargraph/pin/conversions.rb +9 -4
  110. data/lib/solargraph/pin/delegated_method.rb +4 -4
  111. data/lib/solargraph/pin/documenting.rb +3 -2
  112. data/lib/solargraph/pin/local_variable.rb +4 -4
  113. data/lib/solargraph/pin/method.rb +71 -70
  114. data/lib/solargraph/pin/namespace.rb +13 -12
  115. data/lib/solargraph/pin/parameter.rb +28 -27
  116. data/lib/solargraph/pin/proxy_type.rb +2 -0
  117. data/lib/solargraph/pin/reference.rb +17 -0
  118. data/lib/solargraph/pin/search.rb +2 -2
  119. data/lib/solargraph/pin/signature.rb +9 -14
  120. data/lib/solargraph/pin/symbol.rb +1 -0
  121. data/lib/solargraph/pin/until.rb +1 -3
  122. data/lib/solargraph/pin/while.rb +1 -3
  123. data/lib/solargraph/pin_cache.rb +16 -19
  124. data/lib/solargraph/position.rb +35 -17
  125. data/lib/solargraph/range.rb +10 -9
  126. data/lib/solargraph/rbs_map/conversions.rb +312 -206
  127. data/lib/solargraph/rbs_map/core_fills.rb +91 -84
  128. data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
  129. data/lib/solargraph/rbs_map.rb +3 -12
  130. data/lib/solargraph/server_methods.rb +16 -16
  131. data/lib/solargraph/shell.rb +63 -53
  132. data/lib/solargraph/source/chain/array.rb +39 -37
  133. data/lib/solargraph/source/chain/call.rb +49 -44
  134. data/lib/solargraph/source/chain/class_variable.rb +13 -13
  135. data/lib/solargraph/source/chain/constant.rb +3 -1
  136. data/lib/solargraph/source/chain/global_variable.rb +13 -13
  137. data/lib/solargraph/source/chain/hash.rb +8 -6
  138. data/lib/solargraph/source/chain/if.rb +11 -10
  139. data/lib/solargraph/source/chain/instance_variable.rb +3 -1
  140. data/lib/solargraph/source/chain/link.rb +99 -109
  141. data/lib/solargraph/source/chain/literal.rb +4 -6
  142. data/lib/solargraph/source/chain/or.rb +2 -4
  143. data/lib/solargraph/source/chain/q_call.rb +13 -11
  144. data/lib/solargraph/source/chain/variable.rb +15 -13
  145. data/lib/solargraph/source/chain/z_super.rb +28 -30
  146. data/lib/solargraph/source/chain.rb +24 -16
  147. data/lib/solargraph/source/change.rb +3 -3
  148. data/lib/solargraph/source/cursor.rb +18 -18
  149. data/lib/solargraph/source/encoding_fixes.rb +6 -7
  150. data/lib/solargraph/source/source_chainer.rb +46 -32
  151. data/lib/solargraph/source/updater.rb +1 -1
  152. data/lib/solargraph/source.rb +27 -29
  153. data/lib/solargraph/source_map/clip.rb +38 -30
  154. data/lib/solargraph/source_map/mapper.rb +52 -46
  155. data/lib/solargraph/source_map.rb +8 -4
  156. data/lib/solargraph/type_checker/rules.rb +8 -8
  157. data/lib/solargraph/type_checker.rb +95 -101
  158. data/lib/solargraph/version.rb +1 -1
  159. data/lib/solargraph/workspace/config.rb +10 -9
  160. data/lib/solargraph/workspace/gemspecs.rb +1 -1
  161. data/lib/solargraph/workspace.rb +21 -44
  162. data/lib/solargraph/yard_map/helpers.rb +6 -2
  163. data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
  164. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
  165. data/lib/solargraph/yard_map/mapper.rb +12 -12
  166. data/lib/solargraph/yard_tags.rb +20 -20
  167. data/lib/solargraph.rb +5 -5
  168. data/solargraph.gemspec +35 -34
  169. metadata +28 -28
@@ -22,7 +22,7 @@ module Solargraph
22
22
  # @return [Source::Chain]
23
23
  def chain
24
24
  links = generate_links(@node)
25
- Chain.new(links, @node, (Parser.is_ast_node?(@node) && @node.type == :splat))
25
+ Chain.new(links, @node, Parser.is_ast_node?(@node) && @node.type == :splat)
26
26
  end
27
27
 
28
28
  class << self
@@ -39,7 +39,7 @@ module Solargraph
39
39
  # @param starting_line [Integer]
40
40
  #
41
41
  # @return [Source::Chain]
42
- def load_string(code, filename, starting_line)
42
+ def load_string code, filename, starting_line
43
43
  node = Parser.parse(code.sub(/\.$/, ''), filename, starting_line)
44
44
  chain = NodeChainer.new(node).chain
45
45
  chain.links.push(Chain::Link.new) if code.end_with?('.')
@@ -63,10 +63,9 @@ module Solargraph
63
63
  result.concat generate_links(n.children[0])
64
64
  result.push Chain::Call.new(n.children[1].to_s, Location.from_node(n), node_args(n), passed_block(n))
65
65
  elsif n.children[0].nil?
66
- args = []
67
66
  # @sg-ignore Need to add nil check here
68
- n.children[2..-1].each do |c|
69
- args.push NodeChainer.chain(c, @filename, n)
67
+ n.children[2..].map do |c|
68
+ NodeChainer.chain(c, @filename, n)
70
69
  end
71
70
  result.push Chain::Call.new(n.children[1].to_s, Location.from_node(n), node_args(n), passed_block(n))
72
71
  else
@@ -94,13 +93,13 @@ module Solargraph
94
93
  elsif n.type == :const
95
94
  const = unpack_name(n)
96
95
  result.push Chain::Constant.new(const)
97
- elsif [:lvar, :lvasgn].include?(n.type)
96
+ elsif %i[lvar lvasgn].include?(n.type)
98
97
  result.push Chain::Call.new(n.children[0].to_s, Location.from_node(n))
99
- elsif [:ivar, :ivasgn].include?(n.type)
98
+ elsif %i[ivar ivasgn].include?(n.type)
100
99
  result.push Chain::InstanceVariable.new(n.children[0].to_s, n, Location.from_node(n))
101
- elsif [:cvar, :cvasgn].include?(n.type)
100
+ elsif %i[cvar cvasgn].include?(n.type)
102
101
  result.push Chain::ClassVariable.new(n.children[0].to_s)
103
- elsif [:gvar, :gvasgn].include?(n.type)
102
+ elsif %i[gvar gvasgn].include?(n.type)
104
103
  result.push Chain::GlobalVariable.new(n.children[0].to_s)
105
104
  elsif n.type == :or_asgn
106
105
  # @bar ||= 123 translates to:
@@ -113,13 +112,14 @@ module Solargraph
113
112
  or_link = Chain::Or.new([lhs_chain, rhs_chain])
114
113
  # this is just for a call chain, so we don't need to record the assignment
115
114
  result.push(or_link)
116
- elsif [:class, :module, :def, :defs].include?(n.type)
115
+ elsif %i[class module def defs].include?(n.type)
117
116
  # @todo Undefined or what?
118
117
  result.push Chain::UNDEFINED_CALL
119
118
  elsif n.type == :and
120
119
  result.concat generate_links(n.children.last)
121
120
  elsif n.type == :or
122
- result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename, n)])
121
+ result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename),
122
+ NodeChainer.chain(n.children[1], @filename, n)])
123
123
  elsif n.type == :if
124
124
  then_clause = if n.children[1]
125
125
  NodeChainer.chain(n.children[1], @filename, n)
@@ -132,7 +132,7 @@ module Solargraph
132
132
  Source::Chain.new([Source::Chain::Literal.new('nil', nil)], n)
133
133
  end
134
134
  result.push Chain::If.new([then_clause, else_clause])
135
- elsif [:begin, :kwbegin].include?(n.type)
135
+ elsif %i[begin kwbegin].include?(n.type)
136
136
  result.concat generate_links(n.children.last)
137
137
  elsif n.type == :block_pass
138
138
  block_variable_name_node = n.children[0]
@@ -140,12 +140,10 @@ module Solargraph
140
140
  # anonymous block forwarding (e.g., "&")
141
141
  # added in Ruby 3.1 - https://bugs.ruby-lang.org/issues/11256
142
142
  result.push Chain::BlockVariable.new(nil)
143
+ elsif block_variable_name_node.type == :sym
144
+ result.push Chain::BlockSymbol.new(block_variable_name_node.children[0].to_s)
143
145
  else
144
- if block_variable_name_node.type == :sym
145
- result.push Chain::BlockSymbol.new("#{block_variable_name_node.children[0].to_s}")
146
- else
147
- result.push Chain::BlockVariable.new("&#{block_variable_name_node.children[0].to_s}")
148
- end
146
+ result.push Chain::BlockVariable.new("&#{block_variable_name_node.children[0]}")
149
147
  end
150
148
  elsif n.type == :hash
151
149
  result.push Chain::Hash.new('::Hash', n, hash_is_splatted?(n))
@@ -154,7 +152,7 @@ module Solargraph
154
152
  result.push Source::Chain::Array.new(chained_children, n)
155
153
  else
156
154
  lit = infer_literal_node_type(n)
157
- result.push (lit ? Chain::Literal.new(lit, n) : Chain::Link.new)
155
+ result.push(lit ? Chain::Literal.new(lit, n) : Chain::Link.new)
158
156
  end
159
157
  result
160
158
  end
@@ -163,7 +161,9 @@ module Solargraph
163
161
  def hash_is_splatted? node
164
162
  return false unless Parser.is_ast_node?(node) && node.type == :hash
165
163
  return false unless Parser.is_ast_node?(node.children.last) && node.children.last.type == :kwsplat
166
- return false if Parser.is_ast_node?(node.children.last.children[0]) && node.children.last.children[0].type == :hash
164
+ if Parser.is_ast_node?(node.children.last.children[0]) && node.children.last.children[0].type == :hash
165
+ return false
166
+ end
167
167
  true
168
168
  end
169
169
 
@@ -181,7 +181,7 @@ module Solargraph
181
181
  # @return [Array<Source::Chain>]
182
182
  def node_args node
183
183
  # @sg-ignore Need to add nil check here
184
- node.children[2..-1].map do |child|
184
+ node.children[2..].map do |child|
185
185
  NodeChainer.chain(child, @filename, node)
186
186
  end
187
187
  end
@@ -12,17 +12,17 @@ module Solargraph
12
12
 
13
13
  # @param node [Parser::AST::Node]
14
14
  # @return [String]
15
- def unpack_name(node)
16
- pack_name(node).join("::")
15
+ def unpack_name node
16
+ pack_name(node).join('::')
17
17
  end
18
18
 
19
19
  # @param node [Parser::AST::Node]
20
20
  # @return [Array<String>]
21
- def pack_name(node)
21
+ def pack_name node
22
22
  # @type [Array<String>]
23
23
  parts = []
24
24
  if node.is_a?(AST::Node)
25
- node.children.each { |n|
25
+ node.children.each do |n|
26
26
  if n.is_a?(AST::Node)
27
27
  if n.type == :cbase
28
28
  parts = [''] + pack_name(n)
@@ -32,7 +32,7 @@ module Solargraph
32
32
  else
33
33
  parts.push n unless n.nil?
34
34
  end
35
- }
35
+ end
36
36
  end
37
37
  parts
38
38
  end
@@ -41,7 +41,7 @@ module Solargraph
41
41
  # @return [String, nil]
42
42
  def infer_literal_node_type node
43
43
  return nil unless node.is_a?(AST::Node)
44
- if node.type == :str || node.type == :dstr
44
+ if %i[str dstr].include?(node.type)
45
45
  return '::String'
46
46
  elsif node.type == :array
47
47
  return '::Array'
@@ -53,30 +53,30 @@ module Solargraph
53
53
  return '::Integer'
54
54
  elsif node.type == :float
55
55
  return '::Float'
56
- elsif node.type == :sym || node.type == :dsym
56
+ elsif %i[sym dsym].include?(node.type)
57
57
  return '::Symbol'
58
58
  elsif node.type == :regexp
59
59
  return '::Regexp'
60
60
  elsif node.type == :irange
61
61
  return '::Range'
62
- elsif node.type == :true || node.type == :false
62
+ elsif %i[true false].include?(node.type)
63
63
  return '::Boolean'
64
64
  # @todo Support `nil` keyword in types
65
- # elsif node.type == :nil
66
- # return 'NilClass'
65
+ # elsif node.type == :nil
66
+ # return 'NilClass'
67
67
  end
68
68
  nil
69
69
  end
70
70
 
71
71
  # @param node [Parser::AST::Node]
72
72
  # @return [Position]
73
- def get_node_start_position(node)
73
+ def get_node_start_position node
74
74
  Position.new(node.loc.line, node.loc.column)
75
75
  end
76
76
 
77
77
  # @param node [Parser::AST::Node]
78
78
  # @return [Position]
79
- def get_node_end_position(node)
79
+ def get_node_end_position node
80
80
  Position.new(node.loc.last_line, node.loc.last_column)
81
81
  end
82
82
 
@@ -86,19 +86,15 @@ module Solargraph
86
86
  # @return [String]
87
87
  def drill_signature node, signature
88
88
  return signature unless node.is_a?(AST::Node)
89
- if node.type == :const or node.type == :cbase
90
- unless node.children[0].nil?
91
- signature += drill_signature(node.children[0], signature)
92
- end
89
+ if %i[const cbase].include?(node.type)
90
+ signature += drill_signature(node.children[0], signature) unless node.children[0].nil?
93
91
  signature += '::' unless signature.empty?
94
92
  signature += node.children[1].to_s
95
- elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
93
+ elsif %i[lvar ivar cvar].include?(node.type)
96
94
  signature += '.' unless signature.empty?
97
95
  signature += node.children[0].to_s
98
96
  elsif node.type == :send
99
- unless node.children[0].nil?
100
- signature += drill_signature(node.children[0], signature)
101
- end
97
+ signature += drill_signature(node.children[0], signature) unless node.children[0].nil?
102
98
  signature += '.' unless signature.empty?
103
99
  signature += node.children[1].to_s
104
100
  end
@@ -112,7 +108,10 @@ module Solargraph
112
108
  # @sg-ignore Translate to something flow sensitive typing understands
113
109
  return convert_hash(node.children[0]) if node.type == :kwsplat
114
110
  # @sg-ignore Translate to something flow sensitive typing understands
115
- return convert_hash(node.children[0]) if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
111
+ if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
112
+ # @sg-ignore Translate to something flow sensitive typing understands
113
+ return convert_hash(node.children[0])
114
+ end
116
115
  # @sg-ignore Translate to something flow sensitive typing understands
117
116
  return {} unless node.type == :hash
118
117
  result = {}
@@ -151,7 +150,7 @@ module Solargraph
151
150
  end
152
151
 
153
152
  # @param nodes [Enumerable<Parser::AST::Node>]
154
- def any_splatted_call?(nodes)
153
+ def any_splatted_call? nodes
155
154
  nodes.any? { |n| splatted_call?(n) }
156
155
  end
157
156
 
@@ -165,16 +164,16 @@ module Solargraph
165
164
  result.push node
166
165
  if Parser.is_ast_node?(node.children[0]) && node.children[0].children.length > 2
167
166
  # @sg-ignore Need to add nil check here
168
- node.children[0].children[2..-1].each { |child| result.concat call_nodes_from(child) }
167
+ node.children[0].children[2..].each { |child| result.concat call_nodes_from(child) }
169
168
  end
170
169
  # @sg-ignore Need to add nil check here
171
- node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
170
+ node.children[1..].each { |child| result.concat call_nodes_from(child) }
172
171
  elsif node.type == :send
173
172
  result.push node
174
173
  result.concat call_nodes_from(node.children.first)
175
174
  # @sg-ignore Need to add nil check here
176
- node.children[2..-1].each { |child| result.concat call_nodes_from(child) }
177
- elsif [:super, :zsuper].include?(node.type)
175
+ node.children[2..].each { |child| result.concat call_nodes_from(child) }
176
+ elsif %i[super zsuper].include?(node.type)
178
177
  result.push node
179
178
  node.children.each { |child| result.concat call_nodes_from(child) }
180
179
  else
@@ -205,44 +204,44 @@ module Solargraph
205
204
  # @return [Array<AST::Node>] low-level value nodes in
206
205
  # value position. Does not include explicit return
207
206
  # statements
208
- def value_position_nodes_only(node)
207
+ def value_position_nodes_only node
209
208
  DeepInference.value_position_nodes_only(node).map { |n| n || NIL_NODE }
210
209
  end
211
210
 
212
211
  # @param cursor [Solargraph::Source::Cursor]
213
212
  # @return [Parser::AST::Node, nil]
214
213
  def find_recipient_node cursor
215
- return repaired_find_recipient_node(cursor) if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
214
+ if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
215
+ return repaired_find_recipient_node(cursor)
216
+ end
216
217
  source = cursor.source
217
218
  position = cursor.position
218
219
  offset = cursor.offset
219
220
  tree = if source.synchronized?
220
- # @sg-ignore Need to add nil check here
221
- match = source.code[0..offset-1].match(/,\s*\z/)
222
- if match
223
- # @sg-ignore Need to add nil check here
224
- source.tree_at(position.line, position.column - match[0].length)
225
- else
226
- source.tree_at(position.line, position.column)
227
- end
228
- else
229
- source.tree_at(position.line, position.column - 1)
230
- end
221
+ # @sg-ignore Need to add nil check here
222
+ match = source.code[0..(offset - 1)].match(/,\s*\z/)
223
+ if match
224
+ # @sg-ignore Need to add nil check here
225
+ source.tree_at(position.line, position.column - match[0].length)
226
+ else
227
+ source.tree_at(position.line, position.column)
228
+ end
229
+ else
230
+ source.tree_at(position.line, position.column - 1)
231
+ end
231
232
  # @type [AST::Node, nil]
232
233
  prev = nil
233
234
  tree.each do |node|
234
235
  if node.type == :send
235
- args = node.children[2..-1]
236
+ args = node.children[2..]
236
237
  # @sg-ignore Need to add nil check here
237
238
  if !args.empty?
238
239
  # @sg-ignore Need to add nil check here
239
240
  return node if prev && args.include?(prev)
240
- else
241
- if source.synchronized?
242
- return node if source.code[0..offset-1] =~ /\(\s*\z/ && source.code[offset..-1] =~ /^\s*\)/
243
- else
244
- return node if source.code[0..offset-1] =~ /\([^(]*\z/
245
- end
241
+ elsif source.synchronized?
242
+ return node if source.code[0..(offset - 1)] =~ /\(\s*\z/ && source.code[offset..] =~ /^\s*\)/
243
+ elsif source.code[0..(offset - 1)] =~ /\([^(]*\z/
244
+ return node
246
245
  end
247
246
  end
248
247
  prev = node
@@ -255,7 +254,7 @@ module Solargraph
255
254
  def repaired_find_recipient_node cursor
256
255
  cursor = cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
257
256
  node = cursor.source.tree_at(cursor.position.line, cursor.position.column).first
258
- return node if node && node.type == :send
257
+ node if node && node.type == :send
259
258
  end
260
259
 
261
260
  #
@@ -312,18 +311,15 @@ module Solargraph
312
311
  # statements in value positions.
313
312
  module DeepInference
314
313
  class << self
315
- CONDITIONAL_ALL_BUT_FIRST = [:if, :unless]
316
- ONLY_ONE_CHILD = [:return]
317
- FIRST_TWO_CHILDREN = [:rescue]
318
- COMPOUND_STATEMENTS = [:begin, :kwbegin]
319
- SKIPPABLE = [:def, :defs, :class, :sclass, :module]
320
- FUNCTION_VALUE = [:block]
321
- CASE_STATEMENT = [:case]
314
+ CONDITIONAL_ALL_BUT_FIRST = %i[if unless].freeze
315
+ ONLY_ONE_CHILD = [:return].freeze
316
+ FIRST_TWO_CHILDREN = [:rescue].freeze
317
+ COMPOUND_STATEMENTS = %i[begin kwbegin].freeze
318
+ SKIPPABLE = %i[def defs class sclass module].freeze
319
+ FUNCTION_VALUE = [:block].freeze
320
+ CASE_STATEMENT = [:case].freeze
322
321
 
323
322
  # @param node [AST::Node] a method body compound statement
324
- # @param include_explicit_returns [Boolean] If true,
325
- # include the value nodes of the parameter of the
326
- # 'return' statements in the type returned.
327
323
  # @return [Array<AST::Node>] low-level value nodes from
328
324
  # both nodes in value position as well as explicit
329
325
  # return statements in the method's closure.
@@ -336,7 +332,7 @@ module Solargraph
336
332
  # @return [Array<AST::Node>] low-level value nodes in
337
333
  # value position. Does not include explicit return
338
334
  # statements
339
- def value_position_nodes_only(node)
335
+ def value_position_nodes_only node
340
336
  from_value_position_statement(node, include_explicit_returns: false)
341
337
  end
342
338
 
@@ -358,7 +354,7 @@ module Solargraph
358
354
  result.concat from_value_position_compound_statement node
359
355
  elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
360
356
  # @sg-ignore Need to add nil check here
361
- result.concat reduce_to_value_nodes(node.children[1..-1])
357
+ result.concat reduce_to_value_nodes(node.children[1..])
362
358
  # result.push NIL_NODE unless node.children[2]
363
359
  elsif ONLY_ONE_CHILD.include?(node.type)
364
360
  result.concat reduce_to_value_nodes([node.children[0]])
@@ -370,10 +366,12 @@ module Solargraph
370
366
  # @todo any explicit returns actually return from
371
367
  # scope in which the proc is run. This asssumes
372
368
  # that the function is executed here.
373
- result.concat explicit_return_values_from_compound_statement(node.children[2]) if include_explicit_returns
369
+ if include_explicit_returns
370
+ result.concat explicit_return_values_from_compound_statement(node.children[2])
371
+ end
374
372
  elsif CASE_STATEMENT.include?(node.type)
375
373
  # @sg-ignore Need to add nil check here
376
- node.children[1..-1].each do |cc|
374
+ node.children[1..].each do |cc|
377
375
  if cc.nil?
378
376
  result.push NIL_NODE
379
377
  elsif cc.type == :when
@@ -406,7 +404,7 @@ module Solargraph
406
404
  # @return [Array<Parser::AST::Node>]
407
405
  def from_value_position_compound_statement parent
408
406
  result = []
409
- nodes = parent.children.select{|n| n.is_a?(AST::Node)}
407
+ nodes = parent.children.select { |n| n.is_a?(AST::Node) }
410
408
  nodes.each_with_index do |node, idx|
411
409
  if node.type == :block
412
410
  result.concat explicit_return_values_from_compound_statement(node.children[2])
@@ -431,7 +429,10 @@ module Solargraph
431
429
  # value position. we already have the explicit values
432
430
  # from above; now we need to also gather the value
433
431
  # position nodes
434
- result.concat from_value_position_statement(nodes.last, include_explicit_returns: false) if idx == nodes.length - 1
432
+ if idx == nodes.length - 1
433
+ result.concat from_value_position_statement(nodes.last,
434
+ include_explicit_returns: false)
435
+ end
435
436
  end
436
437
  result
437
438
  end
@@ -447,7 +448,7 @@ module Solargraph
447
448
  def explicit_return_values_from_compound_statement parent
448
449
  return [] unless parent.is_a?(::Parser::AST::Node)
449
450
  result = []
450
- nodes = parent.children.select{|n| n.is_a?(::Parser::AST::Node)}
451
+ nodes = parent.children.select { |n| n.is_a?(::Parser::AST::Node) }
451
452
  nodes.each do |node|
452
453
  next if SKIPPABLE.include?(node.type)
453
454
  if node.type == :return
@@ -475,7 +476,7 @@ module Solargraph
475
476
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
476
477
  elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
477
478
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
478
- result.concat reduce_to_value_nodes(node.children[1..-1])
479
+ result.concat reduce_to_value_nodes(node.children[1..])
479
480
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
480
481
  elsif node.type == :return
481
482
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
@@ -14,17 +14,17 @@ module Solargraph
14
14
  node.children.each do |u|
15
15
  loc = get_node_location(u)
16
16
  locals.push Solargraph::Pin::Parameter.new(
17
- location: loc,
18
- closure: callable,
19
- comments: comments_for(node),
20
- name: u.children[0].to_s,
21
- assignment: u.children[1],
22
- asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
23
- # @sg-ignore Need to add nil check here
24
- presence: callable.location.range,
25
- decl: get_decl(u),
26
- source: :parser
27
- )
17
+ location: loc,
18
+ closure: callable,
19
+ comments: comments_for(node),
20
+ name: u.children[0].to_s,
21
+ assignment: u.children[1],
22
+ asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
23
+ # @sg-ignore Need to add nil check here
24
+ presence: callable.location.range,
25
+ decl: get_decl(u),
26
+ source: :parser
27
+ )
28
28
  callable.parameters.push locals.last
29
29
  end
30
30
  end
@@ -36,7 +36,7 @@ module Solargraph
36
36
 
37
37
  # @param callable [Pin::Callable]
38
38
  # @return [void]
39
- def forward(callable)
39
+ def forward callable
40
40
  loc = get_node_location(node)
41
41
  locals.push Solargraph::Pin::Parameter.new(
42
42
  location: loc,
@@ -37,7 +37,7 @@ module Solargraph
37
37
  node.children[0].type == :send &&
38
38
  node.children[0].children[1] == :class_eval &&
39
39
  # @sg-ignore Need to add nil check here
40
- [:cbase, :const].include?(node.children[0].children[0]&.type)
40
+ %i[cbase const].include?(node.children[0].children[0]&.type)
41
41
  end
42
42
  end
43
43
  end
@@ -21,7 +21,7 @@ module Solargraph
21
21
  scope: scope,
22
22
  visibility: scope == :instance && name == 'initialize' ? :private : region.visibility,
23
23
  node: node,
24
- source: :parser,
24
+ source: :parser
25
25
  )
26
26
  if region.visibility == :module_function
27
27
  pins.push Solargraph::Pin::Method.new(
@@ -34,7 +34,7 @@ module Solargraph
34
34
  visibility: :public,
35
35
  parameters: methpin.parameters,
36
36
  node: methpin.node,
37
- source: :parser,
37
+ source: :parser
38
38
  )
39
39
  pins.push Solargraph::Pin::Method.new(
40
40
  location: methpin.location,
@@ -46,7 +46,7 @@ module Solargraph
46
46
  visibility: :private,
47
47
  parameters: methpin.parameters,
48
48
  node: methpin.node,
49
- source: :parser,
49
+ source: :parser
50
50
  )
51
51
  else
52
52
  pins.push methpin
@@ -1,37 +1,38 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class DefsNode < DefNode
8
- include ParserGem::NodeMethods
9
-
10
- def process
11
- s_visi = region.visibility
12
- s_visi = :public if s_visi == :module_function || region.scope != :class
13
- loc = get_node_location(node)
14
- if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
15
- closure = region.closure
16
- else
17
- closure = Solargraph::Pin::Namespace.new(
18
- name: unpack_name(node.children[0])
19
- )
20
- end
21
- pins.push Solargraph::Pin::Method.new(
22
- location: loc,
23
- closure: closure,
24
- name: node.children[1].to_s,
25
- comments: comments_for(node),
26
- scope: :class,
27
- visibility: s_visi,
28
- node: node,
29
- source: :parser,
30
- )
31
- process_children region.update(closure: pins.last, scope: :class)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class DefsNode < DefNode
8
+ include ParserGem::NodeMethods
9
+
10
+ def process
11
+ s_visi = region.visibility
12
+ s_visi = :public if s_visi == :module_function || region.scope != :class
13
+ loc = get_node_location(node)
14
+ closure = if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
15
+ region.closure
16
+ else
17
+ Solargraph::Pin::Namespace.new(
18
+ name: unpack_name(node.children[0]),
19
+ source: :parser
20
+ )
21
+ end
22
+ pins.push Solargraph::Pin::Method.new(
23
+ location: loc,
24
+ closure: closure,
25
+ name: node.children[1].to_s,
26
+ comments: comments_for(node),
27
+ scope: :class,
28
+ visibility: s_visi,
29
+ node: node,
30
+ source: :parser
31
+ )
32
+ process_children region.update(closure: pins.last, scope: :class)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -18,7 +18,7 @@ module Solargraph
18
18
  location: get_node_location(condition_node),
19
19
  closure: region.closure,
20
20
  node: condition_node,
21
- source: :parser,
21
+ source: :parser
22
22
  )
23
23
  NodeProcessor.process(condition_node, region, pins, locals, ivars)
24
24
  end
@@ -28,7 +28,7 @@ module Solargraph
28
28
  location: get_node_location(then_node),
29
29
  closure: region.closure,
30
30
  node: then_node,
31
- source: :parser,
31
+ source: :parser
32
32
  )
33
33
  NodeProcessor.process(then_node, region, pins, locals, ivars)
34
34
  end
@@ -39,7 +39,7 @@ module Solargraph
39
39
  location: get_node_location(else_node),
40
40
  closure: region.closure,
41
41
  node: else_node,
42
- source: :parser,
42
+ source: :parser
43
43
  )
44
44
  NodeProcessor.process(else_node, region, pins, locals, ivars)
45
45
  end
@@ -24,7 +24,8 @@ module Solargraph
24
24
  if named_path.is_a?(Pin::Method)
25
25
  ivars.push Solargraph::Pin::InstanceVariable.new(
26
26
  location: loc,
27
- closure: Pin::Namespace.new(type: :module, closure: region.closure.closure, name: region.closure.name),
27
+ closure: Pin::Namespace.new(type: :module, closure: region.closure.closure,
28
+ name: region.closure.name),
28
29
  name: node.children[0].to_s,
29
30
  comments: comments_for(node),
30
31
  assignment: node.children[1],
@@ -88,7 +88,7 @@ module Solargraph
88
88
  argument
89
89
  ]
90
90
  send_node = node.updated(:send, send_children)
91
- new_asgn = node.updated(asgn.type, [variable_name, send_node])
91
+ new_asgn = node.updated(asgn.type, [variable_name, send_node])
92
92
  NodeProcessor.process(new_asgn, region, pins, locals, ivars)
93
93
  end
94
94
  end
@@ -24,16 +24,14 @@ module Solargraph
24
24
  if sclass.children[0].nil? && names.last != sclass.children[1].to_s
25
25
  names << sclass.children[1].to_s
26
26
  else
27
- names.concat [NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s]
27
+ names.push NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s
28
28
  end
29
29
  name = names.reject(&:empty?).join('::')
30
30
  closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
31
31
  elsif sclass.is_a?(::Parser::AST::Node) && sclass.type == :const
32
32
  names = [region.closure.namespace, region.closure.name]
33
33
  also = NodeMethods.unpack_name(sclass)
34
- if also != region.closure.name
35
- names << also
36
- end
34
+ names << also if also != region.closure.name
37
35
  name = names.reject(&:empty?).join('::')
38
36
  closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
39
37
  else
@@ -42,7 +40,7 @@ module Solargraph
42
40
  pins.push Solargraph::Pin::Singleton.new(
43
41
  location: get_node_location(node),
44
42
  closure: closure,
45
- source: :parser,
43
+ source: :parser
46
44
  )
47
45
  process_children region.update(visibility: :public, scope: :class, closure: pins.last)
48
46
  end