solargraph 0.54.1 → 0.56.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +2 -0
  3. data/.github/workflows/typecheck.yml +3 -1
  4. data/.gitignore +2 -0
  5. data/CHANGELOG.md +70 -0
  6. data/README.md +13 -3
  7. data/lib/solargraph/api_map/cache.rb +10 -1
  8. data/lib/solargraph/api_map/index.rb +175 -0
  9. data/lib/solargraph/api_map/store.rb +79 -126
  10. data/lib/solargraph/api_map.rb +247 -93
  11. data/lib/solargraph/bench.rb +17 -1
  12. data/lib/solargraph/complex_type/type_methods.rb +13 -1
  13. data/lib/solargraph/complex_type/unique_type.rb +118 -9
  14. data/lib/solargraph/complex_type.rb +48 -18
  15. data/lib/solargraph/convention/base.rb +3 -3
  16. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +60 -0
  17. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +100 -0
  18. data/lib/solargraph/convention/struct_definition.rb +101 -0
  19. data/lib/solargraph/convention.rb +5 -3
  20. data/lib/solargraph/doc_map.rb +274 -56
  21. data/lib/solargraph/equality.rb +33 -0
  22. data/lib/solargraph/gem_pins.rb +53 -37
  23. data/lib/solargraph/language_server/host/message_worker.rb +31 -11
  24. data/lib/solargraph/language_server/host.rb +24 -13
  25. data/lib/solargraph/language_server/message/base.rb +19 -12
  26. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
  27. data/lib/solargraph/language_server/message/extended/document.rb +5 -2
  28. data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
  29. data/lib/solargraph/language_server/message/initialize.rb +3 -1
  30. data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
  31. data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -0
  32. data/lib/solargraph/library.rb +13 -11
  33. data/lib/solargraph/location.rb +28 -0
  34. data/lib/solargraph/logging.rb +1 -0
  35. data/lib/solargraph/parser/comment_ripper.rb +12 -6
  36. data/lib/solargraph/parser/flow_sensitive_typing.rb +227 -0
  37. data/lib/solargraph/parser/node_methods.rb +15 -1
  38. data/lib/solargraph/parser/node_processor.rb +3 -1
  39. data/lib/solargraph/parser/parser_gem/class_methods.rb +16 -14
  40. data/lib/solargraph/parser/parser_gem/node_chainer.rb +17 -23
  41. data/lib/solargraph/parser/parser_gem/node_methods.rb +5 -3
  42. data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
  43. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
  44. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +4 -2
  45. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +4 -2
  46. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +23 -2
  47. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
  48. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
  49. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
  50. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
  51. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +21 -0
  52. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
  53. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +4 -3
  54. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +29 -6
  55. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +41 -0
  56. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
  57. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -3
  58. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +28 -16
  59. data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +2 -1
  60. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
  61. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
  62. data/lib/solargraph/parser/parser_gem/node_processors.rb +10 -0
  63. data/lib/solargraph/parser/region.rb +1 -1
  64. data/lib/solargraph/parser.rb +1 -0
  65. data/lib/solargraph/pin/base.rb +326 -43
  66. data/lib/solargraph/pin/base_variable.rb +18 -10
  67. data/lib/solargraph/pin/block.rb +3 -3
  68. data/lib/solargraph/pin/breakable.rb +9 -0
  69. data/lib/solargraph/pin/callable.rb +77 -6
  70. data/lib/solargraph/pin/closure.rb +18 -1
  71. data/lib/solargraph/pin/common.rb +5 -0
  72. data/lib/solargraph/pin/delegated_method.rb +20 -1
  73. data/lib/solargraph/pin/documenting.rb +16 -0
  74. data/lib/solargraph/pin/keyword.rb +7 -2
  75. data/lib/solargraph/pin/local_variable.rb +15 -6
  76. data/lib/solargraph/pin/method.rb +172 -42
  77. data/lib/solargraph/pin/namespace.rb +17 -9
  78. data/lib/solargraph/pin/parameter.rb +61 -11
  79. data/lib/solargraph/pin/proxy_type.rb +12 -6
  80. data/lib/solargraph/pin/reference/override.rb +10 -6
  81. data/lib/solargraph/pin/reference/require.rb +2 -2
  82. data/lib/solargraph/pin/signature.rb +42 -0
  83. data/lib/solargraph/pin/singleton.rb +1 -1
  84. data/lib/solargraph/pin/symbol.rb +3 -2
  85. data/lib/solargraph/pin/until.rb +18 -0
  86. data/lib/solargraph/pin/while.rb +18 -0
  87. data/lib/solargraph/pin.rb +4 -1
  88. data/lib/solargraph/pin_cache.rb +185 -0
  89. data/lib/solargraph/position.rb +16 -0
  90. data/lib/solargraph/range.rb +16 -0
  91. data/lib/solargraph/rbs_map/conversions.rb +199 -66
  92. data/lib/solargraph/rbs_map/core_fills.rb +32 -16
  93. data/lib/solargraph/rbs_map/core_map.rb +34 -11
  94. data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
  95. data/lib/solargraph/rbs_map.rb +74 -16
  96. data/lib/solargraph/shell.rb +19 -18
  97. data/lib/solargraph/source/chain/array.rb +12 -8
  98. data/lib/solargraph/source/chain/block_symbol.rb +1 -1
  99. data/lib/solargraph/source/chain/block_variable.rb +1 -1
  100. data/lib/solargraph/source/chain/call.rb +62 -25
  101. data/lib/solargraph/source/chain/constant.rb +1 -1
  102. data/lib/solargraph/source/chain/hash.rb +9 -3
  103. data/lib/solargraph/source/chain/head.rb +1 -1
  104. data/lib/solargraph/source/chain/if.rb +6 -1
  105. data/lib/solargraph/source/chain/link.rb +19 -5
  106. data/lib/solargraph/source/chain/literal.rb +27 -2
  107. data/lib/solargraph/source/chain/or.rb +1 -1
  108. data/lib/solargraph/source/chain/z_super.rb +1 -1
  109. data/lib/solargraph/source/chain.rb +106 -62
  110. data/lib/solargraph/source/cursor.rb +1 -11
  111. data/lib/solargraph/source/source_chainer.rb +2 -2
  112. data/lib/solargraph/source.rb +2 -1
  113. data/lib/solargraph/source_map/clip.rb +4 -2
  114. data/lib/solargraph/source_map/mapper.rb +9 -5
  115. data/lib/solargraph/source_map.rb +0 -17
  116. data/lib/solargraph/type_checker/checks.rb +4 -0
  117. data/lib/solargraph/type_checker.rb +41 -14
  118. data/lib/solargraph/version.rb +1 -1
  119. data/lib/solargraph/views/_method.erb +10 -10
  120. data/lib/solargraph/views/_namespace.erb +3 -3
  121. data/lib/solargraph/views/document.erb +10 -10
  122. data/lib/solargraph/workspace/config.rb +7 -3
  123. data/lib/solargraph/workspace.rb +16 -6
  124. data/lib/solargraph/yard_map/mapper/to_constant.rb +5 -2
  125. data/lib/solargraph/yard_map/mapper/to_method.rb +55 -15
  126. data/lib/solargraph/yard_map/mapper/to_namespace.rb +5 -2
  127. data/lib/solargraph/yard_map/mapper.rb +5 -3
  128. data/lib/solargraph/yard_map/to_method.rb +4 -2
  129. data/lib/solargraph/yardoc.rb +6 -9
  130. data/lib/solargraph.rb +20 -1
  131. data/rbs/fills/tuple.rbs +150 -0
  132. data/rbs_collection.yaml +19 -0
  133. data/solargraph.gemspec +6 -5
  134. metadata +56 -29
  135. data/lib/solargraph/cache.rb +0 -77
@@ -2,33 +2,33 @@
2
2
  Namespace:
3
3
  </h2>
4
4
  <p>
5
- <a href="solargraph:/document?query=<%= CGI.escape object.namespace.path %>"><%= object.namespace %></a>
5
+ <a href="solargraph:/document?query=<%= CGI.escape pin.namespace.path %>"><%= pin.namespace %></a>
6
6
  </p>
7
7
  <h2>
8
8
  Overview:
9
9
  </h2>
10
- <%= htmlify object.docstring %>
10
+ <%= htmlify pin.docstring %>
11
11
  <p class="document-section">
12
- <big><strong>Visibility:</strong></big> <%= object.visibility %>
12
+ <big><strong>Visibility:</strong></big> <%= pin.visibility %>
13
13
  </p>
14
- <% unless object.tags(:param).empty? %>
14
+ <% unless pin.docstring.tags(:param).empty? %>
15
15
  <h2>
16
16
  Parameters:
17
17
  </h2>
18
18
  <ul>
19
- <% object.tags(:param).each do |tag| %>
19
+ <% pin.docstring.tags(:param).each do |tag| %>
20
20
  <li>
21
21
  <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
22
22
  </li>
23
23
  <% end %>
24
24
  </ul>
25
25
  <% end %>
26
- <% unless object.tags(:raise).empty? %>
26
+ <% unless pin.docstring.tags(:raise).empty? %>
27
27
  <h2>
28
28
  Raises:
29
29
  </h2>
30
30
  <ul>
31
- <% object.tags(:raise).each do |tag| %>
31
+ <% pin.docstring.tags(:raise).each do |tag| %>
32
32
  <li>
33
33
  <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
34
34
  </li>
@@ -38,20 +38,20 @@
38
38
  <h2>
39
39
  Returns:
40
40
  </h2>
41
- <% if object.tag(:return).nil? %>
41
+ <% if pin.docstring.tag(:return).nil? %>
42
42
  <p>
43
43
  Undefined/unknown
44
44
  </p>
45
45
  <% else %>
46
46
  <ul>
47
- <% object.tags(:return).each do |tag| %>
47
+ <% pin.tags(:return).each do |tag| %>
48
48
  <li>
49
49
  <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
50
50
  </li>
51
51
  <% end %>
52
52
  </ul>
53
53
  <% end %>
54
- <% examples = object.tags(:example) %>
54
+ <% examples = pin.docstring.tags(:example) %>
55
55
  <% unless examples.nil? %>
56
56
  <% examples.each do |example| %>
57
57
  <h2>
@@ -1,12 +1,12 @@
1
1
  <h2>
2
2
  Overview:
3
3
  </h2>
4
- <%= htmlify object.docstring %>
4
+ <%= htmlify pin.docstring %>
5
5
  <h2>
6
6
  Class Methods
7
7
  </h2>
8
8
  <ul class="doc-list">
9
- <% object.meths(scope: :class).sort{|a, b| a.name <=> b.name}.each do |meth| %>
9
+ <% api_map.get_methods(pin.path, scope: :class, deep: false).sort{|a, b| a.name <=> b.name}.each do |meth| %>
10
10
  <li>
11
11
  <a href="solargraph:/document?query=<%= CGI.escape(meth.path) %>"><%= meth.name %></a>
12
12
  </li>
@@ -16,7 +16,7 @@
16
16
  Instance Methods
17
17
  </h2>
18
18
  <ul class="doc-list">
19
- <% object.meths(scope: :instance).sort{|a, b| a.name <=> b.name}.each do |meth| %>
19
+ <% api_map.get_methods(pin.path, scope: :instance, deep: false).sort{|a, b| a.name <=> b.name}.each do |meth| %>
20
20
  <li>
21
21
  <a href="solargraph:/document?query=<%= CGI.escape(meth.path) %>"><%= meth.name %></a>
22
22
  </li>
@@ -1,23 +1,23 @@
1
- <% objects.reverse.each do |object| %>
1
+ <% pins.each do |pin| %>
2
2
  <h1>
3
- <%= object.name %>
4
- <% if object.is_a?(YARD::CodeObjects::MethodObject) and !object.parameters.empty? %>
5
- <small>(<%= object.parameters.map {|p| "#{p[0]}#{p[1] and p[0].end_with?(':') ? ' ' : (p[1] ? ' = ' : '')}#{p[1]}"}.join(', ') %>)</small>
3
+ <%= pin.name %>
4
+ <% if pin.is_a?(Solargraph::Pin::Method) && !pin.parameters.empty? %>
5
+ <small>(<%= pin.parameters.map {|p| "#{p[0]}#{p[1] and p[0].end_with?(':') ? ' ' : (p[1] ? ' = ' : '')}#{p[1]}"}.join(', ') %>)</small>
6
6
  <% end %>
7
7
  </h1>
8
- <% unless object.files.empty? %>
8
+ <% unless pins.map(&:location).compact.empty? %>
9
9
  <h2>
10
10
  Defined in:
11
11
  </h2>
12
12
  <ul>
13
- <% object.files.each do |f| %>
13
+ <% pins.map(&:location).compact.map(&:filename).each do |f| %>
14
14
  <li><%= f %></li>
15
15
  <% end %>
16
16
  </ul>
17
17
  <% end %>
18
- <% if object.is_a?(YARD::CodeObjects::NamespaceObject) %>
19
- <%= erb :_namespace, layout: false, locals: {object: object} %>
20
- <% elsif object.is_a?(YARD::CodeObjects::MethodObject) %>
21
- <%= erb :_method, layout: false, locals: {object: object} %>
18
+ <% if pin.is_a?(Solargraph::Pin::Namespace) %>
19
+ <%= erb :_namespace, layout: false, locals: {api_map: api_map, pin: pin} %>
20
+ <% elsif pin.is_a?(Solargraph::Pin::Method) %>
21
+ <%= erb :_method, layout: false, locals: {api_map: api_map, pin: pin} %>
22
22
  <% end %>
23
23
  <% end %>
@@ -15,7 +15,7 @@ module Solargraph
15
15
  attr_reader :directory
16
16
 
17
17
  # @todo To make this strongly typed we'll need a record syntax
18
- # @return [Hash{String => undefined}]
18
+ # @return [Hash{String => Array, Hash, Integer, nil}]
19
19
  attr_reader :raw_data
20
20
 
21
21
  # @param directory [String]
@@ -90,6 +90,7 @@ module Solargraph
90
90
 
91
91
  # A hash of options supported by the formatter
92
92
  #
93
+ # @sg-ignore pending https://github.com/castwide/solargraph/pull/905
93
94
  # @return [Hash]
94
95
  def formatter
95
96
  raw_data['formatter']
@@ -104,6 +105,7 @@ module Solargraph
104
105
 
105
106
  # The maximum number of files to parse from the workspace.
106
107
  #
108
+ # @sg-ignore pending https://github.com/castwide/solargraph/pull/905
107
109
  # @return [Integer]
108
110
  def max_files
109
111
  raw_data['max_files']
@@ -123,7 +125,7 @@ module Solargraph
123
125
  File.join(@directory, '.solargraph.yml')
124
126
  end
125
127
 
126
- # @return [Hash{String => Array, Hash, Integer}]
128
+ # @return [Hash{String => Array<undefined>, Hash{String => undefined}, Integer}]
127
129
  def config_data
128
130
  workspace_config = read_config(workspace_config_path)
129
131
  global_config = read_config(global_config_path)
@@ -226,7 +228,9 @@ module Solargraph
226
228
 
227
229
  # @return [Array<String>]
228
230
  def excluded_directories
229
- @raw_data['exclude']
231
+ # @type [Array<String>]
232
+ excluded = @raw_data['exclude']
233
+ excluded
230
234
  .select { |g| glob_is_directory?(g) }
231
235
  .map { |g| File.absolute_path(glob_to_directory(g), directory) }
232
236
  end
@@ -45,7 +45,7 @@ module Solargraph
45
45
  # or add it to the sources if the workspace is configured to include it.
46
46
  # The source is ignored if the configuration excludes it.
47
47
  #
48
- # @param source [Solargraph::Source]
48
+ # @param sources [Array<Solargraph::Source>]
49
49
  # @return [Boolean] True if the source was added to the workspace
50
50
  def merge *sources
51
51
  unless directory == '*' || sources.all? { |source| source_hash.key?(source.filename) }
@@ -106,7 +106,7 @@ module Solargraph
106
106
  def would_require? path
107
107
  require_paths.each do |rp|
108
108
  full = File.join rp, path
109
- return true if File.exist?(full) or File.exist?(full << ".rb")
109
+ return true if File.file?(full) || File.file?(full << ".rb")
110
110
  end
111
111
  false
112
112
  end
@@ -133,6 +133,15 @@ module Solargraph
133
133
  @gem_rbs_collection ||= read_rbs_collection_path
134
134
  end
135
135
 
136
+ def rbs_collection_config_path
137
+ @rbs_collection_config_path ||= begin
138
+ unless directory.empty? || directory == '*'
139
+ yaml_file = File.join(directory, 'rbs_collection.yaml')
140
+ yaml_file if File.file?(yaml_file)
141
+ end
142
+ end
143
+ end
144
+
136
145
  # Synchronize the workspace from the provided updater.
137
146
  #
138
147
  # @param updater [Source::Updater]
@@ -214,7 +223,7 @@ module Solargraph
214
223
  def configured_require_paths
215
224
  return ['lib'] if directory.empty?
216
225
  return [File.join(directory, 'lib')] if config.require_paths.empty?
217
- config.require_paths.map{|p| File.join(directory, p)}
226
+ config.require_paths.map { |p| File.join(directory, p) }
218
227
  end
219
228
 
220
229
  # @return [void]
@@ -230,10 +239,11 @@ module Solargraph
230
239
 
231
240
  # @return [String, nil]
232
241
  def read_rbs_collection_path
233
- yaml_file = File.join(directory, 'rbs_collection.yaml')
234
- return unless File.file?(yaml_file)
242
+ return unless rbs_collection_config_path
235
243
 
236
- YAML.load_file(yaml_file)&.fetch('path')
244
+ path = YAML.load_file(rbs_collection_config_path)&.fetch('path')
245
+ # make fully qualified
246
+ File.expand_path(path, directory)
237
247
  end
238
248
  end
239
249
  end
@@ -6,17 +6,20 @@ module Solargraph
6
6
  module ToConstant
7
7
  extend YardMap::Helpers
8
8
 
9
+ # @param code_object [YARD::CodeObjects::Base]
9
10
  def self.make code_object, closure = nil, spec = nil
10
11
  closure ||= Solargraph::Pin::Namespace.new(
11
12
  name: code_object.namespace.to_s,
12
- gates: [code_object.namespace.to_s]
13
+ gates: [code_object.namespace.to_s],
14
+ source: :yardoc,
13
15
  )
14
16
  Pin::Constant.new(
15
17
  location: object_location(code_object, spec),
16
18
  closure: closure,
17
19
  name: code_object.name.to_s,
18
20
  comments: code_object.docstring ? code_object.docstring.all.to_s : '',
19
- visibility: code_object.visibility
21
+ visibility: code_object.visibility,
22
+ source: :yardoc
20
23
  )
21
24
  end
22
25
  end
@@ -6,6 +6,11 @@ module Solargraph
6
6
  module ToMethod
7
7
  extend YardMap::Helpers
8
8
 
9
+ VISIBILITY_OVERRIDE = {
10
+ # YARD pays attention to 'private' statements prior to class methods but shouldn't
11
+ ["Rails::Engine", :class, "find_root_with_flag"] => :public
12
+ }
13
+
9
14
  # @param code_object [YARD::CodeObjects::Base]
10
15
  # @param name [String, nil]
11
16
  # @param scope [Symbol, nil]
@@ -16,29 +21,63 @@ module Solargraph
16
21
  def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
17
22
  closure ||= Solargraph::Pin::Namespace.new(
18
23
  name: code_object.namespace.to_s,
19
- gates: [code_object.namespace.to_s]
24
+ gates: [code_object.namespace.to_s],
25
+ type: code_object.namespace.is_a?(YARD::CodeObjects::ClassObject) ? :class : :module,
26
+ source: :yardoc,
20
27
  )
21
28
  location = object_location(code_object, spec)
22
29
  name ||= code_object.name.to_s
23
30
  return_type = ComplexType::SELF if name == 'new'
24
31
  comments = code_object.docstring ? code_object.docstring.all.to_s : ''
25
- pin = Pin::Method.new(
26
- location: location,
27
- closure: closure,
28
- name: name,
29
- comments: comments,
30
- scope: scope || code_object.scope,
31
- visibility: visibility || code_object.visibility,
32
- # @todo Might need to convert overloads to signatures
33
- parameters: [],
34
- explicit: code_object.is_explicit?,
35
- return_type: return_type
36
- )
37
- pin.parameters.concat get_parameters(code_object, location, comments, pin)
32
+ final_scope = scope || code_object.scope
33
+ override_key = [closure.path, final_scope, name]
34
+ final_visibility = VISIBILITY_OVERRIDE[override_key]
35
+ final_visibility ||= VISIBILITY_OVERRIDE[override_key[0..-2]]
36
+ final_visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(name)
37
+ final_visibility ||= visibility
38
+ final_visibility ||= :private if code_object.module_function? && final_scope == :instance
39
+ final_visibility ||= :public if code_object.module_function? && final_scope == :class
40
+ final_visibility ||= code_object.visibility
41
+ if code_object.is_alias?
42
+ origin_code_object = code_object.namespace.aliases[code_object]
43
+ pin = Pin::MethodAlias.new(
44
+ name: name,
45
+ location: location,
46
+ original: origin_code_object.name.to_s,
47
+ closure: closure,
48
+ comments: comments,
49
+ scope: final_scope,
50
+ visibility: final_visibility,
51
+ explicit: code_object.is_explicit?,
52
+ return_type: return_type,
53
+ parameters: [],
54
+ source: :yardoc,
55
+ )
56
+ else
57
+ pin = Pin::Method.new(
58
+ location: location,
59
+ closure: closure,
60
+ name: name,
61
+ comments: comments,
62
+ scope: final_scope,
63
+ visibility: final_visibility,
64
+ # @todo Might need to convert overloads to signatures
65
+ explicit: code_object.is_explicit?,
66
+ return_type: return_type,
67
+ attribute: code_object.is_attribute?,
68
+ parameters: [],
69
+ source: :yardoc,
70
+ )
71
+ pin.parameters.concat get_parameters(code_object, location, comments, pin)
72
+ pin.parameters.freeze
73
+ end
74
+ logger.debug { "ToMethod.make: Just created method pin: #{pin.inspect}" }
38
75
  pin
39
76
  end
40
77
 
41
78
  class << self
79
+ include Logging
80
+
42
81
  private
43
82
 
44
83
  # @param code_object [YARD::CodeObjects::Base]
@@ -59,7 +98,8 @@ module Solargraph
59
98
  name: arg_name(a),
60
99
  presence: nil,
61
100
  decl: arg_type(a),
62
- asgn_code: a[1]
101
+ asgn_code: a[1],
102
+ source: :yardoc,
63
103
  )
64
104
  end
65
105
  end
@@ -6,11 +6,13 @@ module Solargraph
6
6
  module ToNamespace
7
7
  extend YardMap::Helpers
8
8
 
9
+ # @param code_object [YARD::CodeObjects::NamespaceObject]
9
10
  def self.make code_object, spec, closure = nil
10
11
  closure ||= Solargraph::Pin::Namespace.new(
11
12
  name: code_object.namespace.to_s,
12
13
  closure: Pin::ROOT_PIN,
13
- gates: [code_object.namespace.to_s]
14
+ gates: [code_object.namespace.to_s],
15
+ source: :yardoc,
14
16
  )
15
17
  Pin::Namespace.new(
16
18
  location: object_location(code_object, spec),
@@ -18,7 +20,8 @@ module Solargraph
18
20
  comments: code_object.docstring ? code_object.docstring.all.to_s : '',
19
21
  type: code_object.is_a?(YARD::CodeObjects::ClassObject) ? :class : :module,
20
22
  visibility: code_object.visibility,
21
- closure: closure
23
+ closure: closure,
24
+ source: :yardoc,
22
25
  )
23
26
  end
24
27
  end
@@ -12,6 +12,7 @@ module Solargraph
12
12
  def initialize code_objects, spec = nil
13
13
  @code_objects = code_objects
14
14
  @spec = spec
15
+ # @type [Array<Solargraph::Pin::Base>]
15
16
  @pins = []
16
17
  @namespace_pins = {}
17
18
  end
@@ -46,15 +47,16 @@ module Solargraph
46
47
  else
47
48
  code_object.superclass.to_s
48
49
  end
49
- result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin)
50
+ result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin, source: :yard_map)
50
51
  end
51
52
  code_object.class_mixins.each do |m|
52
- result.push Solargraph::Pin::Reference::Extend.new(closure: nspin, name: m.path)
53
+ result.push Solargraph::Pin::Reference::Extend.new(closure: nspin, name: m.path, source: :yard_map)
53
54
  end
54
55
  code_object.instance_mixins.each do |m|
55
56
  result.push Solargraph::Pin::Reference::Include.new(
56
57
  closure: nspin, # @todo Fix this
57
- name: m.path
58
+ name: m.path,
59
+ source: :yard_map
58
60
  )
59
61
  end
60
62
  elsif code_object.is_a?(YARD::CodeObjects::MethodObject)
@@ -23,7 +23,8 @@ module Solargraph
23
23
  name: arg_name(a),
24
24
  presence: nil,
25
25
  decl: arg_type(a),
26
- asgn_code: a[1]
26
+ asgn_code: a[1],
27
+ source: :yard_map
27
28
  )
28
29
  end
29
30
  end
@@ -78,7 +79,8 @@ module Solargraph
78
79
  scope: scope || code_object.scope,
79
80
  visibility: visibility || code_object.visibility,
80
81
  parameters: InnerMethods.get_parameters(code_object, location, comments),
81
- explicit: code_object.is_explicit?
82
+ explicit: code_object.is_explicit?,
83
+ source: :yard_map
82
84
  )
83
85
  end
84
86
  end
@@ -12,7 +12,7 @@ module Solargraph
12
12
  # @param gemspec [Gem::Specification]
13
13
  # @return [String] The path to the cached yardoc.
14
14
  def cache(gemspec)
15
- path = path_for(gemspec)
15
+ path = PinCache.yardoc_path gemspec
16
16
  return path if cached?(gemspec)
17
17
 
18
18
  Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
@@ -26,16 +26,13 @@ module Solargraph
26
26
  #
27
27
  # @param gemspec [Gem::Specification]
28
28
  def cached?(gemspec)
29
- yardoc = File.join(path_for(gemspec), 'complete')
29
+ yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
30
30
  File.exist?(yardoc)
31
31
  end
32
32
 
33
- # Get the absolute path for a cached gem yardoc.
34
- #
35
- # @param gemspec [Gem::Specification]
36
- # @return [String]
37
- def path_for(gemspec)
38
- File.join(Solargraph::Cache.work_dir, 'gems', "#{gemspec.name}-#{gemspec.version}.yardoc")
33
+ def processing?(gemspec)
34
+ yardoc = File.join(PinCache.yardoc_path(gemspec), 'processing')
35
+ File.exist?(yardoc)
39
36
  end
40
37
 
41
38
  # Load a gem's yardoc and return its code objects.
@@ -45,7 +42,7 @@ module Solargraph
45
42
  # @param gemspec [Gem::Specification]
46
43
  # @return [Array<YARD::CodeObjects::Base>]
47
44
  def load!(gemspec)
48
- YARD::Registry.load! path_for(gemspec)
45
+ YARD::Registry.load! PinCache.yardoc_path gemspec
49
46
  YARD::Registry.all
50
47
  end
51
48
  end
data/lib/solargraph.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Encoding.default_external = 'UTF-8'
4
4
 
5
+ require 'bundler'
5
6
  require 'set'
6
7
  require 'yard-solargraph'
7
8
  require 'solargraph/yard_tags'
@@ -42,15 +43,33 @@ module Solargraph
42
43
  autoload :Logging, 'solargraph/logging'
43
44
  autoload :TypeChecker, 'solargraph/type_checker'
44
45
  autoload :Environ, 'solargraph/environ'
46
+ autoload :Equality, 'solargraph/equality'
45
47
  autoload :Convention, 'solargraph/convention'
46
48
  autoload :Parser, 'solargraph/parser'
47
49
  autoload :RbsMap, 'solargraph/rbs_map'
48
50
  autoload :GemPins, 'solargraph/gem_pins'
49
- autoload :Cache, 'solargraph/cache'
51
+ autoload :PinCache, 'solargraph/pin_cache'
50
52
 
51
53
  dir = File.dirname(__FILE__)
52
54
  VIEWS_PATH = File.join(dir, 'solargraph', 'views')
53
55
 
56
+ # @param type [Symbol] Type of assert.
57
+ def self.asserts_on?(type)
58
+ if ENV['SOLARGRAPH_ASSERTS'].nil? || ENV['SOLARGRAPH_ASSERTS'].empty?
59
+ false
60
+ elsif ENV['SOLARGRAPH_ASSERTS'] == 'on'
61
+ true
62
+ else
63
+ logger.warn "Unrecognized SOLARGRAPH_ASSERTS value: #{ENV['SOLARGRAPH_ASSERTS']}"
64
+ false
65
+ end
66
+ end
67
+
68
+ def self.assert_or_log(type, msg = nil, &block)
69
+ raise (msg || block.call) if asserts_on?(type) && ![:combine_with_visibility].include?(type)
70
+ logger.info msg, &block
71
+ end
72
+
54
73
  # A convenience method for Solargraph::Logging.logger.
55
74
  #
56
75
  # @return [Logger]
@@ -0,0 +1,150 @@
1
+ # <-- liberally borrowed from
2
+ # https://github.com/ruby/rbs/blob/master/core/array.rbs, which
3
+ # was generated from
4
+ # https://github.com/ruby/ruby/blob/master/array.c
5
+ # -->
6
+ module Solargraph
7
+ module Fills
8
+ class Tuple[unchecked out A,
9
+ unchecked out B = A,
10
+ unchecked out C = A | B,
11
+ unchecked out D = A | B | C,
12
+ unchecked out E = A | B | C | D,
13
+ unchecked out F = A | B | C | D | E,
14
+ unchecked out G = A | B | C | D | E | F,
15
+ unchecked out H = A | B | C | D | E | F | G,
16
+ unchecked out I = A | B | C | D | E | F | G | H,
17
+ unchecked out J = A | B | C | D | E | F | G | H | I] < Array[A | B | C | D | E | F | G | H | I | J]
18
+ # <!--
19
+ # rdoc-file=array.c
20
+ # - self[index] -> object or nil
21
+ # -->
22
+ # Returns elements from `self`; does not modify `self`.
23
+ #
24
+ # In brief:
25
+ #
26
+ # a = [:foo, 'bar', 2]
27
+ #
28
+ # # Single argument index: returns one element.
29
+ # a[0] # => :foo # Zero-based index.
30
+ #
31
+ # When a single integer argument `index` is given, returns the element at offset
32
+ # `index`:
33
+ #
34
+ # a = [:foo, 'bar', 2]
35
+ # a[0] # => :foo
36
+ # a[2] # => 2
37
+ # a # => [:foo, "bar", 2]
38
+ def []: (0 index) -> A
39
+ | (1 index) -> B
40
+ | (2 index) -> C
41
+ | (3 index) -> D
42
+ | (4 index) -> E
43
+ | (5 index) -> F
44
+ | (6 index) -> G
45
+ | (7 index) -> H
46
+ | (8 index) -> I
47
+ | (9 index) -> J
48
+ | (0 index) -> K
49
+ | (int index) -> nil
50
+
51
+ # <!--
52
+ # rdoc-file=array.c
53
+ # - at(index) -> object or nil
54
+ # -->
55
+ # Returns the element of `self` specified by the given `index` or `nil` if there
56
+ # is no such element; `index` must be an [integer-convertible
57
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
58
+ #
59
+ # For non-negative `index`, returns the element of `self` at offset `index`:
60
+ #
61
+ # a = [:foo, 'bar', 2]
62
+ # a.at(0) # => :foo
63
+ # a.at(2) # => 2
64
+ # a.at(2.0) # => 2
65
+ #
66
+ # Related: Array#[]; see also [Methods for
67
+ # Fetching](rdoc-ref:Array@Methods+for+Fetching).
68
+ #
69
+ def at: (0 index) -> A
70
+ | (1 index) -> B
71
+ | (2 index) -> C
72
+ | (3 index) -> D
73
+ | (4 index) -> E
74
+ | (5 index) -> F
75
+ | (6 index) -> G
76
+ | (7 index) -> H
77
+ | (8 index) -> I
78
+ | (9 index) -> J
79
+ | (int index) -> nil
80
+
81
+ # <!--
82
+ # rdoc-file=array.c
83
+ # - fetch(index) -> element
84
+ # - fetch(index, default_value) -> element or default_value
85
+ # - fetch(index) {|index| ... } -> element or block_return_value
86
+ # -->
87
+ # Returns the element of `self` at offset `index` if `index` is in range;
88
+ # `index` must be an [integer-convertible
89
+ # object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
90
+ #
91
+ # With the single argument `index` and no block, returns the element at offset
92
+ # `index`:
93
+ #
94
+ # a = [:foo, 'bar', 2]
95
+ # a.fetch(1) # => "bar"
96
+ # a.fetch(1.1) # => "bar"
97
+ #
98
+ # With arguments `index` and `default_value` (which may be any object) and no
99
+ # block, returns `default_value` if `index` is out-of-range:
100
+ #
101
+ # a = [:foo, 'bar', 2]
102
+ # a.fetch(1, nil) # => "bar"
103
+ # a.fetch(3, :foo) # => :foo
104
+ #
105
+ # With argument `index` and a block, returns the element at offset `index` if
106
+ # index is in range (and the block is not called); otherwise calls the block
107
+ # with index and returns its return value:
108
+ #
109
+ # a = [:foo, 'bar', 2]
110
+ # a.fetch(1) {|index| raise 'Cannot happen' } # => "bar"
111
+ # a.fetch(50) {|index| "Value for #{index}" } # => "Value for 50"
112
+ #
113
+ # Related: see [Methods for Fetching](rdoc-ref:Array@Methods+for+Fetching).
114
+ #
115
+ def fetch: (0 index) -> A
116
+ | (1 index) -> B
117
+ | (2 index) -> C
118
+ | (3 index) -> D
119
+ | (4 index) -> E
120
+ | (5 index) -> F
121
+ | (6 index) -> G
122
+ | (7 index) -> H
123
+ | (8 index) -> I
124
+ | (9 index) -> J
125
+ | (int index) -> void
126
+ | [T] (0 index, T default) -> (A | T)
127
+ | [T] (1 index, T default) -> (B | T)
128
+ | [T] (2 index, T default) -> (C | T)
129
+ | [T] (3 index, T default) -> (D | T)
130
+ | [T] (4 index, T default) -> (E | T)
131
+ | [T] (5 index, T default) -> (F | T)
132
+ | [T] (6 index, T default) -> (G | T)
133
+ | [T] (7 index, T default) -> (H | T)
134
+ | [T] (8 index, T default) -> (I | T)
135
+ | [T] (9 index, T default) -> (J | T)
136
+ | [T] (int index, T default) -> (A | B | C | D | E | F |G | H | I | J | T)
137
+ | [T] (0 index) { (int index) -> T } -> (A | T)
138
+ | [T] (1 index) { (int index) -> T } -> (B | T)
139
+ | [T] (2 index) { (int index) -> T } -> (C | T)
140
+ | [T] (3 index) { (int index) -> T } -> (D | T)
141
+ | [T] (4 index) { (int index) -> T } -> (E | T)
142
+ | [T] (5 index) { (int index) -> T } -> (F | T)
143
+ | [T] (6 index) { (int index) -> T } -> (G | T)
144
+ | [T] (7 index) { (int index) -> T } -> (H | T)
145
+ | [T] (8 index) { (int index) -> T } -> (I | T)
146
+ | [T] (9 index) { (int index) -> T } -> (J | T)
147
+ | [T] (int index) { (int index) -> T } -> (A | B | C | D | E | F |G | H | I | J | T)
148
+ end
149
+ end
150
+ end