solargraph 0.33.2 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/README.md +1 -1
  4. data/lib/solargraph.rb +5 -0
  5. data/lib/solargraph/api_map.rb +36 -18
  6. data/lib/solargraph/api_map/cache.rb +2 -0
  7. data/lib/solargraph/api_map/source_to_yard.rb +14 -5
  8. data/lib/solargraph/api_map/store.rb +17 -19
  9. data/lib/solargraph/bundle.rb +2 -0
  10. data/lib/solargraph/complex_type.rb +18 -4
  11. data/lib/solargraph/complex_type/type_methods.rb +2 -0
  12. data/lib/solargraph/complex_type/unique_type.rb +2 -0
  13. data/lib/solargraph/convention.rb +38 -0
  14. data/lib/solargraph/convention/base.rb +28 -0
  15. data/lib/solargraph/convention/gemfile.rb +18 -0
  16. data/lib/solargraph/convention/gemspec.rb +25 -0
  17. data/lib/solargraph/convention/rspec.rb +23 -0
  18. data/lib/solargraph/core_fills.rb +66 -42
  19. data/lib/solargraph/diagnostics.rb +2 -0
  20. data/lib/solargraph/diagnostics/base.rb +2 -0
  21. data/lib/solargraph/diagnostics/require_not_found.rb +2 -0
  22. data/lib/solargraph/diagnostics/rubocop.rb +2 -0
  23. data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
  24. data/lib/solargraph/diagnostics/severities.rb +15 -13
  25. data/lib/solargraph/diagnostics/type_check.rb +2 -0
  26. data/lib/solargraph/diagnostics/update_errors.rb +2 -0
  27. data/lib/solargraph/documentor.rb +42 -0
  28. data/lib/solargraph/environ.rb +40 -0
  29. data/lib/solargraph/language_server.rb +19 -17
  30. data/lib/solargraph/language_server/completion_item_kinds.rb +2 -0
  31. data/lib/solargraph/language_server/error_codes.rb +2 -0
  32. data/lib/solargraph/language_server/host.rb +3 -1
  33. data/lib/solargraph/language_server/host/cataloger.rb +2 -0
  34. data/lib/solargraph/language_server/host/diagnoser.rb +2 -0
  35. data/lib/solargraph/language_server/host/dispatch.rb +2 -0
  36. data/lib/solargraph/language_server/host/sources.rb +2 -0
  37. data/lib/solargraph/language_server/message.rb +2 -0
  38. data/lib/solargraph/language_server/message/base.rb +2 -0
  39. data/lib/solargraph/language_server/message/cancel_request.rb +13 -11
  40. data/lib/solargraph/language_server/message/client.rb +11 -9
  41. data/lib/solargraph/language_server/message/client/register_capability.rb +15 -13
  42. data/lib/solargraph/language_server/message/completion_item.rb +11 -9
  43. data/lib/solargraph/language_server/message/completion_item/resolve.rb +2 -0
  44. data/lib/solargraph/language_server/message/exit_notification.rb +2 -0
  45. data/lib/solargraph/language_server/message/extended.rb +2 -0
  46. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
  47. data/lib/solargraph/language_server/message/extended/document.rb +2 -0
  48. data/lib/solargraph/language_server/message/extended/document_gems.rb +2 -0
  49. data/lib/solargraph/language_server/message/extended/download_core.rb +27 -25
  50. data/lib/solargraph/language_server/message/extended/environment.rb +5 -0
  51. data/lib/solargraph/language_server/message/extended/search.rb +2 -0
  52. data/lib/solargraph/language_server/message/initialize.rb +2 -0
  53. data/lib/solargraph/language_server/message/initialized.rb +2 -0
  54. data/lib/solargraph/language_server/message/method_not_found.rb +16 -14
  55. data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -12
  56. data/lib/solargraph/language_server/message/shutdown.rb +2 -0
  57. data/lib/solargraph/language_server/message/text_document.rb +2 -0
  58. data/lib/solargraph/language_server/message/text_document/base.rb +19 -17
  59. data/lib/solargraph/language_server/message/text_document/code_action.rb +2 -0
  60. data/lib/solargraph/language_server/message/text_document/completion.rb +3 -1
  61. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
  62. data/lib/solargraph/language_server/message/text_document/did_change.rb +2 -0
  63. data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -13
  64. data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -13
  65. data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -15
  66. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -0
  67. data/lib/solargraph/language_server/message/text_document/folding_range.rb +2 -0
  68. data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -1
  69. data/lib/solargraph/language_server/message/text_document/hover.rb +3 -1
  70. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +2 -0
  71. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +2 -0
  72. data/lib/solargraph/language_server/message/text_document/references.rb +2 -0
  73. data/lib/solargraph/language_server/message/text_document/rename.rb +2 -0
  74. data/lib/solargraph/language_server/message/text_document/signature_help.rb +7 -1
  75. data/lib/solargraph/language_server/message/workspace.rb +2 -0
  76. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +2 -0
  77. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +2 -0
  78. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
  79. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -0
  80. data/lib/solargraph/language_server/message_types.rb +14 -12
  81. data/lib/solargraph/language_server/request.rb +2 -0
  82. data/lib/solargraph/language_server/symbol_kinds.rb +2 -0
  83. data/lib/solargraph/language_server/transport.rb +2 -0
  84. data/lib/solargraph/language_server/transport/adapter.rb +2 -0
  85. data/lib/solargraph/language_server/transport/data_reader.rb +3 -1
  86. data/lib/solargraph/language_server/uri_helpers.rb +2 -0
  87. data/lib/solargraph/library.rb +2 -0
  88. data/lib/solargraph/location.rb +2 -0
  89. data/lib/solargraph/logging.rb +2 -0
  90. data/lib/solargraph/page.rb +2 -0
  91. data/lib/solargraph/pin.rb +3 -20
  92. data/lib/solargraph/pin/attribute.rb +2 -4
  93. data/lib/solargraph/pin/base.rb +3 -5
  94. data/lib/solargraph/pin/base_method.rb +2 -4
  95. data/lib/solargraph/pin/base_variable.rb +2 -0
  96. data/lib/solargraph/pin/block.rb +2 -4
  97. data/lib/solargraph/pin/class_variable.rb +2 -3
  98. data/lib/solargraph/pin/closure.rb +9 -0
  99. data/lib/solargraph/pin/common.rb +3 -5
  100. data/lib/solargraph/pin/constant.rb +2 -4
  101. data/lib/solargraph/pin/conversions.rb +4 -2
  102. data/lib/solargraph/pin/documenting.rb +2 -0
  103. data/lib/solargraph/pin/duck_method.rb +2 -0
  104. data/lib/solargraph/pin/global_variable.rb +2 -3
  105. data/lib/solargraph/pin/instance_variable.rb +2 -4
  106. data/lib/solargraph/pin/keyword.rb +2 -4
  107. data/lib/solargraph/pin/keyword_param.rb +8 -0
  108. data/lib/solargraph/pin/local_variable.rb +2 -4
  109. data/lib/solargraph/pin/localized.rb +2 -0
  110. data/lib/solargraph/pin/method.rb +14 -4
  111. data/lib/solargraph/pin/method_alias.rb +2 -4
  112. data/lib/solargraph/pin/namespace.rb +22 -14
  113. data/lib/solargraph/pin/parameter.rb +4 -6
  114. data/lib/solargraph/pin/proxy_type.rb +2 -0
  115. data/lib/solargraph/pin/reference.rb +2 -0
  116. data/lib/solargraph/pin/reference/extend.rb +2 -3
  117. data/lib/solargraph/pin/reference/include.rb +2 -3
  118. data/lib/solargraph/pin/reference/override.rb +12 -3
  119. data/lib/solargraph/pin/reference/require.rb +2 -4
  120. data/lib/solargraph/pin/reference/superclass.rb +2 -3
  121. data/lib/solargraph/pin/singleton.rb +2 -0
  122. data/lib/solargraph/pin/symbol.rb +2 -4
  123. data/lib/solargraph/pin/yard_pin.rb +2 -0
  124. data/lib/solargraph/pin/yard_pin/constant.rb +7 -3
  125. data/lib/solargraph/pin/yard_pin/method.rb +12 -10
  126. data/lib/solargraph/pin/yard_pin/namespace.rb +9 -4
  127. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +30 -3
  128. data/lib/solargraph/position.rb +2 -0
  129. data/lib/solargraph/range.rb +2 -0
  130. data/lib/solargraph/server_methods.rb +2 -0
  131. data/lib/solargraph/shell.rb +33 -2
  132. data/lib/solargraph/source.rb +2 -0
  133. data/lib/solargraph/source/chain.rb +2 -0
  134. data/lib/solargraph/source/chain/call.rb +63 -14
  135. data/lib/solargraph/source/chain/class_variable.rb +2 -0
  136. data/lib/solargraph/source/chain/constant.rb +18 -11
  137. data/lib/solargraph/source/chain/global_variable.rb +2 -0
  138. data/lib/solargraph/source/chain/head.rb +2 -0
  139. data/lib/solargraph/source/chain/instance_variable.rb +2 -0
  140. data/lib/solargraph/source/chain/link.rb +2 -0
  141. data/lib/solargraph/source/chain/literal.rb +2 -0
  142. data/lib/solargraph/source/chain/or.rb +2 -0
  143. data/lib/solargraph/source/chain/variable.rb +2 -0
  144. data/lib/solargraph/source/change.rb +2 -0
  145. data/lib/solargraph/source/cursor.rb +4 -1
  146. data/lib/solargraph/source/encoding_fixes.rb +2 -0
  147. data/lib/solargraph/source/flawed_builder.rb +15 -13
  148. data/lib/solargraph/source/node_chainer.rb +2 -0
  149. data/lib/solargraph/source/node_methods.rb +9 -5
  150. data/lib/solargraph/source/source_chainer.rb +2 -0
  151. data/lib/solargraph/source/updater.rb +52 -50
  152. data/lib/solargraph/source_map.rb +15 -7
  153. data/lib/solargraph/source_map/clip.rb +35 -3
  154. data/lib/solargraph/source_map/completion.rb +2 -0
  155. data/lib/solargraph/source_map/mapper.rb +2 -0
  156. data/lib/solargraph/source_map/node_processor.rb +2 -0
  157. data/lib/solargraph/source_map/node_processor/alias_node.rb +2 -0
  158. data/lib/solargraph/source_map/node_processor/args_node.rb +2 -0
  159. data/lib/solargraph/source_map/node_processor/base.rb +5 -3
  160. data/lib/solargraph/source_map/node_processor/begin_node.rb +2 -0
  161. data/lib/solargraph/source_map/node_processor/block_node.rb +2 -0
  162. data/lib/solargraph/source_map/node_processor/casgn_node.rb +2 -0
  163. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +2 -0
  164. data/lib/solargraph/source_map/node_processor/def_node.rb +2 -0
  165. data/lib/solargraph/source_map/node_processor/defs_node.rb +2 -0
  166. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +2 -0
  167. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +3 -1
  168. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +2 -0
  169. data/lib/solargraph/source_map/node_processor/namespace_node.rb +4 -1
  170. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +2 -0
  171. data/lib/solargraph/source_map/node_processor/resbody_node.rb +2 -0
  172. data/lib/solargraph/source_map/node_processor/sclass_node.rb +2 -0
  173. data/lib/solargraph/source_map/node_processor/send_node.rb +11 -6
  174. data/lib/solargraph/source_map/node_processor/sym_node.rb +2 -0
  175. data/lib/solargraph/source_map/region.rb +2 -0
  176. data/lib/solargraph/type_checker.rb +35 -17
  177. data/lib/solargraph/type_checker/param_def.rb +2 -0
  178. data/lib/solargraph/type_checker/problem.rb +2 -0
  179. data/lib/solargraph/version.rb +3 -1
  180. data/lib/solargraph/views/document.erb +3 -3
  181. data/lib/solargraph/views/environment.erb +3 -0
  182. data/lib/solargraph/workspace.rb +5 -1
  183. data/lib/solargraph/workspace/config.rb +14 -0
  184. data/lib/solargraph/yard_map.rb +64 -5
  185. data/lib/solargraph/yard_map/cache.rb +2 -0
  186. data/lib/solargraph/yard_map/core_docs.rb +2 -0
  187. data/lib/solargraph/yard_map/core_gen.rb +2 -0
  188. data/lib/solargraph/yard_map/mapper.rb +15 -14
  189. data/lib/solargraph/yard_map/rdoc_to_yard.rb +129 -0
  190. data/lib/yard-solargraph.rb +8 -0
  191. metadata +11 -2
@@ -1,35 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  module Pin
3
5
  module YardPin
4
6
  class Method < Pin::Method
5
7
  include YardMixin
6
8
 
7
- def initialize code_object, location, name = nil, scope = nil, visibility = nil, closure = nil
9
+ def initialize code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
8
10
  @code_object = code_object
9
- comments = (code_object.docstring ? code_object.docstring.all : nil)
11
+ @spec = spec
10
12
  closure ||= Solargraph::Pin::Namespace.new(
11
- name: code_object.namespace.to_s
13
+ name: code_object.namespace.to_s,
14
+ gates: [code_object.namespace.to_s]
12
15
  )
13
16
  super(
14
17
  location: location,
15
18
  closure: closure,
16
19
  name: name || code_object.name.to_s,
17
- comments: comments,
20
+ comments: nil,
18
21
  scope: scope || code_object.scope,
19
22
  visibility: visibility || code_object.visibility,
20
- args: get_parameters(code_object)
23
+ args: nil
21
24
  )
22
25
  end
23
26
 
24
- # def return_type
25
- # @return_type ||= Solargraph::ComplexType.try_parse(Solargraph::CoreFills::CUSTOM_RETURN_TYPES[path]) if Solargraph::CoreFills::CUSTOM_RETURN_TYPES.has_key?(path)
26
- # super
27
- # end
27
+ def parameters
28
+ @parameters ||= get_parameters(code_object)
29
+ end
28
30
 
