solargraph 0.61.0 → 0.62.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +24 -2
  3. data/.github/workflows/plugins.yml +18 -0
  4. data/.github/workflows/rspec.yml +14 -1
  5. data/.github/workflows/typecheck.yml +6 -0
  6. data/CHANGELOG.md +38 -0
  7. data/lib/solargraph/api_map/index.rb +14 -3
  8. data/lib/solargraph/api_map/store.rb +6 -0
  9. data/lib/solargraph/api_map.rb +34 -2
  10. data/lib/solargraph/collection/gem.rb +12 -10
  11. data/lib/solargraph/collection.rb +0 -1
  12. data/lib/solargraph/complex_type/unique_type.rb +13 -0
  13. data/lib/solargraph/complex_type.rb +23 -3
  14. data/lib/solargraph/convention.rb +0 -4
  15. data/lib/solargraph/diagnostics/type_check.rb +0 -1
  16. data/lib/solargraph/external.rb +56 -28
  17. data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
  18. data/lib/solargraph/language_server/host/dispatch.rb +4 -2
  19. data/lib/solargraph/language_server/host.rb +10 -2
  20. data/lib/solargraph/language_server/message/completion_item/resolve.rb +10 -3
  21. data/lib/solargraph/language_server/message/text_document/definition.rb +1 -1
  22. data/lib/solargraph/library.rb +19 -33
  23. data/lib/solargraph/parser/node_processor/base.rb +6 -0
  24. data/lib/solargraph/parser/parser_gem/node_methods.rb +29 -6
  25. data/lib/solargraph/parser/parser_gem/node_processors/class_definition/class_assignment_node.rb +98 -0
  26. data/lib/solargraph/parser/parser_gem/node_processors/class_definition.rb +54 -0
  27. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +1 -0
  28. data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_assignment_node.rb +65 -0
  29. data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_definition_node.rb +97 -0
  30. data/lib/solargraph/parser/parser_gem/node_processors/data_definition.rb +110 -0
  31. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +1 -0
  32. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -0
  33. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
  34. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +185 -0
  35. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_assignment_node.rb +66 -0
  36. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb +108 -0
  37. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition.rb +170 -0
  38. data/lib/solargraph/parser/parser_gem/node_processors.rb +33 -29
  39. data/lib/solargraph/pin/base.rb +25 -1
  40. data/lib/solargraph/pin/base_variable.rb +31 -1
  41. data/lib/solargraph/pin/callable.rb +11 -2
  42. data/lib/solargraph/pin/delegated_method.rb +5 -0
  43. data/lib/solargraph/pin/duck_method.rb +36 -16
  44. data/lib/solargraph/pin/instance_variable.rb +45 -0
  45. data/lib/solargraph/pin/method.rb +10 -0
  46. data/lib/solargraph/pin/method_alias.rb +4 -0
  47. data/lib/solargraph/pin/parameter.rb +1 -1
  48. data/lib/solargraph/pin/reference/included_mixin.rb +22 -0
  49. data/lib/solargraph/pin/reference.rb +1 -0
  50. data/lib/solargraph/plugin/active_support.rb +100 -0
  51. data/lib/solargraph/plugin/addon.rb +16 -0
  52. data/lib/solargraph/plugin/base.rb +25 -0
  53. data/lib/solargraph/plugin/panel.rb +37 -0
  54. data/lib/solargraph/plugin.rb +26 -0
  55. data/lib/solargraph/rbs_collection.rb +119 -0
  56. data/lib/solargraph/rbs_map/conversions.rb +106 -47
  57. data/lib/solargraph/rbs_map/gem.rb +4 -1
  58. data/lib/solargraph/rbs_map/helpers.rb +7 -6
  59. data/lib/solargraph/rbs_translator.rb +105 -70
  60. data/lib/solargraph/repo.rb +1 -1
  61. data/lib/solargraph/source/chain/call.rb +32 -13
  62. data/lib/solargraph/source/node_map.rb +27 -0
  63. data/lib/solargraph/source.rb +17 -0
  64. data/lib/solargraph/source_map/call.rb +18 -0
  65. data/lib/solargraph/source_map/mapper.rb +1 -1
  66. data/lib/solargraph/source_map.rb +18 -4
  67. data/lib/solargraph/type_checker/rules.rb +2 -2
  68. data/lib/solargraph/type_checker.rb +4 -1
  69. data/lib/solargraph/version.rb +1 -1
  70. data/lib/solargraph/yard_map/macro.rb +51 -1
  71. data/lib/solargraph.rb +2 -0
  72. data/rbs/fills/boolean/0/boolean.rbs +12 -0
  73. data/solargraph.gemspec +1 -1
  74. metadata +21 -11
  75. data/lib/solargraph/collection/rbs.rb +0 -49
  76. data/lib/solargraph/convention/active_support_concern.rb +0 -111
  77. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +0 -61
  78. data/lib/solargraph/convention/data_definition/data_definition_node.rb +0 -93
  79. data/lib/solargraph/convention/data_definition.rb +0 -108
  80. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +0 -62
  81. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +0 -103
  82. data/lib/solargraph/convention/struct_definition.rb +0 -168
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ # The RBS collection declared by a project's rbs_collection.lock.yaml.
5
+ #
6
+ class RbsCollection
7
+ attr_reader :lockfile
8
+
9
+ def initialize lockfile
10
+ @lockfile = File.expand_path(lockfile) if lockfile
11
+ end
12
+
13
+ # @param metagem [Metagem]
14
+ # @return [Array<Pin::Base>]
15
+ def load metagem
16
+ key = best_key(metagem)
17
+ return [] unless key
18
+ mem_cache[key] ||= RbsMap::Path.pins(gem_path_map[key])
19
+ end
20
+
21
+ def gem_keys
22
+ gem_path_map.keys
23
+ end
24
+
25
+ # The names of the stdlib signature sets declared by the collection.
26
+ #
27
+ # +rbs collection install+ resolves these to the signatures which ship
28
+ # with the rbs gem instead of copying them into the collection directory,
29
+ # so they can never be located by a gem name/version lookup.
30
+ #
31
+ # @return [Array<String>]
32
+ def stdlib_names
33
+ @stdlib_names ||= raw_data[:gems].select { |gem| gem.dig(:source, :type).to_s == 'stdlib' }
34
+ .map { |gem| gem[:name].to_s }.uniq
35
+ end
36
+
37
+ private
38
+
39
+ def gem_path_map
40
+ @gem_path_map ||= raw_data[:gems].to_h { |gem| ["#{gem[:name]}-#{gem[:version]}", gem_source_path(gem)] }
41
+ end
42
+
43
+ # The versions available in the collection for each gem name.
44
+ #
45
+ # @return [Hash{String => Array<String>}]
46
+ def versions_by_name
47
+ @versions_by_name ||= raw_data[:gems].group_by { |gem| gem[:name].to_s }
48
+ .transform_values { |gems| gems.map { |gem| gem[:version].to_s } }
49
+ end
50
+
51
+ def best_key metagem
52
+ key = "#{metagem.name}-#{metagem.version}"
53
+ return key if gem_path_map.key?(key)
54
+
55
+ full_key = "#{metagem.name}-#{metagem.version}."
56
+ zero_key = "#{metagem.name}-0"
57
+ found = gem_path_map.find { |key, _| full_key.start_with?("#{key}.") } ||
58
+ gem_path_map.find { |key, _| key == zero_key }
59
+ found&.first || closest_key(metagem)
60
+ end
61
+
62
+ # Signature collections version their directories independently from the
63
+ # gems they describe. gem_rbs_collection, for example, provides
64
+ # +actionpack/6.0+ for every Rails 6 and 7 release and +devise/4.9+ for
65
+ # Devise 4 and 5. When no directory matches a gem's version, fall back to
66
+ # the closest version the collection provides for that gem, preferring the
67
+ # highest one that does not exceed the gem's version.
68
+ #
69
+ # @param metagem [Metagem]
70
+ # @return [String, nil]
71
+ def closest_key metagem
72
+ versions = versions_by_name[metagem.name.to_s]
73
+ return nil if versions.nil? || versions.empty?
74
+ return "#{metagem.name}-#{versions.first}" if versions.size == 1
75
+ parsed = versions.map { |version| [version, parse_version(version)] }
76
+ usable = parsed.compact
77
+ gem_version = parse_version(metagem.version)
78
+ chosen = if gem_version
79
+ usable.reject { |_, parsed_version| parsed_version > gem_version }.max_by { |_, parsed_version| parsed_version }
80
+ end
81
+ chosen ||= usable.min_by { |_, parsed_version| parsed_version }
82
+ chosen ||= parsed.first
83
+ "#{metagem.name}-#{chosen[0]}"
84
+ end
85
+
86
+ # @param value [Object]
87
+ # @return [Gem::Version, nil]
88
+ def parse_version value
89
+ Gem::Version.new value.to_s
90
+ rescue ArgumentError
91
+ nil
92
+ end
93
+
94
+ # @param gem_hash [Hash]
95
+ def gem_source_path gem_hash
96
+ root_path = gem_hash.dig(:source, :path) || raw_data[:path]
97
+ return unless root_path
98
+ gem_path = File.join(root_path, gem_hash[:name], gem_hash[:version])
99
+ File.expand_path(gem_path, File.dirname(lockfile))
100
+ end
101
+
102
+ def gem_rbs_collection_path
103
+ @gem_rbs_collection_path ||= File.expand_path(raw_data[:path]) if raw_data[:path]
104
+ end
105
+
106
+ # @return [Hash]
107
+ def raw_data
108
+ @raw_data ||= if lockfile && File.file?(lockfile)
109
+ YAML.load_file(lockfile, symbolize_names: true)
110
+ else
111
+ { gems: [] }
112
+ end
113
+ end
114
+
115
+ def mem_cache
116
+ @mem_cache ||= {}
117
+ end
118
+ end
119
+ end
@@ -37,6 +37,11 @@ module Solargraph
37
37
 
