solargraph 0.39.15 → 0.39.16

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
  SHA256:
3
- metadata.gz: 7e70e17b5895de1eea7c7455249afbcf26bb1cb59eb4d47ae93d7e37b53e653d
4
- data.tar.gz: ba947a023fcc459c489e84afce5d7af0ccce1d3b0b0ba6a6f4b89c72e6693a8e
3
+ metadata.gz: 949ea02c957254c5fd37a427a4eacbdc55b185c14e2372b659eb0ec4ca3fd254
4
+ data.tar.gz: cdd35fd88fc71ed5421d1a4cbd6033791e44a00bc6bd695ea57055004ea09c94
5
5
  SHA512:
6
- metadata.gz: 1c869730843c3b6f3ad7ea20646c5aed3c22e36b61a8d31e550b13f44de966f8837f9bf35463a9353e755eb6a8352ad2b9c110e5e07a8fd2ad8c6445af1dec83
7
- data.tar.gz: 3abeace1fea2e9ae611c43bc222968f73bcfb3822761bea46935168d398774cb66fa87528fa851ef080e84dc2cd9d577cada3f5478ad0af4896d02595c16d04f
6
+ metadata.gz: 4db457d03f5464a15fedd4b6cd6dc60b591a7574013ef5babb246d33e6469078134511a77f80455dc52e47ac1d8d428b78e02c3bc818fe58b665e32f45331a7c
7
+ data.tar.gz: 17b166d81771a0a508e954c7c83ce9ceed0830a0d7c4f4d568a57cac1eb8b23524be0a23f4eaa049fd99b90415faea7be664c02b939e5103795cabc15a4a3ca4
data/Rakefile CHANGED
@@ -11,4 +11,15 @@ end
11
11
  desc "Open a Pry session preloaded with this library"
12
12
  task :console do
13
13
  sh "pry -I lib -r solargraph.rb"
14
- end
14
+ end
15
+
16
+ desc "Run the type checker"
17
+ task :typecheck do
18
+ sh "bundle exec solargraph typecheck --level typed"
19
+ end
20
+
21
+ desc "Run all tests"
22
+ task :test do
23
+ Rake::Task["typecheck"].invoke
24
+ Rake::Task["spec"].invoke
25
+ end
@@ -386,9 +386,7 @@ module Solargraph
386
386
  # @return [Array<Solargraph::Pin::Base>]
387
387
  def get_path_suggestions path
388
388
  return [] if path.nil?
389
- result = []
390
- result.concat store.get_path_pins(path)
391
- resolve_method_aliases(result)
389
+ resolve_method_aliases store.get_path_pins(path)
392
390
  end
393
391
 
394
392
  # Get an array of pins that match the specified path.
@@ -447,7 +445,7 @@ module Solargraph
447
445
  # @return [Array<Solargraph::Pin::Base>]
448
446
  def locate_pins location
449
447
  return [] if location.nil? || !source_map_hash.has_key?(location.filename)
450
- source_map_hash[location.filename].locate_pins(location)
448
+ resolve_method_aliases source_map_hash[location.filename].locate_pins(location)
451
449
  end
452
450
 
453
451
  # @raise [FileNotFoundError] if the cursor's file is not in the ApiMap
@@ -464,7 +462,7 @@ module Solargraph
464
462
  # @return [Array<Pin::Symbol>]
465
463
  def document_symbols filename
466
464
  return [] unless source_map_hash.has_key?(filename) # @todo Raise error?
467
- source_map_hash[filename].document_symbols
465
+ resolve_method_aliases source_map_hash[filename].document_symbols
468
466
  end
469
467
 
470
468
  # @return [Array<SourceMap>]
@@ -659,6 +657,7 @@ module Solargraph
659
657
  return nil if name.nil?
660
658
  return nil if skip.include?(root)
661
659
  skip.add root
660
+ possibles = []
662
661
  if name == ''
663
662
  if root == ''
664
663
  return ''
@@ -674,16 +673,19 @@ module Solargraph
674
673
  incs = store.get_includes(roots.join('::'))
675
674
  incs.each do |inc|
676
675
  foundinc = inner_qualify(name, inc, skip)
677
- return foundinc unless foundinc.nil?
676
+ possibles.push foundinc unless foundinc.nil?
678
677
  end
679
678
  roots.pop
680
679
  end
681
- incs = store.get_includes('')
682
- incs.each do |inc|
683
- foundinc = inner_qualify(name, inc, skip)
684
- return foundinc unless foundinc.nil?
680
+ if possibles.empty?
681
+ incs = store.get_includes('')
682
+ incs.each do |inc|
683
+ foundinc = inner_qualify(name, inc, skip)
684
+ possibles.push foundinc unless foundinc.nil?
685
+ end
685
686
  end
686
687
  return name if store.namespace_exists?(name)
688
+ return possibles.last
687
689
  end
688
690
  end
689
691
 
@@ -723,7 +725,7 @@ module Solargraph
723
725
  result = []
724
726
  pins.each do |pin|
725
727
  resolved = resolve_method_alias(pin)
726
- next unless visibility.include?(resolved.visibility)
728
+ next if resolved.respond_to?(:visibility) && !visibility.include?(resolved.visibility)
727
729
  result.push resolved
728
730
  end
729
731
  result
@@ -737,15 +739,16 @@ module Solargraph
737
739
  origin = get_method_stack(pin.full_context.namespace, pin.original, scope: pin.scope).first
738
740
  @method_alias_stack.pop
739
741
  return pin if origin.nil?
740
- Pin::Method.new(
742
+ args = {
741
743
  location: pin.location,
742
744
  closure: pin.closure,
743
745
  name: pin.name,
744
746
  comments: origin.comments,
745
747
  scope: origin.scope,
746
- visibility: origin.visibility,
747
- parameters: origin.parameters
748
- )
748
+ visibility: origin.visibility
749
+ }
750
+ args[:parameters] = origin.parameters if origin.is_a?(Pin::Method)
751
+ origin.class.new **args
749
752
  end
750
753
  end
751
754
  end
@@ -218,7 +218,7 @@ module Solargraph
218
218
  @pin_select_cache = {}
219
219
  @namespace_map = set.classify(&:namespace).transform_values(&:to_a)
220
220
  @path_pin_hash = set.classify(&:path).transform_values(&:to_a)
221
- @namespaces = @path_pin_hash.keys.compact
221
+ @namespaces = @path_pin_hash.keys.compact.to_set
222
222
  pins_by_class(Pin::Reference::Include).each do |pin|
223
223
  include_references[pin.namespace] ||= []
224
224
  include_references[pin.namespace].push pin.name
@@ -12,7 +12,7 @@ module Solargraph
12
12
 
13
13
  # @param types [Array<UniqueType>]
14
14
  def initialize types = [UniqueType::UNDEFINED]
15
- @items = types
15
+ @items = types.uniq(&:to_s)
16
16
  end
17
17
 
18
18
  # @param api_map [ApiMap]
@@ -113,7 +113,7 @@ module Solargraph
113
113
  #
114
114
  # @param *strings [Array<String>] The type definitions to parse
115
115
  # @param partial [Boolean] True if the string is part of a another type
116
- # @return [ComplexType]
116
+ # @return [ComplexType, Array, nil]
117
117
  def parse *strings, partial: false
118
118
  @cache ||= {}
119
119
  unless partial
@@ -53,6 +53,7 @@ module Solargraph
53
53
  @return_single_parameter
54
54
  @return_single_parameter
55
55
  )),
56
+ Override.method_return('Array#concat', 'Array'),
56
57
  Override.from_comment('Array#first', %(
57
58
  @overload first(num)
58
59
  @param num [Integer]
@@ -65,6 +66,7 @@ module Solargraph
65
66
  @return [self]
66
67
  @return_single_parameter
67
68
  )),
69
+ Override.method_return('Array#map', 'Array'),
68
70
  Override.method_return('Array#uniq', 'self'),
69
71
  Override.method_return('Array#zip', 'Array, nil'),
70
72
 
@@ -102,6 +104,8 @@ module Solargraph
102
104
  @param_tuple
103
105
  )),
104
106
 
107
+ Override.method_return('Hash#merge', 'Hash'),
108
+
105
109
  Override.from_comment('Integer#+', %(
106
110
  @param y [Numeric]
107
111
  @return [Numeric]
@@ -109,10 +113,6 @@ module Solargraph
109
113
 
110
114
  Override.method_return('Kernel#puts', 'nil'),
111
115
 
112
- # Override.method_return('Module#attr_reader', 'void'),
113
- # Override.method_return('Module#attr_writer', 'void'),
114
- # Override.method_return('Module#attr_accessor', 'void'),
115
-
116
116
  Override.from_comment('Numeric#+', %(
117
117
  @param y [Numeric]
118
118
  @return [Numeric]
@@ -148,6 +148,10 @@ module Solargraph
148
148
  Override.method_return('String#lines', 'Array<String>'),
149
149
  Override.from_comment('String#each_line', %(
150
150
  @yieldparam [String]
151
+ )),
152
+ Override.from_comment('String.new', %(
153
+ @overload new(*)
154
+ @return [self]
151
155
  ))
152
156
  ].concat(
153
157
  methods_with_yieldparam_subtypes.map do |path|
@@ -90,7 +90,8 @@ module Solargraph
90
90
  if node.children[2].is_a?(AST::Node) && node.children[2].type == :const
91
91
  cp = region.closure
92
92
  node.children[2..-1].each do |i|
93
- pins.push Pin::Reference::Include.new(
93
+ type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
94
+ pins.push type.new(
94
95
  location: get_node_location(i),
95
96
  closure: cp,
96
97
  name: unpack_name(i)
@@ -91,7 +91,8 @@ module Solargraph
91
91
  return unless Parser.is_ast_node?(node.children.last)
92
92
  node.children.last.children[0..-2].each do |i|
93
93
  next unless [:COLON2, :COLON3, :CONST].include?(i.type)
94
- pins.push Pin::Reference::Include.new(
94
+ type = region.scope == :class ? Pin::Reference::Extend : Pin::Reference::Include
95
+ pins.push type.new(
95
96
  location: get_node_location(i),
96
97
  closure: region.closure,
97
98
  name: unpack_name(i)
@@ -84,6 +84,14 @@ module Solargraph
84
84
  @explicit
85
85
  end
86
86
 
87
+ def completion_item_kind
88
+ Solargraph::LanguageServer::CompletionItemKinds::METHOD
89
+ end
90
+
91
+ def symbol_kind
92
+ Solargraph::LanguageServer::SymbolKinds::METHOD
93
+ end
94
+
87
95
  private
88
96
 
89
97
  # @return [ComplexType]
@@ -23,16 +23,15 @@ module Solargraph
23
23
 
24
24
  # @return [Hash]
25
25
  def resolve_completion_item
26
- if @resolve_completion_item.nil?
26
+ @resolve_completion_item ||= begin
27
27
  extra = {}
28
28
  alldoc = ''
29
29
  # alldoc += link_documentation unless link_documentation.nil?
30
30
  # alldoc += "\n\n" unless alldoc.empty?
31
31
  alldoc += documentation unless documentation.nil?
32
32
  extra[:documentation] = alldoc unless alldoc.empty?
33
- @resolve_completion_item = completion_item.merge(extra)
33
+ completion_item.merge(extra)
34
34
  end
35
- @resolve_completion_item
36
35
  end
37
36
 
38
37
  # @return [Hash]
@@ -54,11 +54,11 @@ module Solargraph
54
54
  # @param a [Array]
55
55
  # @return [String]
56
56
  def arg_name a
57
- a[0].match(/[A-Za-z0-9_]*/)[0]
57
+ a[0].gsub(/[^a-z0-9_]/i, '')
58
58
  end
59
59
 
60
60
  # @param a [Array]
61
- # @return [Symbol]
61
+ # @return [::Symbol]
62
62
  def arg_type a
63
63
  if a[0].start_with?('**')
64
64
  :kwrestarg
@@ -66,10 +66,10 @@ module Solargraph
66
66
  :restarg
67
67
  elsif a[0].start_with?('&')
68
68
  :blockarg
69
+ elsif a[0].end_with?(':')
70
+ a[1] ? :kwoptarg : :kwarg
69
71
  elsif a[1]
70
72
  :optarg
71
- elsif a[0].end_with?(':')
72
- a[1] ? :kwarg : :kwoptarg
73
73
  else
74
74
  :arg
75
75
  end
@@ -110,18 +110,21 @@ module Solargraph
110
110
  # @param api_map [ApiMap]
111
111
  # @return [ComplexType]
112
112
  def infer_first_defined pins, context, api_map
113
- type = ComplexType::UNDEFINED
113
+ possibles = []
114
114
  pins.each do |pin|
115
115
  # Avoid infinite recursion
116
116
  next if @@inference_stack.include?(pin.identity)
117
117
  @@inference_stack.push pin.identity
118
118
  type = pin.typify(api_map)
119
119
  @@inference_stack.pop
120
- break if type.defined?
120
+ if type.defined?
121
+ possibles.push type
122
+ break if pin.is_a?(Pin::BaseMethod)
123
+ end
121
124
  end
122
- if type.undefined?
125
+ if possibles.empty?
123
126
  # Limit method inference recursion
124
- return type if @@inference_depth >= 10 && pins.first.is_a?(Pin::BaseMethod)
127
+ return ComplexType::UNDEFINED if @@inference_depth >= 10 && pins.first.is_a?(Pin::BaseMethod)
125
128
  @@inference_depth += 1
126
129
  pins.each do |pin|
127
130
  # Avoid infinite recursion
@@ -129,10 +132,20 @@ module Solargraph
129
132
  @@inference_stack.push pin.identity
130
133
  type = pin.probe(api_map)
131
134
  @@inference_stack.pop
132
- break if type.defined?
135
+ if type.defined?
136
+ possibles.push type
137
+ break if pin.is_a?(Pin::BaseMethod)
138
+ end
133
139
  end
134
140
  @@inference_depth -= 1
135
141
  end
142
+ return ComplexType::UNDEFINED if possibles.empty?
143
+ type = if possibles.length > 1
144
+ sorted = possibles.map { |t| t.rooted? ? "::#{t}" : t.to_s }.sort { |a, _| a == 'nil' ? 1 : 0 }
145
+ ComplexType.parse(*sorted)
146
+ else
147
+ possibles.first
148
+ end
136
149
  return type if context.nil? || context.return_type.undefined?
137
150
  type.self_to(context.return_type.namespace)
138
151
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.39.15'
4
+ VERSION = '0.39.16'
5
5
  end
@@ -158,10 +158,12 @@ module Solargraph
158
158
  @cache ||= YardMap::Cache.new
159
159
  end
160
160
 
161
+ # @return [Hash]
161
162
  def pin_class_hash
162
163
  @pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
163
164
  end
164
165
 
166
+ # @return [Array<Pin::Base>]
165
167
  def pins_by_class klass
166
168
  @pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
167
169
  end
@@ -35,10 +35,10 @@ module Solargraph
35
35
  # This method of superclass detection is a bit of a hack. If
36
36
  # the superclass is a Proxy, it is assumed to be undefined in its
37
37
  # yardoc and converted to a fully qualified namespace.
38
- if code_object.superclass.is_a?(YARD::CodeObjects::Proxy)
39
- superclass = "::#{code_object.superclass}"
38
+ superclass = if code_object.superclass.is_a?(YARD::CodeObjects::Proxy)
39
+ "::#{code_object.superclass}"
40
40
  else
41
- superclass = code_object.superclass.to_s
41
+ code_object.superclass.to_s
42
42
  end
43
43
  result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin)
44
44
  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.39.15
4
+ version: 0.39.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport