solargraph 0.12.0 → 0.12.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: 9a0cb900eab77f94ad22582f22dc8ea75c249485
4
- data.tar.gz: 478c5f05faf26850590f928060b35e61903cb807
3
+ metadata.gz: 12ba7fd6f2f9b2393c21aba8249cd43e7c69062f
4
+ data.tar.gz: c102835081a9b19b74180c1f75b7ebaea695e5f1
5
5
  SHA512:
6
- metadata.gz: afcd662f413015ece4a315039be1837a8f95b1a10806d75e6ac2ce8d08fa91d3e0720cd67aa1c383f34c6800f5d2c9a3a722c199a093663f6aefec0e93d92480
7
- data.tar.gz: 9d9dacf3f53e4a53f69f325e9bd56d42d252cba529a91766515c2e3b9080403bd20f8dbdc801168a5b72164e12f02700b4bdc960845abb2706456391c9214e6a
6
+ metadata.gz: 0bd7974b55a00ec8a914e77dffe352af321bbe9e27d1a1c19c74417015bc6d7886077017313e3526489e6a12e2b0933dc586cae2252e31afb0332da75f5a9f76
7
+ data.tar.gz: cdc14d195c758dc1acd151e22155c41390026bb89e9a74756b9b28e24cd68f53fde8c1e8ce20f4c8a3bb1244f0bfa12f034fda91e0438a9c534483e8a61aed01
@@ -23,7 +23,7 @@ module Solargraph
23
23
  ].freeze
24
24
 
25
25
  MAPPABLE_NODES = [
26
- :array, :hash, :str, :dstr, :int, :float, :block, :class, :sclass,
26
+ :array, :hash, :str, :dstr, :int, :float, :sym, :block, :class, :sclass,
27
27
  :module, :def, :defs, :ivasgn, :gvasgn, :lvasgn, :cvasgn, :casgn,
28
28
  :or_asgn, :const, :lvar, :args, :kwargs
29
29
  ].freeze
@@ -35,7 +35,7 @@ module Solargraph
35
35
 
36
36
  METHODS_RETURNING_SELF = [
37
37
  'clone', 'dup', 'freeze', 'taint', 'untaint'
38
- ]
38
+ ].freeze
39
39
 
40
40
  include NodeMethods
41
41
  include YardMethods
@@ -202,7 +202,7 @@ module Solargraph
202
202
  ip = @ivar_pins[namespace]
203
203
  unless ip.nil?
204
204
  ip.select{ |pin| pin.scope == scope }.each do |pin|
205
- result.push pin.suggestion(self)
205
+ result.push pin.suggestion
206
206
  end
207
207
  end
208
208
  result
@@ -214,7 +214,7 @@ module Solargraph
214
214
  ip = @cvar_pins[namespace]
215
215
  unless ip.nil?
216
216
  ip.each do |pin|
217
- result.push pin.suggestion(self)
217
+ result.push pin.suggestion
218
218
  end
219
219
  end
220
220
  result
@@ -532,15 +532,16 @@ module Solargraph
532
532
  @namespace_map = {}
533
533
  @namespace_tree = {}
534
534
  @required = []
535
+ end
536
+
537
+ def process_maps
538
+ cache.clear
535
539
  @ivar_pins = {}
536
540
  @cvar_pins = {}
537
541
  @method_pins = {}
538
542
  @attr_nodes = {}
539
543
  @namespace_includes = {}
540
544
  @superclasses = {}
541
- end
542
-
543
- def process_maps
544
545
  @parent_stack = {}
545
546
  @namespace_map = {}
546
547
  @namespace_tree = {}
@@ -840,7 +841,7 @@ module Solargraph
840
841
  # TODO: The api_map should ignore local variables.
841
842
  type = node.children[0].type
842
843
  children.push node.children[0].children[0], node.children[1]
843
- elsif [:array, :hash, :str, :dstr, :int, :float].include?(node.type)
844
+ elsif [:array, :hash, :str, :dstr, :int, :float, :sym].include?(node.type)
844
845
  # @todo Do we really care about the details?
845
846
  end
846
847
  result = node.updated(type, children)
@@ -896,10 +897,10 @@ module Solargraph
896
897
  if c.kind_of?(AST::Node)
897
898
  if c.type == :ivasgn
898
899
  @ivar_pins[fqn] ||= []
899
- @ivar_pins[fqn].push IvarPin.new(c, fqn, local_scope, get_comment_for(c))
900
+ @ivar_pins[fqn].push IvarPin.new(self, c, fqn, local_scope, get_comment_for(c))
900
901
  elsif c.type == :cvasgn
901
902
  @cvar_pins[fqn] ||= []
902
- @cvar_pins[fqn].push CvarPin.new(c, fqn, get_comment_for(c))
903
+ @cvar_pins[fqn].push CvarPin.new(self, c, fqn, get_comment_for(c))
903
904
  else
904
905
  unless fqn.nil? or in_yardoc
905
906
  if c.kind_of?(AST::Node)
@@ -21,6 +21,11 @@ module Solargraph
21
21
  def set_assignment_node_type node, namespace, value
22
22
  @assignment_node_types[[node, namespace]] = value
23
23
  end
24
+
25
+ def clear
26
+ @signature_types.clear
27
+ @assignment_node_types.clear
28
+ end
24
29
  end
25
30
  end
26
31
  end
@@ -5,20 +5,21 @@ module Solargraph
5
5
  attr_reader :namespace
6
6
  attr_reader :docstring
7
7
 
8
- def initialize node, namespace, docstring
8
+ def initialize api_map, node, namespace, docstring
9
+ @api_map = api_map
9
10
  @node = node
10
11
  @namespace = namespace
11
12
  @docstring = docstring
12
13
  end
13
14
 
14
- def suggestion(api_map)
15
- @suggestion ||= generate_suggestion(api_map)
15
+ def suggestion
16
+ @suggestion ||= generate_suggestion
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- def generate_suggestion(api_map)
21
- type = api_map.infer_assignment_node_type(node, namespace)
21
+ def generate_suggestion
22
+ type = @api_map.infer_assignment_node_type(node, namespace)
22
23
  Suggestion.new(node.children[0], kind: Suggestion::VARIABLE, documentation: docstring, return_type: type)
23
24
  end
24
25
  end
@@ -6,21 +6,22 @@ module Solargraph
6
6
  attr_reader :scope
7
7
  attr_reader :docstring
8
8
 
9
- def initialize node, namespace, scope, docstring
9
+ def initialize api_map, node, namespace, scope, docstring
10
+ @api_map = api_map
10
11
  @node = node
11
12
  @namespace = namespace
12
13
  @scope = scope
13
14
  @docstring = docstring
14
15
  end
15
16
 
16
- def suggestion(api_map)
17
- @suggestion ||= generate_suggestion(api_map)
17
+ def suggestion
18
+ @suggestion ||= generate_suggestion
18
19
  end
19
20
 
20
21
  private
21
22
 
22
- def generate_suggestion(api_map)
23
- type = api_map.infer_assignment_node_type(node, namespace)
23
+ def generate_suggestion
24
+ type = @api_map.infer_assignment_node_type(node, namespace)
24
25
  Suggestion.new(node.children[0], kind: Suggestion::VARIABLE, documentation: docstring, return_type: type)
25
26
  end
26
27
  end
@@ -98,6 +98,8 @@ module Solargraph
98
98
  # @return [Solargraph::ApiMap]
99
99
  def api_map
100
100
  @api_map ||= ApiMap.new(workspace)
101
+ @api_map.refresh
102
+ @api_map
101
103
  end
102
104
 
103
105
  # Get the offset of the specified line and column.
@@ -395,7 +397,11 @@ module Solargraph
395
397
  literal = node_at(index - 1)
396
398
  else
397
399
  beg_sig = get_signature_index_at(index)
398
- literal = node_at(1 + beg_sig)
400
+ if @code[beg_sig] == '.'
401
+ literal = node_at(beg_sig - 1)
402
+ else
403
+ literal = node_at(1 + beg_sig)
404
+ end
399
405
  end
400
406
  type = infer_literal_node_type(literal)
401
407
  if type.nil?
@@ -431,11 +437,19 @@ module Solargraph
431
437
  end
432
438
  end
433
439
  else
434
- if signature.empty?
440
+ if signature.empty? or signature == '[].'
435
441
  result = type
436
442
  else
437
443
  cursed = get_signature_index_at(index)
438
- rest = signature[literal.loc.expression.end_pos+(cursed-literal.loc.expression.end_pos)..-1]
444
+ if signature.start_with?('[].')
445
+ rest = signature[3..-1]
446
+ else
447
+ if signature.start_with?('.')
448
+ rest = signature[literal.loc.expression.end_pos+(cursed-literal.loc.expression.end_pos)..-1]
449
+ else
450
+ rest = signature
451
+ end
452
+ end
439
453
  return type if rest.nil?
440
454
  lit_code = @code[literal.loc.expression.begin_pos..literal.loc.expression.end_pos]
441
455
  rest = rest[lit_code.length..-1] if rest.start_with?(lit_code)
@@ -541,28 +555,30 @@ module Solargraph
541
555
  signature = ''
542
556
  index -=1
543
557
  while index >= 0
544
- break if brackets > 0 or parens > 0 or squares > 0
545
- char = @code[index, 1]
546
- if char == ')'
547
- parens -=1
548
- elsif char == ']'
549
- squares -=1
550
- elsif char == '}'
551
- brackets -= 1
552
- elsif char == '('
553
- parens += 1
554
- elsif char == '{'
555
- brackets += 1
556
- elsif char == '['
557
- squares += 1
558
- signature = ".[]#{signature}" if squares == 0 and @code[index-2] != '%'
559
- end
560
- if brackets == 0 and parens == 0 and squares == 0
561
- break if ['"', "'", ',', ' ', "\t", "\n", ';', '%'].include?(char)
562
- signature = char + signature if char.match(/[a-z0-9:\._@]/i) and @code[index - 1] != '%'
563
- if char == '@'
564
- signature = "@#{signature}" if @code[index-1, 1] == '@'
565
- break
558
+ unless string_at?(index)
559
+ break if brackets > 0 or parens > 0 or squares > 0
560
+ char = @code[index, 1]
561
+ if char == ')'
562
+ parens -=1
563
+ elsif char == ']'
564
+ squares -=1
565
+ elsif char == '}'
566
+ brackets -= 1
567
+ elsif char == '('
568
+ parens += 1
569
+ elsif char == '{'
570
+ brackets += 1
571
+ elsif char == '['
572
+ squares += 1
573
+ signature = ".[]#{signature}" if squares == 0 and @code[index-2] != '%'
574
+ end
575
+ if brackets == 0 and parens == 0 and squares == 0
576
+ break if ['"', "'", ',', ' ', "\t", "\n", ';', '%'].include?(char)
577
+ signature = char + signature if char.match(/[a-z0-9:\._@]/i) and @code[index - 1] != '%'
578
+ if char == '@'
579
+ signature = "@#{signature}" if @code[index-1, 1] == '@'
580
+ break
581
+ end
566
582
  end
567
583
  end
568
584
  index -= 1
@@ -51,6 +51,8 @@ module Solargraph
51
51
  return 'Integer'
52
52
  elsif node.type == :float
53
53
  return 'Float'
54
+ elsif node.type == :sym
55
+ return 'Symbol'
54
56
  end
55
57
  nil
56
58
  end
@@ -93,7 +93,7 @@ module Solargraph
93
93
  arguments: @arguments,
94
94
  params: params,
95
95
  return_type: return_type,
96
- documentation: @helper.html_markup_rdoc(documentation.to_s)
96
+ documentation: documentation.nil? ? nil : @helper.html_markup_rdoc(documentation)
97
97
  }
98
98
  obj.to_json(args)
99
99
  end
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.12.0'
2
+ VERSION = '0.12.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.12.0
4
+ version: 0.12.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-09-12 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser