solargraph 0.52.0 → 0.53.4

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +40 -0
  3. data/.github/workflows/rspec.yml +1 -3
  4. data/.github/workflows/typecheck.yml +34 -0
  5. data/CHANGELOG.md +53 -0
  6. data/README.md +13 -16
  7. data/SPONSORS.md +1 -7
  8. data/lib/solargraph/api_map/cache.rb +59 -21
  9. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  10. data/lib/solargraph/api_map/store.rb +45 -9
  11. data/lib/solargraph/api_map.rb +178 -113
  12. data/lib/solargraph/bench.rb +3 -2
  13. data/lib/solargraph/cache.rb +29 -5
  14. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  15. data/lib/solargraph/complex_type/unique_type.rb +171 -58
  16. data/lib/solargraph/complex_type.rb +62 -9
  17. data/lib/solargraph/convention.rb +0 -1
  18. data/lib/solargraph/converters/dd.rb +5 -0
  19. data/lib/solargraph/converters/dl.rb +3 -0
  20. data/lib/solargraph/converters/dt.rb +3 -0
  21. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  22. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  23. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  24. data/lib/solargraph/diagnostics.rb +2 -2
  25. data/lib/solargraph/doc_map.rb +171 -0
  26. data/lib/solargraph/gem_pins.rb +64 -0
  27. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  28. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  29. data/lib/solargraph/language_server/host/dispatch.rb +15 -5
  30. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  31. data/lib/solargraph/language_server/host/sources.rb +7 -4
  32. data/lib/solargraph/language_server/host.rb +35 -7
  33. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  34. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  35. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  36. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  37. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  38. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  39. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  40. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  41. data/lib/solargraph/library.rb +71 -12
  42. data/lib/solargraph/location.rb +1 -0
  43. data/lib/solargraph/page.rb +6 -0
  44. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  45. data/lib/solargraph/parser/node_methods.rb +47 -8
  46. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  47. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  48. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  49. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  53. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +7 -20
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  65. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  67. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  68. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  69. data/lib/solargraph/parser/parser_gem.rb +12 -0
  70. data/lib/solargraph/parser/snippet.rb +2 -0
  71. data/lib/solargraph/parser.rb +8 -11
  72. data/lib/solargraph/pin/base.rb +63 -8
  73. data/lib/solargraph/pin/base_variable.rb +7 -3
  74. data/lib/solargraph/pin/block.rb +26 -38
  75. data/lib/solargraph/pin/closure.rb +17 -2
  76. data/lib/solargraph/pin/common.rb +7 -3
  77. data/lib/solargraph/pin/conversions.rb +33 -3
  78. data/lib/solargraph/pin/documenting.rb +25 -34
  79. data/lib/solargraph/pin/instance_variable.rb +4 -0
  80. data/lib/solargraph/pin/local_variable.rb +13 -1
  81. data/lib/solargraph/pin/method.rb +110 -16
  82. data/lib/solargraph/pin/namespace.rb +16 -10
  83. data/lib/solargraph/pin/parameter.rb +41 -10
  84. data/lib/solargraph/pin/reference/override.rb +2 -2
  85. data/lib/solargraph/pin/reference.rb +8 -0
  86. data/lib/solargraph/pin/search.rb +3 -3
  87. data/lib/solargraph/pin/signature.rb +114 -2
  88. data/lib/solargraph/pin.rb +0 -1
  89. data/lib/solargraph/range.rb +2 -2
  90. data/lib/solargraph/rbs_map/conversions.rb +213 -61
  91. data/lib/solargraph/rbs_map/core_fills.rb +12 -28
  92. data/lib/solargraph/rbs_map/core_map.rb +2 -12
  93. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  94. data/lib/solargraph/rbs_map.rb +24 -12
  95. data/lib/solargraph/shell.rb +62 -59
  96. data/lib/solargraph/source/chain/array.rb +4 -1
  97. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  98. data/lib/solargraph/source/chain/call.rb +95 -26
  99. data/lib/solargraph/source/chain/constant.rb +15 -1
  100. data/lib/solargraph/source/chain/if.rb +23 -0
  101. data/lib/solargraph/source/chain/link.rb +7 -1
  102. data/lib/solargraph/source/chain/or.rb +1 -1
  103. data/lib/solargraph/source/chain/z_super.rb +2 -2
  104. data/lib/solargraph/source/chain.rb +20 -4
  105. data/lib/solargraph/source/change.rb +3 -0
  106. data/lib/solargraph/source/cursor.rb +2 -0
  107. data/lib/solargraph/source/source_chainer.rb +6 -5
  108. data/lib/solargraph/source.rb +15 -16
  109. data/lib/solargraph/source_map/clip.rb +14 -9
  110. data/lib/solargraph/source_map/mapper.rb +10 -0
  111. data/lib/solargraph/source_map.rb +12 -10
  112. data/lib/solargraph/type_checker/checks.rb +10 -2
  113. data/lib/solargraph/type_checker.rb +96 -21
  114. data/lib/solargraph/version.rb +1 -1
  115. data/lib/solargraph/workspace/config.rb +8 -6
  116. data/lib/solargraph/workspace.rb +15 -2
  117. data/lib/solargraph/yard_map/cache.rb +6 -0
  118. data/lib/solargraph/yard_map/helpers.rb +1 -1
  119. data/lib/solargraph/yard_map/mapper/to_method.rb +16 -3
  120. data/lib/solargraph/yard_map/to_method.rb +11 -4
  121. data/lib/solargraph/yard_map.rb +0 -292
  122. data/lib/solargraph/yardoc.rb +52 -0
  123. data/lib/solargraph.rb +4 -1
  124. data/solargraph.gemspec +2 -2
  125. metadata +35 -58
  126. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  127. data/lib/solargraph/documentor.rb +0 -76
  128. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  129. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  130. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  131. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  132. data/lib/solargraph/parser/legacy.rb +0 -12
  133. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  134. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  135. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  136. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  137. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  138. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  139. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  140. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  141. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  142. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  143. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  144. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  145. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  146. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  147. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  148. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  149. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  150. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  151. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  152. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  153. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  154. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  155. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  156. data/lib/solargraph/parser/rubyvm.rb +0 -40
  157. data/lib/solargraph/rbs_map/core_signs.rb +0 -33
