solargraph 0.39.0 → 0.39.6

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/.rubocop.yml +21 -0
  3. data/lib/solargraph/diagnostics/rubocop.rb +2 -1
  4. data/lib/solargraph/diagnostics/rubocop_helpers.rb +4 -1
  5. data/lib/solargraph/documentor.rb +2 -0
  6. data/lib/solargraph/language_server/host.rb +1 -1
  7. data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -2
  8. data/lib/solargraph/language_server/uri_helpers.rb +22 -3
  9. data/lib/solargraph/parser/legacy/class_methods.rb +4 -0
  10. data/lib/solargraph/parser/legacy/node_chainer.rb +5 -2
  11. data/lib/solargraph/parser/legacy/node_methods.rb +13 -2
  12. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +2 -0
  13. data/lib/solargraph/parser/rubyvm/class_methods.rb +6 -2
  14. data/lib/solargraph/parser/rubyvm/node_chainer.rb +4 -2
  15. data/lib/solargraph/parser/rubyvm/node_methods.rb +4 -0
  16. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +6 -1
  17. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +6 -1
  18. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +4 -41
  19. data/lib/solargraph/parser/rubyvm/node_processors.rb +1 -0
  20. data/lib/solargraph/pin/attribute.rb +1 -1
  21. data/lib/solargraph/pin/base_method.rb +1 -1
  22. data/lib/solargraph/pin/base_variable.rb +1 -1
  23. data/lib/solargraph/pin/block.rb +1 -1
  24. data/lib/solargraph/pin/closure.rb +1 -1
  25. data/lib/solargraph/pin/constant.rb +1 -1
  26. data/lib/solargraph/pin/local_variable.rb +1 -1
  27. data/lib/solargraph/pin/method.rb +1 -1
  28. data/lib/solargraph/pin/method_alias.rb +1 -1
  29. data/lib/solargraph/pin/namespace.rb +1 -1
  30. data/lib/solargraph/pin/parameter.rb +2 -2
  31. data/lib/solargraph/pin/proxy_type.rb +1 -1
  32. data/lib/solargraph/shell.rb +1 -1
  33. data/lib/solargraph/source/chain/call.rb +9 -0
  34. data/lib/solargraph/source/chain/head.rb +14 -8
  35. data/lib/solargraph/source/chain/z_super.rb +184 -0
  36. data/lib/solargraph/source/chain.rb +1 -0
  37. data/lib/solargraph/source.rb +14 -3
  38. data/lib/solargraph/source_map/mapper.rb +11 -7
  39. data/lib/solargraph/type_checker.rb +25 -1
  40. data/lib/solargraph/version.rb +1 -1
  41. data/lib/solargraph/views/_name_type_tag.erb +1 -1
  42. data/lib/solargraph/workspace.rb +1 -1
  43. data/lib/solargraph/yard_map/mapper.rb +3 -0
  44. data/lib/solargraph/yard_map/rdoc_to_yard.rb +13 -6
  45. data/lib/solargraph/yard_map.rb +102 -69
  46. metadata +4 -3
  47. data/.rubocop.yml +0 -6
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class Source
5
+ class Chain
6
+ class ZSuper < Call
7
+ # @return [String]
8
+ attr_reader :word
9
+
10
+ # @return [Array<Chain>]
11
+ attr_reader :arguments
12
+
13
+ # @param word [String]
14
+ # @param arguments [Array<Chain>]
15
+ # @param with_block [Boolean] True if the chain is inside a block
16
+ # @param head [Boolean] True if the call is the start of its chain
17
+ def initialize word, with_block = false
18
+ super(word, [], with_block)
19
+ end
20
+
21
+ def with_block?
22
+ @with_block
23
+ end
24
+
25
+ # @param api_map [ApiMap]
26
+ # @param name_pin [Pin::Base]
27
+ # @param locals [Array<Pin::Base>]
28
+ def resolve api_map, name_pin, locals
29
+ return super_pins(api_map, name_pin)
30
+ end
31
+
32
+ private
33
+
34
+ # @param pins [Array<Pin::Base>]
35
+ # @param api_map [ApiMap]
36
+ # @param context [ComplexType]
37
+ # @param locals [Pin::LocalVariable]
38
+ # @return [Array<Pin::Base>]
39
+ def inferred_pins pins, api_map, context, locals
40
+ result = pins.map do |p|
41
+ overloads = p.docstring.tags(:overload)
42
+ # next p if overloads.empty?
43
+ type = ComplexType::UNDEFINED
44
+ # @param [YARD::Tags::OverloadTag]
45
+ overloads.each do |ol|
46
+ next unless arguments_match(arguments, ol.parameters)
47
+ next if ol.parameters.last && ol.parameters.last.first.start_with?('&') && ol.parameters.last.last.nil? && !with_block?
48
+ match = true
49
+ arguments.each_with_index do |arg, idx|
50
+ achain = arguments[idx]
51
+ next if achain.nil?
52
+ param = ol.parameters[idx]
53
+ if param.nil?
54
+ match = false unless ol.parameters.last && ol.parameters.last.first.start_with?('*')
55
+ break
56
+ end
57
+ par = ol.tags(:param).select { |pp| pp.name == param.first }.first
58
+ next if par.nil? || par.types.nil? || par.types.empty?
59
+ atype = achain.infer(api_map, Pin::ProxyType.anonymous(context), locals)
60
+ other = ComplexType.try_parse(*par.types)
61
+ # @todo Weak type comparison
62
+ unless atype.tag == other.tag || api_map.super_and_sub?(other.tag, atype.tag)
63
+ match = false
64
+ break
65
+ end
66
+ end
67
+ if match
68
+ type = extra_return_type(ol, context)
69
+ type = ComplexType.try_parse(*ol.tag(:return).types).self_to(context.to_s).qualify(api_map, context.namespace) if ol.has_tag?(:return) && ol.tag(:return).types && !ol.tag(:return).types.empty? && (type.nil? || type.undefined?)
70
+ type ||= ComplexType::UNDEFINED
71
+ end
72
+ break if type.defined?
73
+ end
74
+ next p.proxy(type) if type.defined?
75
+ type = extra_return_type(p.docstring, context)
76
+ if type
77
+ next Solargraph::Pin::Method.new(
78
+ location: p.location,
79
+ closure: p.closure,
80
+ name: p.name,
81
+ comments: "@return [#{context.subtypes.first.to_s}]",
82
+ scope: p.scope,
83
+ visibility: p.visibility,
84
+ parameters: p.parameters,
85
+ node: p.node
86
+ )
87
+ end
88
+ if p.is_a?(Pin::Method) && !p.macros.empty?
89
+ result = process_macro(p, api_map, context, locals)
90
+ next result unless result.return_type.undefined?
91
+ elsif !p.directives.empty?
92
+ result = process_directive(p, api_map, context, locals)
93
+ next result unless result.return_type.undefined?
94
+ end
95
+ p
96
+ end
97
+ result.map do |pin|
98
+ next pin if pin.return_type.undefined?
99
+ selfy = pin.return_type.self_to(context.tag)
100
+ selfy == pin.return_type ? pin : pin.proxy(selfy)
101
+ end
102
+ end
103
+
104
+ # @param pin [Pin::Method]
105
+ # @param api_map [ApiMap]
106
+ # @param context [ComplexType]
107
+ # @param locals [Pin::Base]
108
+ # @return [Pin::Base]
109
+ def process_macro pin, api_map, context, locals
110
+ pin.macros.each do |macro|
111
+ result = inner_process_macro(pin, macro, api_map, context, locals)
112
+ return result unless result.return_type.undefined?
113
+ end
114
+ Pin::ProxyType.anonymous(ComplexType::UNDEFINED)
115
+ end
116
+
117
+ # @param pin [Pin::Method]
118
+ # @param api_map [ApiMap]
119
+ # @param context [ComplexType]
120
+ # @param locals [Pin::Base]
121
+ # @return [Pin::ProxyType]
122
+ def process_directive pin, api_map, context, locals
123
+ pin.directives.each do |dir|
124
+ macro = api_map.named_macro(dir.tag.name)
125
+ next if macro.nil?
126
+ result = inner_process_macro(pin, macro, api_map, context, locals)
127
+ return result unless result.return_type.undefined?
128
+ end
129
+ Pin::ProxyType.anonymous ComplexType::UNDEFINED
130
+ end
131
+
132
+ # @param pin [Pin]
133
+ # @param macro [YARD::Tags::MacroDirective]
134
+ # @param api_map [ApiMap]
135
+ # @param context [ComplexType]
136
+ # @param locals [Array<Pin::Base>]
137
+ # @return [Pin::ProxyType]
138
+ def inner_process_macro pin, macro, api_map, context, locals
139
+ vals = arguments.map{ |c| Pin::ProxyType.anonymous(c.infer(api_map, pin, locals)) }
140
+ txt = macro.tag.text.clone
141
+ if txt.empty? && macro.tag.name
142
+ named = api_map.named_macro(macro.tag.name)
143
+ txt = named.tag.text.clone if named
144
+ end
145
+ i = 1
146
+ vals.each do |v|
147
+ txt.gsub!(/\$#{i}/, v.context.namespace)
148
+ i += 1
149
+ end
150
+ docstring = Solargraph::Source.parse_docstring(txt).to_docstring
151
+ tag = docstring.tag(:return)
152
+ unless tag.nil? || tag.types.nil?
153
+ return Pin::ProxyType.anonymous(ComplexType.try_parse(*tag.types))
154
+ end
155
+ Pin::ProxyType.anonymous(ComplexType::UNDEFINED)
156
+ end
157
+
158
+ # @param docstring [YARD::Docstring]
159
+ # @param context [ComplexType]
160
+ # @return [ComplexType]
161
+ def extra_return_type docstring, context
162
+ if docstring.has_tag?(:return_single_parameter) && context.subtypes.one?
163
+ return context.subtypes.first
164
+ elsif docstring.has_tag?(:return_value_parameter) && context.value_types.one?
165
+ return context.value_types.first
166
+ end
167
+ nil
168
+ end
169
+
170
+ # @param arguments [Array<Chain>]
171
+ # @param parameters [Array<String>]
172
+ # @return [Boolean]
173
+ def arguments_match arguments, parameters
174
+ argcount = arguments.length
175
+ # argcount -= 1 if !arguments.empty? && arguments.last.links.first.word.start_with?('&')
176
+ parcount = parameters.length
177
+ parcount -= 1 if !parameters.empty? && parameters.last.first.start_with?('&')
178
+ return false if argcount < parcount && !(argcount == parcount - 1 && parameters.last.first.start_with?('*'))
179
+ true
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -20,6 +20,7 @@ module Solargraph
20
20
  autoload :Head, 'solargraph/source/chain/head'
21
21
  autoload :Or, 'solargraph/source/chain/or'
22
22
  autoload :BlockVariable, 'solargraph/source/chain/block_variable'
23
+ autoload :ZSuper, 'solargraph/source/chain/z_super'
23
24
 
24
25
  @@inference_stack = []
25
26
  @@inference_depth = 0
@@ -338,8 +338,8 @@ module Solargraph
338
338
 
339
339
  def first_not_empty_from line
340
340
  cursor = line
341
- cursor += 1 while cursor < code.lines.length && code.lines[cursor].strip.empty?
342
- cursor = line if cursor > code.lines.length
341
+ cursor += 1 while cursor < code_lines.length && code_lines[cursor].strip.empty?
342
+ cursor = line if cursor > code_lines.length - 1
343
343
  cursor
344
344
  end
345
345
 
@@ -468,8 +468,12 @@ module Solargraph
468
468
  # @return [Integer]
469
469
  attr_writer :version
470
470
 
471
+ # @param val [String]
471
472
  # @return [String]
472
- attr_writer :code
473
+ def code=(val)
474
+ @code_lines= nil
475
+ @code = val
476
+ end
473
477
 
474
478
  # @return [Parser::AST::Node]
475
479
  attr_writer :node
@@ -492,6 +496,13 @@ module Solargraph
492
496
  # @return [Source::Updater]
493
497
  attr_accessor :last_updater
494
498
 
499
+ private
500
+
501
+ # @return [Array<String>]
502
+ def code_lines
503
+ @code_lines ||= code.lines
504
+ end
505
+
495
506
  class << self
496
507
  # @param filename [String]
497
508
  # @return [Solargraph::Source]
@@ -68,7 +68,7 @@ module Solargraph
68
68
  # @param d [YARD::Tags::Directive]
69
69
  parse.directives.each do |d|
70
70
  line_num = find_directive_line_number(cmnt, d.tag.tag_name, last_line)
71
- pos = Solargraph::Position.new(comment_position.line + line_num, comment_position.column)
71
+ pos = Solargraph::Position.new(comment_position.line + line_num - 1, comment_position.column)
72
72
  process_directive(source_position, pos, d)
73
73
  last_line = line_num + 1
74
74
  # @todo The below call assumes the topmost comment line. The above
@@ -79,7 +79,11 @@ module Solargraph
79
79
  end
80
80
  end
81
81
 
82
+ # @param comment [String]
83
+ # @return [Integer]
82
84
  def find_directive_line_number comment, tag, start
85
+ # Avoid overruning the index
86
+ return start unless start < comment.lines.length
83
87
  num = comment.lines[start..-1].find_index do |line|
84
88
  # Legacy method directives might be `@method` instead of `@!method`
85
89
  # @todo Legacy syntax should probably emit a warning
@@ -96,7 +100,7 @@ module Solargraph
96
100
  location = Location.new(@filename, Range.new(comment_position, comment_position))
97
101
  case directive.tag.tag_name
98
102
  when 'method'
99
- namespace = closure_at(source_position)
103
+ namespace = closure_at(source_position) || @pins.first
100
104
  if namespace.location.range.start.line < comment_position.line
101
105
  namespace = closure_at(comment_position)
102
106
  end
@@ -105,9 +109,9 @@ module Solargraph
105
109
  src_node = Parser.parse("def #{directive.tag.name};end", @filename, location.range.start.line)
106
110
  gen_pin = Parser.process_node(src_node, region).first.last
107
111
  return if gen_pin.nil?
108
- # Move the location to the end of the line so the it gets
109
- # recognized as originating from a comment
110
- shifted = Solargraph::Position.new(comment_position.line, @code.lines[comment_position.line].chomp.length)
112
+ # Move the location to the end of the line so it gets recognized
113
+ # as originating from a comment
114
+ shifted = Solargraph::Position.new(comment_position.line, @code.lines[comment_position.line].to_s.chomp.length)
111
115
  # @todo: Smelly instance variable access
112
116
  gen_pin.instance_variable_set(:@comments, docstring.all.to_s)
113
117
  gen_pin.instance_variable_set(:@location, Solargraph::Location.new(@filename, Range.new(shifted, shifted)))
@@ -183,9 +187,9 @@ module Solargraph
183
187
  # @return [void]
184
188
  def process_comment_directives
185
189
  return unless @code =~ MACRO_REGEXP
186
- used = []
190
+ code_lines = @code.lines
187
191
  @source.associated_comments.each do |line, comments|
188
- src_pos = line ? Position.new(line, @code.lines[line].to_s.chomp.index(/[^\s]/) || 0) : Position.new(@code.lines.length, 0)
192
+ src_pos = line ? Position.new(line, code_lines[line].to_s.chomp.index(/[^\s]/) || 0) : Position.new(code_lines.length, 0)
189
193
  com_pos = Position.new(line - 1, 0)
190
194
  process_comment(src_pos, com_pos, comments)
191
195
  end
@@ -248,7 +248,11 @@ module Solargraph
248
248
  if pins.first.is_a?(Pin::BaseMethod)
249
249
  # @type [Pin::BaseMethod]
250
250
  pin = pins.first
251
- ap = arity_problems_for(pin, base.links.last.arguments, location)
251
+ ap = if base.links.last.is_a?(Solargraph::Source::Chain::ZSuper)
252
+ arity_problems_for(pin, fake_args_for(block_pin), location)
253
+ else
254
+ arity_problems_for(pin, base.links.last.arguments, location)
255
+ end
252
256
  unless ap.empty?
253
257
  result.concat ap
254
258
  break
@@ -470,5 +474,25 @@ module Solargraph
470
474
  pin.docstring.has_tag?(:abstract) ||
471
475
  (pin.closure && pin.closure.docstring.has_tag?(:abstract))
472
476
  end
477
+
478
+ def fake_args_for(pin)
479
+ args = []
480
+ with_opts = false
481
+ with_block = false
482
+ pin.parameters.each do |pin|
483
+ if [:kwarg, :kwoptarg, :kwrestarg].include?(pin.decl)
484
+ with_opts = true
485
+ elsif pin.decl == :block
486
+ with_block = true
487
+ elsif pin.decl == :restarg
488
+ args.push Solargraph::Source::Chain.new([Solargraph::Source::Chain::Variable.new(pin.name)], nil, true)
489
+ else
490
+ args.push Solargraph::Source::Chain.new([Solargraph::Source::Chain::Variable.new(pin.name)])
491
+ end
492
+ end
493
+ args.push Solargraph::Parser.chain_string('{}') if with_opts
494
+ args.push Solargraph::Parser.chain_string('&') if with_block
495
+ args
496
+ end
473
497
  end
474
498
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.39.0'
4
+ VERSION = '0.39.6'
5
5
  end
@@ -2,7 +2,7 @@
2
2
  <% unless tag.types.nil? or tag.types.empty? %>
3
3
  [<%= escape(tag.types.join(', ')) %>]
4
4
  <% end %>
5
- <% unless tag.text.empty? %>
5
+ <% unless tag.text.nil? || tag.text.empty? %>
6
6
  <% unless (tag.name.nil? or tag.name.empty?) and (tag.types.nil? or tag.types.empty?) %>
7
7
  -
8
8
  <% end %>
@@ -170,7 +170,7 @@ module Solargraph
170
170
  Dir.chdir base do
171
171
  begin
172
172
  # @type [Gem::Specification]
173
- spec = eval(File.read(file), binding, file)
173
+ spec = eval(File.read(file), TOPLEVEL_BINDING, file)
174
174
  next unless Gem::Specification === spec
175
175
  @gemnames.push spec.name
176
176
  result.concat(spec.require_paths.map { |path| File.join(base, path) })
@@ -17,6 +17,9 @@ module Solargraph
17
17
  @code_objects.each do |co|
18
18
  @pins.concat generate_pins co
19
19
  end
20
+ # Some yardocs contain documentation for dependencies that can be
21
+ # ignored here. The YardMap will load dependencies separately.
22
+ @pins.keep_if { |pin| pin.location.nil? || File.file?(pin.location.filename) } if @spec
20
23
  @pins
21
24
  end
22
25
 
@@ -11,18 +11,23 @@ module Solargraph
11
11
  extend ApiMap::SourceToYard
12
12
 
13
13
  # @param spec [Gem::Specification]
14
- def self.run spec
14
+ # @param cache_dir [String]
15
+ # @return [void]
16
+ def self.run spec, cache_dir: nil
15
17
  Dir.mktmpdir do |tmpdir|
16
18
  rdir = File.join(tmpdir, 'rdoc')
17
19
  Dir.chdir spec.full_gem_path do
18
20
  pins = []
19
21
  pins.push Solargraph::Pin::ROOT_PIN
20
22
  name_hash = {}
21
- cmd = "rdoc -q -N -r -o #{rdir}"
23
+
24
+ argv = ['-q', '-N', '-r', '-o', rdir]
22
25
  spec.load_paths.each do |path|
23
- cmd += " -i #{path}"
26
+ argv.concat ['-i', path]
24
27
  end
25
- `#{cmd}`
28
+ rdoc = RDoc::RDoc.new
29
+ rdoc.document argv
30
+
26
31
  store = RDoc::Store.new(rdir)
27
32
  store.load_all
28
33
  store.cache[:modules].each do |mod|
@@ -64,7 +69,7 @@ module Solargraph
64
69
  closure: namepin,
65
70
  comments: commentary(met.comment),
66
71
  scope: met.type.to_sym,
67
- args: pin.parameters,
72
+ parameters: pin.parameters,
68
73
  visibility: met.visibility,
69
74
  location: locate(met)
70
75
  )
@@ -85,11 +90,13 @@ module Solargraph
85
90
  code_object_map.values.each do |co|
86
91
  YARD::Registry.register(co)
87
92
  end
88
- cache_dir = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}", "yardoc")
93
+ cache_dir ||= File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}", "yardoc")
89
94
  FileUtils.remove_entry_secure cache_dir if File.exist?(cache_dir)
90
95
  FileUtils.mkdir_p cache_dir
91
96
  # @todo Should merge be true?
92
97
  YARD::Registry.save true, cache_dir
98
+ # Clear the serialized cache if it exists
99
+ FileUtils.safe_unlink File.join(CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}.ser")
93
100
  end
94
101
  end
95
102
  end
@@ -102,7 +102,7 @@ module Solargraph
102
102
  else
103
103
  YARD::Registry.load! y
104
104
  end
105
- rescue Exception => e
105
+ rescue StandardError => e
106
106
  Solargraph::Logging.logger.warn "Error loading yardoc '#{y}' #{e.class} #{e.message}"
107
107
  yardocs.delete y
108
108
  nil
@@ -110,52 +110,8 @@ module Solargraph
110
110
 
111
111
  # @return [Array<Solargraph::Pin::Base>]
112
112
  def core_pins
113
- @@core_pins ||= begin
114
- yd = CoreDocs.yardoc_file
115
- ser = File.join(File.dirname(yd), 'core.ser')
116
- result = []
117
- if File.file?(ser)
118
- file = File.open(ser, 'rb')
119
- dump = file.read
120
- file.close
121
- result.concat Marshal.load(dump)
122
- else
123
- load_yardoc CoreDocs.yardoc_file
124
- result.concat Mapper.new(YARD::Registry.all).map
125
- # HACK: Assume core methods with a single `args` parameter accept restarg
126
- result.select { |pin| pin.is_a?(Solargraph::Pin::BaseMethod )}.each do |pin|
127
- if pin.parameters.length == 1 && pin.parameters.first.name == 'args' && pin.parameters.first.decl == :arg
128
- # @todo Smelly instance variable access
129
- pin.parameters.first.instance_variable_set(:@decl, :restarg)
130
- end
131
- end
132
- # HACK: Set missing parameters on `==` methods, e.g., `Symbol#==`
133
- result.select { |pin| pin.name == '==' && pin.parameters.empty? }.each do |pin|
134
- pin.parameters.push Pin::Parameter.new(decl: :arg, name: 'obj2')
135
- end
136
- dump = Marshal.dump(result)
137
- file = File.open(ser, 'wb')
138
- file.write dump
139
- file.close
140
- end
141
- # HACK: Add Errno exception classes
142
- errno = result.select{ |pin| pin.path == 'Errno' }.first
143
- Errno.constants.each do |const|
144
- result.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
145
- result.push Solargraph::Pin::Reference::Superclass.new(closure: result.last, name: 'SystemCallError')
146
- end
147
- CoreFills::OVERRIDES.each do |ovr|
148
- pin = result.select { |p| p.path == ovr.name }.first
149
- next if pin.nil?
150
- (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
151
- pin.docstring.delete_tags tag.to_sym
152
- end
153
- ovr.tags.each do |tag|
154
- pin.docstring.add_tag(tag)
155
- end
156
- end
157
- result
158
- end
113
+ # Using a class variable to reduce loads
114
+ @@core_pins ||= load_core_pins
159
115
  end
160
116
 
161
117
  # @param path [String]
@@ -237,31 +193,12 @@ module Solargraph
237
193
  base = r.split('/').first
238
194
  next if from_std.include?(base)
239
195
  from_std.push base
240
- stdtmp = []
241
- ser = File.join(File.dirname(CoreDocs.yardoc_stdlib_file), "#{base}.ser")
242
- if File.file?(ser)
243
- Solargraph.logger.info "Loading #{base} stdlib from cache"
244
- file = File.open(ser, 'rb')
245
- dump = file.read
246
- file.close
247
- stdtmp.concat Marshal.load(dump)
248
- else
249
- if stdlib_paths[base]
250
- Solargraph.logger.info "Loading #{base} stdlib from yardoc"
251
- stdtmp.concat Mapper.new(stdlib_paths[base]).map
252
- next if stdtmp.empty?
253
- dump = Marshal.dump(stdtmp)
254
- file = File.open(ser, 'wb')
255
- file.write dump
256
- file.close
257
- end
258
- end
196
+ stdtmp = load_stdlib_pins(base)
259
197
  if stdtmp.empty?
260
198
  unresolved_requires.push r
261
199
  else
262
200
  stdlib_fill base, stdtmp
263
201
  result.concat stdtmp
264
- # stdnames[r] = stdtmp
265
202
  end
266
203
  end
267
204
  result.delete_if(&:nil?)
@@ -270,7 +207,6 @@ module Solargraph
270
207
  pins.concat result
271
208
  end
272
209
  end
273
- # pins.concat process_stdlib(stdnames)
274
210
  pins.concat core_pins
275
211
  end
276
212
 
@@ -316,7 +252,12 @@ module Solargraph
316
252
  file = File.open(ser, 'rb')
317
253
  dump = file.read
318
254
  file.close
319
- return Marshal.load(dump)
255
+ begin
256
+ return Marshal.load(dump)
257
+ rescue StandardError => e
258
+ Solargraph.logger.warn "Error loading pin cache: [#{e.class}] #{e.message}"
259
+ File.unlink ser
260
+ end
320
261
  end
321
262
  end
322
263
  if !size.nil? && size > 20_000_000
@@ -379,6 +320,98 @@ module Solargraph
379
320
  end
380
321
  end
381
322
  end
323
+
324
+ def load_core_pins
325
+ yd = CoreDocs.yardoc_file
326
+ ser = File.join(File.dirname(yd), 'core.ser')
327
+ result = if File.file?(ser)
328
+ file = File.open(ser, 'rb')
329
+ dump = file.read
330
+ file.close
331
+ begin
332
+ Marshal.load(dump)
333
+ rescue StandardError => e
334
+ Solargraph.logger.warn "Error loading core pin cache: [#{e.class}] #{e.message}"
335
+ File.unlink ser
336
+ read_core_and_save_cache(yd, ser)
337
+ end
338
+ else
339
+ read_core_and_save_cache(yd, ser)
340
+ end
341
+ # HACK: Add Errno exception classes
342
+ errno = result.select{ |pin| pin.path == 'Errno' }.first
343
+ Errno.constants.each do |const|
344
+ result.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
345
+ result.push Solargraph::Pin::Reference::Superclass.new(closure: result.last, name: 'SystemCallError')
346
+ end
347
+ CoreFills::OVERRIDES.each do |ovr|
348
+ pin = result.select { |p| p.path == ovr.name }.first
349
+ next if pin.nil?
350
+ (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
351
+ pin.docstring.delete_tags tag.to_sym
352
+ end
353
+ ovr.tags.each do |tag|
354
+ pin.docstring.add_tag(tag)
355
+ end
356
+ end
357
+ result
358
+ end
359
+
360
+ def read_core_and_save_cache yd, ser
361
+ result = []
362
+ load_yardoc yd
363
+ result.concat Mapper.new(YARD::Registry.all).map
364
+ # HACK: Assume core methods with a single `args` parameter accept restarg
365
+ result.select { |pin| pin.is_a?(Solargraph::Pin::BaseMethod )}.each do |pin|
366
+ if pin.parameters.length == 1 && pin.parameters.first.name == 'args' && pin.parameters.first.decl == :arg
367
+ # @todo Smelly instance variable access
368
+ pin.parameters.first.instance_variable_set(:@decl, :restarg)
369
+ end
370
+ end
371
+ # HACK: Set missing parameters on `==` methods, e.g., `Symbol#==`
372
+ result.select { |pin| pin.name == '==' && pin.parameters.empty? }.each do |pin|
373
+ pin.parameters.push Pin::Parameter.new(decl: :arg, name: 'obj2')
374
+ end
375
+ dump = Marshal.dump(result)
376
+ file = File.open(ser, 'wb')
377
+ file.write dump
378
+ file.close
379
+ result
380
+ end
381
+
382
+ def load_stdlib_pins base
383
+ ser = File.join(File.dirname(CoreDocs.yardoc_stdlib_file), "#{base}.ser")
384
+ if File.file?(ser)
385
+ Solargraph.logger.info "Loading #{base} stdlib from cache"
386
+ file = File.open(ser, 'rb')
387
+ dump = file.read
388
+ file.close
389
+ begin
390
+ Marshal.load(dump)
391
+ rescue StandardError => e
392
+ Solargraph.logger.warn "Error loading #{base} stdlib pin cache: [#{e.class}] #{e.message}"
393
+ File.unlink ser
394
+ read_stdlib_and_save_cache(base, ser)
395
+ end
396
+ else
397
+ read_stdlib_and_save_cache(base, ser)
398
+ end
399
+ end
400
+
401
+ def read_stdlib_and_save_cache base, ser
402
+ result = []
403
+ if stdlib_paths[base]
404
+ Solargraph.logger.info "Loading #{base} stdlib from yardoc"
405
+ result.concat Mapper.new(stdlib_paths[base]).map
406
+ unless result.empty?
407
+ dump = Marshal.dump(result)
408
+ file = File.open(ser, 'wb')
409
+ file.write dump
410
+ file.close
411
+ end
412
+ end
413
+ result
414
+ end
382
415
  end
383
416
  end
384
417
 
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.39.0
4
+ version: 0.39.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-26 00:00:00.000000000 Z
11
+ date: 2020-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -301,7 +301,6 @@ extra_rdoc_files: []
301
301
  files:
302
302
  - ".gitignore"
303
303
  - ".rspec"
304
- - ".rubocop.yml"
305
304
  - ".travis.yml"
306
305
  - ".yardopts"
307
306
  - Gemfile
@@ -310,6 +309,7 @@ files:
310
309
  - Rakefile
311
310
  - SPONSORS.md
312
311
  - bin/solargraph
312
+ - lib/.rubocop.yml
313
313
  - lib/solargraph.rb
314
314
  - lib/solargraph/api_map.rb
315
315
  - lib/solargraph/api_map/bundler_methods.rb
@@ -513,6 +513,7 @@ files:
513
513
  - lib/solargraph/source/chain/literal.rb
514
514
  - lib/solargraph/source/chain/or.rb
515
515
  - lib/solargraph/source/chain/variable.rb
516
+ - lib/solargraph/source/chain/z_super.rb
516
517
  - lib/solargraph/source/change.rb
517
518
  - lib/solargraph/source/cursor.rb
518
519
  - lib/solargraph/source/encoding_fixes.rb
data/.rubocop.yml DELETED
@@ -1,6 +0,0 @@
1
- Layout/EndOfLine:
2
- EnforcedStyle: lf
3
- Style/MethodDefParentheses:
4
- Enabled: false
5
- Layout/EmptyLineAfterGuardClause:
6
- Enabled: false