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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32fec2551136daaa8c608f7fe94fec4ef24e08ba03723b2ece3e4c8b66342c5b
4
- data.tar.gz: edaa58070c532e97dd1b0ac2e43b7917e08ceb972d19c43f26eba7b9fc62cf5a
3
+ metadata.gz: 0d4c15dc7c4e82dfcfb3b763c111980c3faa3da66857658e5fd8124e08ef999e
4
+ data.tar.gz: 64f641fd49afbcee69e014e65a77f8f0f8649e854d0da67371c11aa48692f257
5
5
  SHA512:
6
- metadata.gz: 46b6981ae2a47c4676a78fdb50ac01f46d70cc37b3f762b9c35936dd13b2cd529fca0ed6d9057bd3106164145967560f50d1836848c395d4d90b953facb48f27
7
- data.tar.gz: c6f70f39fded5af0e588f6792c9dba1872c421fc62993e16e1f734fe828d36e5f287309368fb09b1a7130d9bd7f0aa87a9ac7e9bef8e0de9309247985bc67c9f
6
+ metadata.gz: 9b9442c9027fd4eb15a4958302db194e9ed9031458c34d7554a514969b5415c495bcb633b78ebcd8ba14747268be2ea78ce6117216240b1bca302fe8892bf6ee
7
+ data.tar.gz: 46f1c0eb34c0830dbbda766c6be52730592136e777df71bc9953bb8e391bfd161f31e08db971107d3862f815423174a51fa0334b22de67193272b3ffb9e0a560
data/.gitignore CHANGED
@@ -7,4 +7,3 @@ Gemfile.lock
7
7
  doc
8
8
  coverage
9
9
  /tmp/
10
- guides
data/README.md CHANGED
@@ -44,7 +44,7 @@ When editing code, a `require` call that references a gem will pull the document
44
44
 
45
45
  ### More Information
46
46
 
