solargraph 0.15.3 → 0.15.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 973c57ed92c49cbc1c242f26d30660a0260329c3
4
- data.tar.gz: 0f4313ae7372cac8995a78f23992cc2c91c58d85
3
+ metadata.gz: 24b597ba06561ddd1bc1a8b4552b7d3bb1ee3867
4
+ data.tar.gz: 37bc48eabc24b26b736b64f451402faa0cce7624
5
5
  SHA512:
6
- metadata.gz: 28dad009825df7ce472a842b134f47eb6341171a176c4ebf88c01f092819d7e1cdf3645c88142e18fbe35c9c811ff022eee4715df47b8a053382158b426fa987
7
- data.tar.gz: 86d7d8120d867c48cd2a480b71cc4ee0fd72f39bd2c70cc34ae8a73bbd9706fc031e4b39d522387865f107bba1b43fdd8fae7f9bb3e1a6f849ca0c38077f06ce
6
+ metadata.gz: 9bdf2c98784584111834a166a87daab38c94aa9158db3efd05e655651b5b050afdcf488a7d33b78704f9cb04274a137ca047855df93dd1e91a9b010ce69b0b4a
7
+ data.tar.gz: e7de68f3751c3a86cd7ed7c3ea3003a902ad72cf6fab8cac6f05a13190118b360e0da4926c707ffdaf5a7075a54a23c12e5e6b665d82279653cb3d5335020c80
@@ -187,7 +187,7 @@ module Solargraph
187
187
  resolved = find_namespace_pins(parts.join('::'))
188
188
  resolved.each do |pin|
189
189
  visi = :public
190
- visi = :private if root != '' and pin.path == fqns
190
+ visi = :private if namespace == '' and root != '' and pin.path == fqns
191
191
  result.concat inner_get_constants(pin.path, skip, true, visi)
192
192
  end
193
193
  end
@@ -338,6 +338,7 @@ module Solargraph
338
338
  suggest_unique_variables globals
339
339
  end
340
340
 
341
+ # @return [Array<Solargraph::Pin::GlobalVariable>]
341
342
  def get_global_variable_pins
342
343
  globals = []
343
344
  @sources.values.each do |s|
@@ -366,7 +367,9 @@ module Solargraph
366
367
  if cache.has_signature_type?(signature, namespace, scope)
367
368
  return cache.get_signature_type(signature, namespace, scope)
368
369
  end
369
- return nil if signature.nil? or signature.empty?
370
+ return nil if signature.nil?
371
+ return namespace if signature.empty? and scope == :instance
372
+ return nil if signature.empty? # @todo This might need to return Class<namespace>
370
373
  if !signature.include?('.')
371
374
  fqns = find_fully_qualified_namespace(signature, namespace)
372
375
  unless fqns.nil? or fqns.empty?
@@ -412,6 +415,8 @@ module Solargraph
412
415
  result
413
416
  end
414
417
 
418
+ # @param [String] A fully qualified namespace
419
+ # @return [Symbol] :class, :module, or nil
415
420
  def get_namespace_type fqns
416
421
  return nil if fqns.nil?
417
422
  type = nil
@@ -435,7 +440,7 @@ module Solargraph
435
440
  fqns = find_fully_qualified_namespace(namespace, root)
436
441
  meths = []
437
442
  skip = []
438
- meths.concat inner_get_methods(namespace, root, skip)
443
+ meths.concat inner_get_methods(namespace, root, skip, visibility)
439
444
  yard_meths = yard_map.get_methods(fqns, '', visibility: visibility)
440
445
  if yard_meths.any?
441
446
  meths.concat yard_meths
@@ -522,6 +527,8 @@ module Solargraph
522
527
  arr
523
528
  end
524
529
 
530
+ # Update the ApiMap with the most recent version of the specified file.
531
+ #
525
532
  def update filename
526
533
  filename.gsub!(/\\/, '/')
527
534
  if filename.end_with?('.rb')
@@ -544,11 +551,12 @@ module Solargraph
544
551
  end
545
552
  end
546
553
 
554
+ # @return [Array<Solargraph::ApiMap::Source>]
547
555
  def sources
548
556
  @sources.values
549
557
  end
550
558
 
551
- # @return [Array<String>]
559
+ # @return [Array<Solargraph::Suggestion>]
552
560
  def get_path_suggestions path
553
561
  refresh
554
562
  result = []
@@ -572,6 +580,7 @@ module Solargraph
572
580
  result
573
581
  end
574
582
 
583
+ # @return [Array<String>]
575
584
  def search query
576
585
  refresh
577
586
  rake_yard(@sources.values) if @yard_stale
@@ -619,6 +628,7 @@ module Solargraph
619
628
  @symbol_pins = []
620
629
  @attr_pins = {}
621
630
  @namespace_includes = {}
631
+ @namespace_extends = {}
622
632
  @superclasses = {}
623
633
  @namespace_pins = {}
624
634
  namespace_map.clear
@@ -716,6 +726,10 @@ module Solargraph
716
726
  @namespace_includes[ns] ||= []
717
727
  @namespace_includes[ns].concat(i).uniq!
718
728
  end
729
+ source.namespace_extends.each_pair do |ns, e|
730
+ @namespace_extends[ns] ||= []
731
+ @namespace_extends[ns].concat(e).uniq!
732
+ end
719
733
  source.superclasses.each_pair do |cls, sup|
720
734
  @superclasses[cls] = sup
721
735
  end
@@ -742,7 +756,7 @@ module Solargraph
742
756
  mn = @method_pins[fqns]
743
757
  unless mn.nil?
744
758
  mn.select{ |pin| pin.scope == :class }.each do |pin|
745
- meths.push pin_to_suggestion(pin)
759
+ meths.push pin_to_suggestion(pin) if visibility.include?(pin.visibility)
746
760
  end
747
761
  end
748
762
  if visibility.include?(:public) or visibility.include?(:protected)
@@ -753,6 +767,12 @@ module Solargraph
753
767
  meths.concat get_methods(sc, fqns, visibility: sc_visi)
754
768
  end
755
769
  end
770
+ em = @namespace_extends[fqns]
771
+ unless em.nil?
772
+ em.each do |e|
773
+ meths.concat get_instance_methods(e, fqns, visibility: visibility)
774
+ end
775
+ end
756
776
  meths.uniq
757
777
  end
758
778
 
@@ -875,10 +895,13 @@ module Solargraph
875
895
  result
876
896
  end
877
897
 
898
+ # @return [AST::Node]
878
899
  def file_nodes
879
900
  @sources.values.map(&:node)
880
901
  end
881
902
 
903
+ # @param namespace [String]
904
+ # @return [String]
882
905
  def clean_namespace_string namespace
883
906
  result = namespace.to_s.gsub(/<.*$/, '')
884
907
  if result == 'Class' and namespace.include?('<')
@@ -894,7 +917,18 @@ module Solargraph
894
917
  # @param pin [Solargraph::Pin::Base]
895
918
  # @return [Solargraph::Suggestion]
896
919
  def pin_to_suggestion pin
897
- @pin_suggestions[pin] ||= Suggestion.pull(pin)
920
+ return_type = pin.return_type
921
+ if return_type.nil? and pin.is_a?(Solargraph::Pin::Method)
922
+ sc = @superclasses[pin.namespace]
923
+ while return_type.nil? and !sc.nil?
924
+ sc_path = "#{sc}#{pin.scope == :instance ? '#' : '.'}#{pin.name}"
925
+ sugg = get_path_suggestions(sc_path).first
926
+ break if sugg.nil?
927
+ return_type = sugg.return_type
928
+ sc = @superclasses[sc]
929
+ end
930
+ end
931
+ @pin_suggestions[pin] ||= Suggestion.pull(pin, return_type)
898
932
  end
899
933
 
900
934
  def require_extensions
@@ -70,6 +70,10 @@ module Solargraph
70
70
  @namespace_includes ||= {}
71
71
  end
72
72
 
73
+ def namespace_extends
74
+ @namespaces_extends ||= {}
75
+ end
76
+
73
77
  def superclasses
74
78
  @superclasses ||= {}
75
79
  end
@@ -304,11 +308,16 @@ module Solargraph
304
308
  end
305
309
  end
306
310
  next
307
- elsif c.type == :send and c.children[1] == :include #and node.type == :class
311
+ elsif c.type == :send and c.children[1] == :include
308
312
  namespace_includes[fqn] ||= []
309
313
  c.children[2..-1].each do |i|
310
314
  namespace_includes[fqn].push unpack_name(i)
311
315
  end
316
+ elsif c.type == :send and c.children[1] == :extend
317
+ namespace_extends[fqn] ||= []
318
+ c.children[2..-1].each do |i|
319
+ namespace_extends[fqn].push unpack_name(i)
320
+ end
312
321
  elsif c.type == :send and [:attr_reader, :attr_writer, :attr_accessor].include?(c.children[1])
313
322
  c.children[2..-1].each do |a|
314
323
  if c.children[1] == :attr_reader or c.children[1] == :attr_accessor
@@ -49,7 +49,7 @@ module Solargraph
49
49
  code_object_map[pin.path].docstring = pin.docstring unless pin.docstring.nil?
50
50
  code_object_map[pin.path].files.push pin.source.filename
51
51
  code_object_map[pin.path].parameters = pin.parameters.map do |p|
52
- n = p.match(/^[a-z0-9\-]*?:?/i)[0]
52
+ n = p.match(/^[a-z0-9_]*:?/i)[0]
53
53
  v = nil
54
54
  if p.length > n.length
55
55
  v = p[n.length..-1].gsub(/^ = /, '')
@@ -224,15 +224,10 @@ module Solargraph
224
224
  else
225
225
  type = infer_literal_node_type(node_at(index - 2))
226
226
  if type.nil?
227
- parts = namespace.to_s.split('::')
228
227
  result += get_snippets_at(index) if with_snippets
229
228
  result += get_local_variables_and_methods_at(index)
230
229
  result += ApiMap.get_keywords
231
- while parts.length > 0
232
- ns = parts.join('::')
233
- result += api_map.get_constants(ns, namespace)
234
- parts.pop
235
- end
230
+ result += api_map.get_constants('', namespace)
236
231
  result += api_map.get_constants('')
237
232
  result += api_map.get_instance_methods('Kernel', namespace)
238
233
  result += api_map.get_methods('', namespace)
@@ -417,14 +412,23 @@ module Solargraph
417
412
  remainder = parts[1..-1]
418
413
  if start.start_with?('@@')
419
414
  cv = api_map.get_class_variable_pins(ns_here).select{|s| s.name == start}.first
420
- return (cv.return_type || api_map.infer_assignment_node_type(cv.node, cv.namespace)) unless cv.nil?
415
+ unless cv.nil?
416
+ vartype = (cv.return_type || api_map.infer_assignment_node_type(cv.node, cv.namespace))
417
+ return api_map.infer_signature_type(remainder.join('.'), vartype, scope: :instance)
418
+ end
421
419
  elsif start.start_with?('@')
422
420
  scope = (node.type == :def ? :instance : :class)
423
421
  iv = api_map.get_instance_variable_pins(ns_here, scope).select{|s| s.name == start}.first
424
- return (iv.return_type || api_map.infer_assignment_node_type(iv.node, iv.namespace)) unless iv.nil?
422
+ unless iv.nil?
423
+ vartype = (iv.return_type || api_map.infer_assignment_node_type(iv.node, iv.namespace))
424
+ return api_map.infer_signature_type(remainder.join('.'), vartype, scope: :instance)
425
+ end
425
426
  elsif start.start_with?('$')
426
427
  gv = api_map.get_global_variable_pins.select{|s| s.name == start}.first
427
- return (gv.return_type || api_map.infer_assignment_node_type(gv.node, gv.namespace)) unless gv.nil?
428
+ unless gv.nil?
429
+ vartype = (gv.return_type || api_map.infer_assignment_node_type(gv.node, gv.namespace))
430
+ return api_map.infer_signature_type(remainder.join('.'), vartype, scope: :instance)
431
+ end
428
432
  end
429
433
  var = find_local_variable_node(start, node)
430
434
  if var.nil?
@@ -76,7 +76,7 @@ module Solargraph
76
76
  code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: api_map, cursor: [params['line'].to_i, params['column'].to_i])
77
77
  offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
78
78
  sugg = code_map.signatures_at(offset)
79
- { "status" => "ok", "suggestions" => sugg }.to_json
79
+ { "status" => "ok", "suggestions" => sugg.map{|s| s.as_json(all: true)} }.to_json
80
80
  rescue Exception => e
81
81
  STDERR.puts e
82
82
  STDERR.puts e.backtrace.join("\n")
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.15.3'
2
+ VERSION = '0.15.4'
3
3
  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.15.3
4
+ version: 0.15.4
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-12-13 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser