solargraph 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solargraph.rb +3 -2
- data/lib/solargraph/api_map.rb +86 -63
- data/lib/solargraph/code_map.rb +3 -0
- data/lib/solargraph/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb228dbd2c050d2937573b2e4a4249fb951da217
|
4
|
+
data.tar.gz: 1af21e85d38cc159b53fc69ba05aeb4011d41a4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8804b2ea16a1e6b5e1568a683af153a89da87f219ba00cd6b4338d4044c97f92486cfdc7c3f13009c6547b1750d98f1e5574a40f6f97c73435ab314368f6e48b
|
7
|
+
data.tar.gz: 45928e94fefe7fc5a78609b808666e6805e6a654dabe9b91a964b0c57155641544671848922e1c73434e63fac1e67418beefffebea1da59ec8f58c72efb80b6c
|
data/lib/solargraph.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'solargraph/version'
|
2
|
+
require 'rubygems/package'
|
2
3
|
|
3
4
|
module Solargraph
|
4
5
|
autoload :Analyzer, 'solargraph/analyzer'
|
@@ -21,7 +22,7 @@ cache_dir = File.join(Dir.home, '.solargraph', 'cache')
|
|
21
22
|
version_dir = File.join(cache_dir, '2.0.0')
|
22
23
|
unless File.exist?(version_dir)
|
23
24
|
FileUtils.mkdir_p cache_dir
|
24
|
-
FileUtils.cp File.join(Solargraph::YARDOC_PATH, '2.0.0.tar.gz')
|
25
|
+
FileUtils.cp File.join(Solargraph::YARDOC_PATH, '2.0.0.tar.gz'), cache_dir
|
25
26
|
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(File.join(cache_dir, '2.0.0.tar.gz')))
|
26
27
|
tar_extract.rewind
|
27
28
|
tar_extract.each do |entry|
|
@@ -35,5 +36,5 @@ unless File.exist?(version_dir)
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
tar_extract.close
|
38
|
-
FileUtils.rm File.join(cache_dir, '2.0.0.tar.gz')
|
39
|
+
#FileUtils.rm File.join(cache_dir, '2.0.0.tar.gz')
|
39
40
|
end
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -24,7 +24,7 @@ module Solargraph
|
|
24
24
|
@workspace = workspace
|
25
25
|
clear
|
26
26
|
unless @workspace.nil?
|
27
|
-
files = Dir[File.join workspace, 'lib', '**', '*.rb'] + Dir[File.join workspace, 'app', '**', '*.rb']
|
27
|
+
files = Dir[File.join @workspace, 'lib', '**', '*.rb'] + Dir[File.join @workspace, 'app', '**', '*.rb']
|
28
28
|
files.each { |f|
|
29
29
|
append_file f
|
30
30
|
}
|
@@ -44,6 +44,15 @@ module Solargraph
|
|
44
44
|
workspace and File.exist?(File.join(workspace, '.yardoc'))
|
45
45
|
end
|
46
46
|
|
47
|
+
def yardoc_has_file?(filename)
|
48
|
+
return false unless has_yardoc?
|
49
|
+
return false if filename.nil?
|
50
|
+
if filename.start_with?(File.join(workspace, 'lib'), File.join(workspace, 'app'))
|
51
|
+
return true
|
52
|
+
end
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
47
56
|
def append_file filename
|
48
57
|
append_source File.read(filename), filename
|
49
58
|
end
|
@@ -136,6 +145,9 @@ module Solargraph
|
|
136
145
|
else
|
137
146
|
return result if skip.include?(fqns)
|
138
147
|
skip.push fqns
|
148
|
+
nodes = get_namespace_nodes(fqns)
|
149
|
+
nodes.delete_if { |n| yardoc_has_file?(get_filename_for(n))}
|
150
|
+
return result if nodes.empty?
|
139
151
|
cursor = @namespace_tree
|
140
152
|
parts = fqns.split('::')
|
141
153
|
parts.each { |p|
|
@@ -223,12 +235,15 @@ module Solargraph
|
|
223
235
|
end
|
224
236
|
|
225
237
|
def get_root_for(node)
|
226
|
-
|
238
|
+
s = @parent_stack[node]
|
239
|
+
return nil if s.nil?
|
240
|
+
return node if s.empty?
|
241
|
+
s.last
|
227
242
|
end
|
228
243
|
|
229
244
|
def get_filename_for(node)
|
230
245
|
root = get_root_for(node)
|
231
|
-
root.children[0]
|
246
|
+
root.nil? ? nil : root.children[0]
|
232
247
|
end
|
233
248
|
|
234
249
|
def inner_get_instance_variables(node, scope)
|
@@ -294,14 +309,18 @@ module Solargraph
|
|
294
309
|
meths = []
|
295
310
|
meths += inner_get_methods(namespace, root, []) #unless has_yardoc?
|
296
311
|
yard = YardMap.new(required: @required, workspace: @workspace)
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
312
|
+
yard_meths = yard.get_methods(namespace, root)
|
313
|
+
if yard_meths.any?
|
314
|
+
meths.concat yard_meths
|
315
|
+
else
|
316
|
+
type = get_namespace_type(namespace, root)
|
317
|
+
if type == :class
|
318
|
+
meths += yard.get_instance_methods('Class')
|
319
|
+
elsif type == :module
|
320
|
+
meths += yard.get_methods('Module')
|
321
|
+
end
|
322
|
+
meths
|
303
323
|
end
|
304
|
-
meths
|
305
324
|
end
|
306
325
|
|
307
326
|
def get_method_args node
|
@@ -389,25 +408,27 @@ module Solargraph
|
|
389
408
|
return meths if fqns.nil?
|
390
409
|
nodes = get_namespace_nodes(fqns)
|
391
410
|
nodes.each { |n|
|
392
|
-
|
393
|
-
if n.
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
n.children.each { |c|
|
398
|
-
if c.kind_of?(AST::Node) and c.type == :defs
|
399
|
-
docstring = get_comment_for(c)
|
400
|
-
label = "#{c.children[1]}"
|
401
|
-
args = get_method_args(c)
|
402
|
-
label += " #{args.join(', ')}" unless args.empty?
|
403
|
-
meths.push Suggestion.new(label, insert: c.children[1].to_s, kind: Suggestion::METHOD, detail: 'Method', documentation: docstring) if c.children[1].to_s[0].match(/[a-z_]/i) and c.children[1] != :def
|
404
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :include
|
405
|
-
# TODO: This might not be right. Should we be getting singleton methods
|
406
|
-
# from an include, or only from an extend?
|
407
|
-
i = unpack_name(c.children[2])
|
408
|
-
meths += inner_get_methods(i, root, skip) unless i == 'Kernel'
|
411
|
+
unless yardoc_has_file?(get_filename_for(n))
|
412
|
+
if n.kind_of?(AST::Node)
|
413
|
+
if n.type == :class and !n.children[1].nil?
|
414
|
+
s = unpack_name(n.children[1])
|
415
|
+
meths += inner_get_methods(s, root, skip)
|
409
416
|
end
|
410
|
-
|
417
|
+
n.children.each { |c|
|
418
|
+
if c.kind_of?(AST::Node) and c.type == :defs
|
419
|
+
docstring = get_comment_for(c)
|
420
|
+
label = "#{c.children[1]}"
|
421
|
+
args = get_method_args(c)
|
422
|
+
label += " #{args.join(', ')}" unless args.empty?
|
423
|
+
meths.push Suggestion.new(label, insert: c.children[1].to_s, kind: Suggestion::METHOD, detail: 'Method', documentation: docstring) if c.children[1].to_s[0].match(/[a-z_]/i) and c.children[1] != :def
|
424
|
+
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :include
|
425
|
+
# TODO: This might not be right. Should we be getting singleton methods
|
426
|
+
# from an include, or only from an extend?
|
427
|
+
i = unpack_name(c.children[2])
|
428
|
+
meths += inner_get_methods(i, root, skip) unless i == 'Kernel'
|
429
|
+
end
|
430
|
+
}
|
431
|
+
end
|
411
432
|
end
|
412
433
|
}
|
413
434
|
meths.uniq
|
@@ -420,43 +441,45 @@ module Solargraph
|
|
420
441
|
skip.push fqns
|
421
442
|
nodes = get_namespace_nodes(fqns)
|
422
443
|
nodes.each { |n|
|
423
|
-
|
424
|
-
if n.
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
current_scope = :public
|
429
|
-
n.children.each { |c|
|
430
|
-
if c.kind_of?(AST::Node) and c.type == :send and [:public, :protected, :private].include?(c.children[1])
|
431
|
-
# TODO: Determine the current scope so we can decide whether to
|
432
|
-
# exclude protected or private methods. Right now we're just
|
433
|
-
# assuming public only
|
434
|
-
elsif current_scope == :public
|
435
|
-
if c.kind_of?(AST::Node) and c.type == :def
|
436
|
-
cmnt = get_comment_for(c)
|
437
|
-
label = "#{c.children[0]}"
|
438
|
-
args = get_method_args(c)
|
439
|
-
label += " #{args.join(', ')}" unless args.empty?
|
440
|
-
meths.push Suggestion.new(label, insert: c.children[0].to_s, kind: Suggestion::METHOD, documentation: cmnt, detail: fqns) if c.children[0].to_s[0].match(/[a-z]/i)
|
441
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_reader
|
442
|
-
c.children[2..-1].each { |x|
|
443
|
-
meths.push Suggestion.new(x.children[0], kind: Suggestion::METHOD) if x.type == :sym
|
444
|
-
}
|
445
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_writer
|
446
|
-
c.children[2..-1].each { |x|
|
447
|
-
meths.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::METHOD) if x.type == :sym
|
448
|
-
}
|
449
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_accessor
|
450
|
-
c.children[2..-1].each { |x|
|
451
|
-
meths.push Suggestion.new(x.children[0], kind: Suggestion::METHOD) if x.type == :sym
|
452
|
-
meths.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::METHOD) if x.type == :sym
|
453
|
-
}
|
454
|
-
end
|
444
|
+
unless yardoc_has_file?(get_filename_for(n))
|
445
|
+
if n.kind_of?(AST::Node)
|
446
|
+
if n.type == :class and !n.children[1].nil?
|
447
|
+
s = unpack_name(n.children[1])
|
448
|
+
meths += inner_get_instance_methods(s, namespace, skip)
|
455
449
|
end
|
456
|
-
|
457
|
-
|
450
|
+
current_scope = :public
|
451
|
+
n.children.each { |c|
|
452
|
+
if c.kind_of?(AST::Node) and c.type == :send and [:public, :protected, :private].include?(c.children[1])
|
453
|
+
# TODO: Determine the current scope so we can decide whether to
|
454
|
+
# exclude protected or private methods. Right now we're just
|
455
|
+
# assuming public only
|
456
|
+
elsif current_scope == :public
|
457
|
+
if c.kind_of?(AST::Node) and c.type == :def
|
458
|
+
cmnt = get_comment_for(c)
|
459
|
+
label = "#{c.children[0]}"
|
460
|
+
args = get_method_args(c)
|
461
|
+
label += " #{args.join(', ')}" unless args.empty?
|
462
|
+
meths.push Suggestion.new(label, insert: c.children[0].to_s, kind: Suggestion::METHOD, documentation: cmnt, detail: fqns) if c.children[0].to_s[0].match(/[a-z]/i)
|
463
|
+
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_reader
|
464
|
+
c.children[2..-1].each { |x|
|
465
|
+
meths.push Suggestion.new(x.children[0], kind: Suggestion::METHOD) if x.type == :sym
|
466
|
+
}
|
467
|
+
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_writer
|
468
|
+
c.children[2..-1].each { |x|
|
469
|
+
meths.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::METHOD) if x.type == :sym
|
470
|
+
}
|
471
|
+
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_accessor
|
472
|
+
c.children[2..-1].each { |x|
|
473
|
+
meths.push Suggestion.new(x.children[0], kind: Suggestion::METHOD) if x.type == :sym
|
474
|
+
meths.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::METHOD) if x.type == :sym
|
475
|
+
}
|
476
|
+
end
|
477
|
+
end
|
478
|
+
get_include_strings_from(n).each { |i|
|
479
|
+
meths += inner_get_instance_methods(i, fqns, skip)
|
480
|
+
}
|
458
481
|
}
|
459
|
-
|
482
|
+
end
|
460
483
|
end
|
461
484
|
}
|
462
485
|
meths.uniq
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -8,6 +8,9 @@ module Solargraph
|
|
8
8
|
include NodeMethods
|
9
9
|
|
10
10
|
def initialize code: '', filename: nil, workspace: nil
|
11
|
+
unless workspace.nil?
|
12
|
+
workspace = workspace.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
|
13
|
+
end
|
11
14
|
if workspace.nil? and !filename.nil?
|
12
15
|
filename = filename.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
|
13
16
|
workspace = CodeMap.find_workspace(filename)
|
data/lib/solargraph/version.rb
CHANGED