47
- See [http://solargraph.org/tips](http://solargraph.org/tips) for more tips on using Solargraph with an editor.
47
+ See [http://solargraph.org/guides](http://solargraph.org/guides) for more tips and tutorials for using Solargraph.
48
48
 
49
49
  ## How It Works
50
50
 
data/lib/solargraph.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
  require 'solargraph/version'
3
5
  require 'rubygems/package'
@@ -34,6 +36,9 @@ module Solargraph
34
36
  autoload :Bundle, 'solargraph/bundle'
35
37
  autoload :Logging, 'solargraph/logging'
36
38
  autoload :TypeChecker, 'solargraph/type_checker'
39
+ autoload :Environ, 'solargraph/environ'
40
+ autoload :Convention, 'solargraph/convention'
41
+ autoload :Documentor, 'solargraph/documentor'
37
42
 
38
43
  dir = File.dirname(__FILE__)
39
44
  YARDOC_PATH = File.realpath(File.join(dir, '..', 'yardoc'))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'set'
3
5
  require 'pathname'
@@ -47,6 +49,8 @@ module Solargraph
47
49
  self
48
50
  end
49
51
 
52
+ # @param name [String]
53
+ # @return [YARD::Tags::MacroDirective, nil]
50
54
  def named_macro name
51
55
  store.named_macros[name]
52
56
  end
@@ -83,10 +87,12 @@ module Solargraph
83
87
  end
84
88
  end
85
89
  return self if merged
90
+ implicit.clear
86
91
  pins = []
87
92
  reqs = []
88
93
  # @param map [SourceMap]
89
94
  new_map_hash.values.each do |map|
95
+ implicit.merge map.environ
90
96
  pins.concat map.pins
91
97
  reqs.concat map.requires.map(&:name)
92
98
  end
@@ -106,6 +112,8 @@ module Solargraph
106
112
  result
107
113
  end
108
114
  end
115
+ reqs.concat implicit.requires
116
+ pins.concat implicit.overrides
109
117
  yard_map.change(reqs)
110
118
  new_store = Store.new(pins + yard_map.pins)
111
119
  @mutex.synchronize {
@@ -119,6 +127,12 @@ module Solargraph
119
127
  self
120
128
  end
121
129
 
130
+ # @return [Environ]
131
+ def implicit
132
+ @implicit ||= Environ.new
133
+ end
134
+
135
+ # @return [Hash]
122
136
  def local_path_hash
123
137
  @local_paths ||= {}
124
138
  end
@@ -187,28 +201,26 @@ module Solargraph
187
201
  # may contain both constant and namespace pins.
188
202
  #
189
203
  # @param namespace [String] The namespace
190
- # @param context [String] The context
204
+ # @param contexts [Array<String>] The contexts
191
205
  # @return [Array<Solargraph::Pin::Base>]
192
- def get_constants namespace, context = ''
206
+ def get_constants namespace, *contexts
193
207
  namespace ||= ''
194
- cached = cache.get_constants(namespace, context)
208
+ contexts.push '' if contexts.empty?
209
+ cached = cache.get_constants(namespace, contexts)
195
210
  return cached.clone unless cached.nil?
196
211
  skip = []
197
212
  result = []
198
- bases = context.split('::')
199
- while bases.length > 0
200
- built = bases.join('::')
201
- fqns = qualify(namespace, built)
213
+ contexts.each do |context|
214
+ fqns = qualify(namespace, context)
215
+ visibility = [:public]
216
+ visibility.push :private if fqns == context
217
+ result.concat inner_get_constants(fqns, visibility, skip)
218
+ fqns = qualify(namespace, '')
202
219
  visibility = [:public]
203
220
  visibility.push :private if fqns == context
204
221
  result.concat inner_get_constants(fqns, visibility, skip)
205
- bases.pop
206
222
  end
207
- fqns = qualify(namespace, '')
208
- visibility = [:public]
209
- visibility.push :private if fqns == context
210
- result.concat inner_get_constants(fqns, visibility, skip)
211
- cache.set_constants(namespace, context, result)
223
+ cache.set_constants(namespace, contexts, result)
212
224
  result
213
225
  end
214
226
 
@@ -266,7 +278,7 @@ module Solargraph
266
278
  # @return [Array<Solargraph::Pin::GlobalVariable>]
267
279
  def get_global_variable_pins
268
280
  # @todo Slow version
269
- pins.select{|p| p.kind == Pin::GLOBAL_VARIABLE}
281
+ pins.select{ |p| p.is_a?(Pin::GlobalVariable) }
270
282
  end
271
283
 
272
284
  # Get an array of methods available in a particular context.
@@ -283,10 +295,11 @@ module Solargraph
283
295
  skip = []
284
296
  if fqns == ''
285
297
  # @todo Implement domains
286
- # domains.each do |domain|
287
- # type = ComplexType.parse(domain).first
288
- # result.concat inner_get_methods(type.name, type.scope, [:public], deep, skip)
289
- # end
298
+ implicit.domains.each do |domain|
299
+ type = ComplexType.try_parse(domain)
300
+ next if type.undefined?
301
+ result.concat inner_get_methods(type.name, type.scope, [:public], deep, skip)
302
+ end
290
303
  result.concat inner_get_methods(fqns, :class, visibility, deep, skip)
291
304
  result.concat inner_get_methods(fqns, :instance, visibility, deep, skip)
292
305
  result.concat inner_get_methods('Kernel', :instance, visibility, deep, skip)
@@ -466,11 +479,15 @@ module Solargraph
466
479
  source_map_hash.keys.include?(filename)
467
480
  end
468
481
 
482
+ # True if the specified file is included in the workspace.
483
+ #
484
+ # @param filename [String]
469
485
  def workspaced? filename
470
486
  workspace_filenames.include?(filename)
471
487
  end
472
488
 
473
489
  # @param location [Location]
490
+ # @return [Location]
474
491
  def require_reference_at location
475
492
  map = source_map(location.filename)
476
493
  pin = map.requires.select { |pin| pin.location.range.contain?(location.range.start) }.first
@@ -500,6 +517,7 @@ module Solargraph
500
517
 
501
518
  private
502
519
 
520
+ # @return [Array<String>]
503
521
  def workspace_filenames
504
522
  @workspace_filenames ||= []
505
523
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class ApiMap
3
5
  class Cache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class ApiMap
3
5
  module SourceToYard
@@ -26,12 +28,17 @@ module Solargraph
26
28
  next
27
29
  end
28
30
  if pin.type == :class
29
- code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path)
31
+ code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
32
+ next if pin.location.nil? || pin.location.filename.nil?
33
+ obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
34
+ }
30
35
  else
31
- code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path)
36
+ code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
37
+ next if pin.location.nil? || pin.location.filename.nil?
38
+ obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
39
+ }
32
40
  end
33
41
  code_object_map[pin.path].docstring = pin.docstring
34
- code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil? || code_object_map[pin.path].files.include?(pin.location.filename)
35
42
  store.get_includes(pin.path).each do |ref|
36
43
  code_object_map[pin.path].instance_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
37
44
  end
@@ -45,10 +52,12 @@ module Solargraph
45
52
  code_object_map[pin.path] ||= pin.code_object
46
53
  next
47
54
  end
48
- code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope)
55
+ code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope) { |obj|
56
+ next if pin.location.nil? || pin.location.filename.nil?
57
+ obj.add_file pin.location.filename, pin.location.range.start.line
58
+ }
49
59
  code_object_map[pin.path].docstring = pin.docstring
50
60
  code_object_map[pin.path].visibility = pin.visibility || :public
51
- code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil? || code_object_map[pin.path].files.include?(pin.location.filename)
52
61
  code_object_map[pin.path].parameters = pin.parameters.map do |p|
53
62
  n = p.match(/^[a-z0-9_]*:?/i)[0]
54
63
  v = nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Solargraph
@@ -17,7 +19,7 @@ module Solargraph
17
19
  # @return [Array<Solargraph::Pin::Base>]
18
20
  def get_constants fqns, visibility = [:public]
19
21
  namespace_children(fqns).select { |pin|
20
- !pin.name.empty? and (pin.kind == Pin::NAMESPACE or pin.kind == Pin::CONSTANT) and visibility.include?(pin.visibility)
22
+ !pin.name.empty? and (pin.is_a?(Pin::Namespace) || pin.is_a?(Pin::Constant)) && visibility.include?(pin.visibility)
21
23
  }
22
24
  end
23
25
 
@@ -26,9 +28,8 @@ module Solargraph
26
28
  # @param visibility [Array<Symbol>]
27
29
  # @return [Array<Solargraph::Pin::Base>]
28
30
  def get_methods fqns, scope: :instance, visibility: [:public]
29
- kinds = [Pin::METHOD, Pin::ATTRIBUTE, Pin::METHOD_ALIAS]
30
31
  namespace_children(fqns).select do |pin|
31
- kinds.include?(pin.kind) && pin.scope == scope && visibility.include?(pin.visibility)
32
+ pin.is_a?(Pin::BaseMethod) && pin.scope == scope && visibility.include?(pin.visibility)
32
33
  end
33
34
  end
34
35
 
@@ -61,7 +62,6 @@ module Solargraph
61
62
  # @param scope [Symbol] :class or :instance
62
63
  # @return [Array<Solargraph::Pin::Base>]
63
64
  def get_instance_variables(fqns, scope = :instance)
64
- # namespace_children(fqns).select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context.scope == scope}
65
65
  all_instance_variables.select { |pin|
66
66
  pin.binder.namespace == fqns && pin.binder.scope == scope
67
67
  }
@@ -70,7 +70,7 @@ module Solargraph
70
70
  # @param fqns [String]
71
71
  # @return [Array<Solargraph::Pin::Base>]
72
72
  def get_class_variables(fqns)
73
- namespace_children(fqns).select{|pin| pin.kind == Pin::CLASS_VARIABLE}
73
+ namespace_children(fqns).select{|pin| pin.is_a?(Pin::ClassVariable)}
74
74
  end
75
75
 
76
76
  # @return [Array<Solargraph::Pin::Base>]
@@ -91,13 +91,11 @@ module Solargraph
91
91
 
92
92
  # @return [Array<Solargraph::Pin::Base>]
93
93
  def namespace_pins
94
- # @namespace_pins ||= pins.select{|p| p.kind == Pin::NAMESPACE}
95
94
  @namespace_pins ||= []
96
95
  end
97
96
 
98
97
  # @return [Array<Solargraph::Pin::Base>]
99
98
  def method_pins
100
- # @method_pins ||= pins.select{|p| p.kind == Pin::METHOD or p.kind == Pin::ATTRIBUTE}
101
99
  @method_pins ||= []
102
100
  end
103
101
 
@@ -116,7 +114,7 @@ module Solargraph
116
114
  @named_macros ||= begin
117
115
  result = {}
118
116
  pins.each do |pin|
119
- pin.macros.select{|m| m.tag.tag_name == 'macro'}.each do |macro|
117
+ pin.macros.select{|m| m.tag.tag_name == 'macro' && !m.tag.text.empty? }.each do |macro|
120
118
  next if macro.tag.name.nil? || macro.tag.name.empty?
121
119
  result[macro.tag.name] = macro
122
120
  end
@@ -149,7 +147,7 @@ module Solargraph
149
147
  base = ''
150
148
  name = fqns
151
149
  end
152
- namespace_children(base).select{|pin| pin.name == name and pin.kind == Pin::NAMESPACE}
150
+ namespace_children(base).select{|pin| pin.name == name && pin.is_a?(Pin::Namespace)}
153
151
  end
154
152
 
155
153
  # @return [Array<Solargraph::Pin::Symbol>]
@@ -203,17 +201,17 @@ module Solargraph
203
201
  pins.each do |pin|
204
202
  namespace_map[pin.namespace] ||= []
205
203
  namespace_map[pin.namespace].push pin
206
- namespaces.add pin.path if pin.kind == Pin::NAMESPACE and !pin.path.empty?
207
- namespace_pins.push pin if pin.kind == Pin::NAMESPACE
208
- method_pins.push pin if pin.kind == Pin::METHOD || pin.kind == Pin::ATTRIBUTE
209
- symbols.push pin if pin.kind == Pin::SYMBOL
210
- if pin.kind == Pin::INCLUDE_REFERENCE
204
+ namespaces.add pin.path if pin.is_a?(Pin::Namespace) and !pin.path.empty?
205
+ namespace_pins.push pin if pin.is_a?(Pin::Namespace)
206
+ method_pins.push pin if pin.is_a?(Pin::BaseMethod)
207
+ symbols.push pin if pin.is_a?(Pin::Symbol)
208
+ if pin.is_a?(Pin::Reference::Include)
211
209
  include_references[pin.namespace] ||= []
212
210
  include_references[pin.namespace].push pin.name
213
- elsif pin.kind == Pin::EXTEND_REFERENCE
211
+ elsif pin.is_a?(Pin::Reference::Extend)
214
212
  extend_references[pin.namespace] ||= []
215
213
  extend_references[pin.namespace].push pin.name
216
- elsif pin.kind == Pin::SUPERCLASS_REFERENCE
214
+ elsif pin.is_a?(Pin::Reference::Superclass)
217
215
  superclass_references[pin.namespace] ||= []
218
216
  superclass_references[pin.namespace].push pin.name
219
217
  elsif pin.is_a?(Pin::Block)
@@ -228,12 +226,12 @@ module Solargraph
228
226
  path_pin_hash[pin.path].push pin
229
227
  end
230
228
  end
231
- override_pins.concat CoreFills::OVERRIDES
232
229
  override_pins.each do |ovr|
233
230
  pin = get_path_pins(ovr.name).first
234
231
  next if pin.nil?
235
- pin.docstring.delete_tags(:overload)
236
- pin.docstring.delete_tags(:return)
232
+ (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
233
+ pin.docstring.delete_tags tag.to_sym
234
+ end
237
235
  ovr.tags.each do |tag|
238
236
  pin.docstring.add_tag(tag)
239
237
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  # An aggregation of a workspace and additional sources to be cataloged in an
3
5
  # ApiMap.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  # A container for type data based on YARD type tags.
3
5
  #
@@ -73,10 +75,24 @@ module Solargraph
73
75
 
74
76
  def self_to dst
75
77
  return self unless selfy?
76
- result = @items.map { |i| i.self_to dst }
78
+ red = reduce_class(dst)
79
+ result = @items.map { |i| i.self_to red }
77
80
  ComplexType.parse(*result.map(&:tag))
78
81
  end
79
82
 
83
+ private
84
+
85
+ # @todo This is a quick and dirty hack that forces `self` keywords
86
+ # to reference an instance of their class and never the class itself.
87
+ # This behavior may change depending on which result is expected
88
+ # from YARD conventions. See https://github.com/lsegal/yard/issues/1257
89
+ def reduce_class dst
90
+ while dst =~ /^(Class|Module)\<(.*?)\>$/
91
+ dst = dst.sub(/^(Class|Module)\</, '').sub(/\>$/, '')
92
+ end
93
+ dst
94
+ end
95
+
80
96
  class << self
81
97
  # Parse type strings into a ComplexType.
82
98
  #
@@ -157,11 +173,9 @@ module Solargraph
157
173
  subtype_string += char
158
174
  end
159
175
  end
160
- base.strip!
161
- subtype_string.strip!
162
176
  raise ComplexTypeError, "Unclosed subtype in #{type_string}" if point_stack != 0 || curly_stack != 0 || paren_stack != 0
163
177
  # types.push ComplexType.new([UniqueType.new(base, subtype_string)])
164
- types.push UniqueType.new(base, subtype_string)
178
+ types.push UniqueType.new(base.strip, subtype_string.strip)
165
179
  end
166
180
  unless key_types.nil?
167
181
  raise ComplexTypeError, "Invalid use of key/value parameters" unless partial
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class ComplexType
3
5
  # Methods for accessing type data.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class ComplexType
3
5
  # An individual type signature. A complex type can consist of multiple
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module Solargraph
6
+ # Conventions provide a way to modify an ApiMap based on expectations about
7
+ # one of its sources.
8
+ #
9
+ module Convention
10
+ autoload :Base, 'solargraph/convention/base'
11
+ autoload :Gemfile, 'solargraph/convention/gemfile'
12
+ autoload :Rspec, 'solargraph/convention/rspec'
13
+ autoload :Gemspec, 'solargraph/convention/gemspec'
14
+
15
+ @@conventions = Set.new
16
+
17
+ # @param convention [Class<Convention::Base>]
18
+ # @return [Convention::Base]
19
+ def self.register convention
20
+ @@conventions.add convention.new
21
+ end
22
+
23
+ # @param source [Source]
24
+ # @return [Environ]
25
+ def self.for(source)
26
+ result = Environ.new
27
+ return result if source.filename.nil? || source.filename.empty?
28
+ @@conventions.each do |conv|
29
+ result.merge conv.environ if conv.match?(source)
30
+ end
31
+ result
32
+ end
33
+
34
+ register Gemfile
35
+ register Gemspec
36
+ register Rspec
37
+ end
38
+ end