29
31
  private
30
32
 
31
33
  def get_parameters code_object
32
- return [] unless code_object.kind_of?(YARD::CodeObjects::MethodObject)
34
+ return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
33
35
  args = []
34
36
  code_object.parameters.each do |a|
35
37
  p = a[0]
@@ -1,22 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  module Pin
3
5
  module YardPin
4
6
  class Namespace < Pin::Namespace
5
7
  include YardMixin
6
8
 
7
- def initialize code_object, location
9
+ def initialize code_object, spec
8
10
  @code_object = code_object
11
+ @spec = spec
9
12
  closure = Solargraph::Pin::Namespace.new(
10
13
  name: code_object.namespace.to_s,
11
- closure: Pin::ROOT_PIN
14
+ closure: Pin::ROOT_PIN,
15
+ gates: [code_object.namespace.to_s]
12
16
  )
13
17
  super(
14
18
  location: location,
15
19
  name: code_object.name.to_s,
16
- comments: comments_from(code_object),
20
+ comments: nil,
17
21
  type: namespace_type(code_object),
18
22
  visibility: code_object.visibility,
19
- closure: closure
23
+ closure: closure,
24
+ gates: split_to_gates(code_object.path)
20
25
  )
21
26
  end
22
27
 
@@ -1,12 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  module Pin
3
5
  module YardPin
