solargraph 0.38.6 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/SPONSORS.md +9 -0
  3. data/lib/solargraph.rb +1 -0
  4. data/lib/solargraph/api_map.rb +24 -13
  5. data/lib/solargraph/api_map/bundler_methods.rb +3 -0
  6. data/lib/solargraph/api_map/source_to_yard.rb +1 -6
  7. data/lib/solargraph/api_map/store.rb +19 -3
  8. data/lib/solargraph/complex_type/type_methods.rb +4 -4
  9. data/lib/solargraph/convention/base.rb +0 -5
  10. data/lib/solargraph/core_fills.rb +28 -2
  11. data/lib/solargraph/diagnostics/base.rb +1 -0
  12. data/lib/solargraph/diagnostics/type_check.rb +13 -13
  13. data/lib/solargraph/language_server/host.rb +11 -2
  14. data/lib/solargraph/language_server/host/sources.rb +20 -11
  15. data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -11
  16. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  17. data/lib/solargraph/library.rb +3 -3
  18. data/lib/solargraph/parser.rb +26 -0
  19. data/lib/solargraph/parser/comment_ripper.rb +52 -0
  20. data/lib/solargraph/parser/legacy.rb +12 -0
  21. data/lib/solargraph/parser/legacy/class_methods.rb +105 -0
  22. data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
  23. data/lib/solargraph/parser/legacy/node_chainer.rb +115 -0
  24. data/lib/solargraph/parser/legacy/node_methods.rb +289 -0
  25. data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
  26. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
  27. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
  28. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
  29. data/lib/solargraph/parser/legacy/node_processors/block_node.rb +22 -0
  30. data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +25 -0
  31. data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
  32. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
  33. data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
  34. data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
  35. data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
  36. data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
  37. data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
  38. data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
  39. data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
  40. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +21 -0
  41. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +232 -0
  42. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
  43. data/lib/solargraph/parser/node_methods.rb +43 -0
  44. data/lib/solargraph/parser/node_processor.rb +43 -0
  45. data/lib/solargraph/parser/node_processor/base.rb +77 -0
  46. data/lib/solargraph/{source_map → parser}/region.rb +11 -6
  47. data/lib/solargraph/parser/rubyvm.rb +40 -0
  48. data/lib/solargraph/parser/rubyvm/class_methods.rb +146 -0
  49. data/lib/solargraph/parser/rubyvm/node_chainer.rb +133 -0
  50. data/lib/solargraph/parser/rubyvm/node_methods.rb +279 -0
  51. data/lib/solargraph/parser/rubyvm/node_processors.rb +60 -0
  52. data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
  53. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +62 -0
  54. data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
  55. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +22 -0
  56. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +22 -0
  57. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
  58. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +64 -0
  59. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +57 -0
  60. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
  61. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
  62. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +34 -0
  63. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
  64. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
  65. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
  66. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
  67. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
  68. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
  69. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +21 -0
  70. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
  71. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +292 -0
  72. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
  73. data/lib/solargraph/parser/snippet.rb +13 -0
  74. data/lib/solargraph/pin/attribute.rb +8 -0
  75. data/lib/solargraph/pin/base.rb +1 -1
  76. data/lib/solargraph/pin/base_method.rb +26 -4
  77. data/lib/solargraph/pin/base_variable.rb +7 -8
  78. data/lib/solargraph/pin/block.rb +1 -1
  79. data/lib/solargraph/pin/constant.rb +16 -0
  80. data/lib/solargraph/pin/conversions.rb +2 -2
  81. data/lib/solargraph/pin/method.rb +26 -14
  82. data/lib/solargraph/pin/parameter.rb +56 -2
  83. data/lib/solargraph/pin/reference.rb +1 -0
  84. data/lib/solargraph/pin/reference/override.rb +2 -0
  85. data/lib/solargraph/pin/reference/prepend.rb +10 -0
  86. data/lib/solargraph/pin/yard_pin/constant.rb +2 -4
  87. data/lib/solargraph/pin/yard_pin/method.rb +34 -18
  88. data/lib/solargraph/pin/yard_pin/namespace.rb +3 -11
  89. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +3 -12
  90. data/lib/solargraph/range.rb +8 -2
  91. data/lib/solargraph/shell.rb +17 -11
  92. data/lib/solargraph/source.rb +114 -135
  93. data/lib/solargraph/source/chain.rb +11 -3
  94. data/lib/solargraph/source/chain/call.rb +1 -2
  95. data/lib/solargraph/source/chain/constant.rb +44 -8
  96. data/lib/solargraph/source/chain/link.rb +1 -0
  97. data/lib/solargraph/source/cursor.rb +2 -28
  98. data/lib/solargraph/source/source_chainer.rb +12 -6
  99. data/lib/solargraph/source/updater.rb +2 -0
  100. data/lib/solargraph/source_map.rb +0 -2
  101. data/lib/solargraph/source_map/clip.rb +24 -17
  102. data/lib/solargraph/source_map/mapper.rb +34 -29
  103. data/lib/solargraph/type_checker.rb +367 -275
  104. data/lib/solargraph/type_checker/checks.rb +95 -0
  105. data/lib/solargraph/type_checker/param_def.rb +2 -17
  106. data/lib/solargraph/type_checker/rules.rb +53 -0
  107. data/lib/solargraph/version.rb +1 -1
  108. data/lib/solargraph/views/environment.erb +5 -3
  109. data/lib/solargraph/workspace.rb +17 -2
  110. data/lib/solargraph/workspace/config.rb +15 -7
  111. data/lib/solargraph/yard_map.rb +89 -49
  112. data/lib/solargraph/yard_map/core_docs.rb +1 -1
  113. data/solargraph.gemspec +2 -1
  114. metadata +88 -32
  115. data/OVERVIEW.md +0 -37
  116. data/lib/solargraph/source/flawed_builder.rb +0 -15
  117. data/lib/solargraph/source/node_chainer.rb +0 -111
  118. data/lib/solargraph/source/node_methods.rb +0 -240
  119. data/lib/solargraph/source_map/node_processor.rb +0 -85
  120. data/lib/solargraph/source_map/node_processor/alias_node.rb +0 -21
  121. data/lib/solargraph/source_map/node_processor/args_node.rb +0 -24
  122. data/lib/solargraph/source_map/node_processor/base.rb +0 -103
  123. data/lib/solargraph/source_map/node_processor/begin_node.rb +0 -13
  124. data/lib/solargraph/source_map/node_processor/block_node.rb +0 -21
  125. data/lib/solargraph/source_map/node_processor/casgn_node.rb +0 -21
  126. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +0 -21
  127. data/lib/solargraph/source_map/node_processor/def_node.rb +0 -62
  128. data/lib/solargraph/source_map/node_processor/defs_node.rb +0 -33
  129. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +0 -21
  130. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +0 -34
  131. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +0 -24
  132. data/lib/solargraph/source_map/node_processor/namespace_node.rb +0 -35
  133. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +0 -14
  134. data/lib/solargraph/source_map/node_processor/resbody_node.rb +0 -32
  135. data/lib/solargraph/source_map/node_processor/sclass_node.rb +0 -19
  136. data/lib/solargraph/source_map/node_processor/send_node.rb +0 -217
  137. data/lib/solargraph/source_map/node_processor/sym_node.rb +0 -16
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class LvasgnNode < Base
7
- def process
8
- here = get_node_start_position(node)
9
- presence = Range.new(here, region.closure.location.range.ending)
10
- loc = get_node_location(node)
11
- locals.push Solargraph::Pin::LocalVariable.new(
12
- location: loc,
13
- closure: region.closure,
14
- name: node.children[0].to_s,
15
- assignment: node.children[1],
16
- comments: comments_for(node),
17
- presence: presence
18
- )
19
- process_children
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class NamespaceNode < Base
7
- def process
8
- sc = nil
9
- if node.type == :class and !node.children[1].nil?
10
- sc = unpack_name(node.children[1])
11
- end
12
- loc = get_node_location(node)
13
- nspin = Solargraph::Pin::Namespace.new(
14
- type: node.type,
15
- location: loc,
16
- closure: region.closure,
17
- name: unpack_name(node.children[0]),
18
- comments: comments_for(node),
19
- visibility: :public,
20
- gates: region.closure.gates.freeze
21
- )
22
- pins.push nspin
23
- unless sc.nil?
24
- pins.push Pin::Reference::Superclass.new(
25
- location: loc,
26
- closure: pins.last,
27
- name: sc
28
- )
29
- end
30
- process_children region.update(closure: nspin, visibility: :public)
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class OrasgnNode < Base
7
- def process
8
- new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
9
- NodeProcessor.process(new_node, region, pins, locals)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class ResbodyNode < Base
7
- def process
8
- if node.children[1]
9
- here = get_node_start_position(node.children[1])
10
- presence = Range.new(here, region.closure.location.range.ending)
11
- loc = get_node_location(node.children[1])
12
- types = if node.children[0].nil?
13
- ['Exception']
14
- else
15
- node.children[0].children.map do |child|
16
- unpack_name(child)
17
- end
18
- end
19
- locals.push Solargraph::Pin::LocalVariable.new(
20
- location: loc,
21
- closure: region.closure,
22
- name: node.children[1].children[0].to_s,
23
- comments: "@type [#{types.join(',')}]",
24
- presence: presence
25
- )
26
- end
27
- NodeProcessor.process(node.children[2], region, pins, locals)
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class SclassNode < Base
7
- def process
8
- # @todo Temporarily skipping remote metaclasses
9
- return unless node.children[0].is_a?(AST::Node) && node.children[0].type == :self
10
- pins.push Solargraph::Pin::Singleton.new(
11
- location: get_node_location(node),
12
- closure: region.closure
13
- )
14
- process_children region.update(visibility: :public, scope: :class, closure: pins.last)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,217 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class SendNode < Base
7
- def process
8
- if node.children[0].nil?
9
- if [:private, :public, :protected].include?(node.children[1])
10
- if (node.children.length > 2)
11
- node.children[2..-1].each do |child|
12
- next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
13
- name = child.children[0].to_s
14
- matches = pins.select{ |pin| pin.is_a?(Pin::BaseMethod) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
15
- matches.each do |pin|
16
- # @todo Smelly instance variable access
17
- pin.instance_variable_set(:@visibility, node.children[1])
18
- end
19
- end
20
- else
21
- # @todo Smelly instance variable access
22
- region.instance_variable_set(:@visibility, node.children[1])
23
- end
24
- elsif node.children[1] == :module_function
25
- process_module_function
26
- elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
27
- process_attribute
28
- elsif node.children[1] == :include
29
- process_include
30
- elsif node.children[1] == :extend
31
- process_extend
32
- elsif node.children[1] == :require
33
- process_require
34
- elsif node.children[1] == :private_constant
35
- process_private_constant
36
- elsif node.children[1] == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
37
- process_alias_method
38
- elsif node.children[1] == :private_class_method && node.children[2].is_a?(AST::Node)
39
- # Processing a private class can potentially handle children on its own
40
- return if process_private_class_method
41
- end
42
- elsif node.children[1] == :require && node.children[0].to_s == '(const nil :Bundler)'
43
- pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require')
44
- end
45
- process_children
46
- end
47
-
48
- private
49
-
50
- # @return [void]
51
- def process_attribute
52
- node.children[2..-1].each do |a|
53
- loc = get_node_location(node)
54
- clos = region.closure
55
- cmnt = comments_for(node)
56
- if node.children[1] == :attr_reader || node.children[1] == :attr_accessor
57
- pins.push Solargraph::Pin::Attribute.new(
58
- location: loc,
59
- closure: clos,
60
- name: a.children[0].to_s,
61
- comments: cmnt,
62
- access: :reader,
63
- scope: region.scope || :instance,
64
- visibility: region.visibility
65
- )
66
- end
67
- if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
68
- pins.push Solargraph::Pin::Attribute.new(
69
- location: loc,
70
- closure: clos,
71
- name: "#{a.children[0]}=",
72
- comments: cmnt,
73
- access: :writer,
74
- scope: region.scope || :instance,
75
- visibility: region.visibility
76
- )
77
- end
78
- end
79
- end
80
-
81
- # @return [void]
82
- def process_include
83
- if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
84
- cp = region.closure
85
- node.children[2..-1].each do |i|
86
- pins.push Pin::Reference::Include.new(
87
- location: get_node_location(i),
88
- closure: cp,
89
- name: unpack_name(i)
90
- )
91
- end
92
- end
93
- end
94
-
95
- # @return [void]
96
- def process_extend
97
- node.children[2..-1].each do |i|
98
- loc = get_node_location(node)
99
- if i.type == :self
100
- pins.push Pin::Reference::Extend.new(
101
- location: loc,
102
- closure: region.closure,
103
- name: region.closure.full_context.namespace
104
- )
105
- else
106
- pins.push Pin::Reference::Extend.new(
107
- location: loc,
108
- closure: region.closure,
109
- name: unpack_name(i)
110
- )
111
- end
112
- end
113
- end
114
-
115
- # @return [void]
116
- def process_require
117
- if node.children[2].is_a?(AST::Node) && node.children[2].type == :str
118
- path = node.children[2].children[0].to_s
119
- pins.push Pin::Reference::Require.new(get_node_location(node), path)
120
- end
121
- end
122
-
123
- # @return [void]
124
- def process_module_function
125
- if node.children[2].nil?
126
- # @todo Smelly instance variable access
127
- region.instance_variable_set(:@visibility, :module_function)
128
- elsif node.children[2].type == :sym || node.children[2].type == :str
129
- node.children[2..-1].each do |x|
130
- cn = x.children[0].to_s
131
- ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
132
- unless ref.nil?
133
- pins.delete ref
134
- mm = Solargraph::Pin::Method.new(
135
- location: ref.location,
136
- closure: ref.closure,
137
- name: ref.name,
138
- comments: ref.comments,
139
- scope: :class,
140
- visibility: :public,
141
- args: ref.parameters,
142
- node: ref.node
143
- )
144
- cm = Solargraph::Pin::Method.new(
145
- location: ref.location,
146
- closure: ref.closure,
147
- name: ref.name,
148
- comments: ref.comments,
149
- scope: :instance,
150
- visibility: :private,
151
- args: ref.parameters,
152
- node: ref.node)
153
- pins.push mm, cm
154
- pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
155
- pins.delete ivar
156
- pins.push Solargraph::Pin::InstanceVariable.new(
157
- location: ivar.location,
158
- closure: cm,
159
- name: ivar.name,
160
- comments: ivar.comments,
161
- assignment: ivar.assignment
162
- # scope: :instance
163
- )
164
- pins.push Solargraph::Pin::InstanceVariable.new(
165
- location: ivar.location,
166
- closure: mm,
167
- name: ivar.name,
168
- comments: ivar.comments,
169
- assignment: ivar.assignment
170
- # scope: :class
171
- )
172
- end
173
- end
174
- end
175
- elsif node.children[2].type == :def
176
- NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins, locals
177
- end
178
- end
179
-
180
- # @return [void]
181
- def process_private_constant
182
- if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
183
- cn = node.children[2].children[0].to_s
184
- ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
185
- # HACK: Smelly instance variable access
186
- ref.instance_variable_set(:@visibility, :private) unless ref.nil?
187
- end
188
- end
189
-
190
- # @return [void]
191
- def process_alias_method
192
- loc = get_node_location(node)
193
- pins.push Solargraph::Pin::MethodAlias.new(
194
- location: get_node_location(node),
195
- closure: region.closure,
196
- name: node.children[2].children[0].to_s,
197
- original: node.children[3].children[0].to_s,
198
- scope: region.scope || :instance
199
- )
200
- end
201
-
202
- # @return [Boolean]
203
- def process_private_class_method
204
- if node.children[2].type == :sym || node.children[2].type == :str
205
- ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == node.children[2].children[0].to_s}.first
206
- # HACK: Smelly instance variable access
207
- ref.instance_variable_set(:@visibility, :private) unless ref.nil?
208
- false
209
- else
210
- process_children region.update(scope: :class, visibility: :private)
211
- true
212
- end
213
- end
214
- end
215
- end
216
- end
217
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class SourceMap
5
- module NodeProcessor
6
- class SymNode < Base
7
- def process
8
- pins.push Solargraph::Pin::Symbol.new(
9
- get_node_location(node),
10
- ":#{node.children[0]}"
11
- )
12
- end
13
- end
14
- end
15
- end
16
- end