solargraph 0.11.0 → 0.11.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0d57ee417fd4007c31d34a555f76701a51a19be
4
- data.tar.gz: 8b254f32899b99c3e2faa25361f043d05de235f2
3
+ metadata.gz: 10495d0e5d7c64f8529c0064a10c5a46de6618da
4
+ data.tar.gz: f96a938b6f90628d25221150b7bfbdca07a7bc39
5
5
  SHA512:
6
- metadata.gz: 764e250b3ba7f52b0d4dbaaf4b7180cf4094bfc8b7dabf6e4054ddf342c02f9587470823c2629b3b132c83627ace4e8c738c10755e76c373a922d192f4fd6e43
7
- data.tar.gz: 0abe5016eb85276abc4d2fc44a8f66c166986630b7dd5ba04878b19062e16b4fc45c2b6f195032cd73792964d1ae5dec3b1f0ff5607b6fb47404c6f31c8c6b74
6
+ metadata.gz: f072292781a9e234c51b2de18531cd00e350569a6a28b4fbe4e8041d0dbdadba5429032d2f93a11faa963c7b7665cdd56049a1a62173372aac16ecdad165103d
7
+ data.tar.gz: 8fd69162b003ddfaeb338c0369b8285cf2828e6b250dafb030ee0d8b6efddc0db8c3e94d1d313a4b00f15bf97d27d8dd7b6c57418450691029af308c8960570b
@@ -15,9 +15,9 @@ module Solargraph
15
15
  ].freeze
16
16
 
17
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
18
+ :array, :hash, :str, :int, :float, :block, :class, :sclass, :module,
19
+ :def, :defs, :ivasgn, :gvasgn, :lvasgn, :cvasgn, :casgn, :or_asgn,
20
+ :const, :lvar, :args, :kwargs
21
21
  ].freeze
22
22
 
23
23
  MAPPABLE_METHODS = [
@@ -25,6 +25,10 @@ module Solargraph
25
25
  :attr_accessor, :private, :public, :protected
26
26
  ].freeze
27
27
 
28
+ METHODS_RETURNING_SELF = [
29
+ 'clone', 'dup', 'freeze', 'taint', 'untaint'
30
+ ]
31
+
28
32
  include NodeMethods
29
33
  include YardMethods
30
34
 
@@ -304,11 +308,13 @@ module Solargraph
304
308
  if type.nil?
305
309
  cmnt = get_comment_for(node)
306
310
  if cmnt.nil?
307
- type = infer_literal_node_type(node.children[1])
311
+ name_i = (node.type == :casgn ? 1 : 0)
312
+ sig_i = (node.type == :casgn ? 2 : 1)
313
+ type = infer_literal_node_type(node.children[sig_i])
308
314
  if type.nil?
309
- sig = resolve_node_signature(node.children[1])
315
+ sig = resolve_node_signature(node.children[sig_i])
310
316
  # Avoid infinite loops from variable assignments that reference themselves
311
- return nil if node.children[0].to_s == sig.split('.').first
317
+ return nil if node.children[name_i].to_s == sig.split('.').first
312
318
  type = infer_signature_type(sig, namespace)
313
319
  end
314
320
  else
@@ -570,31 +576,39 @@ module Solargraph
570
576
  s = unpack_name(n.children[1])
571
577
  meths += inner_get_methods(s, root, skip)
572
578
  end
573
- meths += inner_get_methods_from_node(n, root, skip)
579
+ vis = [:public]
580
+ vis.push :private, :protected if namespace == root
581
+ meths += inner_get_methods_from_node(n, root, :class, skip, vis)
574
582
  end
575
583
  end
576
584
  }
577
585
  meths.uniq
578
586
  end
579
587
 
580
- def inner_get_methods_from_node node, root, skip
588
+ def inner_get_methods_from_node node, root, scope, skip, visibility, current_visibility = :public
581
589
  meths = []