4
6
  module YardMixin
7
+ attr_reader :code_object
8
+
9
+ attr_reader :spec
10
+
11
+ @@gate_cache ||= {}
12
+
13
+ def comments
14
+ @comments ||= code_object.docstring ? code_object.docstring.all : ''
15
+ end
16
+
17
+ def location
18
+ return @location if @located
19
+ @located = true
20
+ @location = Solargraph::YardMap::Mapper.object_location(code_object, spec)
21
+ end
22
+
5
23
  private
6
24
 
7
- def comments_from code_object
8
- return nil if code_object.docstring.nil?
9
- code_object.docstring.all
25
+ def split_to_gates namespace
26
+ @@gate_cache[namespace] || begin
27
+ parts = namespace.split('::')
28
+ result = []
29
+ until parts.empty?
30
+ result.push parts.join('::')
31
+ parts.pop
32
+ end
33
+ result.push ''
34
+ @@gate_cache[namespace] = result.freeze
35
+ result
36
+ end
10
37
  end
11
38
  end
12
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  # The zero-based line and column numbers of a position in a string.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  # A pair of positions that compose a section of text.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'socket'
2
4
 
3
5
  module Solargraph
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'backport'
3
5
  require 'benchmark'
@@ -14,6 +16,7 @@ module Solargraph
14
16
  end
15
17
 
16
18
  desc 'socket', 'Run a Solargraph socket server'
19
+
17
20
  option :host, type: :string, aliases: :h, desc: 'The server host', default: '127.0.0.1'
18
21
  option :port, type: :numeric, aliases: :p, desc: 'The server port', default: 7658
19
22
  def socket
@@ -90,10 +93,24 @@ module Solargraph
90
93
  puts Solargraph::YardMap::CoreDocs.available.join("\n")
91
94
  end
92
95
 
93
- desc 'clear-cores', 'Clear the cached core documentation'
94
- def clear_cores
96
+ desc 'clear', 'Delete the cached documentation'
97
+ def clear
98
+ puts "Deleting the cached documentation"
95
99
  Solargraph::YardMap::CoreDocs.clear
96
100
  end
101
+ map 'clear-cache' => :clear
102
+ map 'clear-cores' => :clear
103
+
104
+ desc 'uncache GEM [...GEM]', "Delete cached gem documentation"
105
+ def uncache *gems
106
+ raise ArgumentError, 'No gems specified.' if gems.empty?
107
+ gems.each do |gem|
108
+ Dir[File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{gem}-*")].each do |dir|
109
+ puts "Deleting cache: #{dir}"
110
+ FileUtils.remove_entry_secure dir
111
+ end
112
+ end
113
+ end
97
114
 
98
115
  desc 'reporters', 'Get a list of diagnostics reporters'
99
116
  def reporters
@@ -162,6 +179,20 @@ module Solargraph
162
179
  puts "Scanned #{directory} (#{api_map.pins.length} pins) in #{time.real} seconds."
163
180
  end
164
181
 
182
+ desc 'bundle', 'Generate documentation for bundled gems'
183
+ option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
184
+ option :rebuild, type: :boolean, aliases: :r, desc: 'Rebuild existing documentation', default: false
185
+ def bundle
186
+ Documentor.new(options[:directory]).document
187
+ end
188
+
189
+ desc 'rdoc GEM [VERSION]', 'Use RDoc to cache documentation'
190
+ def rdoc gem, version = '>= 0'
191
+ spec = Gem::Specification.find_by_name(gem, version)
192
+ puts "Caching #{spec.name} #{spec.version} from RDoc"
193
+ Solargraph::YardMap::RdocToYard.run(spec)
194
+ end
195
+
165
196
  private
166
197
 
167
198
  # @param pin [Solargraph::Pin::Base]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parser/current'
2
4
  require 'yard'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # HACK: Fix autoload issue
2
4
  require 'solargraph/source/chain/link'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -28,33 +30,61 @@ module Solargraph
28
30
 
29
31
  private
30
32
 
33
+ # @param pins [Array<Pin::Base>]
34
+ # @param api_map [ApiMap]
35
+ # @param context [ComplexType]
36
+ # @param locals [Pin::LocalVariable]
37
+ # @return [Array<Pin::Base>]
31
38
  def inferred_pins pins, api_map, context, locals
32
39
  result = pins.map do |p|
33
- if CoreFills::METHODS_RETURNING_SUBTYPES.include?(p.path) && !context.subtypes.empty?
34
- next Solargraph::Pin::Method.new(
35
- location: p.location,
36
- closure: p.closure,
37
- name: p.name,
38
- comments: "@return [#{context.subtypes.first.tag}]",
39
- scope: p.scope,
40
- visibility: p.visibility,
41
- args: p.parameters,
42
- node: p.node
43
- )
40
+ overloads = p.docstring.tags(:overload)
41
+ # next p if overloads.empty?
42
+ type = ComplexType::UNDEFINED
43
+ # @param [YARD::Tags::OverloadTag]
44
+ overloads.each do |ol|
45
+ next if arguments.length < ol.parameters.length &&
46
+ !(arguments.length == ol.parameters.length - 1 && ol.parameters.last.first.start_with?('*'))
47
+ match = true
48
+ arguments.each_with_index do |arg, idx|
49
+ achain = arguments[idx]
50
+ next if achain.nil?
51
+ param = ol.parameters[idx]
52
+ if param.nil?
53
+ match = false unless ol.parameters.last && ol.parameters.last.first.start_with?('*')
54
+ break
55
+ end
56
+ par = ol.tags(:param).select { |pp| pp.name == param.first }.first
57
+ next if par.nil? || par.types.nil? || par.types.empty?
58
+ atype = achain.infer(api_map, Pin::ProxyType.anonymous(context), locals)
59
+ other = ComplexType.try_parse(*par.types)
60
+ # @todo Weak type comparison
61
+ unless atype.tag == other.tag || api_map.super_and_sub?(other.tag, atype.tag)
62
+ match = false
63
+ break
64
+ end
65
+ end
66
+ if match
67
+ type = extra_return_type(ol, context)
68
+ type = ComplexType.try_parse(*ol.tag(:return).types).self_to(context.to_s).qualify(api_map, context.namespace) if ol.has_tag?(:return) && ol.tag(:return).types && !ol.tag(:return).types.empty? && (type.nil? || type.undefined?)
69
+ type ||= ComplexType::UNDEFINED
70
+ end
71
+ break if type.defined?
44
72
  end
45
- if CoreFills::METHODS_RETURNING_VALUE_TYPES.include?(p.path) && !context.value_types.empty?
73
+ next p.proxy(type) if type.defined?
74
+ type = extra_return_type(p.docstring, context)
75
+ if type
46
76
  next Solargraph::Pin::Method.new(
47
77
  location: p.location,
48
78
  closure: p.closure,
49
79
  name: p.name,
50
- comments: "@return [#{context.value_types.first.tag}]",
80
+ comments: "@return [#{context.subtypes.first.to_s}]",
51
81
  scope: p.scope,
52
82
  visibility: p.visibility,
53
83
  args: p.parameters,
54
84
  node: p.node
55
85
  )
56
86
  end
57
- if p.kind == Pin::METHOD && !p.macros.empty?
87
+ if p.is_a?(Pin::Method) && !p.macros.empty?
58
88
  result = process_macro(p, api_map, context, locals)
59
89
  next result unless result.return_type.undefined?
60
90
  elsif !p.directives.empty?
@@ -92,9 +122,15 @@ module Solargraph
92
122
  Pin::ProxyType.anonymous ComplexType::UNDEFINED
93
123
  end
94
124
 
125
+ # @param api_map [ApiMap]
126
+ # @param macro [YARD::Tags::MacroDirective]
95
127
  def inner_process_macro pin, macro, api_map, context, locals
96
128
  vals = arguments.map{ |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals)) }
97
129
  txt = macro.tag.text.clone
130
+ if txt.empty? && macro.tag.name
131
+ named = api_map.named_macro(macro.tag.name)
132
+ txt = named.tag.text.clone if named
133
+ end
98
134
  i = 1
99
135
  vals.each do |v|
100
136
  txt.gsub!(/\$#{i}/, v.context.namespace)
@@ -107,6 +143,19 @@ module Solargraph
107
143
  end
108
144
  Pin::ProxyType.anonymous(ComplexType::UNDEFINED)
109
145
  end
146
+
147
+ # @param docstring [YARD::Docstring]
148
+ # @param context [ComplexType]
149
+ def extra_return_type docstring, context
150
+ if docstring.has_tag?(:return_single_parameter) && context.subtypes.one?
151
+ return context.subtypes.first
152
+ elsif docstring.has_tag?(:return_value_parameter) && context.value_types.one?
153
+ return context.value_types.first
154
+ # elsif docstring.has_tag?(:return) && docstring.tag(:return).types && !docstring.tag(:return).types.empty?
155
+ # return ComplexType.try_parse(*docstring.tag(:return).types)
156
+ end
157
+ nil
158
+ end
110
159
  end
111
160
  end
112
161
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -9,20 +11,25 @@ module Solargraph
9
11
  def resolve api_map, name_pin, locals
10
12
  return [Pin::ROOT_PIN] if word.empty?
11
13
  if word.start_with?('::')
12
- context = ''
13
- bottom = word[2..-1]
14
+ bottom = ''
15
+ gates = [word[2..-1].split('::')[0..-2].join('::')]
14
16
  else
15
- context = name_pin.full_context.namespace
16
- bottom = word
17
+ bottom = word.split('::')[0..-2].join('::')
18
+ gates = crawl_gates(name_pin)
17
19
  end
18
- if bottom.include?('::')
19
- ns = bottom.split('::')[0..-2].join('::')
20
- else
21
- ns = ''
20
+ result = api_map.get_constants(bottom, *gates)
21
+ result.select{ |p| p.path == word || "::#{p.path}" == word || p.path.end_with?("::#{word}") }
22
+ end
23
+
24
+ private
25
+
26
+ def crawl_gates pin
27
+ clos = pin
28
+ until clos.nil?
29
+ return clos.gates if clos.is_a?(Pin::Namespace)
30
+ clos = clos.closure
22
31
  end
23
- result = api_map.get_constants(ns, context)
24
- last_name = bottom.split('::').last
25
- result.select{ |p| p.name == last_name }
32
+ ['']
26
33
  end
27
34
  end
28
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  class Chain
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  # A change to be applied to text.