38
38
  private
39
39
 
40
+ # @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
41
+ def type_alias_decls
42
+ @type_alias_decls ||= {}
43
+ end
44
+
40
45
  # @param loader [RBS::EnvironmentLoader]
41
46
  #
42
47
  # @return [void]
@@ -48,11 +53,64 @@ module Solargraph
48
53
  "directories #{loader.dirs}"
49
54
  return
50
55
  end
56
+ # Register up front so expansion does not depend on declaration order.
57
+ core_aware_environment(loader, fallback: environment).type_alias_decls.each_value do |entry|
58
+ type_alias_decls[entry.decl.name.to_s] = entry.decl
59
+ end
60
+ # @sg-ignore Need a downcast here
51
61
  environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
52
62
  rescue RBS::DuplicatedDeclarationError => e
53
63
  Solargraph.logger.warn "RBS conversion failed due to duplicate declarations: [#{e.class}] #{e.message}"
54
64
  end
55
65
 
66
+ # A non-core RbsMap omits core so its pins do not re-declare CoreMap's,
67
+ # which leaves #resolve_type_names unable to bind an alias pointing into
68
+ # core. Resolve alias names against core separately; pins do not.
69
+ #
70
+ # @param loader [RBS::EnvironmentLoader]
71
+ # @param fallback [RBS::Environment] the already-resolved, core-less
72
+ # environment to use if a core-aware one can't be built
73
+ # @return [RBS::Environment]
74
+ def core_aware_environment loader, fallback:
75
+ return fallback unless loader.core_root.nil?
76
+ return fallback unless rebound_alias?(fallback)
77
+
78
+ # Loading core makes RBS add the stringio library, which only the
79
+ # stdlib repository provides.
80
+ core_repository = RBS::Repository.new(no_stdlib: false)
81
+ loader.repository.dirs.each { |dir| core_repository.add(dir) unless core_repository.dirs.include?(dir) }
82
+ core_loader = RBS::EnvironmentLoader.new(repository: core_repository)
83
+ loader.libs.each { |lib| core_loader.add(library: lib.name, version: lib.version) }
84
+ loader.dirs.each { |dir| core_loader.add(path: dir) }
85
+ RBS::Environment.from_loader(core_loader).resolve_type_names
86
+ rescue RBS::DuplicatedDeclarationError => e
87
+ # A local RBS shim may redeclare a core name; nominal tags beat no pins.
88
+ logger.warn do
89
+ "Could not build a core-aware environment for #{loader.libs}: #{e.message}. " \
90
+ 'Type aliases referencing names declared in RBS core will not be expanded ' \
91
+ 'for these libraries, and will be typed by their alias name instead.'
92
+ end
93
+ fallback
94
+ end
95
+
96
+ # A reference into absent core survives #resolve_type_names naming
97
+ # either the alias itself or a name nothing declares.
98
+ #
99
+ # @param environment [RBS::Environment]
100
+ # @return [Boolean]
101
+ def rebound_alias? environment
102
+ decls = environment.type_alias_decls
103
+ decls.any? do |name, entry|
104
+ # @sg-ignore Unresolved call to decl on generic<D>
105
+ type = entry.decl.type
106
+ # @sg-ignore Unresolved call to is_a? on generic<D>
107
+ next false unless type.is_a?(RBS::Types::Alias)
108
+
109
+ # @sg-ignore Unresolved call to to_s on generic<D>
110
+ type.name.to_s == name.to_s || !decls.key?(type.name)
111
+ end
112
+ end
113
+
56
114
  # @param decl [RBS::AST::Declarations::Base]
57
115
  # @param closure [Pin::Closure]
58
116
  # @return [void]
@@ -77,11 +135,12 @@ module Solargraph
77
135
  # @sg-ignore flow sensitive typing should support case/when
78
136
  "Ignoring closure #{closure.inspect} on alias type name #{decl.name}")
79
137
  end
138
+ # @sg-ignore flow sensitive typing should support case/when
139
+ alias_return_type = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted
80
140
  pins.push(
81
- # @sg-ignore Wrong argument type for Solargraph::Pin::Reference::TypeAlias.new: return_type expected Solargraph::ComplexType, received Solargraph::ComplexType::UniqueType, Solargraph::ComplexType
82
141
  Solargraph::Pin::Reference::TypeAlias.new(
83
- # @sg-ignore Unresolved calls to name, type, type_location; return_type type mismatch
84
- name: ComplexType.try_parse(decl.name.to_s).to_s, return_type: RbsTranslator.to_complex_type(decl.type).force_rooted, closure: closure, source: :rbs, type_location: location_decl_to_pin_location(decl.location)
142
+ # @sg-ignore flow sensitive typing should support case/when
143
+ name: ComplexType.try_parse(decl.name.to_s).to_s, return_type: alias_return_type, closure: closure, source: :rbs, type_location: location_decl_to_pin_location(decl.location)
85
144
  )
86
145
  )