@@ -6,23 +6,33 @@ module Solargraph
6
6
  module ToMethod
7
7
  extend YardMap::Helpers
8
8
 
9
+ # @param code_object [YARD::CodeObjects::Base]
10
+ # @param name [String, nil]
11
+ # @param scope [Symbol, nil]
12
+ # @param visibility [Symbol, nil]
13
+ # @param closure [Solargraph::Pin::Namespace, nil]
14
+ # @param spec [Gem::Specification, nil]
15
+ # @return [Solargraph::Pin::Method]
9
16
  def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
10
17
  closure ||= Solargraph::Pin::Namespace.new(
11
18
  name: code_object.namespace.to_s,
12
19
  gates: [code_object.namespace.to_s]
13
20
  )
14
21
  location = object_location(code_object, spec)
22
+ name ||= code_object.name.to_s
23
+ return_type = ComplexType::SELF if name == 'new'
15
24
  comments = code_object.docstring ? code_object.docstring.all.to_s : ''
16
25
  pin = Pin::Method.new(
17
26
  location: location,
18
27
  closure: closure,
19
- name: name || code_object.name.to_s,
28
+ name: name,
20
29
  comments: comments,
21
30
  scope: scope || code_object.scope,
22
31
  visibility: visibility || code_object.visibility,
23
32
  # @todo Might need to convert overloads to signatures
24
33
  parameters: [],
25
- explicit: code_object.is_explicit?
34
+ explicit: code_object.is_explicit?,
35
+ return_type: return_type
26
36
  )
27
37
  pin.parameters.concat get_parameters(code_object, location, comments, pin)
28
38
  pin
@@ -32,6 +42,9 @@ module Solargraph
32
42
  private
33
43
 
34
44
  # @param code_object [YARD::CodeObjects::Base]
45
+ # @param location [Location],
46
+ # @param comments [String]
47
+ # @param pin [Pin::Base]
35
48
  # @return [Array<Solargraph::Pin::Parameter>]
36
49
  def get_parameters code_object, location, comments, pin
37
50
  return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
@@ -51,7 +64,7 @@ module Solargraph
51
64
  end
52
65
  end
53
66
 
54
- # @param a [Array]
67
+ # @param a [Array<String>]
55
68
  # @return [String]
56
69
  def arg_name a
57
70
  a[0].gsub(/[^a-z0-9_]/i, '')
@@ -7,6 +7,8 @@ module Solargraph
7
7
  module_function
8
8
 
9
9
  # @param code_object [YARD::CodeObjects::Base]
10
+ # @param location [Solargraph::Location]
11
+ # @param comments [String]
10
12
  # @return [Array<Solargraph::Pin::Parameter>]
11
13
  def get_parameters code_object, location, comments
12
14
  return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
@@ -26,7 +28,7 @@ module Solargraph
26
28
  end
27
29
  end
28
30
 
29
- # @param a [Array]
31
+ # @param a [Array<String>]
30
32
  # @return [String]
31
33
  def arg_name a
32
34
  a[0].gsub(/[^a-z0-9_]/i, '')
@@ -52,10 +54,15 @@ module Solargraph
52
54
  end
53
55
  private_constant :InnerMethods
54
56
 
55
- # include YardMixin
56
- # extend YardMixin
57
- extend Helpers
57
+ include Helpers
58
58
 
59
+ # @param code_object [YARD::CodeObjects::Base]
60
+ # @param name [String, nil]
61
+ # @param scope [Symbol, nil]
62
+ # @param visibility [Symbol, nil]
63
+ # @param closure [Solargraph::Pin::Base, nil]
64
+ # @param spec [Solargraph::Pin::Base, nil]
65
+ # @return [Solargraph::Pin::Method]
59
66
  def make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