582
590
  node.children.each { |c|
583
591
  if c.kind_of?(AST::Node)
584
- if c.type == :defs
592
+ if c.kind_of?(AST::Node) and c.type == :send and [:public, :protected, :private].include?(c.children[1])
593
+ current_visibility = c.children[1]
594
+ elsif (c.type == :defs and scope == :class) or (c.type == :def and scope == :instance)
595
+ next unless visibility.include?(current_visibility)
585
596
  docstring = get_comment_for(c)
586
- label = "#{c.children[1]}"
597
+ child_index = (scope == :class ? 1 : 0)
598
+ label = "#{c.children[child_index]}"
587
599
  args = get_method_args(c)
588
- if (c.children[1].to_s[0].match(/[a-z_]/i) and c.children[1] != :def)
589
- meths.push Suggestion.new(label, insert: c.children[1].to_s.gsub(/=/, ' = '), kind: Suggestion::METHOD, detail: 'Method', documentation: docstring, arguments: args)
600
+ if (c.children[child_index].to_s[0].match(/[a-z_]/i) and c.children[child_index] != :def)
601
+ meths.push Suggestion.new(label, insert: c.children[child_index].to_s.gsub(/=/, ' = '), kind: Suggestion::METHOD, detail: 'Method', documentation: docstring, arguments: args)
590
602
  end
603
+ elsif c.type == :sclass and scope == :class and c.children[0].type == :self
604
+ meths.concat inner_get_methods_from_node c, root, :instance, skip, visibility
591
605
  elsif c.type == :send and c.children[1] == :include
592
606
  # TODO: This might not be right. Should we be getting singleton methods
593
607
  # from an include, or only from an extend?
594
608
  i = unpack_name(c.children[2])
595
609
  meths.concat inner_get_methods(i, root, skip) unless i == 'Kernel'
596
610
  else
597
- meths.concat inner_get_methods_from_node(c, root, skip)
611
+ meths.concat inner_get_methods_from_node(c, root, scope, skip, visibility, current_visibility)
598
612
  end
599
613
  end
600
614
  }
@@ -686,17 +700,30 @@ module Solargraph
686
700
  result.push Suggestion.new(k, kind: kind, detail: detail)
687
701
  }
688
702
  nodes = get_namespace_nodes(fqns)
689
- nodes.each { |n|
703
+ nodes.each do |n|
704
+ result.concat get_constant_nodes(n, fqns)
690
705
  get_include_strings_from(n).each { |i|
691
706
  result += inner_namespaces_in(i, fqns, skip)
692
707
  }
693
- }
708
+ end
694
709
  end
695
710
  end
696
711
  end
697
712
  result
698
713
  end
699
714
 
715
+ def get_constant_nodes(node, fqns)
716
+ result = []
717
+ node.children.each do |n|
718
+ if n.kind_of?(AST::Node) and n.type == :casgn
719
+ cmnt = get_comment_for(n)
720
+ type = infer_assignment_node_type(n, fqns)
721
+ result.push Suggestion.new(n.children[1].to_s, kind: Suggestion::CONSTANT, documentation: cmnt, return_type: type)
722
+ end
723
+ end
724
+ result
725
+ end
726
+
700
727
  def inner_get_instance_variables(node, namespace, scope)
701
728
  arr = []
702
729
  if node.kind_of?(AST::Node)
@@ -756,6 +783,7 @@ module Solargraph
756
783
  while parts.length > 0 and !type.nil?
757
784
  p = parts.shift
758
785
  next if p.empty?
786
+ next if !type.nil? and !type.empty? and METHODS_RETURNING_SELF.include?(p)
759
787
  if top and scope == :class
760
788
  if p == 'self'
761
789
  top = false
@@ -843,7 +871,7 @@ module Solargraph
843
871
  return node if node.type == :args
844
872
  type = node.type
845
873
  children = []
846
- if node.type == :class or node.type == :block
874
+ if node.type == :class or node.type == :block or node.type == :sclass
847
875
  children += node.children[0, 2]
848
876
  children += get_mappable_nodes(node.children[2..-1], comment_hash)
849
877
  elsif node.type == :const or node.type == :args or node.type == :kwargs
@@ -857,7 +885,7 @@ module Solargraph
857
885
  elsif node.type == :module
858
886
  children += node.children[0, 1]
859
887
  children += get_mappable_nodes(node.children[1..-1], comment_hash)
860
- elsif node.type == :ivasgn or node.type == :gvasgn or node.type == :lvasgn or node.type == :cvasgn
888
+ elsif node.type == :ivasgn or node.type == :gvasgn or node.type == :lvasgn or node.type == :cvasgn or node.type == :casgn
861
889
  children += node.children
862
890
  elsif node.type == :send and node.children[1] == :include
863
891
  children += node.children[0,3]
@@ -553,7 +553,7 @@ module Solargraph
553
553
  if local.type == :def
554
554
  result += api_map.get_instance_methods(scope, visibility: [:public, :private, :protected])
555
555
  else
556
- result += api_map.get_methods(scope, visibility: [:public, :private, :protected])
556
+ result += api_map.get_methods(scope, scope, visibility: [:public, :private, :protected])
557
557
  end
558
558
  if local.type == :def or local.type == :defs
559
559
  result += get_method_arguments_from local
@@ -581,7 +581,7 @@ module Solargraph
581
581
  end
582
582
  end
583
583
  result = []
584
- args = node.children[1]
584
+ args = node.children[(node.type == :def ? 1 : 2)]
585
585
  return result unless args.kind_of?(AST::Node) and args.type == :args
586
586
  args.children.each do |arg|
587
587
  name = arg.children[0].to_s
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.11.0'
2
+ VERSION = '0.11.1'
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.11.0
4
+ version: 0.11.1
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-17 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser