solargraph 0.24.1 → 0.25.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solargraph/api_map.rb +93 -46
  3. data/lib/solargraph/api_map/cache.rb +51 -0
  4. data/lib/solargraph/api_map/probe.rb +23 -12
  5. data/lib/solargraph/api_map/source_to_yard.rb +2 -2
  6. data/lib/solargraph/api_map/store.rb +20 -9
  7. data/lib/solargraph/complex_type.rb +10 -1
  8. data/lib/solargraph/diagnostics/require_not_found.rb +1 -1
  9. data/lib/solargraph/diagnostics/rubocop.rb +35 -27
  10. data/lib/solargraph/diagnostics/type_not_defined.rb +10 -13
  11. data/lib/solargraph/language_server/host.rb +11 -11
  12. data/lib/solargraph/language_server/message.rb +0 -1
  13. data/lib/solargraph/language_server/message/base.rb +24 -4
  14. data/lib/solargraph/language_server/message/text_document/completion.rb +9 -16
  15. data/lib/solargraph/language_server/message/text_document/did_change.rb +0 -2
  16. data/lib/solargraph/language_server/message/text_document/formatting.rb +1 -10
  17. data/lib/solargraph/language_server/transport/socket.rb +0 -1
  18. data/lib/solargraph/language_server/transport/stdio.rb +0 -1
  19. data/lib/solargraph/pin.rb +1 -1
  20. data/lib/solargraph/pin/attribute.rb +4 -7
  21. data/lib/solargraph/pin/base.rb +113 -8
  22. data/lib/solargraph/pin/base_variable.rb +17 -25
  23. data/lib/solargraph/pin/block.rb +2 -2
  24. data/lib/solargraph/pin/block_parameter.rb +8 -10
  25. data/lib/solargraph/pin/constant.rb +2 -2
  26. data/lib/solargraph/pin/conversions.rb +8 -0
  27. data/lib/solargraph/pin/documenting.rb +2 -2
  28. data/lib/solargraph/pin/duck_method.rb +0 -1
  29. data/lib/solargraph/pin/local_variable.rb +8 -2
  30. data/lib/solargraph/pin/method.rb +26 -16
  31. data/lib/solargraph/pin/method_parameter.rb +15 -8
  32. data/lib/solargraph/pin/namespace.rb +2 -2
  33. data/lib/solargraph/pin/reference.rb +7 -0
  34. data/lib/solargraph/pin/yard_pin.rb +10 -0
  35. data/lib/solargraph/pin/yard_pin/constant.rb +14 -0
  36. data/lib/solargraph/pin/yard_pin/method.rb +35 -0
  37. data/lib/solargraph/pin/yard_pin/namespace.rb +27 -0
  38. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +18 -0
  39. data/lib/solargraph/source.rb +59 -15
  40. data/lib/solargraph/source/mapper.rb +46 -99
  41. data/lib/solargraph/version.rb +1 -1
  42. data/lib/solargraph/workspace.rb +11 -2
  43. data/lib/solargraph/workspace/config.rb +47 -1
  44. data/lib/solargraph/yard_map.rb +103 -278
  45. data/lib/solargraph/yard_map/cache.rb +13 -38
  46. metadata +7 -3
  47. data/lib/solargraph/pin/yard_object.rb +0 -119
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c068cbe7c4d090f33124e8a8ab52a9f956992aab3c5db9e5f41ba41f65642be3
4
- data.tar.gz: 1798f2d5c48fa1d794c7441102154d464ce4cb8a75ea77d759c9eea27dbfc492
3
+ metadata.gz: efdf4fdf971f5d10e148b73902701dae0ce549ef38f7304455fefba0465f4e90
4
+ data.tar.gz: 49c3fcc4fb9c3ad339e7e08c256275ac73907edc62f239a4b315938c18b68661
5
5
  SHA512:
6
- metadata.gz: 1aac2a042e292cf73c3bb70559b9a67d7a0d1c75537f669b20cfffd1bb1a41a820c67f9c4a845e23bce24cc5f1384a3dad7055a91b138f910ff4099633834f3f
7
- data.tar.gz: f204e7cbee66ffa0e5a5d0a0086e8415e222a13a576b6a394ca840cf5a7f9401fe9570953db9770274262b1524b820f17c020c711b65c9dac1cc44b157d464dc
6
+ metadata.gz: d3bddec5d8f6f083905349634b6a36144b5e069b1b94abf0d2ab3e3f074e8bc851ceb79a6d42cee9b2aa9af4645f3ed04347228a16db08fc3b94b7ff974aa0e3
7
+ data.tar.gz: 6b384c71d2a38c4e5cd02cabb2801d0b57cf5c5f2eb81d63cb56e37fb90b24c030d308cd2e75dc3977963841d1dfcb1f1e33eb8f220a759b83580296c40fb413
@@ -23,9 +23,6 @@ module Solargraph
23
23
  # @return [Solargraph::Workspace]
24
24
  attr_reader :workspace
25
25
 
26
- # @return [ApiMap::Store]
27
- attr_reader :store
28
-
29
26
  # Get a LiveMap associated with the current workspace.
30
27
  #
31
28
  # @return [Solargraph::LiveMap]
@@ -36,14 +33,13 @@ module Solargraph
36
33
  @workspace = workspace
37
34
  require_extensions
38
35
  @virtual_source = nil
39
- @yard_stale = true
40
- # process_maps
41
36
  @sources = workspace.sources
42
37
  refresh_store_and_maps
43
38
  end
44
39
 
45
40
  # Create an ApiMap with a workspace in the specified directory.
46
41
  #
42
+ # @param directory [String]
47
43
  # @return [ApiMap]
48
44
  def self.load directory
49
45
  self.new(Solargraph::Workspace.new(directory))
@@ -71,17 +67,6 @@ module Solargraph
71
67
  result.uniq
72
68
  end
73
69
 
74
- # Get a YardMap associated with the current workspace.
75
- #
76
- # @return [Solargraph::YardMap]
77
- def yard_map
78
- # refresh
79
- if @yard_map.required.to_set != required.to_set
80
- @yard_map = Solargraph::YardMap.new(required: required, workspace: workspace)
81
- end
82
- @yard_map
83
- end
84
-
85
70
  # Declare a virtual source that will be included in the map regardless of
86
71
  # whether it's in the workspace.
87
72
  #
@@ -91,6 +76,8 @@ module Solargraph
91
76
  # @param source [Solargraph::Source]
92
77
  # @return [Solargraph::Source]
93
78
  def virtualize source
79
+ # @todo Confirm the correct way to handle caches
80
+ cache.clear if (source.nil? and !@virtual_source.nil?) or (!source.nil? and !@virtual_source.nil? and source.pins != @virtual_source.pins)
94
81
  store.remove @virtual_source unless @virtual_source.nil?
95
82
  domains.clear
96
83
  domains.concat workspace.config.domains
@@ -133,12 +120,8 @@ module Solargraph
133
120
  if force
134
121
  refresh_store_and_maps
135
122
  else
136
- store.remove *(current_workspace_sources.reject{ |s| workspace.sources.include?(s) })
137
- @sources = workspace.sources
138
- @sources.push @virtual_source unless @virtual_source.nil?
139
- store.update *(@sources.select{ |s| @stime.nil? or s.stime > @stime })
123
+ update_store_and_maps
140
124
  end
141
- @stime = Time.new
142
125
  true
143
126
  end
144
127
 
@@ -187,6 +170,8 @@ module Solargraph
187
170
  # @return [Array<Solargraph::Pin::Base>]
188
171
  def get_constants namespace, context = ''
189
172
  namespace ||= ''
173
+ cached = cache.get_constants(namespace, context)
174
+ return cached.clone unless cached.nil?
190
175
  skip = []
191
176
  result = []
192
177
  bases = context.split('::')
@@ -202,6 +187,7 @@ module Solargraph
202
187
  visibility = [:public]
203
188
  visibility.push :private if fqns == context
204
189
  result.concat inner_get_constants(fqns, visibility, skip)
190
+ cache.set_constants(namespace, context, result)
205
191
  result
206
192
  end
207
193
 
@@ -212,10 +198,19 @@ module Solargraph
212
198
  # @param context [String] The context to search
213
199
  # @return [String]
214
200
  def qualify namespace, context = ''
215
- inner_qualify namespace, context, []
201
+ # @todo The return for self might work better elsewhere
202
+ return qualify(context) if namespace == 'self'
203
+ cached = cache.get_qualified_namespace(namespace, context)
204
+ return cached.clone unless cached.nil?
205
+ result = inner_qualify(namespace, context, [])
206
+ cache.set_qualified_namespace(namespace, context, result)
207
+ result
216
208
  end
217
209
 
218
210
  # @deprecated Use #qualify instead
211
+ # @param namespace [String]
212
+ # @param context [String]
213
+ # @return [String]
219
214
  def find_fully_qualified_namespace namespace, context = ''
220
215
  qualify namespace, context
221
216
  end
@@ -260,6 +255,8 @@ module Solargraph
260
255
  # @param deep [Boolean] True to include superclasses, mixins, etc.
261
256
  # @return [Array<Solargraph::Pin::Base>]
262
257
  def get_methods fqns, scope: :instance, visibility: [:public], deep: true
258
+ cached = cache.get_methods(fqns, scope, visibility, deep)
259
+ return cached.clone unless cached.nil?
263
260
  result = []
264
261
  skip = []
265
262
  if fqns == ''
@@ -278,6 +275,23 @@ module Solargraph
278
275
  exist = result.map(&:name)
279
276
  result.concat live.reject{|p| exist.include?(p.name)}
280
277
  end
278
+ cache.set_methods(fqns, scope, visibility, deep, result)
279
+ result
280
+ end
281
+
282
+ # Get a stack of method pins for a method name in a namespace. The order
283
+ # of the pins corresponds to the ancestry chain, with highest precedence
284
+ # first.
285
+ #
286
+ # @param fqns [String]
287
+ # @param name [String]
288
+ # @param scope [Symbol] :instance or :class
289
+ # @return [Array<Solargraph::Pin::Base>]
290
+ def get_method_stack fqns, name, scope: :instance
291
+ # cached = cache.get_method_stack(fqns, name, scope)
292
+ # return cached.clone unless cached.nil?
293
+ result = get_methods(fqns, scope: scope, visibility: [:private, :protected, :public]).select{|p| p.name == name}
294
+ # cache.set_method_stack(fqns, name, scope, result)
281
295
  result
282
296
  end
283
297
 
@@ -328,7 +342,10 @@ module Solargraph
328
342
  pins = probe.infer_signature_pins(fragment.base, fragment.named_path, fragment.locals)
329
343
  unless pins.empty?
330
344
  pin = pins.first
331
- if pin.return_complex_types.any? and pin.return_complex_types.first.duck_type?
345
+ if pin.variable? and pin.return_type.nil? and !pin.signature.nil?
346
+ type = probe.infer_signature_type(pin.signature, pin.context, fragment.locals)
347
+ result.concat(get_methods(type)) unless type.nil?
348
+ elsif pin.return_complex_types.any? and pin.return_complex_types.first.duck_type?
332
349
  pin.return_complex_types.each do |t|
333
350
  next unless t.duck_type?
334
351
  result.push Pin::DuckMethod.new(pin.location, t.tag[1..-1])
@@ -350,7 +367,7 @@ module Solargraph
350
367
  end
351
368
  end
352
369
  frag_start = fragment.word.to_s.downcase
353
- filtered = result.uniq(&:identifier).select{|s| s.name.downcase.start_with?(frag_start) and (s.kind != Pin::METHOD or s.name.match(/^[a-z0-9_]*(\!|\?|=)?$/i))}.sort_by.with_index{ |x, idx| [x.name, idx] }
370
+ filtered = result.uniq(&:identifier).select{|s| s.name.downcase.start_with?(frag_start) and (s.kind != Pin::METHOD or s.name.match(/^[a-z0-9_]+(\!|\?|=)?$/i))}.sort_by.with_index{ |x, idx| [x.name, idx] }
354
371
  Completion.new(filtered, fragment.whole_word_range)
355
372
  end
356
373
 
@@ -360,7 +377,7 @@ module Solargraph
360
377
  # @return [Array<Solargraph::Pin::Base>]
361
378
  def define fragment
362
379
  return get_path_suggestions(fragment.namespace) if fragment.whole_signature == 'self'
363
- return [] if fragment.string? or fragment.comment? or fragment.literal? or fragment.whole_signature == 'self'
380
+ return [] if fragment.string? or fragment.comment? or fragment.literal? or KEYWORDS.include?(fragment.whole_signature)
364
381
  if fragment.base_literal?
365
382
  probe.infer_signature_pins fragment.whole_signature, Pin::ProxyMethod.new(fragment.base_literal), fragment.locals
366
383
  else
@@ -406,7 +423,7 @@ module Solargraph
406
423
  return [] if path.nil?
407
424
  result = []
408
425
  result.concat store.get_path_pins(path)
409
- result.concat yard_map.objects(path)
426
+ # result.concat yard_map.objects(path)
410
427
  if result.empty?
411
428
  lp = live_map.get_path_pin(path)
412
429
  result.push lp unless lp.nil?
@@ -430,7 +447,7 @@ module Solargraph
430
447
  found.push k if k.downcase.include?(query.downcase)
431
448
  end
432
449
  end
433
- found.concat(yard_map.search(query)).uniq.sort
450
+ found
434
451
  end
435
452
 
436
453
  # Get YARD documentation for the specified path.
@@ -445,7 +462,7 @@ module Solargraph
445
462
  @yard_stale = false
446
463
  docs = []
447
464
  docs.push code_object_at(path) unless code_object_at(path).nil?
448
- docs.concat yard_map.document(path)
465
+ # docs.concat yard_map.document(path)
449
466
  docs
450
467
  end
451
468
 
@@ -461,6 +478,7 @@ module Solargraph
461
478
  result
462
479
  end
463
480
 
481
+ # @param location [Solargraph::Source::Location]
464
482
  # @return [Solargraph::Pin::Base]
465
483
  def locate_pin location
466
484
  @sources.each do |source|
@@ -477,27 +495,53 @@ module Solargraph
477
495
  @probe ||= Probe.new(self)
478
496
  end
479
497
 
498
+ def unresolved_requires
499
+ # return [] if yard_map_changed?
500
+ yard_map.unresolved_requires
501
+ end
502
+
480
503
  private
481
504
 
505
+ # @return [ApiMap::Store]
506
+ def store
507
+ @store ||= ApiMap::Store.new(@sources, yard_map.pins)
508
+ end
509
+
510
+ # @return [void]
482
511
  def refresh_store_and_maps
483
- @store = ApiMap::Store.new(@sources)
512
+ @yard_stale = true
484
513
  @live_map = Solargraph::LiveMap.new(self)
485
- @yard_map = Solargraph::YardMap.new(required: required, workspace: workspace)
514
+ store.update_yard(yard_map.pins) if yard_map.change(required)
515
+ cache.clear
516
+ @stime = Time.now
486
517
  end
487
518
 
519
+ # @return [void]
520
+ def update_store_and_maps
521
+ @yard_stale = true
522
+ store.remove *(current_workspace_sources.reject{ |s| workspace.sources.include?(s) })
523
+ @sources = workspace.sources
524
+ @sources.push @virtual_source unless @virtual_source.nil?
525
+ store.update *(@sources.select{ |s| @stime.nil? or s.stime > @stime })
526
+ store.update_yard(yard_map.pins) if yard_map.change(required)
527
+ cache.clear
528
+ @stime = Time.now
529
+ end
530
+
531
+ # @return [void]
488
532
  def process_virtual
489
- unless @virtual_source.nil?
490
- map_source @virtual_source
533
+ map_source @virtual_source unless @virtual_source.nil?
534
+ if yard_map.change(required)
535
+ store.update_yard(yard_map.pins)
491
536
  end
537
+ cache.clear
492
538
  end
493
539
 
494
- # @param [Solargraph::Source]
540
+ # @param source [Solargraph::Source]
541
+ # @return [void]
495
542
  def map_source source
496
543
  store.update source
497
544
  path_macros.merge! source.path_macros
498
- source.required.each do |r|
499
- required.push r
500
- end
501
545
  end
502
546
 
503
547
  # @return [Solargraph::ApiMap::Cache]
@@ -525,17 +569,17 @@ module Solargraph
525
569
  fqim = qualify(im, fqns)
526
570
  result.concat inner_get_methods(fqim, scope, visibility, deep, skip) unless fqim.nil?
527
571
  end
528
- result.concat yard_map.get_instance_methods(fqns, visibility: visibility)
572
+ # result.concat yard_map.get_instance_methods(fqns, visibility: visibility)
529
573
  result.concat inner_get_methods('Object', :instance, [:public], deep, skip) unless fqns == 'Object'
530
574
  else
531
575
  store.get_extends(fqns).each do |em|
532
576
  fqem = qualify(em, fqns)
533
577
  result.concat inner_get_methods(fqem, :instance, visibility, deep, skip) unless fqem.nil?
534
578
  end
535
- result.concat yard_map.get_methods(fqns, '', visibility: visibility)
579
+ # result.concat yard_map.get_methods(fqns, '', visibility: visibility)
536
580
  type = get_namespace_type(fqns)
537
581
  result.concat inner_get_methods('Class', :instance, fqns == '' ? [:public] : visibility, deep, skip) if type == :class
538
- result.concat inner_get_methods('Module', :instance, fqns == '' ? [:public] : visibility, deep, skip) if type == :module
582
+ result.concat inner_get_methods('Module', :instance, fqns == '' ? [:public] : visibility, deep, skip) #if type == :module
539
583
  end
540
584
  end
541
585
  result
@@ -546,7 +590,7 @@ module Solargraph
546
590
  skip.push fqns
547
591
  result = []
548
592
  result.concat store.get_constants(fqns, visibility)
549
- result.concat yard_map.get_constants(fqns)
593
+ # result.concat yard_map.get_constants(fqns)
550
594
  store.get_includes(fqns).each do |is|
551
595
  fqis = qualify(is, fqns)
552
596
  result.concat inner_get_constants(fqis, [:public], skip) unless fqis.nil?
@@ -613,11 +657,7 @@ module Solargraph
613
657
  return name if store.namespace_exists?(name)
614
658
  end
615
659
  end
616
- result = yard_map.find_fully_qualified_namespace(name, root)
617
- if result.nil?
618
- result = live_map.get_fqns(name, root)
619
- end
620
- result
660
+ live_map.get_fqns(name, root)
621
661
  end
622
662
 
623
663
  # Get the namespace's type (Class or Module).
@@ -626,8 +666,15 @@ module Solargraph
626
666
  # @return [Symbol] :class, :module, or nil
627
667
  def get_namespace_type fqns
628
668
  pin = store.get_path_pins(fqns).first
629
- return yard_map.get_namespace_type(fqns) if pin.nil?
669
+ return nil if pin.nil?
630
670
  pin.type
631
671
  end
672
+
673
+ # Get a YardMap associated with the current workspace.
674
+ #
675
+ # @return [Solargraph::YardMap]
676
+ def yard_map
677
+ @yard_map ||= Solargraph::YardMap.new(required: required, workspace: workspace)
678
+ end
632
679
  end
633
680
  end
@@ -4,6 +4,10 @@ module Solargraph
4
4
  def initialize
5
5
  @signature_types = {}
6
6
  @assignment_node_types = {}
7
+ @methods = {}
8
+ @method_stacks = {}
9
+ @constants = {}
10
+ @qualified_namespaces = {}
7
11
  end
8
12
 
9
13
  def get_signature_type signature, namespace, scope
@@ -26,9 +30,56 @@ module Solargraph
26
30
  @assignment_node_types[[node, namespace]] = value
27
31
  end
28
32
 
33
+ def get_methods fqns, scope, visibility, deep
34
+ @methods[[fqns, scope, visibility.sort, deep]]
35
+ end
36
+
37
+ def set_methods fqns, scope, visibility, deep, value
38
+ @methods[[fqns, scope, visibility.sort, deep]] = value
39
+ end
40
+
41
+ def get_method_stack fqns, name, scope
42
+ @method_stacks[[fqns, name, scope]]
43
+ end
44
+
45
+ def set_method_stack fqns, name, scope, value
46
+ @method_stacks[[fqns, name, scope]] = value
47
+ end
48
+
49
+ def get_constants namespace, context
50
+ @constants[[namespace, context]]
51
+ end
52
+
53
+ def set_constants namespace, context, value
54
+ @constants[[namespace, context]] = value
55
+ end
56
+
57
+ def get_qualified_namespace name, context
58
+ @qualified_namespaces[[name, context]]
59
+ end
60
+
61
+ def set_qualified_namespace name, context, value
62
+ @qualified_namespaces[[name, context]] = value
63
+ end
64
+
65
+ # @return [void]
29
66
  def clear
30
67
  @signature_types.clear
31
68
  @assignment_node_types.clear
69
+ @methods.clear
70
+ @method_stacks.clear
71
+ @constants.clear
72
+ @qualified_namespaces.clear
73
+ end
74
+
75
+ # @return [Boolean]
76
+ def empty?
77
+ @signature_types.empty? and
78
+ @assignment_node_types.empty? and
79
+ @methods.empty? and
80
+ @method_stacks.empty? and
81
+ @constants.empty? amd
82
+ @qualified_namespaces.empty?
32
83
  end
33
84
  end
34
85
  end
@@ -1,17 +1,23 @@
1
1
  module Solargraph
2
2
  class ApiMap
3
+ # A deep analysis provider for ApiMaps.
4
+ #
3
5
  class Probe
4
6
  include TypeMethods
5
7
 
6
8
  # @return [Solargraph::ApiMap]
7
9
  attr_reader :api_map
8
10
 
11
+ # @param api_map [ApiMap]
9
12
  def initialize api_map
10
13
  @api_map = api_map
11
14
  end
12
15
 
13
16
  # Get all matching pins for the signature.
14
17
  #
18
+ # @param signature [String]
19
+ # @param context_pin [Pin::Base]
20
+ # @param locals [Array<Pin::Base>]
15
21
  # @return [Array<Pin::Base>]
16
22
  def infer_signature_pins signature, context_pin, locals
17
23
  return [] if signature.nil? or signature.empty?
@@ -44,6 +50,9 @@ module Solargraph
44
50
 
45
51
  # Get the return type for the signature.
46
52
  #
53
+ # @param signature [String]
54
+ # @param context_pin [Pin::Base]
55
+ # @param locals [Array<Pin::Base>]
47
56
  # @return [String]
48
57
  def infer_signature_type signature, context_pin, locals
49
58
  pins = infer_signature_pins(signature, context_pin, locals)
@@ -65,6 +74,8 @@ module Solargraph
65
74
  return resolve_word_types(lvars, locals) unless lvars.empty?
66
75
  return api_map.get_global_variable_pins.select{|pin| pin.name == word} if word.start_with?('$')
67
76
  namespace, scope = extract_namespace_and_scope_from_pin(context_pin)
77
+ return api_map.get_class_variable_pins(namespace).select{|pin| pin.name == word} if word.start_with?('@@')
78
+ return api_map.get_instance_variable_pins(namespace, scope).select{|pin| pin.name == word} if word.start_with?('@')
68
79
  return api_map.pins.select{|pin| word_matches_context?(word, namespace, scope, pin)} if variable_name?(word)
69
80
  result = []
70
81
  cparts = namespace.split('::')
@@ -75,7 +86,8 @@ module Solargraph
75
86
  cparts.pop
76
87
  end
77
88
  result.concat api_map.get_path_suggestions(word) if result.empty?
78
- result.concat api_map.get_methods(namespace, scope: scope, visibility: [:public, :private, :protected]).select{|pin| pin.name == word} unless word.include?('::')
89
+ # result.concat api_map.get_methods(namespace, scope: scope, visibility: [:public, :private, :protected]).select{|pin| pin.name == word} unless word.include?('::')
90
+ result.concat api_map.get_method_stack(namespace, word, scope: scope) unless word.include?('::')
79
91
  result.concat api_map.get_constants('', namespace).select{|pin| pin.name == word} if result.empty?
80
92
  resolve_word_types(result, locals)
81
93
  end
@@ -85,8 +97,9 @@ module Solargraph
85
97
  next unless p.return_type.nil?
86
98
  type = resolve_pin_type(p, locals)
87
99
  # @todo Smelly instance variable access
88
- p.instance_variable_set(:@return_type, type)
100
+ p.instance_variable_set(:@return_complex_types, ComplexType.parse(type)) unless type.nil?
89
101
  end
102
+ pins
90
103
  end
91
104
 
92
105
  def infer_self context_pin
@@ -109,7 +122,8 @@ module Solargraph
109
122
  namespace = api_map.qualify(relname, context_pin.namespace)
110
123
  visibility = [:public]
111
124
  visibility.push :protected, :private if internal
112
- result = api_map.get_methods(namespace, scope: scope, visibility: visibility).select{|pin| pin.name == method_name}
125
+ # result = api_map.get_methods(namespace, scope: scope, visibility: visibility).select{|pin| pin.name == method_name}
126
+ result = api_map.get_method_stack(namespace, method_name, scope: scope).select{|pin| visibility.include?(pin.visibility)}
113
127
  # @todo This needs more rules. Probably need to update YardObject for it.
114
128
  return result if result.empty?
115
129
  return result unless method_name == 'new' and result.first.path == 'Class#new'
@@ -165,9 +179,8 @@ module Solargraph
165
179
  #
166
180
  # @return [Pin::Method]
167
181
  def virtual_new_pin new_pin, context_pin
168
- pin = Pin::Method.new(new_pin.location, new_pin.namespace, new_pin.name, new_pin.docstring, new_pin.scope, new_pin.visibility, new_pin.parameters)
182
+ pin = Pin::Method.new(new_pin.location, context_pin.path, new_pin.name, '', :class, new_pin.visibility, new_pin.parameters)
169
183
  # @todo Smelly instance variable access.
170
- # pin.instance_variable_set(:@return_type, context_pin.path)
171
184
  pin.instance_variable_set(:@return_complex_types, ComplexType.parse(context_pin.path))
172
185
  pin
173
186
  end
@@ -177,6 +190,7 @@ module Solargraph
177
190
  # @return [String]
178
191
  def resolve_pin_type pin, locals
179
192
  return pin.return_type unless pin.return_type.nil?
193
+ return pin.namespace if pin.kind == Pin::METHOD and pin.name == 'new' and pin.scope == :class
180
194
  return resolve_block_parameter(pin, locals) if pin.kind == Pin::BLOCK_PARAMETER
181
195
  return resolve_method_parameter(pin) if pin.is_a?(Pin::MethodParameter)
182
196
  return resolve_variable(pin, locals) if pin.variable?
@@ -201,21 +215,18 @@ module Solargraph
201
215
  return nil if subtypes.nil?
202
216
  return subtypes[0]
203
217
  else
204
- unless meth.docstring.nil?
205
- yps = meth.docstring.tags(:yieldparam)
206
- unless yps[pin.index].nil? or yps[pin.index].types.nil? or yps[pin.index].types.empty?
207
- return yps[pin.index].types[0]
208
- end
218
+ yps = meth.docstring.tags(:yieldparam)
219
+ unless yps[pin.index].nil? or yps[pin.index].types.nil? or yps[pin.index].types.empty?
220
+ return yps[pin.index].types[0]
209
221
  end
210
222
  end
211
223
  nil
212
224
  end
213
225
 
214
226
  def resolve_method_parameter pin
215
- matches = api_map.get_methods(pin.namespace, scope: pin.scope, visibility: [:public, :private, :protected]).select{|p| p.name == pin.context.name}
227
+ matches = api_map.get_method_stack(pin.namespace, pin.context.name, scope: pin.scope)
216
228
  matches.each do |m|
217
229
  next unless pin.context.parameters == m.parameters
218
- next if m.docstring.nil?
219
230
  tag = m.docstring.tags(:param).select{|t| t.name == pin.name}.first
220
231
  next if tag.nil? or tag.types.nil?
221
232
  return tag.types[0]