solargraph 0.47.2 → 0.54.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/FUNDING.yml +1 -0
- data/.github/workflows/plugins.yml +40 -0
- data/.github/workflows/rspec.yml +4 -8
- data/.github/workflows/typecheck.yml +34 -0
- data/.yardopts +2 -2
- data/CHANGELOG.md +166 -3
- data/LICENSE +1 -1
- data/README.md +19 -16
- data/SPONSORS.md +2 -9
- data/lib/solargraph/api_map/cache.rb +50 -20
- data/lib/solargraph/api_map/source_to_yard.rb +17 -10
- data/lib/solargraph/api_map/store.rb +68 -15
- data/lib/solargraph/api_map.rb +238 -112
- data/lib/solargraph/bench.rb +3 -2
- data/lib/solargraph/cache.rb +77 -0
- data/lib/solargraph/complex_type/type_methods.rb +116 -35
- data/lib/solargraph/complex_type/unique_type.rb +261 -33
- data/lib/solargraph/complex_type.rb +149 -30
- data/lib/solargraph/convention/rakefile.rb +17 -0
- data/lib/solargraph/convention.rb +2 -3
- data/lib/solargraph/converters/dd.rb +5 -0
- data/lib/solargraph/converters/dl.rb +3 -0
- data/lib/solargraph/converters/dt.rb +3 -0
- data/lib/solargraph/diagnostics/rubocop.rb +23 -8
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +4 -1
- data/lib/solargraph/diagnostics/type_check.rb +1 -0
- data/lib/solargraph/diagnostics.rb +2 -2
- data/lib/solargraph/doc_map.rb +187 -0
- data/lib/solargraph/gem_pins.rb +72 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
- data/lib/solargraph/language_server/host/dispatch.rb +22 -5
- data/lib/solargraph/language_server/host/message_worker.rb +4 -0
- data/lib/solargraph/language_server/host/sources.rb +8 -65
- data/lib/solargraph/language_server/host.rb +88 -93
- data/lib/solargraph/language_server/message/base.rb +1 -1
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
- data/lib/solargraph/language_server/message/extended/download_core.rb +1 -5
- data/lib/solargraph/language_server/message/initialize.rb +27 -0
- data/lib/solargraph/language_server/message/initialized.rb +1 -0
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +4 -1
- data/lib/solargraph/language_server/message/text_document/formatting.rb +5 -4
- data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -6
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
- data/lib/solargraph/language_server/message/text_document.rb +1 -1
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +10 -3
- data/lib/solargraph/language_server/message.rb +1 -0
- data/lib/solargraph/language_server/progress.rb +118 -0
- data/lib/solargraph/language_server/transport/adapter.rb +16 -1
- data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
- data/lib/solargraph/language_server.rb +1 -0
- data/lib/solargraph/library.rb +231 -104
- data/lib/solargraph/location.rb +1 -0
- data/lib/solargraph/page.rb +6 -0
- data/lib/solargraph/parser/comment_ripper.rb +4 -0
- data/lib/solargraph/parser/node_methods.rb +47 -7
- data/lib/solargraph/parser/node_processor/base.rb +11 -1
- data/lib/solargraph/parser/node_processor.rb +1 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -9
- data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
- data/lib/solargraph/parser/parser_gem/node_methods.rb +495 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +14 -4
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/cvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +7 -20
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +47 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +7 -5
- data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors.rb +56 -0
- data/lib/solargraph/parser/parser_gem.rb +12 -0
- data/lib/solargraph/parser/region.rb +1 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +9 -10
- data/lib/solargraph/pin/base.rb +69 -11
- data/lib/solargraph/pin/base_variable.rb +40 -7
- data/lib/solargraph/pin/block.rb +81 -33
- data/lib/solargraph/pin/closure.rb +17 -2
- data/lib/solargraph/pin/common.rb +7 -3
- data/lib/solargraph/pin/conversions.rb +34 -8
- data/lib/solargraph/pin/delegated_method.rb +101 -0
- data/lib/solargraph/pin/documenting.rb +25 -32
- data/lib/solargraph/pin/instance_variable.rb +4 -0
- data/lib/solargraph/pin/local_variable.rb +13 -1
- data/lib/solargraph/pin/method.rb +273 -17
- data/lib/solargraph/pin/namespace.rb +17 -1
- data/lib/solargraph/pin/parameter.rb +40 -28
- data/lib/solargraph/pin/reference/override.rb +2 -2
- data/lib/solargraph/pin/reference.rb +8 -0
- data/lib/solargraph/pin/search.rb +4 -4
- data/lib/solargraph/pin/signature.rb +143 -0
- data/lib/solargraph/pin.rb +2 -1
- data/lib/solargraph/range.rb +4 -6
- data/lib/solargraph/rbs_map/conversions.rb +607 -0
- data/lib/solargraph/rbs_map/core_fills.rb +50 -0
- data/lib/solargraph/rbs_map/core_map.rb +28 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
- data/lib/solargraph/rbs_map.rb +92 -0
- data/lib/solargraph/shell.rb +85 -59
- data/lib/solargraph/source/chain/array.rb +32 -0
- data/lib/solargraph/source/chain/block_symbol.rb +13 -0
- data/lib/solargraph/source/chain/call.rb +125 -61
- data/lib/solargraph/source/chain/constant.rb +15 -1
- data/lib/solargraph/source/chain/if.rb +23 -0
- data/lib/solargraph/source/chain/link.rb +8 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +3 -3
- data/lib/solargraph/source/chain.rb +64 -14
- data/lib/solargraph/source/change.rb +3 -0
- data/lib/solargraph/source/cursor.rb +2 -0
- data/lib/solargraph/source/source_chainer.rb +8 -5
- data/lib/solargraph/source/updater.rb +1 -0
- data/lib/solargraph/source.rb +18 -63
- data/lib/solargraph/source_map/clip.rb +31 -23
- data/lib/solargraph/source_map/mapper.rb +23 -7
- data/lib/solargraph/source_map.rb +36 -11
- data/lib/solargraph/type_checker/checks.rb +10 -2
- data/lib/solargraph/type_checker.rb +229 -100
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +2 -2
- data/lib/solargraph/workspace/config.rb +15 -11
- data/lib/solargraph/workspace.rb +41 -17
- data/lib/solargraph/yard_map/cache.rb +6 -0
- data/lib/solargraph/yard_map/helpers.rb +1 -1
- data/lib/solargraph/yard_map/mapper/to_method.rb +23 -7
- data/lib/solargraph/yard_map/mapper.rb +1 -1
- data/lib/solargraph/yard_map/to_method.rb +11 -4
- data/lib/solargraph/yard_map.rb +1 -443
- data/lib/solargraph/yard_tags.rb +20 -0
- data/lib/solargraph/yardoc.rb +52 -0
- data/lib/solargraph.rb +8 -6
- data/solargraph.gemspec +19 -8
- metadata +164 -99
- data/.travis.yml +0 -19
- data/lib/solargraph/api_map/bundler_methods.rb +0 -22
- data/lib/solargraph/compat.rb +0 -37
- data/lib/solargraph/convention/rspec.rb +0 -30
- data/lib/solargraph/documentor.rb +0 -76
- data/lib/solargraph/language_server/host/cataloger.rb +0 -56
- data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
- data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +0 -23
- data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
- data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
- data/lib/solargraph/parser/legacy.rb +0 -12
- data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
- data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
- data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
- data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
- data/lib/solargraph/parser/rubyvm.rb +0 -40
- data/lib/solargraph/yard_map/core_docs.rb +0 -170
- data/lib/solargraph/yard_map/core_fills.rb +0 -208
- data/lib/solargraph/yard_map/core_gen.rb +0 -76
- data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
- data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
- data/lib/yard-solargraph.rb +0 -33
- data/yardoc/2.2.2.tar.gz +0 -0
@@ -7,7 +7,7 @@ module Solargraph
|
|
7
7
|
class Method < Closure
|
8
8
|
include Solargraph::Parser::NodeMethods
|
9
9
|
|
10
|
-
# @return [Array<Pin::Parameter>]
|
10
|
+
# @return [::Array<Pin::Parameter>]
|
11
11
|
attr_reader :parameters
|
12
12
|
|
13
13
|
# @return [::Symbol] :public, :private, or :protected
|
@@ -18,16 +18,66 @@ module Solargraph
|
|
18
18
|
|
19
19
|
# @param visibility [::Symbol] :public, :protected, or :private
|
20
20
|
# @param explicit [Boolean]
|
21
|
-
|
21
|
+
# @param parameters [::Array<Pin::Parameter>]
|
22
|
+
# @param block [Pin::Signature, nil, ::Symbol]
|
23
|
+
# @param node [Parser::AST::Node, RubyVM::AbstractSyntaxTree::Node, nil]
|
24
|
+
# @param attribute [Boolean]
|
25
|
+
# @param signatures [::Array<Signature>, nil]
|
26
|
+
# @param anon_splat [Boolean]
|
27
|
+
# @param return_type [ComplexType, nil]
|
28
|
+
def initialize visibility: :public, explicit: true, parameters: [], block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false, return_type: nil, **splat
|
22
29
|
super(**splat)
|
23
30
|
@visibility = visibility
|
24
31
|
@explicit = explicit
|
25
32
|
@parameters = parameters
|
33
|
+
@block = block
|
26
34
|
@node = node
|
27
35
|
@attribute = attribute
|
36
|
+
@signatures = signatures
|
37
|
+
@anon_splat = anon_splat
|
38
|
+
@return_type = return_type
|
28
39
|
end
|
29
40
|
|
30
|
-
|
41
|
+
def transform_types(&transform)
|
42
|
+
# @todo 'super' alone should work here I think, but doesn't typecheck at level typed
|
43
|
+
m = super(&transform)
|
44
|
+
m.signatures = m.signatures.map do |sig|
|
45
|
+
sig.transform_types(&transform)
|
46
|
+
end
|
47
|
+
m.parameters = m.parameters.map do |param|
|
48
|
+
param.transform_types(&transform)
|
49
|
+
end
|
50
|
+
m.block = block&.transform_types(&transform)
|
51
|
+
m.signature_help = nil
|
52
|
+
m.documentation = nil
|
53
|
+
m
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param signature [Pin::Signature]
|
57
|
+
# @return [Pin::Method]
|
58
|
+
def with_single_signature(signature)
|
59
|
+
m = proxy signature.return_type
|
60
|
+
m.signature_help = nil
|
61
|
+
m.documentation = nil
|
62
|
+
# @todo populating the single parameters/return_type/block
|
63
|
+
# arguments here seems to be needed for some specs to pass,
|
64
|
+
# even though we have a signature with the same information.
|
65
|
+
# Is this a problem for RBS-populated methods, which don't
|
66
|
+
# populate these three?
|
67
|
+
m.parameters = signature.parameters
|
68
|
+
m.return_type = signature.return_type
|
69
|
+
m.block = signature.block
|
70
|
+
m.signatures = [signature]
|
71
|
+
m
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Pin::Signature, nil]
|
75
|
+
def block
|
76
|
+
return @block unless @block == :undefined
|
77
|
+
@block = signatures.first.block
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [::Array<String>]
|
31
81
|
def parameter_names
|
32
82
|
@parameter_names ||= parameters.map(&:name)
|
33
83
|
end
|
@@ -41,7 +91,100 @@ module Solargraph
|
|
41
91
|
end
|
42
92
|
|
43
93
|
def return_type
|
44
|
-
@return_type ||=
|
94
|
+
@return_type ||= ComplexType.new(signatures.map(&:return_type).flat_map(&:items))
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param parameters [::Array<Parameter>]
|
98
|
+
# @param return_type [ComplexType]
|
99
|
+
# @return [Signature]
|
100
|
+
def generate_signature(parameters, return_type)
|
101
|
+
block = nil
|
102
|
+
yieldparam_tags = docstring.tags(:yieldparam)
|
103
|
+
yieldreturn_tags = docstring.tags(:yieldreturn)
|
104
|
+
generics = docstring.tags(:generic).map(&:name)
|
105
|
+
needs_block_param_signature =
|
106
|
+
parameters.last&.block? || !yieldreturn_tags.empty? || !yieldparam_tags.empty?
|
107
|
+
if needs_block_param_signature
|
108
|
+
yield_parameters = yieldparam_tags.map do |p|
|
109
|
+
name = p.name
|
110
|
+
decl = :arg
|
111
|
+
if name
|
112
|
+
decl = select_decl(name, false)
|
113
|
+
name = clean_param(name)
|
114
|
+
end
|
115
|
+
Pin::Parameter.new(
|
116
|
+
location: location,
|
117
|
+
closure: self,
|
118
|
+
comments: p.text,
|
119
|
+
name: name,
|
120
|
+
decl: decl,
|
121
|
+
presence: location ? location.range : nil,
|
122
|
+
return_type: ComplexType.try_parse(*p.types)
|
123
|
+
)
|
124
|
+
end
|
125
|
+
yield_return_type = ComplexType.try_parse(*yieldreturn_tags.flat_map(&:types))
|
126
|
+
block = Signature.new(generics, yield_parameters, yield_return_type)
|
127
|
+
end
|
128
|
+
Signature.new(generics, parameters, return_type, block)
|
129
|
+
end
|
130
|
+
|
131
|
+
# @return [::Array<Signature>]
|
132
|
+
def signatures
|
133
|
+
@signatures ||= begin
|
134
|
+
top_type = generate_complex_type
|
135
|
+
result = []
|
136
|
+
result.push generate_signature(parameters, top_type) if top_type.defined?
|
137
|
+
result.concat(overloads.map { |meth| generate_signature(meth.parameters, meth.return_type) }) unless overloads.empty?
|
138
|
+
result.push generate_signature(parameters, @return_type || ComplexType::UNDEFINED) if result.empty?
|
139
|
+
result
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# @return [String, nil]
|
144
|
+
def detail
|
145
|
+
# This property is not cached in an instance variable because it can
|
146
|
+
# change when pins get proxied.
|
147
|
+
detail = String.new
|
148
|
+
detail += if signatures.length > 1
|
149
|
+
"(*) "
|
150
|
+
else
|
151
|
+
"(#{signatures.first.parameters.map(&:full).join(', ')}) " unless signatures.first.parameters.empty?
|
152
|
+
end.to_s
|
153
|
+
detail += "=#{probed? ? '~' : (proxied? ? '^' : '>')} #{return_type.to_s}" unless return_type.undefined?
|
154
|
+
detail.strip!
|
155
|
+
return nil if detail.empty?
|
156
|
+
detail
|
157
|
+
end
|
158
|
+
|
159
|
+
# @return [::Array<Hash>]
|
160
|
+
def signature_help
|
161
|
+
@signature_help ||= signatures.map do |sig|
|
162
|
+
{
|
163
|
+
label: name + '(' + sig.parameters.map(&:full).join(', ') + ')',
|
164
|
+
documentation: documentation
|
165
|
+
}
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def desc
|
170
|
+
# ensure the signatures line up when logged
|
171
|
+
if signatures.length > 1
|
172
|
+
"\n#{to_rbs}\n"
|
173
|
+
else
|
174
|
+
to_rbs
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def to_rbs
|
179
|
+
return nil if signatures.empty?
|
180
|
+
|
181
|
+
rbs = "def #{name}: #{signatures.first.to_rbs}"
|
182
|
+
signatures[1..].each do |sig|
|
183
|
+
rbs += "\n"
|
184
|
+
rbs += (' ' * (4 + name.length))
|
185
|
+
rbs += "| #{name}: #{sig.to_rbs}"
|
186
|
+
end
|
187
|
+
rbs
|
45
188
|
end
|
46
189
|
|
47
190
|
def path
|
@@ -72,6 +215,32 @@ module Solargraph
|
|
72
215
|
end
|
73
216
|
@documentation += lines.join("\n")
|
74
217
|
end
|
218
|
+
yieldparam_tags = docstring.tags(:yieldparam)
|
219
|
+
unless yieldparam_tags.nil? or yieldparam_tags.empty?
|
220
|
+
@documentation += "\n\n" unless @documentation.empty?
|
221
|
+
@documentation += "Block Params:\n"
|
222
|
+
lines = []
|
223
|
+
yieldparam_tags.each do |p|
|
224
|
+
l = "* #{p.name}"
|
225
|
+
l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil? or p.types.empty?
|
226
|
+
l += " #{p.text}"
|
227
|
+
lines.push l
|
228
|
+
end
|
229
|
+
@documentation += lines.join("\n")
|
230
|
+
end
|
231
|
+
yieldreturn_tags = docstring.tags(:yieldreturn)
|
232
|
+
unless yieldreturn_tags.empty?
|
233
|
+
@documentation += "\n\n" unless @documentation.empty?
|
234
|
+
@documentation += "Block Returns:\n"
|
235
|
+
lines = []
|
236
|
+
yieldreturn_tags.each do |r|
|
237
|
+
l = "*"
|
238
|
+
l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil? or r.types.empty?
|
239
|
+
l += " #{r.text}"
|
240
|
+
lines.push l
|
241
|
+
end
|
242
|
+
@documentation += lines.join("\n")
|
243
|
+
end
|
75
244
|
return_tags = docstring.tags(:return)
|
76
245
|
unless return_tags.empty?
|
77
246
|
@documentation += "\n\n" unless @documentation.empty?
|
@@ -87,6 +256,7 @@ module Solargraph
|
|
87
256
|
end
|
88
257
|
@documentation += "\n\n" unless @documentation.empty?
|
89
258
|
@documentation += "Visibility: #{visibility}"
|
259
|
+
concat_example_tags
|
90
260
|
end
|
91
261
|
@documentation.to_s
|
92
262
|
end
|
@@ -116,33 +286,90 @@ module Solargraph
|
|
116
286
|
true
|
117
287
|
end
|
118
288
|
|
119
|
-
# @return [Array<Pin::Method>]
|
289
|
+
# @return [::Array<Pin::Method>]
|
120
290
|
def overloads
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
291
|
+
# Ignore overload tags with nil parameters. If it's not an array, the
|
292
|
+
# tag's source is likely malformed.
|
293
|
+
@overloads ||= docstring.tags(:overload).select(&:parameters).map do |tag|
|
294
|
+
Pin::Signature.new(
|
295
|
+
generics,
|
296
|
+
tag.parameters.map do |src|
|
297
|
+
name, decl = parse_overload_param(src.first)
|
127
298
|
Pin::Parameter.new(
|
128
299
|
location: location,
|
129
300
|
closure: self,
|
130
301
|
comments: tag.docstring.all.to_s,
|
131
|
-
name:
|
302
|
+
name: name,
|
303
|
+
decl: decl,
|
132
304
|
presence: location ? location.range : nil,
|
133
|
-
|
305
|
+
return_type: param_type_from_name(tag, src.first)
|
134
306
|
)
|
135
307
|
end,
|
136
|
-
|
308
|
+
ComplexType.try_parse(*tag.docstring.tags(:return).flat_map(&:types))
|
137
309
|
)
|
138
310
|
end
|
311
|
+
@overloads
|
139
312
|
end
|
140
313
|
|
314
|
+
def anon_splat?
|
315
|
+
@anon_splat
|
316
|
+
end
|
317
|
+
|
318
|
+
protected
|
319
|
+
|
320
|
+
attr_writer :block
|
321
|
+
|
322
|
+
attr_writer :parameters
|
323
|
+
|
324
|
+
attr_writer :signatures
|
325
|
+
|
326
|
+
attr_writer :signature_help
|
327
|
+
|
328
|
+
attr_writer :documentation
|
329
|
+
|
141
330
|
private
|
142
331
|
|
332
|
+
# @param name [String]
|
333
|
+
# @param asgn [Boolean]
|
334
|
+
#
|
335
|
+
# @return [::Symbol]
|
336
|
+
def select_decl name, asgn
|
337
|
+
if name.start_with?('**')
|
338
|
+
:kwrestarg
|
339
|
+
elsif name.start_with?('*')
|
340
|
+
:restarg
|
341
|
+
elsif name.start_with?('&')
|
342
|
+
:blockarg
|
343
|
+
elsif name.end_with?(':') && asgn
|
344
|
+
:kwoptarg
|
345
|
+
elsif name.end_with?(':')
|
346
|
+
:kwarg
|
347
|
+
elsif asgn
|
348
|
+
:optarg
|
349
|
+
else
|
350
|
+
:arg
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# @param name [String]
|
355
|
+
# @return [String]
|
356
|
+
def clean_param name
|
357
|
+
name.gsub(/[*&:]/, '')
|
358
|
+
end
|
359
|
+
|
360
|
+
# @param tag [YARD::Tags::OverloadTag]
|
361
|
+
# @param name [String]
|
362
|
+
#
|
363
|
+
# @return [ComplexType]
|
364
|
+
def param_type_from_name(tag, name)
|
365
|
+
param = tag.tags(:param).select { |t| t.name == name }.first
|
366
|
+
return ComplexType::UNDEFINED unless param
|
367
|
+
ComplexType.try_parse(*param.types)
|
368
|
+
end
|
369
|
+
|
143
370
|
# @return [ComplexType]
|
144
371
|
def generate_complex_type
|
145
|
-
tags = docstring.tags(:return).map(&:types).flatten.
|
372
|
+
tags = docstring.tags(:return).map(&:types).flatten.compact
|
146
373
|
return ComplexType::UNDEFINED if tags.empty?
|
147
374
|
ComplexType.try_parse *tags
|
148
375
|
end
|
@@ -173,7 +400,7 @@ module Solargraph
|
|
173
400
|
|
174
401
|
# @param ref [String]
|
175
402
|
# @param api_map [ApiMap]
|
176
|
-
# @return [ComplexType]
|
403
|
+
# @return [ComplexType, nil]
|
177
404
|
def resolve_reference ref, api_map
|
178
405
|
parts = ref.split(/[\.#]/)
|
179
406
|
if parts.first.empty? || parts.one?
|
@@ -208,7 +435,7 @@ module Solargraph
|
|
208
435
|
result = []
|
209
436
|
has_nil = false
|
210
437
|
return ComplexType::NIL if method_body_node.nil?
|
211
|
-
|
438
|
+
returns_from_method_body(method_body_node).each do |n|
|
212
439
|
if n.nil? || [:NIL, :nil].include?(n.type)
|
213
440
|
has_nil = true
|
214
441
|
next
|
@@ -228,6 +455,8 @@ module Solargraph
|
|
228
455
|
ComplexType.try_parse(*result.map(&:tag).uniq)
|
229
456
|
end
|
230
457
|
|
458
|
+
# @param [ApiMap] api_map
|
459
|
+
# @return [ComplexType]
|
231
460
|
def infer_from_iv api_map
|
232
461
|
types = []
|
233
462
|
varname = "@#{name.gsub(/=$/, '')}"
|
@@ -240,6 +469,33 @@ module Solargraph
|
|
240
469
|
return ComplexType::UNDEFINED if types.empty?
|
241
470
|
ComplexType.try_parse(*types.map(&:tag).uniq)
|
242
471
|
end
|
472
|
+
|
473
|
+
# When YARD parses an overload tag, it includes rest modifiers in the parameters names.
|
474
|
+
#
|
475
|
+
# @param name [String]
|
476
|
+
# @return [::Array(String, ::Symbol)]
|
477
|
+
def parse_overload_param(name)
|
478
|
+
if name.start_with?('**')
|
479
|
+
[name[2..-1], :kwrestarg]
|
480
|
+
elsif name.start_with?('*')
|
481
|
+
[name[1..-1], :restarg]
|
482
|
+
else
|
483
|
+
[name, :arg]
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
# @return [void]
|
488
|
+
def concat_example_tags
|
489
|
+
example_tags = docstring.tags(:example)
|
490
|
+
return if example_tags.empty?
|
491
|
+
@documentation += "\n\nExamples:\n\n```ruby\n"
|
492
|
+
@documentation += example_tags.map do |tag|
|
493
|
+
(tag.name && !tag.name.empty? ? "# #{tag.name}\n" : '') +
|
494
|
+
"#{tag.text}\n"
|
495
|
+
end
|
496
|
+
.join("\n")
|
497
|
+
.concat("```\n")
|
498
|
+
end
|
243
499
|
end
|
244
500
|
end
|
245
501
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'solargraph/yard_tags'
|
4
|
+
|
3
5
|
module Solargraph
|
4
6
|
module Pin
|
5
7
|
class Namespace < Closure
|
@@ -11,7 +13,7 @@ module Solargraph
|
|
11
13
|
|
12
14
|
# @param type [::Symbol] :class or :module
|
13
15
|
# @param visibility [::Symbol] :public or :private
|
14
|
-
# @param gates [Array<String>]
|
16
|
+
# @param gates [::Array<String>]
|
15
17
|
def initialize type: :class, visibility: :public, gates: [''], **splat
|
16
18
|
# super(location, namespace, name, comments)
|
17
19
|
super(**splat)
|
@@ -38,6 +40,18 @@ module Solargraph
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
def to_rbs
|
44
|
+
"#{@type.to_s} #{generics_as_rbs}#{return_type.to_rbs}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def desc
|
48
|
+
if name.nil?
|
49
|
+
'(top-level)'
|
50
|
+
else
|
51
|
+
to_rbs
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
def namespace
|
42
56
|
context.namespace
|
43
57
|
end
|
@@ -63,6 +77,7 @@ module Solargraph
|
|
63
77
|
(type == :class ? LanguageServer::SymbolKinds::CLASS : LanguageServer::SymbolKinds::MODULE)
|
64
78
|
end
|
65
79
|
|
80
|
+
# @return [String]
|
66
81
|
def path
|
67
82
|
@path ||= (namespace.empty? ? '' : "#{namespace}::") + name
|
68
83
|
end
|
@@ -71,6 +86,7 @@ module Solargraph
|
|
71
86
|
@return_type ||= ComplexType.try_parse( (type == :class ? 'Class' : 'Module') + "<#{path}>" )
|
72
87
|
end
|
73
88
|
|
89
|
+
# @return [Array<String>]
|
74
90
|
def domains
|
75
91
|
@domains ||= []
|
76
92
|
end
|
@@ -9,10 +9,14 @@ module Solargraph
|
|
9
9
|
# @return [String]
|
10
10
|
attr_reader :asgn_code
|
11
11
|
|
12
|
-
|
12
|
+
# @param decl [::Symbol] :arg, :optarg, :kwarg, :kwoptarg, :restarg, :kwrestarg, :block, :blockarg
|
13
|
+
# @param asgn_code [String, nil]
|
14
|
+
# @param return_type [ComplexType, nil]
|
15
|
+
def initialize decl: :arg, asgn_code: nil, return_type: nil, **splat
|
13
16
|
super(**splat)
|
14
17
|
@asgn_code = asgn_code
|
15
18
|
@decl = decl
|
19
|
+
@return_type = return_type
|
16
20
|
end
|
17
21
|
|
18
22
|
def keyword?
|
@@ -31,14 +35,36 @@ module Solargraph
|
|
31
35
|
decl == :restarg || decl == :kwrestarg
|
32
36
|
end
|
33
37
|
|
38
|
+
def block?
|
39
|
+
[:block, :blockarg].include?(decl)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_rbs
|
43
|
+
case decl
|
44
|
+
when :optarg
|
45
|
+
"?#{super}"
|
46
|
+
when :kwarg
|
47
|
+
"#{name}: #{return_type.to_rbs}"
|
48
|
+
when :kwoptarg
|
49
|
+
"?#{name}: #{return_type.to_rbs}"
|
50
|
+
when :restarg
|
51
|
+
"*#{super}"
|
52
|
+
when :kwrestarg
|
53
|
+
"**#{super}"
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String]
|
34
60
|
def full
|
35
61
|
case decl
|
36
62
|
when :optarg
|
37
|
-
"#{name} = #{asgn_code}"
|
63
|
+
"#{name} = #{asgn_code || '?'}"
|
38
64
|
when :kwarg
|
39
65
|
"#{name}:"
|
40
66
|
when :kwoptarg
|
41
|
-
"#{name}: #{asgn_code}"
|
67
|
+
"#{name}: #{asgn_code || '?'}"
|
42
68
|
when :restarg
|
43
69
|
"*#{name}"
|
44
70
|
when :kwrestarg
|
@@ -50,6 +76,7 @@ module Solargraph
|
|
50
76
|
end
|
51
77
|
end
|
52
78
|
|
79
|
+
# @return [ComplexType]
|
53
80
|
def return_type
|
54
81
|
if @return_type.nil?
|
55
82
|
@return_type = ComplexType::UNDEFINED
|
@@ -73,7 +100,9 @@ module Solargraph
|
|
73
100
|
#
|
74
101
|
# @return [Integer]
|
75
102
|
def index
|
76
|
-
|
103
|
+
# @type [Method, Block]
|
104
|
+
method_pin = closure
|
105
|
+
method_pin.parameter_names.index(name)
|
77
106
|
end
|
78
107
|
|
79
108
|
# @param api_map [ApiMap]
|
@@ -95,7 +124,7 @@ module Solargraph
|
|
95
124
|
|
96
125
|
private
|
97
126
|
|
98
|
-
# @return [YARD::Tags::Tag]
|
127
|
+
# @return [YARD::Tags::Tag, nil]
|
99
128
|
def param_tag
|
100
129
|
found = nil
|
101
130
|
params = closure.docstring.tags(:param)
|
@@ -114,24 +143,7 @@ module Solargraph
|
|
114
143
|
# @return [ComplexType]
|
115
144
|
def typify_block_param api_map
|
116
145
|
if closure.is_a?(Pin::Block) && closure.receiver
|
117
|
-
|
118
|
-
clip = api_map.clip_at(location.filename, location.range.start)
|
119
|
-
locals = clip.locals - [self]
|
120
|
-
meths = chain.define(api_map, closure, locals)
|
121
|
-
meths.each do |meth|
|
122
|
-
if meth.docstring.has_tag?(:yieldparam_single_parameter)
|
123
|
-
type = chain.base.infer(api_map, closure, locals)
|
124
|
-
if type.defined? && !type.subtypes.empty?
|
125
|
-
bmeth = chain.base.define(api_map, closure, locals).first
|
126
|
-
return type.subtypes.first.qualify(api_map, bmeth.context.namespace)
|
127
|
-
end
|
128
|
-
else
|
129
|
-
yps = meth.docstring.tags(:yieldparam)
|
130
|
-
unless yps[index].nil? or yps[index].types.nil? or yps[index].types.empty?
|
131
|
-
return ComplexType.try_parse(yps[index].types.first).self_to(chain.base.infer(api_map, closure, locals).namespace).qualify(api_map, meth.context.namespace)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
146
|
+
return closure.typify_parameters(api_map)[index]
|
135
147
|
end
|
136
148
|
ComplexType::UNDEFINED
|
137
149
|
end
|
@@ -139,7 +151,7 @@ module Solargraph
|
|
139
151
|
# @param api_map [ApiMap]
|
140
152
|
# @return [ComplexType]
|
141
153
|
def typify_method_param api_map
|
142
|
-
meths = api_map.get_method_stack(closure.full_context.
|
154
|
+
meths = api_map.get_method_stack(closure.full_context.tag, closure.name, scope: closure.scope)
|
143
155
|
# meths.shift # Ignore the first one
|
144
156
|
meths.each do |meth|
|
145
157
|
found = nil
|
@@ -159,8 +171,8 @@ module Solargraph
|
|
159
171
|
|
160
172
|
# @param heredoc [YARD::Docstring]
|
161
173
|
# @param api_map [ApiMap]
|
162
|
-
# @param skip [Array]
|
163
|
-
# @return [Array<YARD::Tags::Tag>]
|
174
|
+
# @param skip [::Array]
|
175
|
+
# @return [::Array<YARD::Tags::Tag>]
|
164
176
|
def see_reference heredoc, api_map, skip = []
|
165
177
|
heredoc.ref_tags.each do |ref|
|
166
178
|
next unless ref.tag_name == 'param' && ref.owner
|
@@ -172,8 +184,8 @@ module Solargraph
|
|
172
184
|
|
173
185
|
# @param ref [String]
|
174
186
|
# @param api_map [ApiMap]
|
175
|
-
# @param skip [Array]
|
176
|
-
# @return [Array<YARD::Tags::Tag>, nil]
|
187
|
+
# @param skip [::Array]
|
188
|
+
# @return [::Array<YARD::Tags::Tag>, nil]
|
177
189
|
def resolve_reference ref, api_map, skip
|
178
190
|
return nil if skip.include?(ref)
|
179
191
|
skip.push ref
|
@@ -4,10 +4,10 @@ module Solargraph
|
|
4
4
|
module Pin
|
5
5
|
class Reference
|
6
6
|
class Override < Reference
|
7
|
-
# @return [Array<YARD::Tags::Tag>]
|
7
|
+
# @return [::Array<YARD::Tags::Tag>]
|
8
8
|
attr_reader :tags
|
9
9
|
|
10
|
-
# @return [Array<Symbol>]
|
10
|
+
# @return [::Array<Symbol>]
|
11
11
|
attr_reader :delete
|
12
12
|
|
13
13
|
def initialize location, name, tags, delete = []
|
@@ -9,6 +9,14 @@ 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
|
+
|
13
|
+
attr_reader :generic_values
|
14
|
+
|
15
|
+
# @param generic_values [Array<String>]
|
16
|
+
def initialize generic_values: [], **splat
|
17
|
+
super(**splat)
|
18
|
+
@generic_values = generic_values
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -18,21 +18,21 @@ module Solargraph
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
# @param pins [Array<Pin::Base>]
|
21
|
+
# @param pins [::Array<Pin::Base>]
|
22
22
|
# @param query [String]
|
23
23
|
def initialize pins, query
|
24
24
|
@pins = pins
|
25
25
|
@query = query
|
26
26
|
end
|
27
27
|
|
28
|
-
# @return [Array<Pin::Base>]
|
28
|
+
# @return [::Array<Pin::Base>]
|
29
29
|
def results
|
30
30
|
@results ||= do_query
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
# @return [Array<Pin::Base>]
|
35
|
+
# @return [::Array<Pin::Base>]
|
36
36
|
def do_query
|
37
37
|
return @pins if @query.nil? || @query.empty?
|
38
38
|
@pins.map do |pin|
|
@@ -49,7 +49,7 @@ module Solargraph
|
|
49
49
|
# @return [Float]
|
50
50
|
def fuzzy_string_match str1, str2
|
51
51
|
return (1.0 + (str2.length.to_f / str1.length.to_f)) if str1.downcase.include?(str2.downcase)
|
52
|
-
JaroWinkler.
|
52
|
+
JaroWinkler.similarity(str1, str2, ignore_case: true)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|