solargraph 0.2.0 → 0.2.1
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 +79 -54
- data/lib/solargraph/code_map.rb +7 -3
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +18 -2
- 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: 6c7aa0f4315160d35f462c40d61d8118022b9f94
|
4
|
+
data.tar.gz: 7ee49c7852037b59c9652a37bfeb8c6622920e5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30406ab1d590dde9f8f0f425ac535e7773f1c8d651dbe904472ac11f04323a6e0ef6c1c1951e5f72b1e5d44a90393cc916a656c243f0131619a203048e28bec5
|
7
|
+
data.tar.gz: 8df3a01fafa6cf010913794b0aaa9967bd7373efc8c4c5a041c7bebaf386690612648f05cb3cf0a45a79404efd5d947aaf80662d39903cd47b7579734e3d3e5f
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -23,7 +23,7 @@ module Solargraph
|
|
23
23
|
def initialize workspace = nil
|
24
24
|
@workspace = workspace
|
25
25
|
clear
|
26
|
-
unless @workspace.nil?
|
26
|
+
unless @workspace.nil?
|
27
27
|
files = Dir[File.join workspace, 'lib', '**', '*.rb'] + Dir[File.join workspace, 'app', '**', '*.rb']
|
28
28
|
files.each { |f|
|
29
29
|
append_file f
|
@@ -291,7 +291,8 @@ module Solargraph
|
|
291
291
|
end
|
292
292
|
|
293
293
|
def get_methods(namespace, root = '')
|
294
|
-
meths =
|
294
|
+
meths = []
|
295
|
+
meths += inner_get_methods(namespace, root, []) #unless has_yardoc?
|
295
296
|
yard = YardMap.new(required: @required, workspace: @workspace)
|
296
297
|
meths += yard.get_methods(namespace, root)
|
297
298
|
type = get_namespace_type(namespace, root)
|
@@ -302,39 +303,28 @@ module Solargraph
|
|
302
303
|
end
|
303
304
|
meths
|
304
305
|
end
|
305
|
-
|
306
|
-
def
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
nodes.each { |n|
|
314
|
-
if n.kind_of?(AST::Node)
|
315
|
-
if n.type == :class and !n.children[1].nil?
|
316
|
-
s = unpack_name(n.children[1])
|
317
|
-
meths += inner_get_methods(s, root, skip)
|
318
|
-
end
|
319
|
-
n.children.each { |c|
|
320
|
-
if c.kind_of?(AST::Node) and c.type == :defs
|
321
|
-
docstring = get_comment_for(c)
|
322
|
-
meths.push Suggestion.new(c.children[1], kind: Suggestion::METHOD, documentation: docstring) if c.children[1].to_s[0].match(/[a-z_]/i) and c.children[1] != :def
|
323
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :include
|
324
|
-
# TODO This might not be right. Should we be getting singleton methods
|
325
|
-
# from an include, or only from an extend?
|
326
|
-
i = unpack_name(c.children[2])
|
327
|
-
meths += inner_get_methods(i, root, skip) unless i == 'Kernel'
|
328
|
-
end
|
329
|
-
}
|
306
|
+
|
307
|
+
def get_method_args node
|
308
|
+
list = nil
|
309
|
+
args = []
|
310
|
+
node.children.each { |c|
|
311
|
+
if c.kind_of?(AST::Node) and c.type == :args
|
312
|
+
list = c
|
313
|
+
break
|
330
314
|
end
|
331
315
|
}
|
332
|
-
|
316
|
+
return args if list.nil?
|
317
|
+
list.children.each { |c|
|
318
|
+
if c.type == :arg
|
319
|
+
args.push c.children[0]
|
320
|
+
end
|
321
|
+
}
|
322
|
+
args
|
333
323
|
end
|
334
|
-
|
324
|
+
|
335
325
|
def get_instance_methods(namespace, root = '')
|
336
326
|
meths = []
|
337
|
-
meths += inner_get_instance_methods(namespace, root, []) unless has_yardoc?
|
327
|
+
meths += inner_get_instance_methods(namespace, root, []) #unless has_yardoc?
|
338
328
|
yard = YardMap.new(required: @required, workspace: @workspace)
|
339
329
|
yard_meths = yard.get_instance_methods(namespace, root)
|
340
330
|
if yard_meths.any?
|
@@ -368,6 +358,60 @@ module Solargraph
|
|
368
358
|
}
|
369
359
|
return nil
|
370
360
|
end
|
361
|
+
|
362
|
+
def self.current
|
363
|
+
if @current.nil?
|
364
|
+
@current = ApiMap.new
|
365
|
+
@current.merge(Parser::CurrentRuby.parse(File.read("#{Solargraph::STUB_PATH}/ruby/2.3.0/core.rb")))
|
366
|
+
end
|
367
|
+
@current
|
368
|
+
end
|
369
|
+
|
370
|
+
def get_include_strings_from *nodes
|
371
|
+
arr = []
|
372
|
+
nodes.each { |node|
|
373
|
+
next unless node.kind_of?(AST::Node)
|
374
|
+
arr.push unpack_name(node.children[2]) if (node.type == :send and node.children[1] == :include)
|
375
|
+
node.children.each { |n|
|
376
|
+
arr += get_include_strings_from(n) if n.kind_of?(AST::Node) and n.type != :class and n.type != :module
|
377
|
+
}
|
378
|
+
}
|
379
|
+
arr
|
380
|
+
end
|
381
|
+
|
382
|
+
private
|
383
|
+
|
384
|
+
def inner_get_methods(namespace, root = '', skip = [])
|
385
|
+
meths = []
|
386
|
+
return meths if skip.include?(namespace)
|
387
|
+
skip.push namespace
|
388
|
+
fqns = find_fully_qualified_namespace(namespace, root)
|
389
|
+
return meths if fqns.nil?
|
390
|
+
nodes = get_namespace_nodes(fqns)
|
391
|
+
nodes.each { |n|
|
392
|
+
if n.kind_of?(AST::Node)
|
393
|
+
if n.type == :class and !n.children[1].nil?
|
394
|
+
s = unpack_name(n.children[1])
|
395
|
+
meths += inner_get_methods(s, root, skip)
|
396
|
+
end
|
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'
|
409
|
+
end
|
410
|
+
}
|
411
|
+
end
|
412
|
+
}
|
413
|
+
meths.uniq
|
414
|
+
end
|
371
415
|
|
372
416
|
def inner_get_instance_methods(namespace, root, skip)
|
373
417
|
fqns = find_fully_qualified_namespace(namespace, root)
|
@@ -390,7 +434,10 @@ module Solargraph
|
|
390
434
|
elsif current_scope == :public
|
391
435
|
if c.kind_of?(AST::Node) and c.type == :def
|
392
436
|
cmnt = get_comment_for(c)
|
393
|
-
|
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)
|
394
441
|
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_reader
|
395
442
|
c.children[2..-1].each { |x|
|
396
443
|
meths.push Suggestion.new(x.children[0], kind: Suggestion::METHOD) if x.type == :sym
|
@@ -414,29 +461,7 @@ module Solargraph
|
|
414
461
|
}
|
415
462
|
meths.uniq
|
416
463
|
end
|
417
|
-
|
418
|
-
def self.current
|
419
|
-
if @current.nil?
|
420
|
-
@current = ApiMap.new
|
421
|
-
@current.merge(Parser::CurrentRuby.parse(File.read("#{Solargraph::STUB_PATH}/ruby/2.3.0/core.rb")))
|
422
|
-
end
|
423
|
-
@current
|
424
|
-
end
|
425
|
-
|
426
|
-
def get_include_strings_from *nodes
|
427
|
-
arr = []
|
428
|
-
nodes.each { |node|
|
429
|
-
next unless node.kind_of?(AST::Node)
|
430
|
-
arr.push unpack_name(node.children[2]) if (node.type == :send and node.children[1] == :include)
|
431
|
-
node.children.each { |n|
|
432
|
-
arr += get_include_strings_from(n) if n.kind_of?(AST::Node) and n.type != :class and n.type != :module
|
433
|
-
}
|
434
|
-
}
|
435
|
-
arr
|
436
|
-
end
|
437
|
-
|
438
|
-
private
|
439
|
-
|
464
|
+
|
440
465
|
def mappable?(node)
|
441
466
|
# TODO Add node.type :casgn (constant assignment)
|
442
467
|
if node.kind_of?(AST::Node) and (node.type == :class or node.type == :module or node.type == :def or node.type == :defs or node.type == :ivasgn or node.type == :gvasgn or node.type == :or_asgn)
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -31,7 +31,6 @@ module Solargraph
|
|
31
31
|
tries = 0
|
32
32
|
# Hide incomplete code to avoid syntax errors
|
33
33
|
tmp = "#{@code}\nX".gsub(/[\.@]([\s])/, '#\1').gsub(/([\A\s]?)def([\s]*?[\n\Z])/, '\1#ef\2')
|
34
|
-
#tmp = code
|
35
34
|
begin
|
36
35
|
@node, comments = Parser::CurrentRuby.parse_with_comments(tmp)
|
37
36
|
@api_map.append_node(@node, comments, filename)
|
@@ -213,7 +212,12 @@ module Solargraph
|
|
213
212
|
if parts.length == 0
|
214
213
|
return @api_map.get_methods(first, ns_here)
|
215
214
|
end
|
216
|
-
|
215
|
+
meth = parts.shift
|
216
|
+
if meth == 'new'
|
217
|
+
obj = first
|
218
|
+
else
|
219
|
+
obj = get_method_return_value first, ns_here, meth
|
220
|
+
end
|
217
221
|
while parts.length > 0
|
218
222
|
obj = get_instance_method_return_value obj, ns_here, parts.shift
|
219
223
|
end
|
@@ -263,7 +267,7 @@ module Solargraph
|
|
263
267
|
parens = 0
|
264
268
|
signature = ''
|
265
269
|
index -=1
|
266
|
-
while index
|
270
|
+
while index >= 0
|
267
271
|
break if brackets > 0 or parens > 0 or squares > 0
|
268
272
|
char = @code[index, 1]
|
269
273
|
if char == ')'
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -96,7 +96,10 @@ module Solargraph
|
|
96
96
|
unless ns.nil?
|
97
97
|
ns.meths(scope: :class, visibility: [:public]).each { |m|
|
98
98
|
n = m.to_s.split('.').last
|
99
|
-
|
99
|
+
label = "#{n}"
|
100
|
+
args = get_method_args(m)
|
101
|
+
label += " #{args.join(', ')}" unless args.empty?
|
102
|
+
meths.push Suggestion.new(label, insert: "#{n}", kind: Suggestion::METHOD, detail: "#{ns}") if n.to_s.match(/^[a-z]/i)
|
100
103
|
}
|
101
104
|
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Class'
|
102
105
|
meths += get_instance_methods('Class')
|
@@ -122,7 +125,10 @@ module Solargraph
|
|
122
125
|
ns.meths(scope: :instance, visibility: [:public]).each { |m|
|
123
126
|
n = m.to_s.split('#').last
|
124
127
|
if n.to_s.match(/^[a-z]/i) and !m.to_s.start_with?('Kernel#') and !m.docstring.to_s.include?(':nodoc:')
|
125
|
-
|
128
|
+
label = "#{n}"
|
129
|
+
args = get_method_args(m)
|
130
|
+
label += " #{args.join(', ')}" unless args.empty?
|
131
|
+
meths.push Suggestion.new(label, insert: "#{n}", kind: Suggestion::METHOD, documentation: m.docstring, code_object: m, detail: "#{ns}", location: "#{m.file}:#{m.line}")
|
126
132
|
end
|
127
133
|
}
|
128
134
|
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Object'
|
@@ -133,6 +139,16 @@ module Solargraph
|
|
133
139
|
}
|
134
140
|
meths
|
135
141
|
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def get_method_args meth
|
146
|
+
args = []
|
147
|
+
meth.parameters.each { |a|
|
148
|
+
args.push a[0]
|
149
|
+
}
|
150
|
+
args
|
151
|
+
end
|
136
152
|
end
|
137
153
|
|
138
154
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|