solargraph 0.58.3 → 0.59.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 +12 -5
- data/.github/workflows/plugins.yml +54 -34
- data/.github/workflows/rspec.yml +15 -28
- data/.github/workflows/typecheck.yml +6 -3
- data/.rubocop.yml +38 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +24 -0
- 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 +12 -3
- data/lib/solargraph/api_map/index.rb +29 -18
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +40 -30
- data/lib/solargraph/api_map.rb +160 -78
- data/lib/solargraph/bench.rb +2 -3
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +31 -18
- data/lib/solargraph/complex_type/unique_type.rb +221 -63
- data/lib/solargraph/complex_type.rb +173 -59
- data/lib/solargraph/convention/active_support_concern.rb +111 -111
- data/lib/solargraph/convention/base.rb +50 -50
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -1
- 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 +1 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/rakefile.rb +1 -1
- 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 +2 -2
- data/lib/solargraph/converters/dd.rb +2 -0
- data/lib/solargraph/converters/dl.rb +2 -0
- data/lib/solargraph/converters/dt.rb +2 -0
- data/lib/solargraph/converters/misc.rb +2 -0
- 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 +4 -8
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/doc_map.rb +38 -39
- data/lib/solargraph/environ.rb +52 -52
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +4 -15
- data/lib/solargraph/language_server/error_codes.rb +10 -10
- 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 +35 -28
- data/lib/solargraph/language_server/message/base.rb +1 -1
- data/lib/solargraph/language_server/message/client/register_capability.rb +1 -3
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +6 -8
- 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 +7 -7
- data/lib/solargraph/language_server/message/extended/download_core.rb +2 -1
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/extended/search.rb +1 -1
- data/lib/solargraph/language_server/message/initialize.rb +20 -14
- data/lib/solargraph/language_server/message/initialized.rb +28 -28
- 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 +17 -10
- 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 +13 -6
- data/lib/solargraph/language_server/message/text_document/references.rb +17 -10
- data/lib/solargraph/language_server/message/text_document/rename.rb +20 -13
- 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/text_document.rb +28 -28
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +34 -28
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +38 -30
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +23 -17
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +1 -1
- data/lib/solargraph/language_server/progress.rb +143 -143
- data/lib/solargraph/language_server/request.rb +4 -2
- data/lib/solargraph/language_server/transport/adapter.rb +68 -68
- data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
- data/lib/solargraph/language_server/uri_helpers.rb +2 -2
- data/lib/solargraph/language_server.rb +20 -20
- data/lib/solargraph/library.rb +57 -38
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +22 -4
- data/lib/solargraph/page.rb +1 -1
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +324 -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 +30 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +51 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +181 -73
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
- 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 +11 -12
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +9 -8
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
- 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/namespace_node.rb +40 -40
- 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/sym_node.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -1
- 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 +2 -0
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +2 -0
- data/lib/solargraph/pin/base.rb +126 -82
- 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 +3 -5
- 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 +158 -104
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +102 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +20 -0
- data/lib/solargraph/pin/search.rb +8 -7
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/singleton.rb +11 -11
- 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 +22 -19
- data/lib/solargraph/position.rb +17 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +367 -231
- data/lib/solargraph/rbs_map/core_fills.rb +18 -11
- 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 +76 -32
- data/lib/solargraph/server_methods.rb +1 -1
- data/lib/solargraph/shell.rb +258 -66
- data/lib/solargraph/source/chain/array.rb +3 -12
- data/lib/solargraph/source/chain/block_symbol.rb +13 -13
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/call.rb +96 -56
- data/lib/solargraph/source/chain/class_variable.rb +1 -1
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/head.rb +19 -19
- 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 +12 -22
- data/lib/solargraph/source/chain/literal.rb +22 -15
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +2 -0
- data/lib/solargraph/source/chain/variable.rb +3 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -3
- data/lib/solargraph/source/chain.rb +51 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +33 -18
- 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 +54 -30
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +69 -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 +196 -122
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +14 -11
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +50 -28
- data/lib/solargraph/yard_map/cache.rb +25 -25
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
- 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_map.rb +17 -18
- data/lib/solargraph/yard_tags.rb +2 -2
- data/lib/solargraph/yardoc.rb +7 -4
- data/lib/solargraph.rb +33 -10
- data/rbs/fills/rubygems/0/dependency.rbs +193 -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 +37 -35
- metadata +41 -42
- 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
- data/rbs/fills/tuple/tuple.rbs +0 -149
|
@@ -15,6 +15,7 @@ module Solargraph
|
|
|
15
15
|
|
|
16
16
|
# @param decl [::Symbol] :arg, :optarg, :kwarg, :kwoptarg, :restarg, :kwrestarg, :block, :blockarg
|
|
17
17
|
# @param asgn_code [String, nil]
|
|
18
|
+
# @param [Hash{Symbol => Object}] splat
|
|
18
19
|
def initialize decl: :arg, asgn_code: nil, **splat
|
|
19
20
|
super(**splat)
|
|
20
21
|
@asgn_code = asgn_code
|
|
@@ -29,21 +30,41 @@ module Solargraph
|
|
|
29
30
|
super || closure&.type_location
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def combine_with
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
def combine_with other, attrs = {}
|
|
34
|
+
# Parameters can only be combined with local variables in the same closure
|
|
35
|
+
return self unless other.closure == closure
|
|
36
|
+
|
|
37
|
+
new_attrs = if other.is_a?(Parameter)
|
|
38
|
+
{
|
|
39
|
+
decl: assert_same(other, :decl),
|
|
40
|
+
asgn_code: choose(other, :asgn_code)
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
{
|
|
44
|
+
decl: decl,
|
|
45
|
+
asgn_code: asgn_code
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
super(other, new_attrs.merge(attrs))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def combine_return_type other
|
|
52
|
+
out = super
|
|
53
|
+
if out&.undefined?
|
|
54
|
+
# allow our return_type method to provide a better type
|
|
55
|
+
# using :param tag
|
|
56
|
+
out = nil
|
|
57
|
+
end
|
|
58
|
+
out
|
|
39
59
|
end
|
|
40
60
|
|
|
41
61
|
def keyword?
|
|
42
|
-
[
|
|
62
|
+
%i[kwarg kwoptarg].include?(decl)
|
|
43
63
|
end
|
|
44
64
|
|
|
45
65
|
def kwrestarg?
|
|
46
|
-
|
|
66
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
67
|
+
decl == :kwrestarg || (assignment && %i[HASH hash].include?(assignment.type))
|
|
47
68
|
end
|
|
48
69
|
|
|
49
70
|
def needs_consistent_name?
|
|
@@ -52,26 +73,31 @@ module Solargraph
|
|
|
52
73
|
|
|
53
74
|
# @return [String]
|
|
54
75
|
def arity_decl
|
|
55
|
-
name =
|
|
56
|
-
|
|
76
|
+
name = self.name || '(anon)'
|
|
77
|
+
return_type&.to_rbs || 'untyped'
|
|
57
78
|
case decl
|
|
58
79
|
when :arg
|
|
59
|
-
|
|
80
|
+
''
|
|
60
81
|
when :optarg
|
|
61
|
-
|
|
82
|
+
'?'
|
|
62
83
|
when :kwarg
|
|
63
84
|
"#{name}:"
|
|
64
85
|
when :kwoptarg
|
|
65
86
|
"?#{name}:"
|
|
66
87
|
when :restarg
|
|
67
|
-
|
|
88
|
+
'*'
|
|
68
89
|
when :kwrestarg
|
|
69
|
-
|
|
90
|
+
'**'
|
|
70
91
|
else
|
|
71
92
|
"(unknown decl: #{decl})"
|
|
72
93
|
end
|
|
73
94
|
end
|
|
74
95
|
|
|
96
|
+
# @return [String]
|
|
97
|
+
def type_arity_decl
|
|
98
|
+
arity_decl + return_type.items.count.to_s
|
|
99
|
+
end
|
|
100
|
+
|
|
75
101
|
def arg?
|
|
76
102
|
decl == :arg
|
|
77
103
|
end
|
|
@@ -80,12 +106,20 @@ module Solargraph
|
|
|
80
106
|
decl == :restarg
|
|
81
107
|
end
|
|
82
108
|
|
|
109
|
+
def mandatory_positional?
|
|
110
|
+
decl == :arg
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def positional?
|
|
114
|
+
!keyword?
|
|
115
|
+
end
|
|
116
|
+
|
|
83
117
|
def rest?
|
|
84
|
-
|
|
118
|
+
%i[restarg kwrestarg].include?(decl)
|
|
85
119
|
end
|
|
86
120
|
|
|
87
121
|
def block?
|
|
88
|
-
[
|
|
122
|
+
%i[block blockarg].include?(decl)
|
|
89
123
|
end
|
|
90
124
|
|
|
91
125
|
def to_rbs
|
|
@@ -123,6 +157,11 @@ module Solargraph
|
|
|
123
157
|
end
|
|
124
158
|
end
|
|
125
159
|
|
|
160
|
+
def reset_generated!
|
|
161
|
+
@return_type = nil if param_tag
|
|
162
|
+
super
|
|
163
|
+
end
|
|
164
|
+
|
|
126
165
|
# @return [String]
|
|
127
166
|
def full
|
|
128
167
|
full_name + case decl
|
|
@@ -135,50 +174,67 @@ module Solargraph
|
|
|
135
174
|
end
|
|
136
175
|
end
|
|
137
176
|
|
|
177
|
+
# @sg-ignore super always sets @return_type to something
|
|
138
178
|
# @return [ComplexType]
|
|
139
179
|
def return_type
|
|
140
180
|
if @return_type.nil?
|
|
141
181
|
@return_type = ComplexType::UNDEFINED
|
|
142
182
|
found = param_tag
|
|
143
|
-
@return_type = ComplexType.try_parse(*found.types) unless found.nil?
|
|
183
|
+
@return_type = ComplexType.try_parse(*found.types) unless found.nil? || found.types.nil?
|
|
184
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
144
185
|
if @return_type.undefined?
|
|
145
|
-
|
|
186
|
+
case decl
|
|
187
|
+
when :restarg
|
|
146
188
|
@return_type = ComplexType.try_parse('::Array')
|
|
147
|
-
|
|
189
|
+
when :kwrestarg
|
|
148
190
|
@return_type = ComplexType.try_parse('::Hash')
|
|
149
|
-
|
|
191
|
+
when :blockarg
|
|
150
192
|
@return_type = ComplexType.try_parse('::Proc')
|
|
151
193
|
end
|
|
152
194
|
end
|
|
153
195
|
end
|
|
154
196
|
super
|
|
155
|
-
@return_type
|
|
156
197
|
end
|
|
157
198
|
|
|
158
199
|
# The parameter's zero-based location in the block's signature.
|
|
159
200
|
#
|
|
201
|
+
# @sg-ignore Need to add nil check here
|
|
160
202
|
# @return [Integer]
|
|
161
203
|
def index
|
|
162
|
-
# @type [Method, Block]
|
|
163
204
|
method_pin = closure
|
|
205
|
+
# @sg-ignore Need to add nil check here
|
|
164
206
|
method_pin.parameter_names.index(name)
|
|
165
207
|
end
|
|
166
208
|
|
|
167
209
|
# @param api_map [ApiMap]
|
|
168
210
|
def typify api_map
|
|
169
|
-
|
|
170
|
-
|
|
211
|
+
new_type = super
|
|
212
|
+
return new_type if new_type.defined?
|
|
213
|
+
|
|
214
|
+
# sniff based on param tags
|
|
215
|
+
new_type = closure.is_a?(Pin::Block) ? typify_block_param(api_map) : typify_method_param(api_map)
|
|
216
|
+
|
|
217
|
+
return adjust_type api_map, new_type.self_to_type(full_context) if new_type.defined?
|
|
218
|
+
|
|
219
|
+
adjust_type api_map, super.self_to_type(full_context)
|
|
171
220
|
end
|
|
172
221
|
|
|
173
222
|
# @param atype [ComplexType]
|
|
174
223
|
# @param api_map [ApiMap]
|
|
175
|
-
def compatible_arg?
|
|
224
|
+
def compatible_arg? atype, api_map
|
|
176
225
|
# make sure we get types from up the method
|
|
177
226
|
# inheritance chain if we don't have them on this pin
|
|
178
227
|
ptype = typify api_map
|
|
179
|
-
|
|
228
|
+
return true if ptype.undefined?
|
|
229
|
+
|
|
230
|
+
return true if atype.conforms_to?(api_map,
|
|
231
|
+
ptype,
|
|
232
|
+
:method_call,
|
|
233
|
+
%i[allow_empty_params allow_undefined])
|
|
234
|
+
ptype.generic?
|
|
180
235
|
end
|
|
181
236
|
|
|
237
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
182
238
|
def documentation
|
|
183
239
|
tag = param_tag
|
|
184
240
|
return '' if tag.nil? || tag.text.nil?
|
|
@@ -187,12 +243,19 @@ module Solargraph
|
|
|
187
243
|
|
|
188
244
|
private
|
|
189
245
|
|
|
246
|
+
def generate_complex_type
|
|
247
|
+
nil
|
|
248
|
+
end
|
|
249
|
+
|
|
190
250
|
# @return [YARD::Tags::Tag, nil]
|
|
191
251
|
def param_tag
|
|
252
|
+
# @sg-ignore Need to add nil check here
|
|
192
253
|
params = closure.docstring.tags(:param)
|
|
254
|
+
# @sg-ignore Need to add nil check here
|
|
193
255
|
params.each do |p|
|
|
194
256
|
return p if p.name == name
|
|
195
257
|
end
|
|
258
|
+
# @sg-ignore Need to add nil check here
|
|
196
259
|
params[index] if index && params[index] && (params[index].name.nil? || params[index].name.empty?)
|
|
197
260
|
end
|
|
198
261
|
|
|
@@ -200,15 +263,14 @@ module Solargraph
|
|
|
200
263
|
# @return [ComplexType]
|
|
201
264
|
def typify_block_param api_map
|
|
202
265
|
block_pin = closure
|
|
203
|
-
if block_pin.is_a?(Pin::Block) && block_pin.receiver
|
|
204
|
-
return block_pin.typify_parameters(api_map)[index]
|
|
205
|
-
end
|
|
266
|
+
return block_pin.typify_parameters(api_map)[index] if block_pin.is_a?(Pin::Block) && block_pin.receiver && index
|
|
206
267
|
ComplexType::UNDEFINED
|
|
207
268
|
end
|
|
208
269
|
|
|
209
270
|
# @param api_map [ApiMap]
|
|
210
271
|
# @return [ComplexType]
|
|
211
272
|
def typify_method_param api_map
|
|
273
|
+
# @sg-ignore Need to add nil check here
|
|
212
274
|
meths = api_map.get_method_stack(closure.full_context.tag, closure.name, scope: closure.scope)
|
|
213
275
|
# meths.shift # Ignore the first one
|
|
214
276
|
meths.each do |meth|
|
|
@@ -219,10 +281,14 @@ module Solargraph
|
|
|
219
281
|
found = p
|
|
220
282
|
break
|
|
221
283
|
end
|
|
222
|
-
if found.nil?
|
|
223
|
-
found = params[index]
|
|
284
|
+
if found.nil? && !index.nil? && params[index] && (params[index].name.nil? || params[index].name.empty?)
|
|
285
|
+
found = params[index]
|
|
286
|
+
end
|
|
287
|
+
unless found.nil? || found.types.nil?
|
|
288
|
+
return ComplexType.try_parse(*found.types).qualify(api_map,
|
|
289
|
+
# @sg-ignore Need to add nil check here
|
|
290
|
+
*meth.closure.gates)
|
|
224
291
|
end
|
|
225
|
-
return ComplexType.try_parse(*found.types).qualify(api_map, *meth.closure.gates) unless found.nil? || found.types.nil?
|
|
226
292
|
end
|
|
227
293
|
ComplexType::UNDEFINED
|
|
228
294
|
end
|
|
@@ -230,6 +296,7 @@ module Solargraph
|
|
|
230
296
|
# @param heredoc [YARD::Docstring]
|
|
231
297
|
# @param api_map [ApiMap]
|
|
232
298
|
# @param skip [::Array]
|
|
299
|
+
#
|
|
233
300
|
# @return [::Array<YARD::Tags::Tag>]
|
|
234
301
|
def see_reference heredoc, api_map, skip = []
|
|
235
302
|
# This should actually be an intersection type
|
|
@@ -237,7 +304,7 @@ module Solargraph
|
|
|
237
304
|
heredoc.ref_tags.each do |ref|
|
|
238
305
|
# @sg-ignore ref should actually be an intersection type
|
|
239
306
|
next unless ref.tag_name == 'param' && ref.owner
|
|
240
|
-
# @
|
|
307
|
+
# @todo ref should actually be an intersection type
|
|
241
308
|
result = resolve_reference(ref.owner.to_s, api_map, skip)
|
|
242
309
|
return result unless result.nil?
|
|
243
310
|
end
|
|
@@ -257,14 +324,13 @@ module Solargraph
|
|
|
257
324
|
else
|
|
258
325
|
fqns = api_map.qualify(parts.first, namespace)
|
|
259
326
|
return nil if fqns.nil?
|
|
327
|
+
# @sg-ignore Need to add nil check here
|
|
260
328
|
path = fqns + ref[parts.first.length] + parts.last
|
|
261
329
|
end
|
|
262
330
|
pins = api_map.get_path_pins(path)
|
|
263
331
|
pins.each do |pin|
|
|
264
332
|
params = pin.docstring.tags(:param)
|
|
265
333
|
return params unless params.empty?
|
|
266
|
-
end
|
|
267
|
-
pins.each do |pin|
|
|
268
334
|
params = see_reference(pin.docstring, api_map, skip)
|
|
269
335
|
return params unless params.empty?
|
|
270
336
|
end
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
5
|
class ProxyType < Base
|
|
6
|
-
# @param return_type [ComplexType]
|
|
6
|
+
# @param return_type [ComplexType, ComplexType::UniqueType]
|
|
7
7
|
# @param gates [Array<String>, nil] Namespaces to try while resolving non-rooted types
|
|
8
8
|
# @param binder [ComplexType, ComplexType::UniqueType, nil]
|
|
9
9
|
# @param gates [Array<String>, nil]
|
|
10
|
+
# @param [Hash{Symbol => Object}] splat
|
|
10
11
|
def initialize return_type: ComplexType::UNDEFINED, binder: nil, gates: nil, **splat
|
|
11
12
|
super(**splat)
|
|
12
13
|
@gates = gates
|
|
@@ -22,9 +23,11 @@ module Solargraph
|
|
|
22
23
|
# @param closure [Pin::Namespace, nil] Used as the closure for this pin
|
|
23
24
|
# @param binder [ComplexType, ComplexType::UniqueType, nil]
|
|
24
25
|
# @return [ProxyType]
|
|
26
|
+
# @param [Hash{Symbol => Object}] kwargs
|
|
25
27
|
def self.anonymous context, closure: nil, binder: nil, **kwargs
|
|
26
28
|
unless closure
|
|
27
29
|
parts = context.namespace.split('::')
|
|
30
|
+
# @sg-ignore Need to add nil check here
|
|
28
31
|
namespace = parts[0..-2].join('::').to_s
|
|
29
32
|
closure = Solargraph::Pin::Namespace.new(name: namespace, source: :proxy_type)
|
|
30
33
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Pin
|
|
5
|
-
class Reference
|
|
6
|
-
class Require < Reference
|
|
7
|
-
def initialize location, name, **splat
|
|
8
|
-
# super(location, '', name)
|
|
9
|
-
super(location: location, name: name, closure: Pin::ROOT_PIN, **splat)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
class Reference
|
|
6
|
+
class Require < Reference
|
|
7
|
+
def initialize location, name, **splat
|
|
8
|
+
# super(location, '', name)
|
|
9
|
+
super(location: location, name: name, closure: Pin::ROOT_PIN, **splat)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
class Reference
|
|
6
|
+
class TypeAlias < Reference
|
|
7
|
+
# @param return_type [ComplexType]
|
|
8
|
+
# @param [Hash{Symbol => Object}] splat
|
|
9
|
+
def initialize return_type:, **splat
|
|
10
|
+
super(**splat)
|
|
11
|
+
@return_type = return_type
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -9,10 +9,28 @@ module Solargraph
|
|
|
9
9
|
autoload :Prepend, 'solargraph/pin/reference/prepend'
|
|
10
10
|
autoload :Extend, 'solargraph/pin/reference/extend'
|
|
11
11
|
autoload :Override, 'solargraph/pin/reference/override'
|
|
12
|
+
autoload :TypeAlias, 'solargraph/pin/reference/type_alias'
|
|
12
13
|
|
|
13
14
|
attr_reader :generic_values
|
|
14
15
|
|
|
16
|
+
# A Reference is a pin that associates a type with another type.
|
|
17
|
+
# The existing type is marked as the closure. The name of the
|
|
18
|
+
# type we're associating with it is the 'name' field, and
|
|
19
|
+
# subtypes are in the 'generic_values' field.
|
|
20
|
+
#
|
|
21
|
+
# These pins are a little different - the name is a rooted name,
|
|
22
|
+
# which may be relative or absolute, preceded with ::, not a
|
|
23
|
+
# fully qualified namespace, which is implicitly in the root
|
|
24
|
+
# namespace and is never preceded by ::.
|
|
25
|
+
#
|
|
26
|
+
# @todo can the above be represented in a less subtle way?
|
|
27
|
+
# @todo consider refactoring so that we can replicate more
|
|
28
|
+
# complex types like Hash{String => Integer} and has both key
|
|
29
|
+
# types and subtypes.
|
|
30
|
+
#
|
|
31
|
+
# @param name [String] rooted name of the referenced type
|
|
15
32
|
# @param generic_values [Array<String>]
|
|
33
|
+
# @param [Hash{Symbol => Object}] splat
|
|
16
34
|
def initialize generic_values: [], **splat
|
|
17
35
|
super(**splat)
|
|
18
36
|
@generic_values = generic_values
|
|
@@ -30,8 +48,10 @@ module Solargraph
|
|
|
30
48
|
)
|
|
31
49
|
end
|
|
32
50
|
|
|
51
|
+
# @sg-ignore Need to add nil check here
|
|
33
52
|
# @return [Array<String>]
|
|
34
53
|
def reference_gates
|
|
54
|
+
# @sg-ignore Need to add nil check here
|
|
35
55
|
closure.gates
|
|
36
56
|
end
|
|
37
57
|
end
|
|
@@ -41,19 +41,20 @@ module Solargraph
|
|
|
41
41
|
match = [fuzzy_string_match(pin.path, @query), fuzzy_string_match(pin.name, @query)].max
|
|
42
42
|
Result.new(match, pin) if match > 0.7
|
|
43
43
|
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
.compact
|
|
45
|
+
# @param a [self]
|
|
46
|
+
# @param b [self]
|
|
47
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1050
|
|
48
|
+
.sort { |a, b| b.match <=> a.match }
|
|
49
|
+
.map(&:pin)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# @param str1 [String]
|
|
53
53
|
# @param str2 [String]
|
|
54
|
+
#
|
|
54
55
|
# @return [Float]
|
|
55
56
|
def fuzzy_string_match str1, str2
|
|
56
|
-
return 1.0 + (str2.length.to_f / str1.length
|
|
57
|
+
return 1.0 + (str2.length.to_f / str1.length) if str1.downcase.include?(str2.downcase)
|
|
57
58
|
JaroWinkler.similarity(str1, str2, ignore_case: true)
|
|
58
59
|
end
|
|
59
60
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Solargraph
|
|
2
4
|
module Pin
|
|
3
5
|
class Signature < Callable
|
|
@@ -5,11 +7,8 @@ module Solargraph
|
|
|
5
7
|
# to the method pin
|
|
6
8
|
attr_writer :closure
|
|
7
9
|
|
|
8
|
-
def initialize **splat
|
|
9
|
-
super(**splat)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
10
|
def generics
|
|
11
|
+
# @type [Array<::String, nil>]
|
|
13
12
|
@generics ||= [].freeze
|
|
14
13
|
end
|
|
15
14
|
|
|
@@ -17,8 +16,7 @@ module Solargraph
|
|
|
17
16
|
@identity ||= "signature#{object_id}"
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
# @ sg-ignore need boolish support for ? methods
|
|
22
20
|
def dodgy_return_type_source?
|
|
23
21
|
super || closure&.dodgy_return_type_source?
|
|
24
22
|
end
|
|
@@ -32,8 +30,11 @@ module Solargraph
|
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def typify api_map
|
|
33
|
+
# @sg-ignore Need to add nil check here
|
|
35
34
|
if return_type.defined?
|
|
35
|
+
# @sg-ignore Need to add nil check here
|
|
36
36
|
qualified = return_type.qualify(api_map, closure.namespace)
|
|
37
|
+
# @sg-ignore Need to add nil check here
|
|
37
38
|
logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
|
|
38
39
|
return qualified
|
|
39
40
|
end
|
|
@@ -44,13 +45,15 @@ module Solargraph
|
|
|
44
45
|
method_stack = closure.rest_of_stack api_map
|
|
45
46
|
logger.debug { "Signature#typify(self=#{self}) - method_stack: #{method_stack}" }
|
|
46
47
|
method_stack.each do |pin|
|
|
47
|
-
sig = pin.signatures.find { |s| s.arity ==
|
|
48
|
+
sig = pin.signatures.find { |s| s.arity == arity }
|
|
48
49
|
next unless sig
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
# @sg-ignore Need to add nil check here
|
|
51
|
+
next if sig.return_type.undefined?
|
|
52
|
+
# @sg-ignore Need to add nil check here
|
|
53
|
+
qualified = sig.return_type.qualify(api_map, closure.namespace)
|
|
54
|
+
# @sg-ignore Need to add nil check here
|
|
55
|
+
logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
|
|
56
|
+
return qualified
|
|
54
57
|
end
|
|
55
58
|
out = super
|
|
56
59
|
logger.debug { "Signature#typify(self=#{self}) => #{out}" }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
module Pin
|
|
5
|
-
class Singleton < Closure
|
|
6
|
-
def initialize name: '', location: nil, closure: nil, **splat
|
|
7
|
-
super
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
module Pin
|
|
5
|
+
class Singleton < Closure
|
|
6
|
+
def initialize name: '', location: nil, closure: nil, **splat
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
5
|
class Symbol < Base
|
|
6
|
-
# @param location [Solargraph::Location]
|
|
6
|
+
# @param location [Solargraph::Location, nil]
|
|
7
7
|
# @param name [String]
|
|
8
|
+
# @param [Hash{Symbol => Object}] kwargs
|
|
8
9
|
def initialize(location, name, **kwargs)
|
|
9
10
|
# @sg-ignore "Unrecognized keyword argument kwargs to Solargraph::Pin::Base#initialize"
|
|
10
11
|
super(location: location, name: name, **kwargs)
|
data/lib/solargraph/pin/until.rb
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
|
-
class Until <
|
|
5
|
+
class Until < CompoundStatement
|
|
6
6
|
include Breakable
|
|
7
7
|
|
|
8
|
-
# @param receiver [Parser::AST::Node, nil]
|
|
9
8
|
# @param node [Parser::AST::Node, nil]
|
|
10
|
-
# @param
|
|
11
|
-
# @param args [::Array<Parameter>]
|
|
9
|
+
# @param [Hash{Symbol => Object}] splat
|
|
12
10
|
def initialize node: nil, **splat
|
|
13
11
|
super(**splat)
|
|
14
12
|
@node = node
|
data/lib/solargraph/pin/while.rb
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module Solargraph
|
|
4
4
|
module Pin
|
|
5
|
-
class While <
|
|
5
|
+
class While < CompoundStatement
|
|
6
6
|
include Breakable
|
|
7
7
|
|
|
8
|
-
# @param receiver [Parser::AST::Node, nil]
|
|
9
8
|
# @param node [Parser::AST::Node, nil]
|
|
10
|
-
# @param
|
|
11
|
-
# @param args [::Array<Parameter>]
|
|
9
|
+
# @param [Hash{Symbol => Object}] splat
|
|
12
10
|
def initialize node: nil, **splat
|
|
13
11
|
super(**splat)
|
|
14
12
|
@node = node
|
data/lib/solargraph/pin.rb
CHANGED
|
@@ -38,6 +38,8 @@ module Solargraph
|
|
|
38
38
|
autoload :Until, 'solargraph/pin/until'
|
|
39
39
|
autoload :While, 'solargraph/pin/while'
|
|
40
40
|
autoload :Callable, 'solargraph/pin/callable'
|
|
41
|
+
autoload :CompoundStatement,
|
|
42
|
+
'solargraph/pin/compound_statement'
|
|
41
43
|
|
|
42
44
|
ROOT_PIN = Pin::Namespace.new(type: :class, name: '', closure: nil, source: :pin_rb)
|
|
43
45
|
end
|