solargraph 0.9.2 → 0.10.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/lib/solargraph.rb +1 -0
- data/lib/solargraph/api_map.rb +157 -49
- data/lib/solargraph/code_map.rb +70 -61
- data/lib/solargraph/node_methods.rb +2 -46
- data/lib/solargraph/suggestion.rb +1 -0
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +6 -2
- data/lib/solargraph/yard_methods.rb +29 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b294bc8ca569c676481b4ae6e7278a751efb3948
|
4
|
+
data.tar.gz: 362d7969bffa45dcc69750cdd5ad0ce2553e896c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d194a846f91e5d8ac0f148068a7d95816675ba8d2a8a086546ebb84cf742ff7934ee4151086ffa19e24a083bde32072314ef987b363404f4207110198ef48950
|
7
|
+
data.tar.gz: 1bec252ba431ee8489f931195c9d9527985ca261596d99fe07b549d5e94bfa43e82ebf87669230ad9ed2688022af704e62ef1be28b59717e8f1e55459b1f99d5
|
data/lib/solargraph.rb
CHANGED
@@ -14,6 +14,7 @@ module Solargraph
|
|
14
14
|
autoload :Mapper, 'solargraph/mapper'
|
15
15
|
autoload :Server, 'solargraph/server'
|
16
16
|
autoload :YardMap, 'solargraph/yard_map'
|
17
|
+
autoload :YardMethods, 'solargraph/yard_methods'
|
17
18
|
|
18
19
|
YARDOC_PATH = File.join(File.realpath(File.dirname(__FILE__)), '..', 'yardoc')
|
19
20
|
YARD_EXTENSION_FILE = File.join(File.realpath(File.dirname(__FILE__)), 'yard-solargraph.rb')
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'parser/current'
|
3
|
-
require 'yard'
|
4
3
|
require 'yaml'
|
5
4
|
|
6
5
|
module Solargraph
|
@@ -13,13 +12,21 @@ module Solargraph
|
|
13
12
|
'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
|
14
13
|
'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
|
15
14
|
'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
|
16
|
-
]
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
MAPPABLE_NODES = [
|
18
|
+
# @todo Add node.type :casgn (constant assignment)
|
19
|
+
:array, :hash, :str, :int, :float, :block, :class, :module, :def, :defs,
|
20
|
+
:ivasgn, :gvasgn, :lvasgn, :cvasgn, :or_asgn, :const, :lvar, :args, :kwargs
|
21
|
+
].freeze
|
17
22
|
|
18
23
|
MAPPABLE_METHODS = [
|
19
|
-
:include, :extend, :require, :autoload, :attr_reader, :attr_writer,
|
20
|
-
|
24
|
+
:include, :extend, :require, :autoload, :attr_reader, :attr_writer,
|
25
|
+
:attr_accessor, :private, :public, :protected
|
26
|
+
].freeze
|
21
27
|
|
22
28
|
include NodeMethods
|
29
|
+
include YardMethods
|
23
30
|
|
24
31
|
attr_reader :workspace
|
25
32
|
attr_reader :required
|
@@ -203,6 +210,15 @@ module Solargraph
|
|
203
210
|
arr
|
204
211
|
end
|
205
212
|
|
213
|
+
def get_class_variables(namespace)
|
214
|
+
nodes = get_namespace_nodes(namespace) || @file_nodes.values
|
215
|
+
arr = []
|
216
|
+
nodes.each { |n|
|
217
|
+
arr += inner_get_class_variables(n)
|
218
|
+
}
|
219
|
+
arr
|
220
|
+
end
|
221
|
+
|
206
222
|
def find_parent(node, *types)
|
207
223
|
parents = @parent_stack[node]
|
208
224
|
parents.each { |p|
|
@@ -236,7 +252,7 @@ module Solargraph
|
|
236
252
|
@yardoc_files.include?(file)
|
237
253
|
end
|
238
254
|
|
239
|
-
def infer_instance_variable(var, namespace, scope
|
255
|
+
def infer_instance_variable(var, namespace, scope)
|
240
256
|
result = nil
|
241
257
|
vn = nil
|
242
258
|
fqns = find_fully_qualified_namespace(namespace)
|
@@ -252,12 +268,35 @@ module Solargraph
|
|
252
268
|
tag = cmnt.tag(:type)
|
253
269
|
result = tag.types[0] unless tag.nil? or tag.types.empty?
|
254
270
|
end
|
255
|
-
result =
|
271
|
+
result = infer_literal_node_type(vn.children[1]) if result.nil?
|
272
|
+
if result.nil?
|
273
|
+
signature = resolve_node_signature(vn.children[1])
|
274
|
+
result = infer_signature_type(signature, namespace)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
result
|
278
|
+
end
|
279
|
+
|
280
|
+
def infer_class_variable(var, namespace)
|
281
|
+
result = nil
|
282
|
+
vn = nil
|
283
|
+
fqns = find_fully_qualified_namespace(namespace)
|
284
|
+
unless fqns.nil?
|
285
|
+
get_namespace_nodes(fqns).each { |node|
|
286
|
+
vn = find_class_variable_assignment(var, node)
|
287
|
+
break unless vn.nil?
|
288
|
+
}
|
289
|
+
end
|
290
|
+
unless vn.nil?
|
291
|
+
cmnt = get_comment_for(vn)
|
292
|
+
unless cmnt.nil?
|
293
|
+
tag = cmnt.tag(:type)
|
294
|
+
result = tag.types[0] unless tag.nil? or tag.types.empty?
|
295
|
+
end
|
296
|
+
result = infer_literal_node_type(vn.children[1]) if result.nil?
|
256
297
|
if result.nil?
|
257
298
|
signature = resolve_node_signature(vn.children[1])
|
258
|
-
|
259
|
-
sig_scope = (sig_ns.nil? ? :instance : :class)
|
260
|
-
result = infer_signature_type(signature, namespace, scope: sig_scope)
|
299
|
+
result = infer_signature_type(signature, namespace)
|
261
300
|
end
|
262
301
|
end
|
263
302
|
result
|
@@ -280,48 +319,48 @@ module Solargraph
|
|
280
319
|
nil
|
281
320
|
end
|
282
321
|
|
322
|
+
def find_class_variable_assignment(var, node)
|
323
|
+
node.children.each { |c|
|
324
|
+
next unless c.kind_of?(AST::Node)
|
325
|
+
if c.type == :cvasgn
|
326
|
+
if c.children[0].to_s == var
|
327
|
+
return c
|
328
|
+
end
|
329
|
+
else
|
330
|
+
inner = find_class_variable_assignment(var, c)
|
331
|
+
return inner unless inner.nil?
|
332
|
+
end
|
333
|
+
}
|
334
|
+
nil
|
335
|
+
end
|
336
|
+
|
283
337
|
def get_global_variables
|
284
338
|
# TODO: Get them
|
285
339
|
[]
|
286
340
|
end
|
287
341
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
unless p == 'new' and scope != :instance
|
309
|
-
if scope == :instance
|
310
|
-
meths = get_instance_methods(type)
|
311
|
-
meths += get_methods('') if top or type.to_s == ''
|
312
|
-
else
|
313
|
-
meths = get_methods(type)
|
314
|
-
end
|
315
|
-
meths.delete_if{ |m| m.insert != p }
|
316
|
-
return nil if meths.empty?
|
317
|
-
type = nil
|
318
|
-
match = meths[0].return_type
|
319
|
-
type = find_fully_qualified_namespace(match) unless match.nil?
|
342
|
+
def infer_signature_type signature, namespace, scope: :class
|
343
|
+
return nil if signature.nil? or signature.empty?
|
344
|
+
if namespace.end_with?('#class')
|
345
|
+
return infer_signature_type signature, namespace[0..-7], scope: (scope == :class ? :instance : :class)
|
346
|
+
end
|
347
|
+
parts = signature.split('.', 2)
|
348
|
+
if parts[0].start_with?('@@')
|
349
|
+
type = infer_class_variable(parts[0], namespace)
|
350
|
+
inner_infer_signature_type parts[1], type, scope: :instance
|
351
|
+
elsif parts[0].start_with?('@')
|
352
|
+
type = infer_instance_variable(parts[0], namespace, scope)
|
353
|
+
inner_infer_signature_type parts[1], type, scope: :instance
|
354
|
+
else
|
355
|
+
type = find_fully_qualified_namespace(parts[0], namespace)
|
356
|
+
if type.nil?
|
357
|
+
# It's a method call
|
358
|
+
type = inner_infer_signature_type(parts[0], namespace, scope: scope)
|
359
|
+
inner_infer_signature_type(parts[1], type, scope: :instance)
|
360
|
+
else
|
361
|
+
inner_infer_signature_type(parts[1], type, scope: :class)
|
320
362
|
end
|
321
|
-
scope = :instance
|
322
|
-
top = false
|
323
363
|
end
|
324
|
-
type
|
325
364
|
end
|
326
365
|
|
327
366
|
def get_namespace_type namespace, root = ''
|
@@ -384,6 +423,9 @@ module Solargraph
|
|
384
423
|
#
|
385
424
|
# @return [Array<Solargraph::Suggestion>]
|
386
425
|
def get_instance_methods(namespace, root = '', visibility: [:public])
|
426
|
+
if namespace.end_with?('#class')
|
427
|
+
return get_methods(namespace.split('#').first, root, visibility: visibility)
|
428
|
+
end
|
387
429
|
meths = []
|
388
430
|
meths += inner_get_instance_methods(namespace, root, []) #unless has_yardoc?
|
389
431
|
fqns = find_fully_qualified_namespace(namespace, root)
|
@@ -613,10 +655,77 @@ module Solargraph
|
|
613
655
|
arr
|
614
656
|
end
|
615
657
|
|
658
|
+
def inner_get_class_variables(node)
|
659
|
+
arr = []
|
660
|
+
if node.kind_of?(AST::Node)
|
661
|
+
node.children.each { |c|
|
662
|
+
next unless c.kind_of?(AST::Node)
|
663
|
+
if c.type == :cvasgn
|
664
|
+
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: get_comment_for(c))
|
665
|
+
end
|
666
|
+
arr += inner_get_class_variables(c) unless [:class, :module].include?(c.type)
|
667
|
+
}
|
668
|
+
end
|
669
|
+
arr
|
670
|
+
end
|
671
|
+
|
672
|
+
# Get a fully qualified namespace for the given signature.
|
673
|
+
# The signature should be in the form of a method chain, e.g.,
|
674
|
+
# method1.method2
|
675
|
+
#
|
676
|
+
# @return [String] The fully qualified namespace for the signature's type
|
677
|
+
# or nil if a type could not be determined
|
678
|
+
def inner_infer_signature_type signature, namespace, scope: :instance
|
679
|
+
if signature.nil? or signature.empty?
|
680
|
+
if scope == :class
|
681
|
+
return "#{namespace}#class"
|
682
|
+
else
|
683
|
+
return "#{namespace}"
|
684
|
+
end
|
685
|
+
end
|
686
|
+
if !namespace.nil? and namespace.end_with?('#class')
|
687
|
+
return inner_infer_signature_type signature, namespace[0..-7], scope: (scope == :class ? :instance : :class)
|
688
|
+
end
|
689
|
+
parts = signature.split('.')
|
690
|
+
type = find_fully_qualified_namespace(namespace)
|
691
|
+
type ||= ''
|
692
|
+
top = true
|
693
|
+
while parts.length > 0 and !type.nil?
|
694
|
+
p = parts.shift
|
695
|
+
if top and scope == :class
|
696
|
+
#next if p == 'new'
|
697
|
+
if p == 'new'
|
698
|
+
scope = :instance
|
699
|
+
type = namespace
|
700
|
+
top = false
|
701
|
+
next
|
702
|
+
end
|
703
|
+
first_class = find_fully_qualified_namespace(p, namespace)
|
704
|
+
sub = nil
|
705
|
+
sub = infer_signature_type(parts.join('.'), first_class, scope: :class) unless first_class.nil?
|
706
|
+
return sub unless sub.to_s == ''
|
707
|
+
end
|
708
|
+
unless p == 'new' and scope != :instance
|
709
|
+
if scope == :instance
|
710
|
+
meths = get_instance_methods(type)
|
711
|
+
meths += get_methods('') if top or type.to_s == ''
|
712
|
+
else
|
713
|
+
meths = get_methods(type)
|
714
|
+
end
|
715
|
+
meths.delete_if{ |m| m.insert != p }
|
716
|
+
return nil if meths.empty?
|
717
|
+
type = nil
|
718
|
+
match = meths[0].return_type
|
719
|
+
type = find_fully_qualified_namespace(match) unless match.nil?
|
720
|
+
end
|
721
|
+
scope = :instance
|
722
|
+
top = false
|
723
|
+
end
|
724
|
+
type
|
725
|
+
end
|
726
|
+
|
616
727
|
def mappable?(node)
|
617
|
-
|
618
|
-
# TODO Add node.type :casgn (constant assignment)
|
619
|
-
if node.kind_of?(AST::Node) and (node.type == :class or node.type == :module or node.type == :def or node.type == :defs or node.type == :ivasgn or node.type == :gvasgn or node.type == :lvasgn or node.type == :or_asgn or node.type == :const or node.type == :lvar or node.type == :args or node.type == :kwargs)
|
728
|
+
if node.kind_of?(AST::Node) and MAPPABLE_NODES.include?(node.type)
|
620
729
|
true
|
621
730
|
elsif node.kind_of?(AST::Node) and node.type == :send and node.children[0] == nil and MAPPABLE_METHODS.include?(node.children[1])
|
622
731
|
true
|
@@ -653,7 +762,6 @@ module Solargraph
|
|
653
762
|
if node.type == :class or node.type == :block
|
654
763
|
children += node.children[0, 2]
|
655
764
|
children += get_mappable_nodes(node.children[2..-1], comment_hash)
|
656
|
-
#children += get_mappable_nodes(node.children, comment_hash)
|
657
765
|
elsif node.type == :const or node.type == :args or node.type == :kwargs
|
658
766
|
children += node.children
|
659
767
|
elsif node.type == :def
|
@@ -665,7 +773,7 @@ module Solargraph
|
|
665
773
|
elsif node.type == :module
|
666
774
|
children += node.children[0, 1]
|
667
775
|
children += get_mappable_nodes(node.children[1..-1], comment_hash)
|
668
|
-
elsif node.type == :ivasgn or node.type == :gvasgn or node.type == :lvasgn
|
776
|
+
elsif node.type == :ivasgn or node.type == :gvasgn or node.type == :lvasgn or node.type == :cvasgn
|
669
777
|
children += node.children
|
670
778
|
elsif node.type == :send and node.children[1] == :include
|
671
779
|
children += node.children[0,3]
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -177,6 +177,11 @@ module Solargraph
|
|
177
177
|
word
|
178
178
|
end
|
179
179
|
|
180
|
+
def get_class_variables_at(index)
|
181
|
+
ns = namespace_at(index) || ''
|
182
|
+
api_map.get_class_variables(ns)
|
183
|
+
end
|
184
|
+
|
180
185
|
def get_instance_variables_at(index)
|
181
186
|
node = parent_node_from(index, :def, :defs, :class, :module)
|
182
187
|
ns = namespace_at(index) || ''
|
@@ -195,7 +200,7 @@ module Solargraph
|
|
195
200
|
namespace = namespace_at(index)
|
196
201
|
if signature.include?('.')
|
197
202
|
# Check for literals first
|
198
|
-
type =
|
203
|
+
type = infer_literal_node_type(node_at(index - 2))
|
199
204
|
if type.nil?
|
200
205
|
nearest = @code[0, index].rindex('.')
|
201
206
|
revised = signature[0..nearest-index-1]
|
@@ -209,6 +214,8 @@ module Solargraph
|
|
209
214
|
else
|
210
215
|
result.concat api_map.get_instance_methods(type)
|
211
216
|
end
|
217
|
+
elsif signature.start_with?('@@')
|
218
|
+
result.concat get_class_variables_at(index)
|
212
219
|
elsif signature.start_with?('@')
|
213
220
|
result.concat get_instance_variables_at(index)
|
214
221
|
elsif phrase.start_with?('$')
|
@@ -235,12 +242,6 @@ module Solargraph
|
|
235
242
|
end
|
236
243
|
result += api_map.namespaces_in('')
|
237
244
|
result += api_map.get_instance_methods('Kernel')
|
238
|
-
#unless @filename.nil? or @api_map.yardoc_has_file?(@filename)
|
239
|
-
# m = @code.match(/# +@bind \[([a-z0-9_:]*)/i)
|
240
|
-
# unless m.nil?
|
241
|
-
# @api_map.get_instance_methods(m[1])
|
242
|
-
# end
|
243
|
-
#end
|
244
245
|
end
|
245
246
|
result = reduce_starting_with(result, word_at(index)) if filtered
|
246
247
|
result.uniq{|s| s.path}.sort{|a,b| a.label <=> b.label}
|
@@ -291,7 +292,20 @@ module Solargraph
|
|
291
292
|
def infer_signature_at index
|
292
293
|
signature = get_signature_at(index)
|
293
294
|
node = parent_node_from(index, :class, :module, :def, :defs) || @node
|
294
|
-
infer_signature_from_node signature, node
|
295
|
+
result = infer_signature_from_node signature, node
|
296
|
+
if result.nil? or result.empty?
|
297
|
+
# Check for yieldparams
|
298
|
+
parts = signature.split('.', 2)
|
299
|
+
yp = get_yieldparams_at(index).keep_if{|s| s.to_s == parts[0]}.first
|
300
|
+
unless yp.nil?
|
301
|
+
if parts[1].nil? or parts[1].empty?
|
302
|
+
result = yp.return_type
|
303
|
+
else
|
304
|
+
result = api_map.infer_signature_type(parts[1], yp.return_type, scope: :instance)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
result
|
295
309
|
end
|
296
310
|
|
297
311
|
def local_variable_in_node?(name, node)
|
@@ -310,62 +324,24 @@ module Solargraph
|
|
310
324
|
start = parts[0]
|
311
325
|
return nil if start.nil?
|
312
326
|
remainder = parts[1..-1]
|
313
|
-
scope = :instance
|
314
327
|
var = find_local_variable_node(start, node)
|
315
328
|
if var.nil?
|
316
|
-
|
317
|
-
scope2 = (node.type == :def ? :instance : :class)
|
318
|
-
type = api_map.infer_instance_variable(start, ns_here, scope2)
|
319
|
-
else
|
320
|
-
if node.type == :def or node.type == :defs
|
321
|
-
args = get_method_arguments_from(node).keep_if{|a| a.label == start}
|
322
|
-
if args.empty?
|
323
|
-
scope = :class
|
324
|
-
type = api_map.find_fully_qualified_namespace(start, ns_here)
|
325
|
-
if type.nil?
|
326
|
-
# It's a method call
|
327
|
-
sig_scope = (node.type == :def ? :instance : :class)
|
328
|
-
type = api_map.infer_signature_type(start, ns_here, scope: sig_scope)
|
329
|
-
else
|
330
|
-
return nil if remainder.empty?
|
331
|
-
end
|
332
|
-
else
|
333
|
-
cmnt = api_map.get_comment_for(node)
|
334
|
-
unless cmnt.nil?
|
335
|
-
params = cmnt.tags(:param)
|
336
|
-
unless params.nil?
|
337
|
-
params.each do |p|
|
338
|
-
if p.name == args[0].label
|
339
|
-
type = p.types[0]
|
340
|
-
break
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
else
|
347
|
-
scope = :class
|
348
|
-
type = api_map.find_fully_qualified_namespace(start, ns_here)
|
349
|
-
if type.nil?
|
350
|
-
# It's a method call
|
351
|
-
sig_scope = (node.type == :def ? :instance : :class)
|
352
|
-
type = api_map.infer_signature_type(start, ns_here, scope: sig_scope)
|
353
|
-
else
|
354
|
-
return nil if remainder.empty?
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
329
|
+
return api_map.infer_signature_type(signature, ns_here)
|
358
330
|
else
|
359
331
|
# Signature starts with a local variable
|
360
332
|
type = get_type_comment(var)
|
361
|
-
type =
|
333
|
+
type = infer_literal_node_type(var.children[1]) if type.nil?
|
362
334
|
if type.nil?
|
363
335
|
vsig = resolve_node_signature(var.children[1])
|
364
336
|
type = infer_signature_from_node vsig, node
|
365
337
|
end
|
366
338
|
end
|
367
339
|
unless type.nil?
|
368
|
-
|
340
|
+
if remainder.empty?
|
341
|
+
inferred = type
|
342
|
+
else
|
343
|
+
inferred = api_map.infer_signature_type(remainder.join('.'), type, scope: :instance)
|
344
|
+
end
|
369
345
|
end
|
370
346
|
inferred
|
371
347
|
end
|
@@ -424,7 +400,10 @@ module Solargraph
|
|
424
400
|
if brackets == 0 and parens == 0 and squares == 0
|
425
401
|
break if ['"', "'", ',', ' ', "\t", "\n"].include?(char)
|
426
402
|
signature = char + signature if char.match(/[a-z0-9:\._@]/i)
|
427
|
-
|
403
|
+
if char == '@'
|
404
|
+
signature = "@#{signature}" if @code[index-1, 1] == '@'
|
405
|
+
break
|
406
|
+
end
|
428
407
|
end
|
429
408
|
index -= 1
|
430
409
|
end
|
@@ -482,13 +461,7 @@ module Solargraph
|
|
482
461
|
if local.type == :def or local.type == :defs
|
483
462
|
result += get_method_arguments_from local
|
484
463
|
end
|
485
|
-
|
486
|
-
block_node = parent_node_from(index, :block)
|
487
|
-
unless block_node.nil? or block_node.children[1].nil?
|
488
|
-
block_node.children[1].children.each do |a|
|
489
|
-
result.push Suggestion.new(a.children[0], kind: Suggestion::PROPERTY)
|
490
|
-
end
|
491
|
-
end
|
464
|
+
result += get_yieldparams_at(index)
|
492
465
|
result += api_map.get_methods('Kernel')
|
493
466
|
result
|
494
467
|
end
|
@@ -506,6 +479,7 @@ module Solargraph
|
|
506
479
|
end
|
507
480
|
result = []
|
508
481
|
args = node.children[1]
|
482
|
+
return result unless args.kind_of?(AST::Node) and args.type == :args
|
509
483
|
args.children.each do |arg|
|
510
484
|
name = arg.children[0].to_s
|
511
485
|
result.push Suggestion.new(name, kind: Suggestion::PROPERTY, insert: name, return_type: param_hash[name])
|
@@ -513,6 +487,41 @@ module Solargraph
|
|
513
487
|
result
|
514
488
|
end
|
515
489
|
|
490
|
+
def get_yieldparams_at index
|
491
|
+
block_node = parent_node_from(index, :block)
|
492
|
+
scope_node = parent_node_from(index, :class, :module, :def, :defs) || @node
|
493
|
+
return [] if block_node.nil?
|
494
|
+
get_yieldparams_from block_node, scope_node
|
495
|
+
end
|
496
|
+
|
497
|
+
def get_yieldparams_from block_node, scope_node
|
498
|
+
return [] unless block_node.kind_of?(AST::Node) and block_node.type == :block
|
499
|
+
result = []
|
500
|
+
unless block_node.nil? or block_node.children[1].nil?
|
501
|
+
recv = resolve_node_signature(block_node.children[0].children[0])
|
502
|
+
fqns = namespace_from(block_node)
|
503
|
+
lvarnode = find_local_variable_node(recv, scope_node)
|
504
|
+
if lvarnode.nil?
|
505
|
+
sig = api_map.infer_signature_type(recv, fqns)
|
506
|
+
else
|
507
|
+
tmp = resolve_node_signature(lvarnode.children[1])
|
508
|
+
sig = infer_signature_from_node tmp, scope_node
|
509
|
+
end
|
510
|
+
meth = api_map.get_instance_methods(sig, fqns).keep_if{ |s| s.to_s == block_node.children[0].children[1].to_s }.first
|
511
|
+
yps = []
|
512
|
+
unless meth.nil? or meth.documentation.nil?
|
513
|
+
yps = meth.documentation.tags(:yieldparam) || []
|
514
|
+
end
|
515
|
+
i = 0
|
516
|
+
block_node.children[1].children.each do |a|
|
517
|
+
rt = (yps[i].nil? ? nil : yps[i].types[0])
|
518
|
+
result.push Suggestion.new(a.children[0], kind: Suggestion::PROPERTY, return_type: rt)
|
519
|
+
i += 1
|
520
|
+
end
|
521
|
+
end
|
522
|
+
result
|
523
|
+
end
|
524
|
+
|
516
525
|
# @param suggestions [Array<Solargraph::Suggestion>]
|
517
526
|
# @param word [String]
|
518
527
|
def reduce_starting_with(suggestions, word)
|
@@ -39,7 +39,7 @@ module Solargraph
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def infer_literal_node_type node
|
43
43
|
if node.type == :str
|
44
44
|
return 'String'
|
45
45
|
elsif node.type == :array
|
@@ -60,53 +60,9 @@ module Solargraph
|
|
60
60
|
#
|
61
61
|
# @return [String]
|
62
62
|
def resolve_node_signature node
|
63
|
-
#stack_node_signature(node).join('.')
|
64
63
|
drill_signature node, ''
|
65
64
|
end
|
66
65
|
|
67
|
-
def stack_node_signature node
|
68
|
-
parts = []
|
69
|
-
if node.kind_of?(AST::Node)
|
70
|
-
if node.type == :send
|
71
|
-
unless node.children[0].nil?
|
72
|
-
parts = [unpack_name(node.children[0])] + parts
|
73
|
-
end
|
74
|
-
parts += stack_node_signature(node.children[1])
|
75
|
-
else
|
76
|
-
parts = [unpack_name(node)] + stack_node_signature(node.children[1])
|
77
|
-
end
|
78
|
-
else
|
79
|
-
parts.push node.to_s
|
80
|
-
end
|
81
|
-
parts
|
82
|
-
end
|
83
|
-
|
84
|
-
def yard_options
|
85
|
-
if @yard_options.nil?
|
86
|
-
@yard_options = {
|
87
|
-
include: [],
|
88
|
-
exclude: [],
|
89
|
-
flags: []
|
90
|
-
}
|
91
|
-
unless workspace.nil?
|
92
|
-
yardopts_file = File.join(workspace, '.yardopts')
|
93
|
-
if File.exist?(yardopts_file)
|
94
|
-
yardopts = File.read(yardopts_file)
|
95
|
-
yardopts.lines.each { |line|
|
96
|
-
arg = line.strip
|
97
|
-
if arg.start_with?('-')
|
98
|
-
@yard_options[:flags].push arg
|
99
|
-
else
|
100
|
-
@yard_options[:include].push arg
|
101
|
-
end
|
102
|
-
}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
@yard_options[:include].concat ['app/**/*.rb', 'lib/**/*.rb'] if @yard_options[:include].empty?
|
106
|
-
end
|
107
|
-
@yard_options
|
108
|
-
end
|
109
|
-
|
110
66
|
private
|
111
67
|
|
112
68
|
def drill_signature node, signature
|
@@ -117,7 +73,7 @@ module Solargraph
|
|
117
73
|
end
|
118
74
|
signature += '::' unless signature.empty?
|
119
75
|
signature += node.children[1].to_s
|
120
|
-
elsif node.type == :lvar
|
76
|
+
elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
|
121
77
|
signature += '.' unless signature.empty?
|
122
78
|
signature += node.children[0].to_s
|
123
79
|
elsif node.type == :send
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -127,8 +127,13 @@ module Solargraph
|
|
127
127
|
elsif c.kind_of?(YARD::CodeObjects::ModuleObject)
|
128
128
|
detail = 'Module'
|
129
129
|
kind = Suggestion::MODULE
|
130
|
+
elsif c.kind_of?(YARD::CodeObjects::ConstantObject)
|
131
|
+
detail = 'Constant'
|
132
|
+
kind = Suggestion::CONSTANT
|
133
|
+
else
|
134
|
+
next
|
130
135
|
end
|
131
|
-
result.push Suggestion.new(c.to_s.split('::').last, detail: detail, kind: kind)
|
136
|
+
result.push Suggestion.new(c.to_s.split('::').last, detail: detail, kind: kind, documentation: c.docstring)
|
132
137
|
}
|
133
138
|
cache.set_constants(namespace, scope, result)
|
134
139
|
result
|
@@ -231,7 +236,6 @@ module Solargraph
|
|
231
236
|
end
|
232
237
|
}
|
233
238
|
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Object'
|
234
|
-
#if ns.superclass.kind_of?(YARD::CodeObjects::Proxy)
|
235
239
|
unless ns.nil?
|
236
240
|
meths += get_instance_methods(ns.superclass.to_s)
|
237
241
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module YardMethods
|
3
|
+
def yard_options
|
4
|
+
if @yard_options.nil?
|
5
|
+
@yard_options = {
|
6
|
+
include: [],
|
7
|
+
exclude: [],
|
8
|
+
flags: []
|
9
|
+
}
|
10
|
+
unless workspace.nil?
|
11
|
+
yardopts_file = File.join(workspace, '.yardopts')
|
12
|
+
if File.exist?(yardopts_file)
|
13
|
+
yardopts = File.read(yardopts_file)
|
14
|
+
yardopts.lines.each { |line|
|
15
|
+
arg = line.strip
|
16
|
+
if arg.start_with?('-')
|
17
|
+
@yard_options[:flags].push arg
|
18
|
+
else
|
19
|
+
@yard_options[:include].push arg
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@yard_options[:include].concat ['app/**/*.rb', 'lib/**/*.rb'] if @yard_options[:include].empty?
|
25
|
+
end
|
26
|
+
@yard_options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/solargraph/views/search.erb
|
147
147
|
- lib/solargraph/yard_map.rb
|
148
148
|
- lib/solargraph/yard_map/cache.rb
|
149
|
+
- lib/solargraph/yard_methods.rb
|
149
150
|
- lib/yard-solargraph.rb
|
150
151
|
- yardoc/2.0.0.tar.gz
|
151
152
|
homepage: http://castwide.com
|