87
146
  when RBS::AST::Declarations::Module
@@ -255,10 +314,10 @@ module Solargraph
255
314
  # @type [Hash{String => ComplexType, ComplexType::UniqueType}]
256
315
  generic_defaults = {}
257
316
  decl.type_params.each do |param|
258
- if param.default_type
259
- complex_type = RbsTranslator.to_complex_type(param.default_type).force_rooted
260
- generic_defaults[param.name.to_s] = complex_type
261
- end
317
+ next unless param.default_type
318
+ # @sg-ignore Wrong argument type for to_complex_type: type expected RBS::Types::Bases::Base, received union of concrete subtypes, nil
319
+ complex_type = RbsTranslator.to_complex_type(param.default_type, type_alias_decls: type_alias_decls).force_rooted
320
+ generic_defaults[param.name.to_s] = complex_type
262
321
  end
263
322
 
264
323
  class_name = fqns(decl.name)
@@ -282,7 +341,6 @@ module Solargraph
282
341
  if decl.super_class
283
342
  type = build_type(decl.super_class.name, decl.super_class.args)
284
343
  generic_values = type.all_params.map(&:to_s)
285
- superclass_name = decl.super_class.name.to_s
286
344
  pins.push Solargraph::Pin::Reference::Superclass.new(
287
345
  type_location: location_decl_to_pin_location(decl.super_class.location),
288
346
  closure: class_pin,
@@ -394,7 +452,7 @@ module Solargraph
394
452
  # @param decl [RBS::AST::Declarations::Constant]
395
453
  # @return [void]
396
454
  def constant_decl_to_pin decl
397
- tag = RbsTranslator.to_complex_type(decl.type)
455
+ tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls)
398
456
  pins.push create_constant(decl.name.relative!.to_s, tag, decl.comment&.string, decl)
399
457
  end
400
458
 
@@ -410,7 +468,7 @@ module Solargraph
410
468
  type_location: location_decl_to_pin_location(decl.location),
411
469
  source: :rbs
412
470
  )
413
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
471
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
414
472
  pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
415
473
  pins.push pin
416
474
  end
@@ -516,51 +574,51 @@ module Solargraph
516
574
  pin.instance_variable_set(:@return_type, ComplexType::VOID)
517
575
  end
518
576
  end
519
- if decl.singleton?
520
- final_scope = :class
521
- name = decl.name.to_s
522
- visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
523
- pin = Solargraph::Pin::Method.new(
524
- name: name,
525
- closure: closure,
526
- comments: decl.comment&.string,
527
- type_location: location_decl_to_pin_location(decl.location),
528
- visibility: visibility,
529
- scope: final_scope,
530
- signatures: [],
531
- generics: generics,
532
- source: :rbs
533
- )
534
- pin.signatures.concat method_def_to_sigs(decl, pin)
535
- pins.push pin
536
- end
577
+ return unless decl.singleton?
578
+ final_scope = :class
579
+ name = decl.name.to_s
580
+ visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
581
+ pin = Solargraph::Pin::Method.new(
582
+ name: name,
583
+ closure: closure,
584
+ comments: decl.comment&.string,
585
+ type_location: location_decl_to_pin_location(decl.location),
586
+ visibility: visibility,
587
+ scope: final_scope,
588
+ signatures: [],
589
+ generics: generics,
590
+ source: :rbs
591
+ )
592
+ pin.signatures.concat method_def_to_sigs(decl, pin)
593
+ pins.push pin
537
594
  end
538
595
 
539
596
  # @param decl [RBS::AST::Members::MethodDefinition]
540
597
  # @param pin [Pin::Method]
541
598
  # @return [void]
542
599
  def method_def_to_sigs decl, pin
543
- # rubocop:disable Style/SafeNavigationChainLength
544
- implicit_nil = decl.overloads.first&.annotations&.map(&:string)&.include?('implicitly-returns-nil') || false
545
- # rubocop:enable Style/SafeNavigationChainLength
546
600
  # @param overload [RBS::AST::Members::MethodDefinition::Overload]
547
601
  decl.overloads.map do |overload|
602
+ # RBS attaches this annotation to a single overload, not to the method as a whole
603
+ implicit_nil = overload.annotations.map(&:string).include?('implicitly-returns-nil')
548
604
  type_location = location_decl_to_pin_location(overload.method_type.location)
549
605
  generics = overload.method_type.type_params.map(&:name).map(&:to_s)
550
606
  signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin, implicit_nil)
551
607
  block = if overload.method_type.block
552
- block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin, implicit_nil)
608
+ # the annotation describes the method's return value, not the block's
609
+ block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin, false)
553
610
  Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type, source: :rbs,
554
611
  type_location: type_location, closure: pin)
555
612
  end
556
- Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block, source: :rbs,
613
+ Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block,
614
+ block_required: overload.method_type.block&.required || false, source: :rbs,
557
615
  type_location: type_location, closure: pin)
558
616
  end
559
617
  end
560
618
 
561
619
  # @param location [RBS::Location, nil]
562
620
  # @return [Solargraph::Location, nil]
563
- def location_decl_to_pin_location(location)
621
+ def location_decl_to_pin_location location
564
622
  return nil if location&.name.nil?
565
623
 
566
624
  start_pos = Position.new(location.start_line - 1, location.start_column)
@@ -575,7 +633,7 @@ module Solargraph
575
633
  # @return [Array(Array<Pin::Parameter>, ComplexType)]
576
634
  def parts_of_function type, pin, implicit_nil
577
635
  [
578
- RbsTranslator.to_parameter_pins(type, pin, pin.parameter_names),
636
+ RbsTranslator.to_parameter_pins(type, pin, pin.parameter_names, type_alias_decls: type_alias_decls),
579
637
  extract_method_type_return_type(type, implicit_nil).force_rooted
580
638
  ]
581
639
  end
@@ -598,7 +656,7 @@ module Solargraph
598
656
  visibility: visibility,
599
657
  source: :rbs
600
658
  )
601
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
659
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
602
660
  pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
603
661
  logger.debug do
604
662
  "Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}"
@@ -629,12 +687,12 @@ module Solargraph
629
687
  pin.parameters <<
630
688
  Solargraph::Pin::Parameter.new(
631
689
  name: 'value',
632
- return_type: RbsTranslator.to_complex_type(decl.type).force_rooted,
690
+ return_type: RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted,
633
691
  source: :rbs,
634
692
  closure: pin,
635
693
  type_location: type_location
636
694
  )
637
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
695
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
638
696
  pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
639
697
  pins.push pin
640
698
  end
@@ -659,7 +717,7 @@ module Solargraph
659
717
  comments: decl.comment&.string,
660
718
  source: :rbs
661
719
  )
662
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
720
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
663
721
  pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
664
722
  pins.push pin
665
723
  end
@@ -676,7 +734,7 @@ module Solargraph
676
734
  type_location: location_decl_to_pin_location(decl.location),
677
735
  source: :rbs
678
736
  )
679
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
737
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
680
738
  pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
681
739
  pins.push pin
682
740
  end
@@ -693,7 +751,7 @@ module Solargraph
693
751
  type_location: location_decl_to_pin_location(decl.location),
694
752
  source: :rbs
695
753
  )
696
- rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
754
+ rooted_tag = RbsTranslator.to_complex_type(decl.type, type_alias_decls: type_alias_decls).force_rooted.rooted_tags
697
755
  pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
698
756
  pins.push pin
699
757
  end
@@ -762,7 +820,7 @@ module Solargraph
762
820
  'int' => 'Integer',
763
821
  'untyped' => '',
764
822
  'NilClass' => 'nil'
765
- }
823
+ }.freeze
766
824
  private_constant :RBS_TO_YARD_TYPE
767
825
 
768
826
  # Extract a ComplexType from a MethodType's return type.
@@ -771,18 +829,19 @@ module Solargraph
771
829
  #
772
830
  # @param type [RBS::MethodType]
773
831
  # @return [ComplexType]
832
+ # @param [Object] implicit_nil
774
833
  def extract_method_type_return_type type, implicit_nil
775
- tag = RbsTranslator.to_complex_type(type.type.return_type)
776
- return ComplexType.parse("#{tag}, nil") if tag && implicit_nil
777
- tag
834
+ tag = RbsTranslator.to_complex_type(type.type.return_type, type_alias_decls: type_alias_decls)
835
+ return ComplexType.parse("#{tag}, nil") if tag && implicit_nil
836
+ tag
778
837
  end
779
838
 
780
839
  # @param type_name [RBS::TypeName]
781
840
  # @param type_args [Enumerable<RBS::Types::Bases::Base>]
782
841
  # @return [ComplexType::UniqueType]
783
- def build_type(type_name, type_args = [])
842
+ def build_type type_name, type_args = []
784
843
  base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
785
- params = type_args.map { |arg| RbsTranslator.to_complex_type(arg).force_rooted }
844
+ params = type_args.map { |arg| RbsTranslator.to_complex_type(arg, type_alias_decls: type_alias_decls).force_rooted }
786
845
  if base == 'Hash' && params.length == 2
787
846
  ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
788
847
  else
@@ -6,7 +6,10 @@ module Solargraph
6
6
  # @param metagem [Metagem]
7
7
  def initialize metagem
8
8
  super()
9
- loader.add path: Pathname.new(metagem.full_path)
9
+ # Gems ship their signatures in sig/, the directory RBS itself
10
+ # loads; other .rbs files (e.g., the rbs gem's core/) are not the
11
+ # gem's own API
12
+ loader.add path: Pathname.new(metagem.full_path).join('sig')
10
13
  end
11
14
  end
12
15
  end
@@ -44,12 +44,13 @@ module Solargraph
44
44
  # @param pin [Pin::Method]
45
45
  out = pins.reduce(combined_pin) do |memo, pin|
46
46
  next pin if memo.nil?
47
- if memo == pin && memo.source != :combined
48
- # @todo we should track down situations where we are handled
49
- # the same pin from the same source here and eliminate them -
50
- # this is an efficiency workaround for now
51
- next memo
52
- end
47
+ # @todo Maybe wrong now. External runs multiple rounds of combinations
48
+ # if memo == pin && memo.source != :combined
49
+ # # @todo we should track down situations where we are handled
50
+ # # the same pin from the same source here and eliminate them -
51
+ # # this is an efficiency workaround for now
52
+ # next memo
53
+ # end
53
54
  memo.combine_with(pin)
54
55
  end
55
56
  Solargraph.logger.debug { "GemPins.combine_method_pins(pins.length=#{pins.length}, pins=#{pins}) => #{out.inspect}" }