solargraph 0.8.1 → 0.8.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/api_map.rb +14 -3
- data/lib/solargraph/code_map.rb +165 -173
- data/lib/solargraph/suggestion.rb +1 -1
- data/lib/solargraph/version.rb +1 -1
- 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: e47975025923e6fefaa775875a539c14a8ce263b
|
4
|
+
data.tar.gz: 253ceb89deba6b4a3e63a7861a167c7bd24e64eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b563880f6b352616b38c1accb2d0f07b189e23b25cbcc816c54bf1a3acae1b1e130b0f7f565110008bb4561234ff423bbb553843ffef1aba958164e61dd161a7
|
7
|
+
data.tar.gz: c6dbd8e28a73bf8ce205508b87146d6a189b8c216d42a2c72f1c5ce8d32796fb57a52f967278e36a07f89e8f5e3fa108ee6a0cbd048e8df858b9c032347ba19e
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -337,6 +337,7 @@ module Solargraph
|
|
337
337
|
while parts.length > 0 and !type.nil?
|
338
338
|
p = parts.shift
|
339
339
|
if top and scope == :class
|
340
|
+
next if p == 'new'
|
340
341
|
first_class = find_fully_qualified_namespace(p, namespace)
|
341
342
|
sub = nil
|
342
343
|
sub = infer_signature_type(parts.join('.'), first_class, scope: :class) unless first_class.nil?
|
@@ -580,7 +581,7 @@ module Solargraph
|
|
580
581
|
def mappable?(node)
|
581
582
|
return true if node.kind_of?(AST::Node) and [:array, :hash, :str, :int, :float].include?(node.type)
|
582
583
|
# TODO Add node.type :casgn (constant assignment)
|
583
|
-
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 == :lvasgn or node.type == :or_asgn or node.type == :const or node.type == :lvar)
|
584
|
+
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 == :lvasgn or node.type == :or_asgn or node.type == :const or node.type == :lvar or node.type == :args or node.type == :kwargs)
|
584
585
|
true
|
585
586
|
elsif node.kind_of?(AST::Node) and node.type == :send and node.children[0] == nil and MAPPABLE_METHODS.include?(node.children[1])
|
586
587
|
true
|
@@ -618,7 +619,7 @@ module Solargraph
|
|
618
619
|
children += node.children[0, 2]
|
619
620
|
children += get_mappable_nodes(node.children[2..-1], comment_hash)
|
620
621
|
#children += get_mappable_nodes(node.children, comment_hash)
|
621
|
-
elsif node.type == :const
|
622
|
+
elsif node.type == :const or node.type == :args or node.type == :kwargs
|
622
623
|
children += node.children
|
623
624
|
elsif node.type == :def
|
624
625
|
children += node.children[0, 2]
|
@@ -634,7 +635,10 @@ module Solargraph
|
|
634
635
|
elsif node.type == :send and node.children[1] == :include
|
635
636
|
children += node.children[0,3]
|
636
637
|
elsif node.type == :send and node.children[1] == :require
|
637
|
-
|
638
|
+
if node.children[2].children[0].kind_of?(String)
|
639
|
+
path = node.children[2].children[0].to_s
|
640
|
+
@required.push(path) unless local_path?(path)
|
641
|
+
end
|
638
642
|
children += node.children[0, 3]
|
639
643
|
elsif node.type == :send and node.children[1] == :autoload
|
640
644
|
@required.push(node.children[3].children[0]) if node.children[3].children[0].kind_of?(String)
|
@@ -653,6 +657,13 @@ module Solargraph
|
|
653
657
|
result
|
654
658
|
end
|
655
659
|
|
660
|
+
def local_path? path
|
661
|
+
return false if workspace.nil?
|
662
|
+
return true if File.exist?(File.join workspace, 'lib', path)
|
663
|
+
return true if File.exist?(File.join workspace, 'lib', "#{path}.rb")
|
664
|
+
false
|
665
|
+
end
|
666
|
+
|
656
667
|
def map_parents node, tree = []
|
657
668
|
if node.kind_of?(AST::Node)
|
658
669
|
@parent_stack[node] = tree
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -3,9 +3,9 @@ require 'parser/current'
|
|
3
3
|
module Solargraph
|
4
4
|
class CodeMap
|
5
5
|
attr_accessor :node
|
6
|
-
attr_accessor :api_map
|
7
6
|
attr_reader :code
|
8
7
|
attr_reader :parsed
|
8
|
+
attr_reader :workspace
|
9
9
|
|
10
10
|
include NodeMethods
|
11
11
|
|
@@ -17,49 +17,54 @@ module Solargraph
|
|
17
17
|
filename = filename.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
|
18
18
|
workspace = CodeMap.find_workspace(filename)
|
19
19
|
end
|
20
|
+
@workspace = workspace
|
20
21
|
@filename = filename
|
21
22
|
@api_map = api_map
|
22
|
-
if @api_map.nil?
|
23
|
-
@api_map = ApiMap.new(workspace)
|
24
|
-
end
|
25
23
|
@code = code.gsub(/\r/, '')
|
26
24
|
tries = 0
|
27
25
|
tmp = @code
|
28
26
|
begin
|
29
27
|
node, comments = Parser::CurrentRuby.parse_with_comments(tmp)
|
30
|
-
@node =
|
28
|
+
@node = self.api_map.append_node(node, comments, filename)
|
31
29
|
@parsed = tmp
|
32
30
|
@code.freeze
|
33
31
|
@parsed.freeze
|
34
32
|
rescue Parser::SyntaxError => e
|
35
33
|
if tries < 10
|
36
|
-
STDERR.puts "Error parsing #{filename}: #{e.message}"
|
37
|
-
STDERR.puts "Retrying..."
|
38
34
|
tries += 1
|
39
|
-
|
40
|
-
|
41
|
-
if tmp[spot] == '@' or tmp[spot] == ':'
|
42
|
-
# Stub unfinished instance variables and symbols
|
43
|
-
spot -= 1
|
44
|
-
elsif tmp[spot - 1] == '.'
|
45
|
-
# Stub unfinished method calls
|
46
|
-
repl = '#' if spot == tmp.length or tmp[spot] == '\n'
|
47
|
-
spot -= 2
|
35
|
+
if tries == 10 and e.message.include?('token $end')
|
36
|
+
tmp += "\nend"
|
48
37
|
else
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
38
|
+
spot = e.diagnostic.location.begin_pos
|
39
|
+
repl = '_'
|
40
|
+
if tmp[spot] == '@' or tmp[spot] == ':'
|
41
|
+
# Stub unfinished instance variables and symbols
|
42
|
+
spot -= 1
|
43
|
+
elsif tmp[spot - 1] == '.'
|
44
|
+
# Stub unfinished method calls
|
45
|
+
repl = '#' if spot == tmp.length or tmp[spot] == '\n'
|
46
|
+
spot -= 2
|
47
|
+
else
|
48
|
+
# Stub the whole line
|
49
|
+
spot = beginning_of_line_from(tmp, spot)
|
50
|
+
repl = '#'
|
51
|
+
if tmp[spot+1..-1].rstrip == 'end'
|
52
|
+
repl= 'end;end'
|
53
|
+
end
|
54
54
|
end
|
55
|
+
tmp = tmp[0..spot] + repl + tmp[spot+repl.length+1..-1].to_s
|
55
56
|
end
|
56
|
-
tmp = tmp[0..spot] + repl + tmp[spot+repl.length+1..-1].to_s
|
57
57
|
retry
|
58
58
|
end
|
59
59
|
raise e
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# @return [Solargraph::ApiMap]
|
64
|
+
def api_map
|
65
|
+
@api_map ||= ApiMap.new(workspace)
|
66
|
+
end
|
67
|
+
|
63
68
|
def self.find_workspace filename
|
64
69
|
return nil if filename.nil?
|
65
70
|
dirname = filename
|
@@ -103,6 +108,9 @@ module Solargraph
|
|
103
108
|
tree_at(index).first
|
104
109
|
end
|
105
110
|
|
111
|
+
# Determine if the specified index is inside a string.
|
112
|
+
#
|
113
|
+
# @return [Boolean]
|
106
114
|
def string_at?(index)
|
107
115
|
n = node_at(index)
|
108
116
|
n.kind_of?(AST::Node) and n.type == :str
|
@@ -132,6 +140,14 @@ module Solargraph
|
|
132
140
|
parts.join("::")
|
133
141
|
end
|
134
142
|
|
143
|
+
def namespace_from(node)
|
144
|
+
if node.respond_to?(:loc)
|
145
|
+
namespace_at(node.loc.expression.begin_pos)
|
146
|
+
else
|
147
|
+
namespace_at(0)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
135
151
|
def phrase_at index
|
136
152
|
word = ''
|
137
153
|
cursor = index - 1
|
@@ -161,50 +177,44 @@ module Solargraph
|
|
161
177
|
def get_instance_variables_at(index)
|
162
178
|
node = parent_node_from(index, :def, :defs, :class, :module)
|
163
179
|
ns = namespace_at(index) || ''
|
164
|
-
|
180
|
+
api_map.get_instance_variables(ns, (node.type == :def ? :instance : :class))
|
165
181
|
end
|
166
182
|
|
167
183
|
def suggest_at index, filtered: false, with_snippets: false
|
168
|
-
node = node_at(index - 2)
|
169
184
|
return [] if string_at?(index)
|
170
185
|
result = []
|
171
186
|
phrase = phrase_at(index)
|
172
187
|
signature = get_signature_at(index)
|
173
|
-
|
188
|
+
namespace = namespace_at(index)
|
189
|
+
if signature.include?('.')
|
190
|
+
# Check for literals first
|
174
191
|
type = infer(node_at(index - 2))
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
scope = :instance if !node.nil? and node.type == :def
|
186
|
-
obj = @api_map.infer_instance_variable(var, ns, scope)
|
187
|
-
type = @api_map.infer_signature_type(parts.join('.'), obj, scope: :instance)
|
188
|
-
result = @api_map.get_instance_methods(type) unless type.nil?
|
192
|
+
if type.nil?
|
193
|
+
nearest = @code[0, index].rindex('.')
|
194
|
+
revised = signature[0..nearest-index-1]
|
195
|
+
type = infer_signature_at(nearest) unless revised.empty?
|
196
|
+
if !type.nil?
|
197
|
+
result.concat api_map.get_instance_methods(type) unless type.nil?
|
198
|
+
elsif !revised.include?('.')
|
199
|
+
fqns = api_map.find_fully_qualified_namespace(revised, namespace)
|
200
|
+
result.concat api_map.get_methods(fqns) unless fqns.nil?
|
201
|
+
end
|
189
202
|
else
|
190
|
-
result
|
203
|
+
result.concat api_map.get_instance_methods(type)
|
191
204
|
end
|
205
|
+
elsif signature.start_with?('@')
|
206
|
+
result.concat get_instance_variables_at(index)
|
192
207
|
elsif phrase.start_with?('$')
|
193
|
-
result
|
194
|
-
elsif phrase.start_with?(':') and !phrase.start_with?('::')
|
195
|
-
# TODO: It's a symbol. Nothing to do for now.
|
196
|
-
return []
|
208
|
+
result.concat api_map.get_global_variables
|
197
209
|
elsif phrase.include?('::')
|
198
210
|
parts = phrase.split('::', -1)
|
199
211
|
ns = parts[0..-2].join('::')
|
200
212
|
if parts.last.include?('.')
|
201
213
|
ns = parts[0..-2].join('::') + '::' + parts.last[0..parts.last.index('.')-1]
|
202
|
-
result =
|
214
|
+
result = api_map.get_methods(ns)
|
203
215
|
else
|
204
|
-
result =
|
216
|
+
result = api_map.namespaces_in(ns)
|
205
217
|
end
|
206
|
-
elsif signature.include?('.')
|
207
|
-
result = resolve_signature_at @code[0, index].rindex('.')
|
208
218
|
else
|
209
219
|
current_namespace = namespace_at(index)
|
210
220
|
parts = current_namespace.to_s.split('::')
|
@@ -213,17 +223,17 @@ module Solargraph
|
|
213
223
|
result += ApiMap.get_keywords
|
214
224
|
while parts.length > 0
|
215
225
|
ns = parts.join('::')
|
216
|
-
result +=
|
226
|
+
result += api_map.namespaces_in(ns)
|
217
227
|
parts.pop
|
218
228
|
end
|
219
|
-
result +=
|
220
|
-
result +=
|
221
|
-
unless @filename.nil? or @api_map.yardoc_has_file?(@filename)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
229
|
+
result += api_map.namespaces_in('')
|
230
|
+
result += api_map.get_instance_methods('Kernel')
|
231
|
+
#unless @filename.nil? or @api_map.yardoc_has_file?(@filename)
|
232
|
+
# m = @code.match(/# +@bind \[([a-z0-9_:]*)/i)
|
233
|
+
# unless m.nil?
|
234
|
+
# @api_map.get_instance_methods(m[1])
|
235
|
+
# end
|
236
|
+
#end
|
227
237
|
end
|
228
238
|
result = reduce_starting_with(result, word_at(index)) if filtered
|
229
239
|
result.uniq{|s| s.path}
|
@@ -237,6 +247,7 @@ module Solargraph
|
|
237
247
|
end
|
238
248
|
|
239
249
|
def resolve_object_at index
|
250
|
+
return [] if string_at?(index)
|
240
251
|
signature = get_signature_at(index)
|
241
252
|
cursor = index
|
242
253
|
while @code[cursor] =~ /[a-z0-9_\?]/i
|
@@ -245,149 +256,117 @@ module Solargraph
|
|
245
256
|
break if cursor >= @code.length
|
246
257
|
end
|
247
258
|
return [] if signature.to_s == ''
|
259
|
+
path = nil
|
248
260
|
ns_here = namespace_at(index)
|
249
|
-
|
261
|
+
node = parent_node_from(index, :class, :module, :def, :defs) || @node
|
250
262
|
parts = signature.split('.')
|
251
263
|
if parts.length > 1
|
252
264
|
beginner = parts[0..-2].join('.')
|
265
|
+
type = infer_signature_from_node(beginner, node)
|
253
266
|
ender = parts.last
|
267
|
+
path = "#{type}##{ender}"
|
254
268
|
else
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
if var.nil?
|
260
|
-
# It's not a local variable
|
261
|
-
fqns = @api_map.find_fully_qualified_namespace(beginner, ns_here)
|
262
|
-
if fqns.nil?
|
263
|
-
# It's a method call
|
264
|
-
if ender.nil?
|
265
|
-
return @api_map.yard_map.objects(beginner, ns_here)
|
266
|
-
else
|
267
|
-
sig_scope = (scope.type == :def ? :instance : :class)
|
268
|
-
type = @api_map.infer_signature_type(beginner, ns_here, scope: sig_scope)
|
269
|
-
return [] if type.nil?
|
270
|
-
path = type
|
271
|
-
path += "##{ender}" unless ender.nil?
|
272
|
-
return @api_map.yard_map.objects(path, ns_here)
|
273
|
-
end
|
269
|
+
if local_variable_in_node?(signature, node)
|
270
|
+
path = infer_signature_from_node(signature, node)
|
271
|
+
elsif signature.start_with?('@')
|
272
|
+
path = api_map.infer_instance_variable(signature, ns_here, (node.type == :def ? :instance : :class))
|
274
273
|
else
|
275
|
-
path =
|
276
|
-
path += "##{ender}" unless ender.nil?
|
277
|
-
return @api_map.yard_map.objects(path, ns_here)
|
274
|
+
path = signature
|
278
275
|
end
|
279
|
-
|
280
|
-
|
281
|
-
type = get_type_comment(var)
|
282
|
-
type = infer(var.children[1]) if type.nil?
|
283
|
-
if type.nil?
|
284
|
-
vsig = resolve_node_signature(var.children[1])
|
285
|
-
vparts = vsig.split('.')
|
286
|
-
fqns = @api_map.find_fully_qualified_namespace(vparts[0], ns_here)
|
287
|
-
if fqns.nil?
|
288
|
-
vtype = @api_map.infer_signature_type(vsig, ns_here, scope: :instance)
|
289
|
-
else
|
290
|
-
vtype = @api_map.infer_signature_type(vparts[1..-1].join('.'), fqns, scope: :class)
|
291
|
-
end
|
292
|
-
return [] if vtype.nil?
|
293
|
-
fqns = @api_map.find_fully_qualified_namespace(vtype, ns_here)
|
294
|
-
if ender.nil?
|
295
|
-
signature = parts[1..-1].join('.')
|
296
|
-
else
|
297
|
-
signature = parts[1..-2].join('.')
|
298
|
-
end
|
299
|
-
type = @api_map.infer_signature_type(signature, fqns, scope: :instance)
|
300
|
-
end
|
301
|
-
unless type.nil?
|
302
|
-
path = type
|
303
|
-
path += "##{ender}" unless ender.nil?
|
304
|
-
return @api_map.yard_map.objects(path, ns_here)
|
276
|
+
if path.nil?
|
277
|
+
path = api_map.find_fully_qualified_namespace(signature, ns_here)
|
305
278
|
end
|
306
279
|
end
|
307
|
-
return []
|
280
|
+
return [] if path.nil?
|
281
|
+
return api_map.yard_map.objects(path, ns_here)
|
308
282
|
end
|
309
283
|
|
310
|
-
|
311
|
-
# on its inferred type.
|
312
|
-
#
|
313
|
-
# @return [Array<Solargraph::Suggestion>]
|
314
|
-
def resolve_signature_at index
|
315
|
-
result = []
|
284
|
+
def infer_signature_at index
|
316
285
|
signature = get_signature_at(index)
|
317
|
-
|
318
|
-
|
286
|
+
node = parent_node_from(index, :class, :module, :def, :defs) || @node
|
287
|
+
infer_signature_from_node signature, node
|
288
|
+
end
|
289
|
+
|
290
|
+
def local_variable_in_node?(name, node)
|
291
|
+
return true unless find_local_variable_node(name, node).nil?
|
292
|
+
if node.type == :def or node.type == :defs
|
293
|
+
args = get_method_arguments_from(node).keep_if{|a| a.label == name}
|
294
|
+
return true unless args.empty?
|
295
|
+
end
|
296
|
+
false
|
297
|
+
end
|
298
|
+
|
299
|
+
def infer_signature_from_node signature, node
|
300
|
+
inferred = nil
|
319
301
|
parts = signature.split('.')
|
320
|
-
|
302
|
+
ns_here = namespace_from(node)
|
303
|
+
start = parts[0]
|
304
|
+
remainder = parts[1..-1]
|
305
|
+
scope = :instance
|
306
|
+
var = find_local_variable_node(start, node)
|
321
307
|
if var.nil?
|
322
|
-
|
323
|
-
|
324
|
-
if fqns.nil?
|
325
|
-
# It's a method call
|
326
|
-
sig_scope = (scope.type == :def ? :instance : :class)
|
327
|
-
type = @api_map.infer_signature_type(signature, ns_here, scope: sig_scope)
|
328
|
-
result.concat @api_map.get_instance_methods(type) unless type.nil?
|
308
|
+
if start.start_with?('@')
|
309
|
+
type = api_map.infer_instance_variable(start, ns_here, (node.type == :def ? :instance : :class))
|
329
310
|
else
|
330
|
-
if
|
331
|
-
|
311
|
+
if node.type == :def or node.type == :defs
|
312
|
+
args = get_method_arguments_from(node).keep_if{|a| a.label == start}
|
313
|
+
if args.empty?
|
314
|
+
scope = :class
|
315
|
+
type = api_map.find_fully_qualified_namespace(start, ns_here)
|
316
|
+
if type.nil?
|
317
|
+
# It's a method call
|
318
|
+
sig_scope = (node.type == :def ? :instance : :class)
|
319
|
+
type = api_map.infer_signature_type(start, ns_here, scope: sig_scope)
|
320
|
+
else
|
321
|
+
return nil if remainder.empty?
|
322
|
+
end
|
323
|
+
else
|
324
|
+
cmnt = api_map.get_comment_for(node)
|
325
|
+
params = cmnt.tags(:param)
|
326
|
+
params.each do |p|
|
327
|
+
if p.name == args[0].label
|
328
|
+
type = p.types[0]
|
329
|
+
break
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
332
333
|
else
|
333
|
-
|
334
|
+
scope = :class
|
335
|
+
type = api_map.find_fully_qualified_namespace(start, ns_here)
|
336
|
+
if type.nil?
|
337
|
+
# It's a method call
|
338
|
+
sig_scope = (node.type == :def ? :instance : :class)
|
339
|
+
type = api_map.infer_signature_type(start, ns_here, scope: sig_scope)
|
340
|
+
else
|
341
|
+
return nil if remainder.empty?
|
342
|
+
end
|
334
343
|
end
|
335
344
|
end
|
336
345
|
else
|
337
|
-
#
|
346
|
+
# Signature starts with a local variable
|
338
347
|
type = get_type_comment(var)
|
339
348
|
type = infer(var.children[1]) if type.nil?
|
340
|
-
skipdat = false
|
341
349
|
if type.nil?
|
342
350
|
vsig = resolve_node_signature(var.children[1])
|
343
|
-
|
344
|
-
fqns = @api_map.find_fully_qualified_namespace(vparts[0], ns_here)
|
345
|
-
if fqns.nil?
|
346
|
-
lvar = find_local_variable_node(vparts[0], scope)
|
347
|
-
if lvar.nil?
|
348
|
-
vtype = @api_map.infer_signature_type(vsig, ns_here, scope: :instance)
|
349
|
-
else
|
350
|
-
type = get_type_comment(lvar)
|
351
|
-
type = infer(lvar.children[1]) if type.nil?
|
352
|
-
if type.nil?
|
353
|
-
type = @api_map.infer_signature_type(resolve_node_signature(lvar.children[1]), ns_here, scope: :class)
|
354
|
-
end
|
355
|
-
unless type.nil?
|
356
|
-
signature = "#{vparts[1..-1].join('.')}"
|
357
|
-
skipdat = true
|
358
|
-
end
|
359
|
-
end
|
360
|
-
else
|
361
|
-
vtype = @api_map.infer_signature_type(vparts[1..-1].join('.'), fqns, scope: :class)
|
362
|
-
type = fqns
|
363
|
-
signature = parts[1..-1].join('.')
|
364
|
-
skipdat = true
|
365
|
-
end
|
366
|
-
unless skipdat
|
367
|
-
fqns = @api_map.find_fully_qualified_namespace(vtype, ns_here)
|
368
|
-
signature = parts[1..-1].join('.')
|
369
|
-
type = @api_map.infer_signature_type(signature, fqns, scope: :instance)
|
370
|
-
end
|
371
|
-
else
|
372
|
-
signature = signature.split('.')[1..-1].join('.')
|
373
|
-
end
|
374
|
-
unless type.nil?
|
375
|
-
lparts = signature.split('.')
|
376
|
-
if lparts.length >= 1
|
377
|
-
lsig = signature
|
378
|
-
ltype = @api_map.infer_signature_type(lsig, type, scope: :instance)
|
379
|
-
result.concat @api_map.get_instance_methods(ltype) unless ltype.nil?
|
380
|
-
else
|
381
|
-
result.concat @api_map.get_instance_methods(type)
|
382
|
-
end
|
351
|
+
type = infer_signature_from_node vsig, node
|
383
352
|
end
|
384
353
|
end
|
354
|
+
unless type.nil?
|
355
|
+
inferred = api_map.infer_signature_type(remainder.join('.'), type, scope: scope)
|
356
|
+
end
|
357
|
+
inferred
|
358
|
+
end
|
359
|
+
|
360
|
+
def suggest_for_signature_at index
|
361
|
+
result = []
|
362
|
+
type = infer_signature_at(index)
|
363
|
+
result.concat api_map.get_instance_methods(type) unless type.nil?
|
385
364
|
result
|
386
365
|
end
|
387
366
|
|
388
367
|
def get_type_comment node
|
389
368
|
obj = nil
|
390
|
-
cmnt =
|
369
|
+
cmnt = api_map.get_comment_for(node)
|
391
370
|
unless cmnt.nil?
|
392
371
|
tag = cmnt.tag(:type)
|
393
372
|
obj = tag.types[0] unless tag.nil? or tag.types.empty?
|
@@ -463,16 +442,29 @@ module Solargraph
|
|
463
442
|
result += get_local_variables_from(local)
|
464
443
|
scope = namespace_at(index) || @node
|
465
444
|
if local.type == :def
|
466
|
-
result +=
|
445
|
+
result += api_map.get_instance_methods(scope, visibility: [:public, :private, :protected])
|
467
446
|
else
|
468
|
-
result +=
|
447
|
+
result += api_map.get_methods(scope, visibility: [:public, :private, :protected])
|
469
448
|
end
|
470
|
-
|
449
|
+
if local.type == :def or local.type == :defs
|
450
|
+
result += get_method_arguments_from local
|
451
|
+
end
|
452
|
+
result += api_map.get_methods('Kernel')
|
471
453
|
result
|
472
454
|
end
|
473
455
|
|
474
456
|
private
|
475
457
|
|
458
|
+
def get_method_arguments_from node
|
459
|
+
result = []
|
460
|
+
args = node.children[1]
|
461
|
+
args.children.each do |arg|
|
462
|
+
name = arg.children[0].to_s
|
463
|
+
result.push Suggestion.new(name, kind: Suggestion::VARIABLE, insert: name)
|
464
|
+
end
|
465
|
+
result
|
466
|
+
end
|
467
|
+
|
476
468
|
def reduce_starting_with(suggestions, word)
|
477
469
|
suggestions.reject { |s|
|
478
470
|
!s.label.start_with?(word)
|
@@ -485,7 +477,7 @@ module Solargraph
|
|
485
477
|
node.children.each { |c|
|
486
478
|
if c.kind_of?(AST::Node)
|
487
479
|
if c.type == :lvasgn
|
488
|
-
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation:
|
480
|
+
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: api_map.get_comment_for(c))
|
489
481
|
else
|
490
482
|
arr += get_local_variables_from(c) unless [:class, :module, :def, :defs].include?(c.type)
|
491
483
|
end
|
data/lib/solargraph/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.2
|
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-
|
11
|
+
date: 2017-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|