solargraph 0.58.2 → 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.
- checksums.yaml +4 -4
- data/.envrc +3 -0
- data/.github/workflows/linting.yml +4 -5
- data/.github/workflows/plugins.yml +41 -34
- data/.github/workflows/rspec.yml +44 -23
- data/.github/workflows/typecheck.yml +2 -2
- data/.rubocop.yml +32 -5
- data/.rubocop_todo.yml +50 -966
- data/Gemfile +3 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -3
- data/lib/solargraph/api_map/index.rb +23 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +33 -28
- data/lib/solargraph/api_map.rb +150 -82
- data/lib/solargraph/bench.rb +44 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +28 -17
- data/lib/solargraph/complex_type/unique_type.rb +218 -57
- data/lib/solargraph/complex_type.rb +170 -57
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
- data/lib/solargraph/convention/data_definition.rb +5 -2
- 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 +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
- data/lib/solargraph/convention/struct_definition.rb +8 -4
- 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/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +11 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/diagnostics/type_check.rb +11 -10
- data/lib/solargraph/diagnostics/update_errors.rb +37 -41
- data/lib/solargraph/doc_map.rb +133 -373
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +21 -20
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +3 -3
- data/lib/solargraph/language_server/host/message_worker.rb +4 -3
- data/lib/solargraph/language_server/host/sources.rb +2 -1
- data/lib/solargraph/language_server/host.rb +30 -22
- 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 +12 -18
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- 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 +10 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
- 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 -19
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +5 -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 +3 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
- 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 -17
- 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 +85 -44
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +24 -4
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +326 -108
- data/lib/solargraph/parser/node_processor/base.rb +34 -4
- data/lib/solargraph/parser/node_processor.rb +8 -7
- data/lib/solargraph/parser/parser_gem/class_methods.rb +32 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +50 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +91 -70
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +12 -12
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -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 +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +14 -12
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +25 -23
- data/lib/solargraph/pin/base.rb +126 -80
- data/lib/solargraph/pin/base_variable.rb +273 -24
- data/lib/solargraph/pin/block.rb +29 -6
- data/lib/solargraph/pin/breakable.rb +7 -1
- data/lib/solargraph/pin/callable.rb +65 -21
- data/lib/solargraph/pin/closure.rb +7 -10
- data/lib/solargraph/pin/common.rb +24 -6
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +43 -45
- data/lib/solargraph/pin/conversions.rb +10 -4
- data/lib/solargraph/pin/delegated_method.rb +19 -8
- data/lib/solargraph/pin/documenting.rb +4 -2
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +15 -59
- data/lib/solargraph/pin/method.rb +153 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +100 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference.rb +19 -0
- data/lib/solargraph/pin/search.rb +3 -2
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/symbol.rb +2 -1
- data/lib/solargraph/pin/until.rb +2 -4
- data/lib/solargraph/pin/while.rb +2 -4
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +490 -73
- data/lib/solargraph/position.rb +14 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +343 -214
- data/lib/solargraph/rbs_map/core_fills.rb +91 -84
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
- data/lib/solargraph/rbs_map.rb +77 -32
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +128 -73
- data/lib/solargraph/source/chain/array.rb +39 -37
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/if.rb +12 -10
- data/lib/solargraph/source/chain/instance_variable.rb +24 -1
- data/lib/solargraph/source/chain/link.rb +99 -109
- data/lib/solargraph/source/chain/literal.rb +9 -6
- data/lib/solargraph/source/chain/or.rb +10 -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 +49 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +23 -17
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +56 -32
- data/lib/solargraph/source/updater.rb +5 -1
- data/lib/solargraph/source.rb +59 -35
- data/lib/solargraph/source_map/clip.rb +48 -29
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +71 -42
- data/lib/solargraph/source_map.rb +21 -9
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +81 -8
- data/lib/solargraph/type_checker.rb +195 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +13 -10
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +149 -30
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +13 -8
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +33 -23
- data/lib/solargraph.rb +29 -8
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -0
- data/rbs/shims/ast/0/node.rbs +1 -1
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/solargraph.gemspec +36 -34
- metadata +38 -33
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
|
@@ -14,6 +14,7 @@ module Solargraph
|
|
|
14
14
|
# @param block [Signature, nil]
|
|
15
15
|
# @param return_type [ComplexType, nil]
|
|
16
16
|
# @param parameters [::Array<Pin::Parameter>]
|
|
17
|
+
# @param [Hash{Symbol => Object}] splat
|
|
17
18
|
def initialize block: nil, return_type: nil, parameters: [], **splat
|
|
18
19
|
super(**splat)
|
|
19
20
|
@block = block
|
|
@@ -21,15 +22,22 @@ module Solargraph
|
|
|
21
22
|
@parameters = parameters
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def reset_generated!
|
|
26
|
+
parameters.each(&:reset_generated!)
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @sg-ignore Need to add nil check here
|
|
24
31
|
# @return [String]
|
|
25
32
|
def method_namespace
|
|
33
|
+
# @sg-ignore Need to add nil check here
|
|
26
34
|
closure.namespace
|
|
27
35
|
end
|
|
28
36
|
|
|
29
37
|
# @param other [self]
|
|
30
38
|
#
|
|
31
39
|
# @return [Pin::Signature, nil]
|
|
32
|
-
def combine_blocks
|
|
40
|
+
def combine_blocks other
|
|
33
41
|
if block.nil?
|
|
34
42
|
other.block
|
|
35
43
|
elsif other.block.nil?
|
|
@@ -44,10 +52,10 @@ module Solargraph
|
|
|
44
52
|
# @param attrs [Hash{Symbol => Object}]
|
|
45
53
|
#
|
|
46
54
|
# @return [self]
|
|
47
|
-
def combine_with
|
|
55
|
+
def combine_with other, attrs = {}
|
|
48
56
|
new_attrs = {
|
|
49
57
|
block: combine_blocks(other),
|
|
50
|
-
return_type: combine_return_type(other)
|
|
58
|
+
return_type: combine_return_type(other)
|
|
51
59
|
}.merge(attrs)
|
|
52
60
|
new_attrs[:parameters] = choose_parameters(other).clone.freeze unless new_attrs.key?(:parameters)
|
|
53
61
|
super(other, new_attrs)
|
|
@@ -65,8 +73,10 @@ module Solargraph
|
|
|
65
73
|
# @param other [self]
|
|
66
74
|
#
|
|
67
75
|
# @return [Array<Pin::Parameter>]
|
|
68
|
-
def choose_parameters
|
|
69
|
-
|
|
76
|
+
def choose_parameters other
|
|
77
|
+
if other.arity != arity
|
|
78
|
+
raise "Trying to combine two pins with different arities - \nself =#{inspect}, \nother=#{other.inspect}, \n\n self.arity=#{arity}, \nother.arity=#{other.arity}"
|
|
79
|
+
end
|
|
70
80
|
# @param param [Pin::Parameter]
|
|
71
81
|
# @param other_param [Pin::Parameter]
|
|
72
82
|
parameters.zip(other.parameters).map do |param, other_param|
|
|
@@ -80,6 +90,7 @@ module Solargraph
|
|
|
80
90
|
end
|
|
81
91
|
end
|
|
82
92
|
|
|
93
|
+
# @sg-ignore Need to add nil check here
|
|
83
94
|
# @return [Array<Pin::Parameter>]
|
|
84
95
|
def blockless_parameters
|
|
85
96
|
if parameters.last&.block?
|
|
@@ -89,25 +100,47 @@ module Solargraph
|
|
|
89
100
|
end
|
|
90
101
|
end
|
|
91
102
|
|
|
92
|
-
#
|
|
103
|
+
# e.g., [["T"], "", "?", "foo:"] - parameter arity declarations,
|
|
104
|
+
# ignoring positional names. Used to match signatures.
|
|
105
|
+
#
|
|
106
|
+
# @return [Array<Array<String>, String, nil>]
|
|
93
107
|
def arity
|
|
94
108
|
[generics, blockless_parameters.map(&:arity_decl), block&.arity]
|
|
95
109
|
end
|
|
96
110
|
|
|
111
|
+
# e.g., [["T"], "1", "?3", "foo:5"] - parameter arity
|
|
112
|
+
# declarations, including the number of unique types in each
|
|
113
|
+
# parameter. Used to determine whether combining two
|
|
114
|
+
# signatures has lost useful information mapping specific
|
|
115
|
+
# parameter types to specific return types.
|
|
116
|
+
#
|
|
117
|
+
# @return [Array<Array, String, nil>]
|
|
118
|
+
def type_arity
|
|
119
|
+
[generics, blockless_parameters.map(&:type_arity_decl), block&.type_arity]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Same as type_arity, but includes return type arity at the front.
|
|
123
|
+
#
|
|
124
|
+
# @return [Array<Array, String, nil>]
|
|
125
|
+
def full_type_arity
|
|
126
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
127
|
+
[return_type ? return_type.items.count.to_s : nil] + type_arity
|
|
128
|
+
end
|
|
129
|
+
|
|
97
130
|
# @param generics_to_resolve [Enumerable<String>]
|
|
98
131
|
# @param arg_types [Array<ComplexType>, nil]
|
|
99
132
|
# @param return_type_context [ComplexType, nil]
|
|
100
133
|
# @param yield_arg_types [Array<ComplexType>, nil]
|
|
101
134
|
# @param yield_return_type_context [ComplexType, nil]
|
|
102
|
-
# @param context [ComplexType, nil]
|
|
103
135
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
136
|
+
#
|
|
104
137
|
# @return [self]
|
|
105
|
-
def resolve_generics_from_context
|
|
138
|
+
def resolve_generics_from_context generics_to_resolve,
|
|
106
139
|
arg_types = nil,
|
|
107
140
|
return_type_context = nil,
|
|
108
141
|
yield_arg_types = nil,
|
|
109
142
|
yield_return_type_context = nil,
|
|
110
|
-
resolved_generic_values: {}
|
|
143
|
+
resolved_generic_values: {}
|
|
111
144
|
callable = super(generics_to_resolve, return_type_context, resolved_generic_values: resolved_generic_values)
|
|
112
145
|
callable.parameters = callable.parameters.each_with_index.map do |param, i|
|
|
113
146
|
if arg_types.nil?
|
|
@@ -118,10 +151,12 @@ module Solargraph
|
|
|
118
151
|
resolved_generic_values: resolved_generic_values)
|
|
119
152
|
end
|
|
120
153
|
end
|
|
121
|
-
callable.block
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
154
|
+
if callable.block?
|
|
155
|
+
callable.block = block.resolve_generics_from_context(generics_to_resolve,
|
|
156
|
+
yield_arg_types,
|
|
157
|
+
yield_return_type_context,
|
|
158
|
+
resolved_generic_values: resolved_generic_values)
|
|
159
|
+
end
|
|
125
160
|
callable
|
|
126
161
|
end
|
|
127
162
|
|
|
@@ -137,9 +172,11 @@ module Solargraph
|
|
|
137
172
|
end
|
|
138
173
|
end
|
|
139
174
|
|
|
175
|
+
# @sg-ignore Need to add nil check here
|
|
140
176
|
# @return [String]
|
|
141
177
|
def method_name
|
|
142
|
-
raise "closure was nil in #{
|
|
178
|
+
raise "closure was nil in #{inspect}" if closure.nil?
|
|
179
|
+
# @sg-ignore Need to add nil check here
|
|
143
180
|
@method_name ||= closure.name
|
|
144
181
|
end
|
|
145
182
|
|
|
@@ -148,15 +185,15 @@ module Solargraph
|
|
|
148
185
|
# @param return_type_context [ComplexType, nil]
|
|
149
186
|
# @param yield_arg_types [Array<ComplexType>, nil]
|
|
150
187
|
# @param yield_return_type_context [ComplexType, nil]
|
|
151
|
-
# @param context [ComplexType, nil]
|
|
152
188
|
# @param resolved_generic_values [Hash{String => ComplexType}]
|
|
189
|
+
#
|
|
153
190
|
# @return [self]
|
|
154
|
-
def resolve_generics_from_context_until_complete
|
|
191
|
+
def resolve_generics_from_context_until_complete generics_to_resolve,
|
|
155
192
|
arg_types = nil,
|
|
156
193
|
return_type_context = nil,
|
|
157
194
|
yield_arg_types = nil,
|
|
158
195
|
yield_return_type_context = nil,
|
|
159
|
-
resolved_generic_values: {}
|
|
196
|
+
resolved_generic_values: {}
|
|
160
197
|
# See
|
|
161
198
|
# https://github.com/soutaro/steep/tree/master/lib/steep/type_inference
|
|
162
199
|
# and
|
|
@@ -174,7 +211,7 @@ module Solargraph
|
|
|
174
211
|
resolved_generic_values: resolved_generic_values)
|
|
175
212
|
if last_resolved_generic_values == resolved_generic_values
|
|
176
213
|
# erase anything unresolved
|
|
177
|
-
return new_pin.erase_generics(
|
|
214
|
+
return new_pin.erase_generics(generics)
|
|
178
215
|
end
|
|
179
216
|
new_pin.resolve_generics_from_context_until_complete(generics_to_resolve,
|
|
180
217
|
arg_types,
|
|
@@ -184,11 +221,10 @@ module Solargraph
|
|
|
184
221
|
resolved_generic_values: resolved_generic_values)
|
|
185
222
|
end
|
|
186
223
|
|
|
187
|
-
# @return [Array<String>]
|
|
188
224
|
# @yieldparam [ComplexType]
|
|
189
225
|
# @yieldreturn [ComplexType]
|
|
190
226
|
# @return [self]
|
|
191
|
-
def transform_types
|
|
227
|
+
def transform_types &transform
|
|
192
228
|
# @todo 'super' alone should work here I think, but doesn't typecheck at level typed
|
|
193
229
|
callable = super(&transform)
|
|
194
230
|
callable.block = block.transform_types(&transform) if block?
|
|
@@ -206,6 +242,9 @@ module Solargraph
|
|
|
206
242
|
parcount = mandatory_positional_param_count
|
|
207
243
|
parcount -= 1 if !parameters.empty? && parameters.last.block?
|
|
208
244
|
return false if block? && !with_block
|
|
245
|
+
# @todo this and its caller should be changed so that this can
|
|
246
|
+
# look at the kwargs provided and check names against what
|
|
247
|
+
# we acccept
|
|
209
248
|
return false if argcount < parcount && !(argcount == parcount - 1 && parameters.last.restarg?)
|
|
210
249
|
true
|
|
211
250
|
end
|
|
@@ -215,8 +254,13 @@ module Solargraph
|
|
|
215
254
|
parameters.count(&:arg?)
|
|
216
255
|
end
|
|
217
256
|
|
|
257
|
+
# @return [String]
|
|
258
|
+
def parameters_to_rbs
|
|
259
|
+
"#{rbs_generics}(#{parameters.map(&:to_rbs).join(', ')}) #{"{ #{block.to_rbs} } " unless block.nil?}"
|
|
260
|
+
end
|
|
261
|
+
|
|
218
262
|
def to_rbs
|
|
219
|
-
|
|
263
|
+
"#{parameters_to_rbs}-> #{return_type&.to_rbs || 'untyped'}"
|
|
220
264
|
end
|
|
221
265
|
|
|
222
266
|
def block?
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
|
-
class Closure <
|
|
5
|
+
class Closure < CompoundStatement
|
|
6
6
|
# @return [::Symbol] :class or :instance
|
|
7
7
|
attr_reader :scope
|
|
8
8
|
|
|
9
9
|
# @param scope [::Symbol] :class or :instance
|
|
10
|
-
# @param generics [::Array<Pin::
|
|
10
|
+
# @param generics [::Array<Pin::String>, nil]
|
|
11
11
|
# @param generic_defaults [Hash{String => ComplexType}]
|
|
12
|
-
|
|
12
|
+
# @param [Hash{Symbol => Object}] splat
|
|
13
|
+
def initialize scope: :class, generics: nil, generic_defaults: {}, **splat
|
|
13
14
|
super(**splat)
|
|
14
15
|
@scope = scope
|
|
15
16
|
@generics = generics
|
|
@@ -25,10 +26,10 @@ module Solargraph
|
|
|
25
26
|
# @param attrs [Hash{Symbol => Object}]
|
|
26
27
|
#
|
|
27
28
|
# @return [self]
|
|
28
|
-
def combine_with
|
|
29
|
+
def combine_with other, attrs = {}
|
|
29
30
|
new_attrs = {
|
|
30
31
|
scope: assert_same(other, :scope),
|
|
31
|
-
generics: generics.empty? ? other.generics : generics
|
|
32
|
+
generics: generics.empty? ? other.generics : generics
|
|
32
33
|
}.merge(attrs)
|
|
33
34
|
super(other, new_attrs)
|
|
34
35
|
end
|
|
@@ -44,10 +45,6 @@ module Solargraph
|
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
def binder
|
|
48
|
-
@binder || context
|
|
49
|
-
end
|
|
50
|
-
|
|
51
48
|
# @param api_map [Solargraph::ApiMap]
|
|
52
49
|
# @return [void]
|
|
53
50
|
def rebind api_map; end
|
|
@@ -65,7 +62,7 @@ module Solargraph
|
|
|
65
62
|
def rbs_generics
|
|
66
63
|
return '' if generics.empty?
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
"[#{generics.map(&:to_s).join(', ')}] "
|
|
69
66
|
end
|
|
70
67
|
end
|
|
71
68
|
end
|
|
@@ -6,15 +6,30 @@ module Solargraph
|
|
|
6
6
|
# @!method source
|
|
7
7
|
# @abstract
|
|
8
8
|
# @return [Source, nil]
|
|
9
|
+
# @!method reset_generated!
|
|
10
|
+
# @abstract
|
|
11
|
+
# @return [void]
|
|
9
12
|
# @type @closure [Pin::Closure, nil]
|
|
13
|
+
# @type @binder [ComplexType, ComplexType::UniqueType, nil]
|
|
14
|
+
|
|
15
|
+
# @todo Missed nil violation
|
|
16
|
+
# @return [Location, nil]
|
|
17
|
+
attr_accessor :location
|
|
10
18
|
|
|
11
|
-
# @
|
|
12
|
-
|
|
19
|
+
# @param value [Pin::Closure]
|
|
20
|
+
# @return [void]
|
|
21
|
+
def closure= value
|
|
22
|
+
@closure = value
|
|
23
|
+
# remove cached values generated from closure
|
|
24
|
+
reset_generated!
|
|
25
|
+
end
|
|
13
26
|
|
|
14
|
-
# @sg-ignore Solargraph::Pin::Common#closure return type could not be inferred
|
|
15
27
|
# @return [Pin::Closure, nil]
|
|
16
28
|
def closure
|
|
17
|
-
|
|
29
|
+
unless @closure
|
|
30
|
+
Solargraph.assert_or_log(:closure,
|
|
31
|
+
"Closure not set on #{self.class} #{name.inspect} from #{source.inspect}")
|
|
32
|
+
end
|
|
18
33
|
@closure
|
|
19
34
|
end
|
|
20
35
|
|
|
@@ -23,12 +38,13 @@ module Solargraph
|
|
|
23
38
|
@name ||= ''
|
|
24
39
|
end
|
|
25
40
|
|
|
41
|
+
# @todo redundant with Base#return_type?
|
|
26
42
|
# @return [ComplexType]
|
|
27
43
|
def return_type
|
|
28
44
|
@return_type ||= ComplexType::UNDEFINED
|
|
29
45
|
end
|
|
30
46
|
|
|
31
|
-
# @return [ComplexType]
|
|
47
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
32
48
|
def context
|
|
33
49
|
# Get the static context from the nearest namespace
|
|
34
50
|
@context ||= find_context
|
|
@@ -40,7 +56,8 @@ module Solargraph
|
|
|
40
56
|
context.namespace.to_s
|
|
41
57
|
end
|
|
42
58
|
|
|
43
|
-
# @return [ComplexType]
|
|
59
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
60
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1100
|
|
44
61
|
def binder
|
|
45
62
|
@binder || context
|
|
46
63
|
end
|
|
@@ -70,6 +87,7 @@ module Solargraph
|
|
|
70
87
|
elsif here.is_a?(Pin::Method)
|
|
71
88
|
return here.context
|
|
72
89
|
end
|
|
90
|
+
# @sg-ignore Need to add nil check here
|
|
73
91
|
here = here.closure
|
|
74
92
|
end
|
|
75
93
|
ComplexType::ROOT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
# A series of statements where if a given statement executes, /all
|
|
6
|
+
# of the previous statements in the sequence must have executed as
|
|
7
|
+
# well/. In other words, the statements are run from the top in
|
|
8
|
+
# sequence, until interrupted by something like a
|
|
9
|
+
# return/break/next/raise/etc.
|
|
10
|
+
#
|
|
11
|
+
# This mix-in is used in flow sensitive typing to determine how
|
|
12
|
+
# far we can assume a given assertion about a type can be trusted
|
|
13
|
+
# to be true.
|
|
14
|
+
#
|
|
15
|
+
# Some examples in Ruby:
|
|
16
|
+
#
|
|
17
|
+
# * Bodies of methods and Ruby blocks
|
|
18
|
+
# * Branches of conditionals and loops - if/elsif/else,
|
|
19
|
+
# unless/else, when, until, ||=, ?:, switch/case/else
|
|
20
|
+
# * The body of begin-end/try/rescue/ensure statements
|
|
21
|
+
#
|
|
22
|
+
# Compare/contrast with:
|
|
23
|
+
#
|
|
24
|
+
# * Scope - a sequence where variables declared are not available
|
|
25
|
+
# after the end of the scope. Note that this is not necessarily
|
|
26
|
+
# true for a compound statement.
|
|
27
|
+
# * Compound statement - synonym
|
|
28
|
+
# * Block - in Ruby this has a special meaning (a closure passed to a method), but
|
|
29
|
+
# in general parlance this is also a synonym.
|
|
30
|
+
# * Closure - a sequence which is also a scope
|
|
31
|
+
# * Namespace - a named sequence which is also a scope and a
|
|
32
|
+
# closure
|
|
33
|
+
#
|
|
34
|
+
# See:
|
|
35
|
+
# https://cse.buffalo.edu/~regan/cse305/RubyBNF.pdf
|
|
36
|
+
# https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html
|
|
37
|
+
# https://en.wikipedia.org/wiki/Block_(programming)
|
|
38
|
+
#
|
|
39
|
+
# Note:
|
|
40
|
+
#
|
|
41
|
+
# Just because statement #1 in a sequence is executed, it doesn't
|
|
42
|
+
# mean that future ones will. Consider the effect of
|
|
43
|
+
# break/next/return/raise/etc. on control flow.
|
|
44
|
+
class CompoundStatement < Pin::Base
|
|
45
|
+
attr_reader :node
|
|
46
|
+
|
|
47
|
+
# @param node [Parser::AST::Node, nil]
|
|
48
|
+
# @param [Hash{Symbol => Object}] splat
|
|
49
|
+
def initialize node: nil, **splat
|
|
50
|
+
super(**splat)
|
|
51
|
+
@node = node
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -1,45 +1,43 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Pin
|
|
5
|
-
class Constant < BaseVariable
|
|
6
|
-
attr_reader :visibility
|
|
7
|
-
|
|
8
|
-
# @param visibility [::Symbol] The visibility of the constant (:public, :protected, or :private)
|
|
9
|
-
# @param splat [Hash] Additional options supported by superclasses
|
|
10
|
-
def initialize visibility: :public, **splat
|
|
11
|
-
super(**splat)
|
|
12
|
-
@visibility = visibility
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def return_type
|
|
16
|
-
@return_type ||= generate_complex_type
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def completion_item_kind
|
|
20
|
-
Solargraph::LanguageServer::CompletionItemKinds::CONSTANT
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# @return [Integer]
|
|
24
|
-
def symbol_kind
|
|
25
|
-
LanguageServer::SymbolKinds::CONSTANT
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def path
|
|
29
|
-
@path ||= context.namespace.to_s.empty? ? name : "#{context.namespace}::#{name}"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
# @return [ComplexType]
|
|
35
|
-
def generate_complex_type
|
|
36
|
-
tags = docstring.tags(:return).map(&:types).flatten.
|
|
37
|
-
if tags.empty?
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
class Constant < BaseVariable
|
|
6
|
+
attr_reader :visibility
|
|
7
|
+
|
|
8
|
+
# @param visibility [::Symbol] The visibility of the constant (:public, :protected, or :private)
|
|
9
|
+
# @param splat [Hash] Additional options supported by superclasses
|
|
10
|
+
def initialize visibility: :public, **splat
|
|
11
|
+
super(**splat)
|
|
12
|
+
@visibility = visibility
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def return_type
|
|
16
|
+
@return_type ||= generate_complex_type
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def completion_item_kind
|
|
20
|
+
Solargraph::LanguageServer::CompletionItemKinds::CONSTANT
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Integer]
|
|
24
|
+
def symbol_kind
|
|
25
|
+
LanguageServer::SymbolKinds::CONSTANT
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def path
|
|
29
|
+
@path ||= context.namespace.to_s.empty? ? name : "#{context.namespace}::#{name}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# @return [ComplexType]
|
|
35
|
+
def generate_complex_type
|
|
36
|
+
tags = docstring.tags(:return).map(&:types).flatten.compact
|
|
37
|
+
tags = docstring.tags(:type).map(&:types).flatten.compact if tags.empty?
|
|
38
|
+
return ComplexType::UNDEFINED if tags.empty?
|
|
39
|
+
ComplexType.try_parse(*tags)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -43,7 +43,7 @@ module Solargraph
|
|
|
43
43
|
data: {
|
|
44
44
|
path: path,
|
|
45
45
|
return_type: return_type.tag,
|
|
46
|
-
location:
|
|
46
|
+
location: location&.to_hash,
|
|
47
47
|
deprecated: deprecated?
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -72,7 +72,13 @@ module Solargraph
|
|
|
72
72
|
# This property is not cached in an instance variable because it can
|
|
73
73
|
# change when pins get proxied.
|
|
74
74
|
detail = String.new
|
|
75
|
-
|
|
75
|
+
unless return_type.undefined?
|
|
76
|
+
detail += "=#{if probed?
|
|
77
|
+
'~'
|
|
78
|
+
else
|
|
79
|
+
(proxied? ? '^' : '>')
|
|
80
|
+
end} #{return_type}"
|
|
81
|
+
end
|
|
76
82
|
detail.strip!
|
|
77
83
|
return nil if detail.empty?
|
|
78
84
|
detail
|
|
@@ -80,7 +86,7 @@ module Solargraph
|
|
|
80
86
|
|
|
81
87
|
# Get a markdown-flavored link to a documentation page.
|
|
82
88
|
#
|
|
83
|
-
# @return [String]
|
|
89
|
+
# @return [String, nil]
|
|
84
90
|
def link_documentation
|
|
85
91
|
@link_documentation ||= generate_link
|
|
86
92
|
end
|
|
@@ -116,7 +122,7 @@ module Solargraph
|
|
|
116
122
|
# @return [String]
|
|
117
123
|
def escape_brackets text
|
|
118
124
|
# text.gsub(/(\<|\>)/, "\\#{$1}")
|
|
119
|
-
text.gsub(
|
|
125
|
+
text.gsub('<', '\<').gsub('>', '\>')
|
|
120
126
|
end
|
|
121
127
|
end
|
|
122
128
|
end
|
|
@@ -13,10 +13,12 @@ module Solargraph
|
|
|
13
13
|
#
|
|
14
14
|
# @param method [Method, nil] an already resolved method pin.
|
|
15
15
|
# @param receiver [Source::Chain, nil] the source code used to resolve the receiver for this delegated method.
|
|
16
|
-
# @param name [String]
|
|
17
|
-
# @param receiver_method_name [String] the method name that will be called on the receiver (defaults to :name).
|
|
16
|
+
# @param name [String, nil]
|
|
17
|
+
# @param receiver_method_name [String, nil] the method name that will be called on the receiver (defaults to :name).
|
|
18
|
+
# @param [Hash{Symbol => Object}] splat
|
|
18
19
|
def initialize(method: nil, receiver: nil, name: method&.name, receiver_method_name: name, **splat)
|
|
19
20
|
raise ArgumentError, 'either :method or :receiver is required' if (method && receiver) || (!method && !receiver)
|
|
21
|
+
# @sg-ignore Need to add nil check here
|
|
20
22
|
super(name: name, **splat)
|
|
21
23
|
|
|
22
24
|
@receiver_chain = receiver
|
|
@@ -34,7 +36,6 @@ module Solargraph
|
|
|
34
36
|
@resolved_method&.send(:location)
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
|
|
38
39
|
def type_location
|
|
39
40
|
return super if super
|
|
40
41
|
|
|
@@ -58,7 +59,7 @@ module Solargraph
|
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
# @param api_map [ApiMap]
|
|
61
|
-
def resolvable?
|
|
62
|
+
def resolvable? api_map
|
|
62
63
|
resolve_method(api_map)
|
|
63
64
|
!!@resolved_method
|
|
64
65
|
end
|
|
@@ -69,30 +70,40 @@ module Solargraph
|
|
|
69
70
|
#
|
|
70
71
|
# @param api_map [ApiMap]
|
|
71
72
|
# @return [Pin::Method, nil]
|
|
73
|
+
# @sg-ignore Declared return type ::Solargraph::Pin::Method, nil
|
|
74
|
+
# does not match inferred type nil, false for
|
|
75
|
+
# Solargraph::Pin::DelegatedMethod#resolve_method
|
|
72
76
|
def resolve_method api_map
|
|
73
77
|
return if @resolved_method
|
|
74
78
|
|
|
79
|
+
# @sg-ignore Need to add nil check here
|
|
75
80
|
resolver = @receiver_chain.define(api_map, self, []).first
|
|
76
81
|
|
|
77
82
|
unless resolver
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
# @sg-ignore Need to add nil check here
|
|
84
|
+
Solargraph.logger.warn "Delegated receiver for #{path} was resolved to nil from `#{print_chain(@receiver_chain)}'"
|
|
80
85
|
return
|
|
81
86
|
end
|
|
82
87
|
|
|
88
|
+
# @sg-ignore Need to add nil check here
|
|
83
89
|
receiver_type = resolver.return_type
|
|
84
90
|
|
|
91
|
+
# @sg-ignore Need to add nil check here
|
|
85
92
|
return if receiver_type.undefined?
|
|
86
93
|
|
|
87
94
|
receiver_path, method_scope =
|
|
95
|
+
# @sg-ignore Need to add nil check here
|
|
88
96
|
if @receiver_chain.constant?
|
|
89
97
|
# HACK: the `return_type` of a constant is Class<Whatever>, but looking up a method expects
|
|
90
98
|
# the arguments `"Whatever"` and `scope: :class`.
|
|
99
|
+
# @sg-ignore Need to add nil check here
|
|
91
100
|
[receiver_type.to_s.sub(/^Class<(.+)>$/, '\1'), :class]
|
|
92
101
|
else
|
|
102
|
+
# @sg-ignore Need to add nil check here
|
|
93
103
|
[receiver_type.to_s, :instance]
|
|
94
104
|
end
|
|
95
105
|
|
|
106
|
+
# @sg-ignore Need to add nil check here
|
|
96
107
|
method_stack = api_map.get_method_stack(receiver_path, @receiver_method_name, scope: method_scope)
|
|
97
108
|
@resolved_method = method_stack.first
|
|
98
109
|
end
|
|
@@ -101,10 +112,10 @@ module Solargraph
|
|
|
101
112
|
#
|
|
102
113
|
# @param chain [Source::Chain]
|
|
103
114
|
# @return [String]
|
|
104
|
-
def print_chain
|
|
115
|
+
def print_chain chain
|
|
105
116
|
out = +''
|
|
106
117
|
chain.links.each_with_index do |link, index|
|
|
107
|
-
if index
|
|
118
|
+
if index.positive?
|
|
108
119
|
if Source::Chain::Constant
|
|
109
120
|
out << '::' unless link.word.start_with?('::')
|
|
110
121
|
else
|
|
@@ -62,7 +62,7 @@ module Solargraph
|
|
|
62
62
|
|
|
63
63
|
# @return [String]
|
|
64
64
|
def to_code
|
|
65
|
-
"\n```ruby\n#{Documenting.normalize_indentation(@plaintext)}#{@plaintext.end_with?("\n")
|
|
65
|
+
"\n```ruby\n#{Documenting.normalize_indentation(@plaintext)}#{"\n" unless @plaintext.end_with?("\n")}```\n\n"
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# @return [String]
|
|
@@ -78,7 +78,8 @@ module Solargraph
|
|
|
78
78
|
# line and at least two spaces of indentation. This is a common
|
|
79
79
|
# convention in Ruby core documentation, e.g., String#split.
|
|
80
80
|
sections = [DocSection.new(false)]
|
|
81
|
-
Documenting.normalize_indentation(Documenting.strip_html_comments(docstring.to_s.gsub("\t",
|
|
81
|
+
Documenting.normalize_indentation(Documenting.strip_html_comments(docstring.to_s.gsub("\t",
|
|
82
|
+
' '))).lines.each do |l|
|
|
82
83
|
if l.start_with?(' ')
|
|
83
84
|
# Code block
|
|
84
85
|
sections.push DocSection.new(true) unless sections.last.code?
|
|
@@ -104,6 +105,7 @@ module Solargraph
|
|
|
104
105
|
left = text.lines.map do |line|
|
|
105
106
|
match = line.match(/^ +/)
|
|
106
107
|
next 0 unless match
|
|
108
|
+
# @sg-ignore Need to add nil check here
|
|
107
109
|
match[0].length
|
|
108
110
|
end.min
|
|
109
111
|
return text if left.nil? || left.zero?
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
5
|
class InstanceVariable < BaseVariable
|
|
6
|
-
# @
|
|
6
|
+
# @sg-ignore Need to add nil check here
|
|
7
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
7
8
|
def binder
|
|
9
|
+
# @sg-ignore Need to add nil check here
|
|
8
10
|
closure.binder
|
|
9
11
|
end
|
|
10
12
|
|
|
13
|
+
# @sg-ignore Need to add nil check here
|
|
11
14
|
# @return [::Symbol]
|
|
12
15
|
def scope
|
|
16
|
+
# @sg-ignore Need to add nil check here
|
|
13
17
|
closure.binder.scope
|
|
14
18
|
end
|
|
15
19
|
|