solargraph 0.17.3 → 0.17.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e42b128f6b533cce21220f0f3bc674fc2a20157
4
- data.tar.gz: 3a9d391b9f2982529a0de8cb038dd593924093c4
3
+ metadata.gz: 633e0f95c131f673e3c6372233ab7cfa49fe972a
4
+ data.tar.gz: d934af34ec402bac6d4604dff276e4070e56b3d9
5
5
  SHA512:
6
- metadata.gz: 987ecb11f32e4b621d734c388d2365b03a2af86b37e2ee6fea5b81fafc2edc63ac37908070fd91ce24aa47772c8772f8be2526ba1ec246edba64a9606fc529d2
7
- data.tar.gz: a3f0bc9c84895bf888f6729d7eba91fe078ba946fbdff9f4cc6736546b6a7561dffc084d6339eb258a16f2d1aab0a6eb553f68ea7591fc7b5c1ba71300b731b7
6
+ metadata.gz: e70e12fa5c2a7daef95b96c7c31dd0b52d2dd7bf4c2ccf7cbafb0f0d86b6fecfc4165c11225f1fa7a6173e5bb09c99a509d669a1726c9f1d4b8db9e13f45fc19
7
+ data.tar.gz: 3c923301b70d4091fd4c508921ef1a577968183fe117d5a0fb730cddc3c7ee2705779cdc5bbba388abf85b82016d56521079624c39c32a7c8c77fbf72e0fe2b3
@@ -32,7 +32,7 @@ module Solargraph
32
32
  workspace_files.each do |wf|
33
33
  begin
34
34
  @@source_cache[wf] ||= Source.load(wf)
35
- rescue Parser::SyntaxError => e
35
+ rescue Parser::SyntaxError, EncodingError => e
36
36
  STDERR.puts "Failed to load #{wf}: #{e.message}"
37
37
  @@source_cache[wf] = Source.virtual('', wf)
38
38
  end
@@ -202,31 +202,27 @@ module Solargraph
202
202
  # will include constant variables, classes, and modules.
203
203
  #
204
204
  # @param namespace [String] The namespace to match
205
- # @param root [String] The context to search
205
+ # @param context [String] The context to search
206
206
  # @return [Array<Solargraph::Suggestion>]
207
- def get_constants namespace, root = ''
208
- result = []
207
+ def get_constants namespace, context = ''
209
208
  skip = []
210
- fqns = find_fully_qualified_namespace(namespace, root)
211
- return [] if fqns.nil?
212
- if fqns.empty?
213
- result.concat inner_get_constants('', skip, false, [:public])
209
+ result = []
210
+ if context.empty?
211
+ visi = [:public]
212
+ visi.push :private if namespace.empty?
213
+ result.concat inner_get_constants(namespace, visi, skip)
214
214
  else
215
- parts = fqns.split('::')
216
- while parts.length > 0
217
- resolved = find_namespace_pins(parts.join('::'))
218
- resolved.each do |pin|
219
- visi = [:public]
220
- visi.push :private if namespace == '' and root != '' and pin.path == fqns
221
- result.concat inner_get_constants(pin.path, skip, true, visi)
222
- end
215
+ parts = context.split('::')
216
+ until parts.empty?
217
+ subcontext = parts.join('::')
218
+ fqns = find_fully_qualified_namespace(namespace, subcontext)
219
+ visi = [:public]
220
+ visi.push :private if namespace.empty? and subcontext == context
221
+ result.concat inner_get_constants(fqns, visi, skip)
223
222
  parts.pop
224
- break unless namespace.empty?
225
223
  end
226
- result.concat inner_get_constants('', [], false) if namespace.empty?
227
224
  end
228
- result.concat yard_map.get_constants(fqns)
229
- result
225
+ result.map{|pin| Suggestion.pull(pin)}
230
226
  end
231
227
 
232
228
  # Get a fully qualified namespace name. This method will start the search
@@ -347,7 +343,8 @@ module Solargraph
347
343
  return nil if pins.nil?
348
344
  pin = pins.select{|p| p.name == var and p.scope == scope}.first
349
345
  return nil if pin.nil?
350
- type = pin.return_type
346
+ type = nil
347
+ type = find_fully_qualified_namespace(pin.return_type, pin.namespace) unless pin.return_type.nil?
351
348
  if type.nil?
352
349
  zparts = resolve_node_signature(pin.assignment_node).split('.')
353
350
  ztype = infer_signature_type(zparts[0..-2].join('.'), namespace, scope: :instance, call_node: pin.assignment_node)
@@ -363,8 +360,8 @@ module Solargraph
363
360
  pins = @cvar_pins[fqns]
364
361
  return nil if pins.nil?
365
362
  pin = pins.select{|p| p.name == var}.first
366
- return nil if pin.nil?
367
- pin.return_type
363
+ return nil if pin.nil? or pin.return_type.nil?
364
+ find_fully_qualified_namespace(pin.return_type, pin.namespace)
368
365
  end
369
366
 
370
367
  # @return [Array<Solargraph::Suggestion>]
@@ -796,12 +793,12 @@ module Solargraph
796
793
  @symbol_pins.push Suggestion.new(pin.name, kind: Suggestion::CONSTANT, return_type: 'Symbol')
797
794
  end
798
795
  source.namespace_includes.each_pair do |ns, i|
799
- @namespace_includes[ns] ||= []
800
- @namespace_includes[ns].concat(i).uniq!
796
+ @namespace_includes[ns || ''] ||= []
797
+ @namespace_includes[ns || ''].concat(i).uniq!
801
798
  end
802
799
  source.namespace_extends.each_pair do |ns, e|
803
- @namespace_extends[ns] ||= []
804
- @namespace_extends[ns].concat(e).uniq!
800
+ @namespace_extends[ns || ''] ||= []
801
+ @namespace_extends[ns || ''].concat(e).uniq!
805
802
  end
806
803
  source.superclasses.each_pair do |cls, sup|
807
804
  @superclasses[cls] = sup
@@ -849,6 +846,7 @@ module Solargraph
849
846
  meths.concat get_instance_methods(e, fqns, visibility: visibility)
850
847
  end
851
848
  end
849
+ meths.concat get_instance_methods('', '', visibility: [:public])
852
850
  meths.uniq
853
851
  end
854
852
 
@@ -960,32 +958,21 @@ module Solargraph
960
958
  type
961
959
  end
962
960
 
963
- def inner_get_constants here, skip = [], deep = true, visibility = [:public]
964
- return [] if skip.include?(here)
965
- skip.push here
961
+ def inner_get_constants fqns, visibility, skip
962
+ return [] if skip.include?(fqns)
963
+ skip.push fqns
966
964
  result = []
967
- cp = @const_pins[here]
968
- unless cp.nil?
969
- cp.each do |pin|
970
- result.push pin_to_suggestion(pin) if pin.visibility == :public or visibility.include?(:private)
971
- end
972
- end
973
- np = @namespace_pins[here]
974
- unless np.nil?
975
- np.each do |pin|
976
- if pin.visibility == :public || visibility.include?(:private)
977
- result.push pin_to_suggestion(pin)
978
- if deep
979
- get_include_strings_from(pin.node).each do |i|
980
- result.concat inner_get_constants(i, skip, false, [:public])
981
- end
982
- end
983
- end
965
+ result.concat @const_pins[fqns] if @const_pins.has_key?(fqns)
966
+ result.concat @namespace_pins[fqns] if @namespace_pins.has_key?(fqns)
967
+ result.keep_if{|pin| visibility.include?(pin.visibility)}
968
+ result.concat yard_map.get_constants(fqns)
969
+ is = @namespace_includes[fqns]
970
+ unless is.nil?
971
+ is.each do |i|
972
+ here = find_fully_qualified_namespace(i, fqns)
973
+ result.concat inner_get_constants(here, [:public], skip)
984
974
  end
985
975
  end
986
- get_include_strings_from(*get_namespace_nodes(here)).each do |i|
987
- result.concat inner_get_constants(i, skip, false, [:public])
988
- end
989
976
  result
990
977
  end
991
978
 
@@ -1011,14 +998,15 @@ module Solargraph
1011
998
  # @param pin [Solargraph::Pin::Base]
1012
999
  # @return [Solargraph::Suggestion]
1013
1000
  def pin_to_suggestion pin
1014
- return_type = pin.return_type
1001
+ return_type = nil
1002
+ return_type = find_fully_qualified_namespace(pin.return_type, pin.namespace) unless pin.return_type.nil?
1015
1003
  if return_type.nil? and pin.is_a?(Solargraph::Pin::Method)
1016
1004
  sc = @superclasses[pin.namespace]
1017
1005
  while return_type.nil? and !sc.nil?
1018
1006
  sc_path = "#{sc}#{pin.scope == :instance ? '#' : '.'}#{pin.name}"
1019
1007
  sugg = get_path_suggestions(sc_path).first
1020
1008
  break if sugg.nil?
1021
- return_type = sugg.return_type
1009
+ return_type = find_fully_qualified_namespace(sugg.return_type, sugg.namespace) unless sugg.return_type.nil?
1022
1010
  sc = @superclasses[sc]
1023
1011
  end
1024
1012
  end
@@ -3,6 +3,12 @@ require 'parser/current'
3
3
  module Solargraph
4
4
  class ApiMap
5
5
  class Source
6
+ class FlawedBuilder < Parser::Builders::Default
7
+ def string_value(token)
8
+ value(token)
9
+ end
10
+ end
11
+
6
12
  # @return [String]
7
13
  attr_reader :code
8
14
 
@@ -34,7 +40,7 @@ module Solargraph
34
40
  @comments = comments
35
41
  @directives = {}
36
42
  @path_macros = {}
37
- @docstring_hash = associate_comments(node, comments)
43
+ @docstring_hash = associate_comments(node, comments) || {}
38
44
  @filename = filename
39
45
  @mtime = (!filename.nil? and File.exist?(filename) ? File.mtime(filename) : nil)
40
46
  @namespace_nodes = {}
@@ -189,6 +195,7 @@ module Solargraph
189
195
  private
190
196
 
191
197
  def associate_comments node, comments
198
+ return nil if comments.nil?
192
199
  comment_hash = Parser::Source::Comment.associate_locations(node, comments)
193
200
  yard_hash = {}
194
201
  comment_hash.each_pair { |k, v|
@@ -381,13 +388,12 @@ module Solargraph
381
388
  class << self
382
389
  # @return [Solargraph::ApiMap::Source]
383
390
  def load filename
384
- code = File.read(filename).gsub(/\r/, '')
385
- Source.virtual(code, filename)
391
+ Source.virtual(File.read(filename), filename)
386
392
  end
387
393
 
388
394
  # @return [Solargraph::ApiMap::Source]
389
395
  def virtual code, filename = nil
390
- node, comments = Parser::CurrentRuby.parse_with_comments(code)
396
+ node, comments = Source.parse(code, filename)
391
397
  Source.new(code, node, comments, filename)
392
398
  end
393
399
 
@@ -407,6 +413,15 @@ module Solargraph
407
413
  [line, col]
408
414
  end
409
415
 
416
+ def parse code, filename = nil
417
+ parser = Parser::CurrentRuby.new(FlawedBuilder.new)
418
+ parser.diagnostics.all_errors_are_fatal = true
419
+ parser.diagnostics.ignore_warnings = true
420
+ buffer = Parser::Source::Buffer.new(filename, 1)
421
+ buffer.source = code
422
+ parser.parse_with_comments(buffer)
423
+ end
424
+
410
425
  def fix code, filename = nil, offset = nil
411
426
  tries = 0
412
427
  code.gsub!(/\r/, '')
@@ -417,7 +432,7 @@ module Solargraph
417
432
  fixed_position = false
418
433
  tmp = code
419
434
  begin
420
- node, comments = Parser::CurrentRuby.parse_with_comments(tmp)
435
+ node, comments = parse(tmp, filename)
421
436
  Source.new(code, node, comments, filename, stubs)
422
437
  rescue Parser::SyntaxError => e
423
438
  if tries < 10
@@ -437,9 +452,9 @@ module Solargraph
437
452
  end
438
453
  retry
439
454
  end
440
- STDERR.puts "Unable to parse code: #{e.message}"
441
- virt = Source.virtual('', filename)
442
- Source.new(code, virt.node, virt.comments, filename)
455
+ STDERR.puts "Unable to parse file #{filename.nil? ? 'undefined' : filename}: #{e.message}"
456
+ node, comments = parse(code.gsub(/[^\s]/, ' '), filename)
457
+ Source.new(code, node, comments, filename)
443
458
  end
444
459
  end
445
460
 
@@ -241,6 +241,7 @@ module Solargraph
241
241
  result.concat api_map.get_constants('')
242
242
  result.concat api_map.get_instance_methods('Kernel', namespace)
243
243
  result.concat api_map.get_methods('', namespace)
244
+ result.concat api_map.get_instance_methods('', namespace)
244
245
  else
245
246
  result.concat api_map.get_instance_methods(type) unless @code[index - 1] != '.'
246
247
  end
@@ -213,12 +213,16 @@ module Solargraph
213
213
  end
214
214
 
215
215
  def run!
216
- Thread.new do
217
- while true
218
- check_workspaces
219
- sleep 1
220
- end
221
- end
216
+ # @todo The thread for checking workspaces is temporarily disabled due
217
+ # to high CPU cost. We need to determine whether the process should
218
+ # be optimized or eliminated altogether.
219
+ #
220
+ # Thread.new do
221
+ # while true
222
+ # check_workspaces
223
+ # sleep 1
224
+ # end
225
+ # end
222
226
  super
223
227
  end
224
228
 
@@ -146,6 +146,7 @@ module Solargraph
146
146
  #
147
147
  # @param pin [Solargraph::Pin::Base]
148
148
  def self.pull pin, return_type = nil
149
+ return pin if pin.kind_of?(Suggestion)
149
150
  Suggestion.new(pin.name, insert: pin.name.gsub(/=$/, ' = '), kind: pin.kind, docstring: pin.docstring, detail: pin.namespace, arguments: pin.parameters, path: pin.path, return_type: return_type || pin.return_type, location: pin.location)
150
151
  end
151
152
  end
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.17.3'
2
+ VERSION = '0.17.4'
3
3
  end
@@ -330,6 +330,7 @@ module Solargraph
330
330
 
331
331
  def process_requires
332
332
  required.each do |r|
333
+ next if !workspace.nil? and File.exist?(File.join workspace, 'lib', "#{r}.rb")
333
334
  spec = Gem::Specification.find_by_path(r)
334
335
  begin
335
336
  spec = Gem::Specification.find_by_name(r) if spec.nil?
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.17.3
4
+ version: 0.17.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: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser