solargraph 0.59.0.dev.1 → 0.59.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +3 -1
- data/.github/workflows/plugins.yml +12 -3
- data/.github/workflows/rspec.yml +9 -54
- data/.github/workflows/typecheck.yml +2 -1
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +40 -931
- data/CHANGELOG.md +22 -1
- data/Gemfile +3 -1
- data/Rakefile +25 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/constants.rb +0 -1
- data/lib/solargraph/api_map/index.rb +11 -11
- data/lib/solargraph/api_map/source_to_yard.rb +9 -8
- data/lib/solargraph/api_map/store.rb +28 -20
- data/lib/solargraph/api_map.rb +70 -41
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/type_methods.rb +14 -16
- data/lib/solargraph/complex_type/unique_type.rb +56 -47
- data/lib/solargraph/complex_type.rb +70 -62
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
- data/lib/solargraph/convention/data_definition.rb +1 -1
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
- data/lib/solargraph/convention/struct_definition.rb +3 -3
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +19 -17
- data/lib/solargraph/converters/dl.rb +17 -15
- data/lib/solargraph/converters/dt.rb +17 -15
- data/lib/solargraph/converters/misc.rb +3 -1
- data/lib/solargraph/diagnostics/rubocop.rb +10 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
- data/lib/solargraph/diagnostics/type_check.rb +10 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +370 -132
- data/lib/solargraph/equality.rb +3 -3
- data/lib/solargraph/gem_pins.rb +19 -18
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +2 -3
- data/lib/solargraph/language_server/host/message_worker.rb +2 -2
- data/lib/solargraph/language_server/host/sources.rb +1 -1
- data/lib/solargraph/language_server/host.rb +24 -21
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +197 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
- data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +29 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +68 -95
- data/lib/solargraph/location.rb +10 -12
- data/lib/solargraph/logging.rb +4 -6
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +12 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -44
- data/lib/solargraph/parser/node_processor/base.rb +4 -4
- data/lib/solargraph/parser/node_processor.rb +1 -1
- data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -6
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -2
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +76 -64
- data/lib/solargraph/pin/base_variable.rb +28 -71
- data/lib/solargraph/pin/block.rb +3 -2
- data/lib/solargraph/pin/breakable.rb +2 -0
- data/lib/solargraph/pin/callable.rb +23 -26
- data/lib/solargraph/pin/closure.rb +5 -4
- data/lib/solargraph/pin/common.rb +5 -2
- data/lib/solargraph/pin/compound_statement.rb +3 -3
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +9 -4
- data/lib/solargraph/pin/delegated_method.rb +4 -4
- data/lib/solargraph/pin/documenting.rb +3 -2
- data/lib/solargraph/pin/local_variable.rb +4 -4
- data/lib/solargraph/pin/method.rb +74 -70
- data/lib/solargraph/pin/namespace.rb +13 -12
- data/lib/solargraph/pin/parameter.rb +28 -27
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +18 -0
- data/lib/solargraph/pin/search.rb +2 -2
- data/lib/solargraph/pin/signature.rb +9 -14
- data/lib/solargraph/pin/symbol.rb +1 -0
- data/lib/solargraph/pin/until.rb +1 -3
- data/lib/solargraph/pin/while.rb +1 -3
- data/lib/solargraph/pin_cache.rb +71 -488
- data/lib/solargraph/position.rb +38 -17
- data/lib/solargraph/range.rb +10 -9
- data/lib/solargraph/rbs_map/conversions.rb +327 -221
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
- data/lib/solargraph/rbs_map.rb +5 -15
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +224 -66
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +49 -44
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +3 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -6
- data/lib/solargraph/source/chain/if.rb +11 -10
- data/lib/solargraph/source/chain/instance_variable.rb +3 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +4 -6
- data/lib/solargraph/source/chain/or.rb +2 -4
- data/lib/solargraph/source/chain/q_call.rb +13 -11
- data/lib/solargraph/source/chain/variable.rb +15 -13
- data/lib/solargraph/source/chain/z_super.rb +28 -30
- data/lib/solargraph/source/chain.rb +26 -16
- data/lib/solargraph/source/change.rb +3 -3
- data/lib/solargraph/source/cursor.rb +18 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +46 -32
- data/lib/solargraph/source/updater.rb +1 -1
- data/lib/solargraph/source.rb +27 -29
- data/lib/solargraph/source_map/clip.rb +38 -30
- data/lib/solargraph/source_map/mapper.rb +51 -47
- data/lib/solargraph/source_map.rb +8 -4
- data/lib/solargraph/type_checker/rules.rb +8 -8
- data/lib/solargraph/type_checker.rb +95 -102
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +11 -10
- data/lib/solargraph/workspace/gemspecs.rb +3 -3
- data/lib/solargraph/workspace.rb +45 -165
- data/lib/solargraph/yard_map/helpers.rb +6 -2
- data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
- data/lib/solargraph/yard_map/mapper.rb +12 -12
- data/lib/solargraph/yard_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +26 -33
- data/lib/solargraph.rb +7 -5
- data/solargraph.gemspec +36 -35
- metadata +33 -38
|
@@ -13,7 +13,9 @@ module Solargraph
|
|
|
13
13
|
@cursor = cursor
|
|
14
14
|
closure_pin = closure
|
|
15
15
|
# @sg-ignore Need to add nil check here
|
|
16
|
-
|
|
16
|
+
if closure_pin.is_a?(Pin::Block) && !Solargraph::Range.from_node(closure_pin.receiver).contain?(cursor.range.start)
|
|
17
|
+
closure_pin.rebind(api_map)
|
|
18
|
+
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
# @return [Array<Pin::Base>] Relevant pins for infering the type of the Cursor's position
|
|
@@ -21,8 +23,12 @@ module Solargraph
|
|
|
21
23
|
return [] if cursor.comment? || cursor.chain.literal?
|
|
22
24
|
result = cursor.chain.define(api_map, closure, locals)
|
|
23
25
|
result.concat file_global_methods
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if result.empty?
|
|
27
|
+
result.concat((source_map.pins + source_map.locals).select do |p|
|
|
28
|
+
# @sg-ignore Need to add nil check here
|
|
29
|
+
p.name == cursor.word && p.location.range.contain?(cursor.position)
|
|
30
|
+
end)
|
|
31
|
+
end
|
|
26
32
|
result
|
|
27
33
|
end
|
|
28
34
|
|
|
@@ -34,7 +40,9 @@ module Solargraph
|
|
|
34
40
|
# @return [Completion]
|
|
35
41
|
def complete
|
|
36
42
|
return package_completions([]) if !source_map.source.parsed? || cursor.string?
|
|
37
|
-
|
|
43
|
+
if cursor.chain.literal? && cursor.chain.links.last.word == '<Symbol>'
|
|
44
|
+
return package_completions(api_map.get_symbols)
|
|
45
|
+
end
|
|
38
46
|
return Completion.new([], cursor.range) if cursor.chain.literal?
|
|
39
47
|
if cursor.comment?
|
|
40
48
|
tag_complete
|
|
@@ -128,12 +136,11 @@ module Solargraph
|
|
|
128
136
|
next unless param.keyword?
|
|
129
137
|
result.push Pin::KeywordParam.new(pin.location, "#{param.name}:")
|
|
130
138
|
end
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
end
|
|
139
|
+
next unless !pin.parameters.empty? && pin.parameters.last.kwrestarg?
|
|
140
|
+
pin.docstring.tags(:param).each do |tag|
|
|
141
|
+
next if done.include?(tag.name)
|
|
142
|
+
done.push tag.name
|
|
143
|
+
result.push Pin::KeywordParam.new(pin.location, "#{tag.name}:")
|
|
137
144
|
end
|
|
138
145
|
end
|
|
139
146
|
result
|
|
@@ -143,10 +150,10 @@ module Solargraph
|
|
|
143
150
|
# @return [Completion]
|
|
144
151
|
def package_completions result
|
|
145
152
|
frag_start = cursor.start_of_word.to_s.downcase
|
|
146
|
-
filtered = result.uniq(&:name).select
|
|
153
|
+
filtered = result.uniq(&:name).select do |s|
|
|
147
154
|
s.name.downcase.start_with?(frag_start) &&
|
|
148
|
-
(!s.is_a?(Pin::Method) || s.name.match(/^[a-z0-9_]+(
|
|
149
|
-
|
|
155
|
+
(!s.is_a?(Pin::Method) || s.name.match(/^[a-z0-9_]+(!|\?|=)?$/i))
|
|
156
|
+
end
|
|
150
157
|
Completion.new(filtered, cursor.range)
|
|
151
158
|
end
|
|
152
159
|
|
|
@@ -154,7 +161,7 @@ module Solargraph
|
|
|
154
161
|
def tag_complete
|
|
155
162
|
result = []
|
|
156
163
|
# @sg-ignore Need to add nil check here
|
|
157
|
-
match = source_map.code[0..cursor.offset-1].match(/[\[<, ]([a-z0-9_:]*)\z/i)
|
|
164
|
+
match = source_map.code[0..(cursor.offset - 1)].match(/[\[<, ]([a-z0-9_:]*)\z/i)
|
|
158
165
|
if match
|
|
159
166
|
# @sg-ignore Need to add nil check here
|
|
160
167
|
full = match[1]
|
|
@@ -170,7 +177,7 @@ module Solargraph
|
|
|
170
177
|
end
|
|
171
178
|
else
|
|
172
179
|
# @sg-ignore Need to add nil check here
|
|
173
|
-
result.concat api_map.get_constants('', full.end_with?('::') ? '' : context_pin.full_context.namespace, *gates)
|
|
180
|
+
result.concat api_map.get_constants('', full.end_with?('::') ? '' : context_pin.full_context.namespace, *gates) # .select { |pin| pin.name.start_with?(full) }
|
|
174
181
|
end
|
|
175
182
|
end
|
|
176
183
|
package_completions(result)
|
|
@@ -183,25 +190,24 @@ module Solargraph
|
|
|
183
190
|
if cursor.chain.constant? || cursor.start_of_constant?
|
|
184
191
|
full = cursor.chain.links.first.word
|
|
185
192
|
type = if cursor.chain.undefined?
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
end
|
|
196
|
-
end
|
|
193
|
+
cursor.chain.base.infer(api_map, context_pin, locals)
|
|
194
|
+
elsif full.include?('::') && cursor.chain.links.length == 1
|
|
195
|
+
# @sg-ignore Need to add nil check here
|
|
196
|
+
ComplexType.try_parse(full.split('::')[0..-2].join('::'))
|
|
197
|
+
elsif cursor.chain.links.length > 1
|
|
198
|
+
ComplexType.try_parse(full)
|
|
199
|
+
else
|
|
200
|
+
ComplexType::UNDEFINED
|
|
201
|
+
end
|
|
197
202
|
if type.undefined?
|
|
198
203
|
if full.include?('::')
|
|
199
204
|
result.concat api_map.get_constants(full, *gates)
|
|
200
205
|
else
|
|
201
|
-
result.concat api_map.get_constants('', cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates)
|
|
206
|
+
result.concat api_map.get_constants('', cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates) # .select { |pin| pin.name.start_with?(full) }
|
|
202
207
|
end
|
|
203
208
|
else
|
|
204
|
-
result.concat api_map.get_constants(type.namespace,
|
|
209
|
+
result.concat api_map.get_constants(type.namespace,
|
|
210
|
+
cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates)
|
|
205
211
|
end
|
|
206
212
|
else
|
|
207
213
|
type = cursor.chain.base.infer(api_map, closure, locals)
|
|
@@ -210,14 +216,16 @@ module Solargraph
|
|
|
210
216
|
if cursor.word.start_with?('@@')
|
|
211
217
|
return package_completions(api_map.get_class_variable_pins(context_pin.full_context.namespace))
|
|
212
218
|
elsif cursor.word.start_with?('@')
|
|
213
|
-
return package_completions(api_map.get_instance_variable_pins(closure.full_context.namespace,
|
|
219
|
+
return package_completions(api_map.get_instance_variable_pins(closure.full_context.namespace,
|
|
220
|
+
closure.context.scope))
|
|
214
221
|
elsif cursor.word.start_with?('$')
|
|
215
222
|
return package_completions(api_map.get_global_variable_pins)
|
|
216
223
|
end
|
|
217
224
|
result.concat locals
|
|
218
225
|
result.concat file_global_methods unless closure.binder.namespace.empty?
|
|
219
226
|
result.concat api_map.get_constants(context_pin.context.namespace, *gates)
|
|
220
|
-
result.concat api_map.get_methods(closure.binder.namespace, scope: closure.binder.scope,
|
|
227
|
+
result.concat api_map.get_methods(closure.binder.namespace, scope: closure.binder.scope,
|
|
228
|
+
visibility: %i[public private protected])
|
|
221
229
|
result.concat api_map.get_methods('Kernel')
|
|
222
230
|
result.concat api_map.keyword_pins.to_a
|
|
223
231
|
end
|
|
@@ -12,7 +12,7 @@ module Solargraph
|
|
|
12
12
|
|
|
13
13
|
private_class_method :new
|
|
14
14
|
|
|
15
|
-
DIRECTIVE_REGEXP = /(
|
|
15
|
+
DIRECTIVE_REGEXP = /(@!method|@!attribute|@!visibility|@!domain|@!macro|@!parse|@!override)/
|
|
16
16
|
|
|
17
17
|
# Generate the data.
|
|
18
18
|
#
|
|
@@ -29,10 +29,10 @@ module Solargraph
|
|
|
29
29
|
@locals.each { |l| l.source = :code }
|
|
30
30
|
process_comment_directives
|
|
31
31
|
[@pins, @locals]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
# rescue Exception => e
|
|
33
|
+
# Solargraph.logger.warn "Error mapping #{source.filename}: [#{e.class}] #{e.message}"
|
|
34
|
+
# Solargraph.logger.warn e.backtrace.join("\n")
|
|
35
|
+
# [[], []]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# @param filename [String]
|
|
@@ -63,9 +63,9 @@ module Solargraph
|
|
|
63
63
|
|
|
64
64
|
# @param position [Solargraph::Position]
|
|
65
65
|
# @return [Solargraph::Pin::Closure]
|
|
66
|
-
def closure_at
|
|
66
|
+
def closure_at position
|
|
67
67
|
# @sg-ignore Need to add nil check here
|
|
68
|
-
pins.select{|pin| pin.is_a?(Pin::Closure) and pin.location.range.contain?(position)}.last
|
|
68
|
+
pins.select { |pin| pin.is_a?(Pin::Closure) and pin.location.range.contain?(position) }.last
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
# @param source_position [Position]
|
|
@@ -94,7 +94,7 @@ module Solargraph
|
|
|
94
94
|
# Avoid overruning the index
|
|
95
95
|
return start unless start < comment.lines.length
|
|
96
96
|
# @sg-ignore Need to add nil check here
|
|
97
|
-
num = comment.lines[start
|
|
97
|
+
num = comment.lines[start..].find_index do |line|
|
|
98
98
|
# Legacy method directives might be `@method` instead of `@!method`
|
|
99
99
|
# @todo Legacy syntax should probably emit a warning
|
|
100
100
|
line.include?("@!#{tag}") || (tag == 'method' && line.include?("@#{tag}"))
|
|
@@ -114,11 +114,8 @@ module Solargraph
|
|
|
114
114
|
case directive.tag.tag_name
|
|
115
115
|
when 'method'
|
|
116
116
|
namespace = closure_at(source_position) || @pins.first
|
|
117
|
-
# @
|
|
118
|
-
|
|
119
|
-
if namespace.location.range.start.line < comment_position.line
|
|
120
|
-
namespace = closure_at(comment_position)
|
|
121
|
-
end
|
|
117
|
+
# @sg-ignore Need to add nil check here
|
|
118
|
+
namespace = closure_at(comment_position) if namespace.location.range.start.line < comment_position.line
|
|
122
119
|
begin
|
|
123
120
|
src = Solargraph::Source.load_string("def #{directive.tag.name};end", @source.filename)
|
|
124
121
|
region = Parser::Region.new(source: src, closure: namespace)
|
|
@@ -128,19 +125,20 @@ module Solargraph
|
|
|
128
125
|
return if gen_pin.nil?
|
|
129
126
|
# Move the location to the end of the line so it gets recognized
|
|
130
127
|
# as originating from a comment
|
|
131
|
-
shifted = Solargraph::Position.new(comment_position.line,
|
|
128
|
+
shifted = Solargraph::Position.new(comment_position.line,
|
|
129
|
+
@code.lines[comment_position.line].to_s.chomp.length)
|
|
132
130
|
# @todo: Smelly instance variable access
|
|
133
131
|
gen_pin.instance_variable_set(:@comments, docstring.all.to_s)
|
|
134
132
|
gen_pin.instance_variable_set(:@location, Solargraph::Location.new(@filename, Range.new(shifted, shifted)))
|
|
135
133
|
gen_pin.instance_variable_set(:@explicit, false)
|
|
136
134
|
@pins.push gen_pin
|
|
137
|
-
rescue Parser::SyntaxError
|
|
135
|
+
rescue Parser::SyntaxError
|
|
138
136
|
# @todo Handle error in directive
|
|
139
137
|
end
|
|
140
138
|
when 'attribute'
|
|
141
139
|
return if directive.tag.name.nil?
|
|
142
140
|
namespace = closure_at(source_position)
|
|
143
|
-
t =
|
|
141
|
+
t = directive.tag.types.nil? || directive.tag.types.empty? ? nil : directive.tag.types.join
|
|
144
142
|
if t.nil? || t.include?('r')
|
|
145
143
|
pins.push Solargraph::Pin::Method.new(
|
|
146
144
|
location: location,
|
|
@@ -166,34 +164,34 @@ module Solargraph
|
|
|
166
164
|
source: :source_map
|
|
167
165
|
)
|
|
168
166
|
pins.push method_pin
|
|
169
|
-
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last,
|
|
167
|
+
method_pin.parameters.push Pin::Parameter.new(name: 'value', decl: :arg, closure: pins.last,
|
|
168
|
+
source: :source_map)
|
|
170
169
|
if pins.last.return_type.defined?
|
|
171
|
-
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.to_s.split(', '),
|
|
170
|
+
pins.last.docstring.add_tag YARD::Tags::Tag.new(:param, '', pins.last.return_type.to_s.split(', '),
|
|
171
|
+
'value')
|
|
172
172
|
end
|
|
173
173
|
end
|
|
174
174
|
when 'visibility'
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return unless [:private, :protected, :public].include?(kind)
|
|
176
|
+
kind = directive.tag.text&.to_sym
|
|
177
|
+
return unless %i[private protected public].include?(kind)
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
name = directive.tag.name
|
|
180
|
+
closure = closure_at(source_position) || @pins.first
|
|
181
|
+
# @sg-ignore Need to add nil check here
|
|
182
|
+
closure = closure_at(comment_position) if closure.location.range.start.line < comment_position.line
|
|
183
|
+
if closure.is_a?(Pin::Method) && no_empty_lines?(comment_position.line, source_position.line)
|
|
184
|
+
# @todo Smelly instance variable access
|
|
185
|
+
closure.instance_variable_set(:@visibility, kind)
|
|
186
|
+
else
|
|
187
|
+
matches = pins.select do |pin|
|
|
188
|
+
pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == namespace && pin.context.scope == namespace.is_a?(Pin::Singleton) ? :class : :instance
|
|
186
189
|
end
|
|
187
|
-
|
|
190
|
+
matches.each do |pin|
|
|
188
191
|
# @todo Smelly instance variable access
|
|
189
|
-
|
|
190
|
-
else
|
|
191
|
-
matches = pins.select{ |pin| pin.is_a?(Pin::Method) && pin.name == name && pin.namespace == namespace && pin.context.scope == namespace.is_a?(Pin::Singleton) ? :class : :instance }
|
|
192
|
-
matches.each do |pin|
|
|
193
|
-
# @todo Smelly instance variable access
|
|
194
|
-
pin.instance_variable_set(:@visibility, kind)
|
|
195
|
-
end
|
|
192
|
+
pin.instance_variable_set(:@visibility, kind)
|
|
196
193
|
end
|
|
194
|
+
end
|
|
197
195
|
|
|
198
196
|
when 'parse'
|
|
199
197
|
begin
|
|
@@ -204,21 +202,21 @@ module Solargraph
|
|
|
204
202
|
# @todo These pins may need to be marked not explicit
|
|
205
203
|
index = @pins.length
|
|
206
204
|
loff = if @code.lines[comment_position.line].strip.end_with?('@!parse')
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
comment_position.line + 1
|
|
206
|
+
else
|
|
207
|
+
comment_position.line
|
|
208
|
+
end
|
|
211
209
|
locals = []
|
|
212
210
|
ivars = []
|
|
213
211
|
Parser.process_node(src.node, region, @pins, locals, ivars)
|
|
214
212
|
@pins.concat ivars
|
|
215
213
|
# @sg-ignore Need to add nil check here
|
|
216
|
-
@pins[index
|
|
214
|
+
@pins[index..].each do |p|
|
|
217
215
|
# @todo Smelly instance variable access
|
|
218
216
|
p.location.range.start.instance_variable_set(:@line, p.location.range.start.line + loff)
|
|
219
217
|
p.location.range.ending.instance_variable_set(:@line, p.location.range.ending.line + loff)
|
|
220
218
|
end
|
|
221
|
-
rescue Parser::SyntaxError
|
|
219
|
+
rescue Parser::SyntaxError
|
|
222
220
|
# @todo Handle parser errors in !parse directives
|
|
223
221
|
end
|
|
224
222
|
when 'domain'
|
|
@@ -226,7 +224,6 @@ module Solargraph
|
|
|
226
224
|
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
227
225
|
namespace.domains.concat directive.tag.types unless directive.tag.types.nil?
|
|
228
226
|
when 'override'
|
|
229
|
-
# @sg-ignore Need to add nil check here
|
|
230
227
|
pins.push Pin::Reference::Override.new(location, directive.tag.name, docstring.tags,
|
|
231
228
|
source: :source_map)
|
|
232
229
|
when 'macro'
|
|
@@ -237,7 +234,7 @@ module Solargraph
|
|
|
237
234
|
# @param line1 [Integer]
|
|
238
235
|
# @param line2 [Integer]
|
|
239
236
|
# @sg-ignore Need to add nil check here
|
|
240
|
-
def no_empty_lines?
|
|
237
|
+
def no_empty_lines? line1, line2
|
|
241
238
|
# @sg-ignore Need to add nil check here
|
|
242
239
|
@code.lines[line1..line2].none? { |line| line.strip.empty? }
|
|
243
240
|
end
|
|
@@ -248,7 +245,7 @@ module Solargraph
|
|
|
248
245
|
ctxt = ''
|
|
249
246
|
num = nil
|
|
250
247
|
started = false
|
|
251
|
-
comment.lines.each
|
|
248
|
+
comment.lines.each do |l|
|
|
252
249
|
# Trim the comment and minimum leading whitespace
|
|
253
250
|
p = l.encode('UTF-8', invalid: :replace, replace: '?').gsub(/^#+/, '')
|
|
254
251
|
if num.nil? && !p.strip.empty?
|
|
@@ -259,8 +256,8 @@ module Solargraph
|
|
|
259
256
|
# @sg-ignore Need to add nil check here
|
|
260
257
|
num = cur if cur < num
|
|
261
258
|
end
|
|
262
|
-
ctxt +=
|
|
263
|
-
|
|
259
|
+
ctxt += p[num..].to_s if started
|
|
260
|
+
end
|
|
264
261
|
ctxt
|
|
265
262
|
end
|
|
266
263
|
|
|
@@ -269,7 +266,14 @@ module Solargraph
|
|
|
269
266
|
return unless @code.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
|
|
270
267
|
code_lines = @code.lines
|
|
271
268
|
@source.associated_comments.each do |line, comments|
|
|
272
|
-
src_pos =
|
|
269
|
+
src_pos = if line
|
|
270
|
+
Position.new(line,
|
|
271
|
+
code_lines[line].to_s.chomp.index(/[^\s]/) || 0)
|
|
272
|
+
else
|
|
273
|
+
Position.new(
|
|
274
|
+
code_lines.length, 0
|
|
275
|
+
)
|
|
276
|
+
end
|
|
273
277
|
# @sg-ignore Need to add nil check here
|
|
274
278
|
com_pos = Position.new(line + 1 - comments.lines.length, 0)
|
|
275
279
|
process_comment(src_pos, com_pos, comments)
|
|
@@ -62,7 +62,9 @@ module Solargraph
|
|
|
62
62
|
#
|
|
63
63
|
# @return [Integer]
|
|
64
64
|
def api_hash
|
|
65
|
-
@api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select
|
|
65
|
+
@api_hash ||= (pins_by_class(Pin::Constant) + pins_by_class(Pin::Namespace).select do |pin|
|
|
66
|
+
pin.namespace.to_s > ''
|
|
67
|
+
end + pins_by_class(Pin::Reference) + pins_by_class(Pin::Method).map(&:node) + locals).hash
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
# @return [String, nil]
|
|
@@ -144,7 +146,7 @@ module Solargraph
|
|
|
144
146
|
|
|
145
147
|
# @param location [Location]
|
|
146
148
|
# @return [Array<Pin::LocalVariable>]
|
|
147
|
-
def locals_at
|
|
149
|
+
def locals_at location
|
|
148
150
|
return [] if location.filename != filename
|
|
149
151
|
closure = locate_closure_pin(location.range.start.line, location.range.start.character)
|
|
150
152
|
locals.select { |pin| pin.visible_at?(closure, location) }
|
|
@@ -208,8 +210,10 @@ module Solargraph
|
|
|
208
210
|
# @todo Attribute pins should not be treated like closures, but
|
|
209
211
|
# there's probably a better way to handle it
|
|
210
212
|
next if pin.is_a?(Pin::Method) && pin.attribute?
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
found = pin if (klasses.empty? || klasses.any? do |kls|
|
|
214
|
+
pin.is_a?(kls)
|
|
215
|
+
# @sg-ignore Need to add nil check here
|
|
216
|
+
end) && pin.location.range.contain?(position)
|
|
213
217
|
# @sg-ignore Need to add nil check here
|
|
214
218
|
break if pin.location.range.start.line > line
|
|
215
219
|
end
|
|
@@ -23,11 +23,11 @@ module Solargraph
|
|
|
23
23
|
# @param overrides [Hash{Symbol => Symbol}]
|
|
24
24
|
def initialize level, overrides
|
|
25
25
|
@rank = if LEVELS.key?(level)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
LEVELS[level]
|
|
27
|
+
else
|
|
28
|
+
Solargraph.logger.warn "Unrecognized TypeChecker level #{level}, assuming normal"
|
|
29
|
+
0
|
|
30
|
+
end
|
|
31
31
|
@level = LEVELS[LEVELS.values.index(@rank)]
|
|
32
32
|
@overrides = overrides
|
|
33
33
|
end
|
|
@@ -83,11 +83,12 @@ module Solargraph
|
|
|
83
83
|
# @todo 13: Need to validate config
|
|
84
84
|
# @todo 8: flow sensitive typing should support .class == .class
|
|
85
85
|
# @todo 6: need boolish support for ? methods
|
|
86
|
+
# @todo 6: flow sensitive typing needs better handling of ||= on lvars
|
|
86
87
|
# @todo 5: literal arrays in this module turn into ::Solargraph::Source::Chain::Array
|
|
87
88
|
# @todo 5: flow sensitive typing needs to handle 'raise if'
|
|
88
|
-
# @todo 5: flow sensitive typing needs better handling of ||= on lvars
|
|
89
89
|
# @todo 4: flow sensitive typing needs to eliminate literal from union with [:bar].include?(foo)
|
|
90
90
|
# @todo 4: nil? support in flow sensitive typing
|
|
91
|
+
# @todo 3: flow sensitive typing ought to be able to handle 'when ClassName'
|
|
91
92
|
# @todo 2: downcast output of Enumerable#select
|
|
92
93
|
# @todo 2: flow sensitive typing should handle return nil if location&.name.nil?
|
|
93
94
|
# @todo 2: flow sensitive typing should handle is_a? and next
|
|
@@ -98,7 +99,6 @@ module Solargraph
|
|
|
98
99
|
# @todo 2: Need to handle duck-typed method calls on union types
|
|
99
100
|
# @todo 2: Need better handling of #compact
|
|
100
101
|
# @todo 2: flow sensitive typing should allow shadowing of Kernel#caller
|
|
101
|
-
# @todo 2: flow sensitive typing ought to be able to handle 'when ClassName'
|
|
102
102
|
# @todo 1: flow sensitive typing not smart enough to handle this case
|
|
103
103
|
# @todo 1: flow sensitive typing needs to handle if foo = bar
|
|
104
104
|
# @todo 1: flow sensitive typing needs to handle "if foo.nil?"
|
|
@@ -149,7 +149,7 @@ module Solargraph
|
|
|
149
149
|
|
|
150
150
|
# @param type [Symbol]
|
|
151
151
|
# @param level [Symbol]
|
|
152
|
-
def report?
|
|
152
|
+
def report? type, level
|
|
153
153
|
rank >= LEVELS[@overrides.fetch(type, level)]
|
|
154
154
|
end
|
|
155
155
|
end
|