60
67
  closure ||= Solargraph::Pin::Namespace.new(
61
68
  name: code_object.namespace.to_s,
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'yard'
4
4
  require 'solargraph/yard_tags'
5
- require 'rubygems/package'
6
- require 'set'
7
5
 
8
6
  module Solargraph
9
7
  # The YardMap provides access to YARD documentation for the Ruby core, the
@@ -14,297 +12,7 @@ module Solargraph
14
12
 
15
13
  autoload :Cache, 'solargraph/yard_map/cache'
16
14
  autoload :Mapper, 'solargraph/yard_map/mapper'
17
- autoload :RdocToYard, 'solargraph/yard_map/rdoc_to_yard'
18
15
  autoload :Helpers, 'solargraph/yard_map/helpers'
19
16
  autoload :ToMethod, 'solargraph/yard_map/to_method'
20
-
21
- include ApiMap::BundlerMethods
22
-
23
- # @return [Boolean]
24
- attr_writer :with_dependencies
25
-
26
- # @param required [Array<String>, Set<String>]
27
- # @param directory [String]
28
- # @param source_gems [Array<String>, Set<String>]
29
- # @param with_dependencies [Boolean]
30
- def initialize(required: [], directory: '', source_gems: [], with_dependencies: true)
31
- @with_dependencies = with_dependencies
32
- change required.to_set, directory, source_gems.to_set
33
- end
34
-
35
- # @return [Array<Solargraph::Pin::Base>]
36
- def pins
37
- @pins ||= []
38
- end
39
-
40
- def with_dependencies?
41
- @with_dependencies ||= true unless @with_dependencies == false
42
- @with_dependencies
43
- end
44
-
45
- # @param new_requires [Set<String>] Required paths to use for loading gems
46
- # @param new_directory [String] The workspace directory
47
- # @param new_source_gems [Set<String>] Gems under local development (i.e., part of the workspace)
48
- # @return [Boolean]
49
- def change new_requires, new_directory, new_source_gems
50
- return false if new_requires == base_required && new_directory == @directory && new_source_gems == @source_gems
51
- @gem_paths = {}
52
- base_required.replace new_requires
53
- required.replace new_requires
54
- # HACK: Hardcoded YAML handling
55
- required.add 'psych' if new_requires.include?('yaml')
56
- @source_gems = new_source_gems
57
- @directory = new_directory
58
- process_requires
59
- @rebindable_method_names = nil
60
- @pin_class_hash = nil
61
- @pin_select_cache = {}
62
- pins.each { |p| p.source = :yard }
63
- true
64
- end
65
-
66
- # @return [Set<String>]
67
- def rebindable_method_names
68
- @rebindable_method_names ||= pins_by_class(Pin::Method)
69
- .select { |pin| pin.comments && pin.comments.include?('@yieldreceiver') }
70
- .map(&:name)
71
- .concat(['instance_eval', 'instance_exec', 'class_eval', 'class_exec', 'module_eval', 'module_exec', 'define_method'])
72
- .to_set
73
- end
74
-
75
- # @return [Array<String>]
76
- def yardocs
77
- @yardocs ||= []
78
- end
79
-
80
- # @return [Set<String>]
81
- def required
82
- @required ||= Set.new
83
- end
84
-
85
- # @return [Array<String>]
86
- def unresolved_requires
87
- @unresolved_requires ||= []
88
- end
89
-
90
- # @return [Array<String>]
91
- def missing_docs
92
- @missing_docs ||= []
93
- end
94
-
95
- # @param y [String]
96
- # @return [YARD::Registry]
97
- def load_yardoc y
98
- if y.is_a?(Array)
99
- YARD::Registry.load y, true
100
- else
101
- YARD::Registry.load! y
102
- end
103
- rescue StandardError => e
104
- Solargraph::Logging.logger.warn "Error loading yardoc '#{y}' #{e.class} #{e.message}"
105
- yardocs.delete y
106
- nil
107
- end
108
-
109
- # @param path [String]
110
- # @return [Pin::Base]
111
- def path_pin path
112
- pins.select { |p| p.path == path }.first
113
- end
114
-
115
- # Get the location of a file referenced by a require path.
116
- #
117
- # @param path [String]
118
- # @return [Location]
119
- def require_reference path
120
- # @type [Gem::Specification]
121
- spec = spec_for_require(path)
122
- spec.full_require_paths.each do |rp|
123
- file = File.join(rp, path)
124
- file = [file, file + ".rb"].find { |file| File.file?(file) }
125
- next unless file
126
- return Solargraph::Location.new(file, Solargraph::Range.from_to(0, 0, 0, 0))
127
- end
128
- nil
129
- rescue Gem::LoadError
130
- nil
131
- end
132
-
133
- def base_required
134
- @base_required ||= Set.new
135
- end
136
-
137
- def directory
138
- @directory ||= ''
139
- end
140
-
141
- private
142
-
143
- # @return [YardMap::Cache]
144
- def cache
145
- @cache ||= YardMap::Cache.new
146
- end
147
-
148
- # @return [Hash{Class<Pin::Base> => Array<Pin::Base>}]
149
- def pin_class_hash
150
- @pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
151
- end
152
-
153
- # @return [Array<Pin::Base>]
154
- def pins_by_class klass
155
- @pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
156
- end
157
-
158
- # @param ns [YARD::CodeObjects::NamespaceObject]
159
- # @return [Array<YARD::CodeObjects::Base>]
160
- def recurse_namespace_object ns
161
- result = []
162
- ns.children.each do |c|
163
- result.push c
164
- result.concat recurse_namespace_object(c) if c.respond_to?(:children)
165
- end
166
- result
167
- end
168
-
169
- # @return [void]
170
- def process_requires
171
- @gemset = process_gemsets
172
- required.merge @gemset.keys if required.include?('bundler/require')
173
- pins.clear
174
- unresolved_requires.clear
175
- missing_docs.clear
176
- environ = Convention.for_global(self)
177
- done = []
178
- already_errored = []
179
- (required + environ.requires).each do |r|
180
- next if r.nil? || r.empty? || done.include?(r)
181
- done.push r
182
- cached = cache.get_path_pins(r)
183
- unless cached.nil?
184
- pins.concat cached
185
- next
186
- end
187
- result = pins_for_require r, already_errored
188
- result.delete_if(&:nil?)
189
- unless result.empty?
190
- cache.set_path_pins r, result
191
- pins.concat result
192
- end
193
- end
194
- if required.include?('yaml') && required.include?('psych')
195
- # HACK: Hardcoded YAML handling
196
- # @todo Why can't this be handled with an override or a virtual pin?
197
- pin = path_pin('YAML')
198
- pin.instance_variable_set(:@return_type, ComplexType.parse('Module<Psych>')) unless pin.nil?
199
- end
200
- pins.concat environ.pins
201
- end
202
-
203
- def process_error(req, result, already_errored, yd = 1)
204
- base = req.split('/').first
205
- return if already_errored.include?(base)
206
- already_errored.push base
207
- if yd.nil?
208
- missing_docs.push req
209
- else
210
- unresolved_requires.push req
211
- end
212
- end
213
-
214
- def process_gemsets
215
- return {} if directory.empty? || !File.file?(File.join(directory, 'Gemfile'))
216
- require_from_bundle(directory)
217
- end
218
-
219
- # @param r [String]
220
- def pins_for_require r, already_errored
221
- result = []
222
- begin
223
- name = r.split('/').first.to_s
224
- return [] if name.empty?
225
-
226
- spec = spec_for_require(r)
227
- return [] if @source_gems.include?(spec.name) || @gem_paths.key?(spec.name)
228
- @gem_paths[spec.name] = spec.full_gem_path
229
-
230
- yd = yardoc_file_for_spec(spec)
231
- # YARD detects gems for certain libraries that do not have a yardoc
232
- # but exist in the stdlib. `fileutils` is an example. Treat those
233
- # cases as errors and check the stdlib yardoc.
234
- if yd.nil?
235
- process_error(r, result, already_errored, nil)
236
- return []
237
- end
238
- unless yardocs.include?(yd)
239
- yardocs.unshift yd
240
- result.concat process_yardoc yd, spec
241
- if with_dependencies?
242
- (spec.dependencies - spec.development_dependencies).each do |dep|
243
- result.concat pins_for_require dep.name, already_errored
244
- end
245
- end
246
- end
247
- rescue Gem::LoadError, NoYardocError
248
- process_error(r, result, already_errored)
249
- end
250
- return result
251
- end
252
-
253
- # @param y [String, nil]
254
- # @param spec [Gem::Specification, nil]
255
- # @return [Array<Pin::Base>]
256
- def process_yardoc y, spec = nil
257
- return [] if y.nil?
258
- if spec
259
- cache = Solargraph::Cache.load('gems', "#{spec.name}-#{spec.version}.ser")
260
- return cache if cache
261
- end
262
- size = Dir.glob(File.join(y, '**', '*'))
263
- .map{ |f| File.size(f) }
264
- .inject(:+)
265
- if !size.nil? && size > 20_000_000
266
- Solargraph::Logging.logger.warn "Yardoc at #{y} is too large to process (#{size} bytes)"
267
- return []
268
- end
269
- Solargraph.logger.info "Loading #{spec.name} #{spec.version} from #{y}"
270
- load_yardoc y
271
- result = Mapper.new(YARD::Registry.all, spec).map
272
- raise NoYardocError, "Yardoc at #{y} is empty" if result.empty?
273
- if spec
274
- Solargraph::Cache.save 'gems', "#{spec.name}-#{spec.version}.ser", result
275
- end
276
- result
277
- end
278
-
279
- # @param spec [Gem::Specification]
280
- # @return [String]
281
- def yardoc_file_for_spec spec
282
- YARD::Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
283
- end
284
-
285
- # @param path [String]
286
- # @return [Gem::Specification]
287
- def spec_for_require path
288
- relatives = path.split('/')
289
- spec = nil
290
- while spec.nil? && !relatives.empty?
291
- name = relatives.join('-')
292
- spec = Gem::Specification.find_by_name(name, @gemset[name])
293
- relatives.pop
294
- end
295
- raise Gem::LoadError if spec.nil?
296
-
297
- # Avoid loading the spec again if it's going to be skipped anyway
298
- return spec if @source_gems.include?(spec.name)
299
- # Avoid loading the spec again if it's already the correct version
300
- if @gemset[spec.name] && spec.version != @gemset[spec.name]
301
- begin
302
- return Gem::Specification.find_by_name(spec.name, "= #{@gemset[spec.name]}")
303
- rescue Gem::LoadError
304
- Solargraph.logger.warn "Unable to load #{spec.name} #{@gemset[spec.name]} specified by workspace, using #{spec.version} instead"
305
- end
306
- end
307
- spec
308
- end
309
17
  end
310
18
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ # Methods for caching and loading YARD documentation for gems.
5
+ #
6
+ module Yardoc
7
+ module_function
8
+
9
+ # Build and cache a gem's yardoc and return the path. If the cache already
10
+ # exists, do nothing and return the path.
11
+ #
12
+ # @param gemspec [Gem::Specification]
13
+ # @return [String] The path to the cached yardoc.
14
+ def cache(gemspec)
15
+ path = path_for(gemspec)
16
+ return path if cached?(gemspec)
17
+
18
+ Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
19
+ Dir.chdir gemspec.gem_dir do
20
+ `yardoc --db #{path} --no-output --plugin solargraph`
21
+ end
22
+ path
23
+ end
24
+
25
+ # True if the gem yardoc is cached.
26
+ #
27
+ # @param gemspec [Gem::Specification]
28
+ def cached?(gemspec)
29
+ yardoc = File.join(path_for(gemspec), 'complete')
30
+ File.exist?(yardoc)
31
+ end
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")
39
+ end
40
+
41
+ # Load a gem's yardoc and return its code objects.
42
+ #
43
+ # @note This method modifies the global YARD registry.
44
+ #
45
+ # @param gemspec [Gem::Specification]
46
+ # @return [Array<YARD::CodeObjects::Base>]
47
+ def load!(gemspec)
48
+ YARD::Registry.load! path_for(gemspec)
49
+ YARD::Registry.all
50
+ end
51
+ end
52
+ end
data/lib/solargraph.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Encoding.default_external = 'UTF-8'
4
4
 
5
+ require 'set'
5
6
  require 'yard-solargraph'
6
7
  require 'solargraph/yard_tags'
7
8
  require 'solargraph/version'
@@ -26,8 +27,10 @@ module Solargraph
26
27
  autoload :Source, 'solargraph/source'
27
28
  autoload :SourceMap, 'solargraph/source_map'
28
29
  autoload :ApiMap, 'solargraph/api_map'
30
+ autoload :Yardoc, 'solargraph/yardoc'
29
31
  autoload :YardMap, 'solargraph/yard_map'
30
32
  autoload :Pin, 'solargraph/pin'
33
+ autoload :DocMap, 'solargraph/doc_map'
31
34
  autoload :ServerMethods, 'solargraph/server_methods'
32
35
  autoload :LanguageServer, 'solargraph/language_server'
33
36
  autoload :Workspace, 'solargraph/workspace'
@@ -40,9 +43,9 @@ module Solargraph
40
43
  autoload :TypeChecker, 'solargraph/type_checker'
41
44
  autoload :Environ, 'solargraph/environ'
42
45
  autoload :Convention, 'solargraph/convention'
43
- autoload :Documentor, 'solargraph/documentor'
44
46
  autoload :Parser, 'solargraph/parser'
45
47
  autoload :RbsMap, 'solargraph/rbs_map'
48
+ autoload :GemPins, 'solargraph/gem_pins'
46
49
  autoload :Cache, 'solargraph/cache'
47
50
 
48
51
  dir = File.dirname(__FILE__)
data/solargraph.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.metadata["changelog_uri"] = "https://github.com/castwide/solargraph/blob/master/CHANGELOG.md"
22
22
  s.metadata["source_code_uri"] = "https://github.com/castwide/solargraph"
23
23
 
24
- s.required_ruby_version = '>= 2.6'
24
+ s.required_ruby_version = '>= 3.0'
25
25
 
26
26
  s.add_runtime_dependency 'backport', '~> 1.2'
27
27
  s.add_runtime_dependency 'benchmark'
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_runtime_dependency 'observer', '~> 0.1'
35
35
  s.add_runtime_dependency 'ostruct', '~> 0.6'
36
36
  s.add_runtime_dependency 'parser', '~> 3.0'
37
- s.add_runtime_dependency 'rbs', '~> 3.0'
37
+ s.add_runtime_dependency 'rbs', '~> 3.3'
38
38
  s.add_runtime_dependency 'reverse_markdown', '>= 2.0', '< 4'
39
39
  s.add_runtime_dependency 'rubocop', '~> 1.38'
40
40
  s.add_runtime_dependency 'thor', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.52.0
4
+ version: 0.53.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
11
+ date: 2025-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '3.0'
173
+ version: '3.3'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '3.0'
180
+ version: '3.3'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: reverse_markdown
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -380,7 +380,9 @@ extensions: []
380
380
  extra_rdoc_files: []
381
381
  files:
382
382
  - ".github/FUNDING.yml"
383
+ - ".github/workflows/plugins.yml"
383
384
  - ".github/workflows/rspec.yml"
385
+ - ".github/workflows/typecheck.yml"
384
386
  - ".gitignore"
385
387
  - ".rspec"
386
388
  - ".yardopts"
@@ -394,7 +396,6 @@ files:
394
396
  - lib/.rubocop.yml
395
397
  - lib/solargraph.rb
396
398
  - lib/solargraph/api_map.rb
397
- - lib/solargraph/api_map/bundler_methods.rb
398
399
  - lib/solargraph/api_map/cache.rb
399
400
  - lib/solargraph/api_map/source_to_yard.rb
400
401
  - lib/solargraph/api_map/store.rb
@@ -420,8 +421,9 @@ files:
420
421
  - lib/solargraph/diagnostics/severities.rb
421
422
  - lib/solargraph/diagnostics/type_check.rb
422
423
  - lib/solargraph/diagnostics/update_errors.rb
423
- - lib/solargraph/documentor.rb
424
+ - lib/solargraph/doc_map.rb
424
425
  - lib/solargraph/environ.rb
426
+ - lib/solargraph/gem_pins.rb
425
427
  - lib/solargraph/language_server.rb
426
428
  - lib/solargraph/language_server/completion_item_kinds.rb
427
429
  - lib/solargraph/language_server/error_codes.rb
@@ -489,60 +491,33 @@ files:
489
491
  - lib/solargraph/page.rb
490
492
  - lib/solargraph/parser.rb
491
493
  - lib/solargraph/parser/comment_ripper.rb
492
- - lib/solargraph/parser/legacy.rb
493
- - lib/solargraph/parser/legacy/class_methods.rb
494
- - lib/solargraph/parser/legacy/flawed_builder.rb
495
- - lib/solargraph/parser/legacy/node_chainer.rb
496
- - lib/solargraph/parser/legacy/node_methods.rb
497
- - lib/solargraph/parser/legacy/node_processors.rb
498
- - lib/solargraph/parser/legacy/node_processors/alias_node.rb
499
- - lib/solargraph/parser/legacy/node_processors/args_node.rb
500
- - lib/solargraph/parser/legacy/node_processors/begin_node.rb
501
- - lib/solargraph/parser/legacy/node_processors/block_node.rb
502
- - lib/solargraph/parser/legacy/node_processors/casgn_node.rb
503
- - lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb
504
- - lib/solargraph/parser/legacy/node_processors/def_node.rb
505
- - lib/solargraph/parser/legacy/node_processors/defs_node.rb
506
- - lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb
507
- - lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb
508
- - lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb
509
- - lib/solargraph/parser/legacy/node_processors/namespace_node.rb
510
- - lib/solargraph/parser/legacy/node_processors/orasgn_node.rb
511
- - lib/solargraph/parser/legacy/node_processors/resbody_node.rb
512
- - lib/solargraph/parser/legacy/node_processors/sclass_node.rb
513
- - lib/solargraph/parser/legacy/node_processors/send_node.rb
514
- - lib/solargraph/parser/legacy/node_processors/sym_node.rb
515
494
  - lib/solargraph/parser/node_methods.rb
516
495
  - lib/solargraph/parser/node_processor.rb
517
496
  - lib/solargraph/parser/node_processor/base.rb
497
+ - lib/solargraph/parser/parser_gem.rb
498
+ - lib/solargraph/parser/parser_gem/class_methods.rb
499
+ - lib/solargraph/parser/parser_gem/flawed_builder.rb
500
+ - lib/solargraph/parser/parser_gem/node_chainer.rb
501
+ - lib/solargraph/parser/parser_gem/node_methods.rb
502
+ - lib/solargraph/parser/parser_gem/node_processors.rb
503
+ - lib/solargraph/parser/parser_gem/node_processors/alias_node.rb
504
+ - lib/solargraph/parser/parser_gem/node_processors/args_node.rb
505
+ - lib/solargraph/parser/parser_gem/node_processors/begin_node.rb
506
+ - lib/solargraph/parser/parser_gem/node_processors/block_node.rb
507
+ - lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb
508
+ - lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb
509
+ - lib/solargraph/parser/parser_gem/node_processors/def_node.rb
510
+ - lib/solargraph/parser/parser_gem/node_processors/defs_node.rb
511
+ - lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb
512
+ - lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb
513
+ - lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb
514
+ - lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb
515
+ - lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb
516
+ - lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb
517
+ - lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb
518
+ - lib/solargraph/parser/parser_gem/node_processors/send_node.rb
519
+ - lib/solargraph/parser/parser_gem/node_processors/sym_node.rb
518
520
  - lib/solargraph/parser/region.rb
519
- - lib/solargraph/parser/rubyvm.rb
520
- - lib/solargraph/parser/rubyvm/class_methods.rb
521
- - lib/solargraph/parser/rubyvm/node_chainer.rb
522
- - lib/solargraph/parser/rubyvm/node_methods.rb
523
- - lib/solargraph/parser/rubyvm/node_processors.rb
524
- - lib/solargraph/parser/rubyvm/node_processors/alias_node.rb
525
- - lib/solargraph/parser/rubyvm/node_processors/args_node.rb
526
- - lib/solargraph/parser/rubyvm/node_processors/begin_node.rb
527
- - lib/solargraph/parser/rubyvm/node_processors/block_node.rb
528
- - lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb
529
- - lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb
530
- - lib/solargraph/parser/rubyvm/node_processors/def_node.rb
531
- - lib/solargraph/parser/rubyvm/node_processors/defs_node.rb
532
- - lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb
533
- - lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb
534
- - lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb
535
- - lib/solargraph/parser/rubyvm/node_processors/lit_node.rb
536
- - lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb
537
- - lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb
538
- - lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb
539
- - lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb
540
- - lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb
541
- - lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb
542
- - lib/solargraph/parser/rubyvm/node_processors/scope_node.rb
543
- - lib/solargraph/parser/rubyvm/node_processors/send_node.rb
544
- - lib/solargraph/parser/rubyvm/node_processors/sym_node.rb
545
- - lib/solargraph/parser/rubyvm/node_wrapper.rb
546
521
  - lib/solargraph/parser/snippet.rb
547
522
  - lib/solargraph/pin.rb
548
523
  - lib/solargraph/pin/base.rb
@@ -583,13 +558,13 @@ files:
583
558
  - lib/solargraph/rbs_map/conversions.rb
584
559
  - lib/solargraph/rbs_map/core_fills.rb
585
560
  - lib/solargraph/rbs_map/core_map.rb
586
- - lib/solargraph/rbs_map/core_signs.rb
587
561
  - lib/solargraph/rbs_map/stdlib_map.rb
588
562
  - lib/solargraph/server_methods.rb
589
563
  - lib/solargraph/shell.rb
590
564
  - lib/solargraph/source.rb
591
565
  - lib/solargraph/source/chain.rb
592
566
  - lib/solargraph/source/chain/array.rb
567
+ - lib/solargraph/source/chain/block_symbol.rb
593
568
  - lib/solargraph/source/chain/block_variable.rb
594
569
  - lib/solargraph/source/chain/call.rb
595
570
  - lib/solargraph/source/chain/class_variable.rb
@@ -597,6 +572,7 @@ files:
597
572
  - lib/solargraph/source/chain/global_variable.rb
598
573
  - lib/solargraph/source/chain/hash.rb
599
574
  - lib/solargraph/source/chain/head.rb
575
+ - lib/solargraph/source/chain/if.rb
600
576
  - lib/solargraph/source/chain/instance_variable.rb
601
577
  - lib/solargraph/source/chain/link.rb
602
578
  - lib/solargraph/source/chain/literal.rb
@@ -637,6 +613,7 @@ files:
637
613
  - lib/solargraph/yard_map/mapper/to_namespace.rb
638
614
  - lib/solargraph/yard_map/to_method.rb
639
615
  - lib/solargraph/yard_tags.rb
616
+ - lib/solargraph/yardoc.rb
640
617
  - solargraph.gemspec
641
618
  homepage: https://solargraph.org
642
619
  licenses:
@@ -654,7 +631,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
654
631
  requirements:
655
632
  - - ">="
656
633
  - !ruby/object:Gem::Version
657
- version: '2.6'
634
+ version: '3.0'
658
635
  required_rubygems_version: !ruby/object:Gem::Requirement
659
636
  requirements:
660
637
  - - ">="