solargraph 0.17.3 → 0.17.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.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map.rb +40 -52
- data/lib/solargraph/api_map/source.rb +23 -8
- data/lib/solargraph/code_map.rb +1 -0
- data/lib/solargraph/server.rb +10 -6
- data/lib/solargraph/suggestion.rb +1 -0
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 633e0f95c131f673e3c6372233ab7cfa49fe972a
|
4
|
+
data.tar.gz: d934af34ec402bac6d4604dff276e4070e56b3d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e70e12fa5c2a7daef95b96c7c31dd0b52d2dd7bf4c2ccf7cbafb0f0d86b6fecfc4165c11225f1fa7a6173e5bb09c99a509d669a1726c9f1d4b8db9e13f45fc19
|
7
|
+
data.tar.gz: 3c923301b70d4091fd4c508921ef1a577968183fe117d5a0fb730cddc3c7ee2705779cdc5bbba388abf85b82016d56521079624c39c32a7c8c77fbf72e0fe2b3
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -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
|
205
|
+
# @param context [String] The context to search
|
206
206
|
# @return [Array<Solargraph::Suggestion>]
|
207
|
-
def get_constants namespace,
|
208
|
-
result = []
|
207
|
+
def get_constants namespace, context = ''
|
209
208
|
skip = []
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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 =
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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.
|
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 =
|
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
|
964
|
-
return [] if skip.include?(
|
965
|
-
skip.push
|
961
|
+
def inner_get_constants fqns, visibility, skip
|
962
|
+
return [] if skip.include?(fqns)
|
963
|
+
skip.push fqns
|
966
964
|
result = []
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
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 =
|
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
|
-
|
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 =
|
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 =
|
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
|
441
|
-
|
442
|
-
Source.new(code,
|
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
|
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -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
|
data/lib/solargraph/server.rb
CHANGED
@@ -213,12 +213,16 @@ module Solargraph
|
|
213
213
|
end
|
214
214
|
|
215
215
|
def run!
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|