solargraph 0.10.0 → 0.10.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 +32 -26
- data/lib/solargraph/code_map.rb +78 -13
- data/lib/solargraph/suggestion.rb +1 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +7 -5
- 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: 41e2a41af1ef29061e085cd34a1666aa8e962327
|
4
|
+
data.tar.gz: 8f785cd7a3a8113b47633c07e5b3816f028e1618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adcca5889793480021d29af723d2d83062b5578ccf083f36555b6bd311d620981d671999c6df52a57618a22fa18842ac7d5b0dacb3fd7880efd38c27a2752456
|
7
|
+
data.tar.gz: 630beb7fabb5a5c7d59ab30da28f72863f36d1111eca3f7a4b6f65e5d2cd91d3573f495b669964e77e02bac67ae95bb741b9f37a6ac08f109c00e3f2812f594c
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -89,32 +89,6 @@ module Solargraph
|
|
89
89
|
root
|
90
90
|
end
|
91
91
|
|
92
|
-
def associate_comments node, comments
|
93
|
-
comment_hash = Parser::Source::Comment.associate_locations(node, comments)
|
94
|
-
yard_hash = {}
|
95
|
-
comment_hash.each_pair { |k, v|
|
96
|
-
ctxt = ''
|
97
|
-
num = nil
|
98
|
-
started = false
|
99
|
-
v.each { |l|
|
100
|
-
# Trim the comment and minimum leading whitespace
|
101
|
-
p = l.text.gsub(/^#/, '')
|
102
|
-
if num.nil? and !p.strip.empty?
|
103
|
-
num = p.index(/[^ ]/)
|
104
|
-
started = true
|
105
|
-
elsif started and !p.strip.empty?
|
106
|
-
cur = p.index(/[^ ]/)
|
107
|
-
num = cur if cur < num
|
108
|
-
end
|
109
|
-
if started
|
110
|
-
ctxt += "#{p[num..-1]}\n"
|
111
|
-
end
|
112
|
-
}
|
113
|
-
yard_hash[k] = YARD::Docstring.parser.parse(ctxt).to_docstring
|
114
|
-
}
|
115
|
-
yard_hash
|
116
|
-
end
|
117
|
-
|
118
92
|
def get_comment_for node
|
119
93
|
filename = get_filename_for(node)
|
120
94
|
return nil if @file_comments[filename].nil?
|
@@ -378,6 +352,7 @@ module Solargraph
|
|
378
352
|
#
|
379
353
|
# @return [Array<Solargraph::Suggestion>]
|
380
354
|
def get_methods(namespace, root = '', visibility: [:public])
|
355
|
+
namespace = clean_namespace_string(namespace)
|
381
356
|
meths = []
|
382
357
|
meths += inner_get_methods(namespace, root, []) #unless has_yardoc?
|
383
358
|
yard_meths = yard_map.get_methods(namespace, root, visibility: visibility)
|
@@ -423,6 +398,7 @@ module Solargraph
|
|
423
398
|
#
|
424
399
|
# @return [Array<Solargraph::Suggestion>]
|
425
400
|
def get_instance_methods(namespace, root = '', visibility: [:public])
|
401
|
+
namespace = clean_namespace_string(namespace)
|
426
402
|
if namespace.end_with?('#class')
|
427
403
|
return get_methods(namespace.split('#').first, root, visibility: visibility)
|
428
404
|
end
|
@@ -498,6 +474,32 @@ module Solargraph
|
|
498
474
|
|
499
475
|
private
|
500
476
|
|
477
|
+
def associate_comments node, comments
|
478
|
+
comment_hash = Parser::Source::Comment.associate_locations(node, comments)
|
479
|
+
yard_hash = {}
|
480
|
+
comment_hash.each_pair { |k, v|
|
481
|
+
ctxt = ''
|
482
|
+
num = nil
|
483
|
+
started = false
|
484
|
+
v.each { |l|
|
485
|
+
# Trim the comment and minimum leading whitespace
|
486
|
+
p = l.text.gsub(/^#/, '')
|
487
|
+
if num.nil? and !p.strip.empty?
|
488
|
+
num = p.index(/[^ ]/)
|
489
|
+
started = true
|
490
|
+
elsif started and !p.strip.empty?
|
491
|
+
cur = p.index(/[^ ]/)
|
492
|
+
num = cur if cur < num
|
493
|
+
end
|
494
|
+
if started
|
495
|
+
ctxt += "#{p[num..-1]}\n"
|
496
|
+
end
|
497
|
+
}
|
498
|
+
yard_hash[k] = YARD::Docstring.parser.parse(ctxt).to_docstring
|
499
|
+
}
|
500
|
+
yard_hash
|
501
|
+
end
|
502
|
+
|
501
503
|
def inner_get_methods(namespace, root = '', skip = [])
|
502
504
|
meths = []
|
503
505
|
return meths if skip.include?(namespace)
|
@@ -850,5 +852,9 @@ module Solargraph
|
|
850
852
|
e = node.location.expression.end.end_pos
|
851
853
|
src[b..e].strip.gsub(/,$/, '')
|
852
854
|
end
|
855
|
+
|
856
|
+
def clean_namespace_string namespace
|
857
|
+
namespace.to_s.gsub(/<.*$/, '')
|
858
|
+
end
|
853
859
|
end
|
854
860
|
end
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -59,6 +59,8 @@ module Solargraph
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# Get the ApiMap that was generated for this CodeMap.
|
63
|
+
#
|
62
64
|
# @return [Solargraph::ApiMap]
|
63
65
|
def api_map
|
64
66
|
@api_map ||= ApiMap.new(workspace)
|
@@ -69,6 +71,8 @@ module Solargraph
|
|
69
71
|
# cursor's location in the code when generating suggestions.
|
70
72
|
# The line and column numbers should start at zero.
|
71
73
|
#
|
74
|
+
# @param line [Integer]
|
75
|
+
# @param col [Integer]
|
72
76
|
# @return [Integer]
|
73
77
|
def get_offset line, col
|
74
78
|
offset = 0
|
@@ -80,6 +84,11 @@ module Solargraph
|
|
80
84
|
offset + col
|
81
85
|
end
|
82
86
|
|
87
|
+
# Get an array of nodes containing the specified index, starting with the
|
88
|
+
# topmost node and ending with the nearest.
|
89
|
+
#
|
90
|
+
# @param index [Integer]
|
91
|
+
# @return [Array<AST::Node>]
|
83
92
|
def tree_at(index)
|
84
93
|
arr = []
|
85
94
|
arr.push @node
|
@@ -87,6 +96,10 @@ module Solargraph
|
|
87
96
|
arr
|
88
97
|
end
|
89
98
|
|
99
|
+
# Get the nearest node that contains the specified index.
|
100
|
+
#
|
101
|
+
# @param index [Integer]
|
102
|
+
# @return [AST::Node]
|
90
103
|
def node_at(index)
|
91
104
|
tree_at(index).first
|
92
105
|
end
|
@@ -109,6 +122,12 @@ module Solargraph
|
|
109
122
|
false
|
110
123
|
end
|
111
124
|
|
125
|
+
# Find the nearest parent node from the specified index. If one or more
|
126
|
+
# types are provided, find the nearest node whose type is in the list.
|
127
|
+
#
|
128
|
+
# @param index [Integer]
|
129
|
+
# @param types [Array<Symbol>]
|
130
|
+
# @return [AST::Node]
|
112
131
|
def parent_node_from(index, *types)
|
113
132
|
arr = tree_at(index)
|
114
133
|
arr.each { |a|
|
@@ -151,6 +170,12 @@ module Solargraph
|
|
151
170
|
end
|
152
171
|
end
|
153
172
|
|
173
|
+
# Select the phrase that directly precedes the specified index.
|
174
|
+
# A phrase can consist of most types of characters other than whitespace,
|
175
|
+
# semi-colons, equal signs, parentheses, or brackets.
|
176
|
+
#
|
177
|
+
# @param index [Integer]
|
178
|
+
# @return [String]
|
154
179
|
def phrase_at index
|
155
180
|
word = ''
|
156
181
|
cursor = index - 1
|
@@ -164,6 +189,11 @@ module Solargraph
|
|
164
189
|
word
|
165
190
|
end
|
166
191
|
|
192
|
+
# Select the word that directly precedes the specified index.
|
193
|
+
# A word can only consist of letters, numbers, and underscores.
|
194
|
+
#
|
195
|
+
# @param index [Integer]
|
196
|
+
# @return [String]
|
167
197
|
def word_at index
|
168
198
|
word = ''
|
169
199
|
cursor = index - 1
|
@@ -289,19 +319,47 @@ module Solargraph
|
|
289
319
|
return api_map.yard_map.objects(path, ns_here)
|
290
320
|
end
|
291
321
|
|
322
|
+
# Infer the type of the signature located at the specified index.
|
323
|
+
#
|
324
|
+
# @example
|
325
|
+
# # Given the following code:
|
326
|
+
# nums = [1, 2, 3]
|
327
|
+
# nums.join
|
328
|
+
# # ...and given an index that points at the end of "nums.join",
|
329
|
+
# # infer_signature_at will identify nums as an Array and the return
|
330
|
+
# # type of Array#join as a String, so the signature's type will be
|
331
|
+
# # String.
|
332
|
+
#
|
333
|
+
# @return [String]
|
292
334
|
def infer_signature_at index
|
293
335
|
signature = get_signature_at(index)
|
294
336
|
node = parent_node_from(index, :class, :module, :def, :defs) || @node
|
295
337
|
result = infer_signature_from_node signature, node
|
296
338
|
if result.nil? or result.empty?
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
339
|
+
arg = nil
|
340
|
+
if node.type == :def or node.type == :defs or node.type == :block
|
341
|
+
# Check for method arguments
|
342
|
+
parts = signature.split('.', 2)
|
343
|
+
# @type [Solargraph::Suggestion]
|
344
|
+
arg = get_method_arguments_from(node).keep_if{|s| s.to_s == parts[0] }.first
|
345
|
+
unless arg.nil?
|
346
|
+
if parts[1].nil?
|
347
|
+
result = arg.return_type
|
348
|
+
else
|
349
|
+
result = api_map.infer_signature_type(parts[1], parts[0], :instance)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
if arg.nil?
|
354
|
+
# Check for yieldparams
|
355
|
+
parts = signature.split('.', 2)
|
356
|
+
yp = get_yieldparams_at(index).keep_if{|s| s.to_s == parts[0]}.first
|
357
|
+
unless yp.nil?
|
358
|
+
if parts[1].nil? or parts[1].empty?
|
359
|
+
result = yp.return_type
|
360
|
+
else
|
361
|
+
result = api_map.infer_signature_type(parts[1], yp.return_type, scope: :instance)
|
362
|
+
end
|
305
363
|
end
|
306
364
|
end
|
307
365
|
end
|
@@ -367,11 +425,11 @@ module Solargraph
|
|
367
425
|
# A signature is a method call that can start with a constant, method, or
|
368
426
|
# variable and does not include any method arguments. Examples:
|
369
427
|
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
428
|
+
# Code Signature
|
429
|
+
# -----------------------------------------
|
430
|
+
# String.new String.new
|
431
|
+
# @x.bar @x.bar
|
432
|
+
# y.split(', ').length y.split.length
|
375
433
|
#
|
376
434
|
# @param index [Integer]
|
377
435
|
# @return [String]
|
@@ -447,6 +505,7 @@ module Solargraph
|
|
447
505
|
# Get an array of local variables and methods that can be accessed from
|
448
506
|
# the specified location in the code.
|
449
507
|
#
|
508
|
+
# @param index [Integer]
|
450
509
|
# @return [Array<Solargraph::Suggestion>]
|
451
510
|
def get_local_variables_and_methods_at(index)
|
452
511
|
result = []
|
@@ -468,7 +527,13 @@ module Solargraph
|
|
468
527
|
|
469
528
|
private
|
470
529
|
|
530
|
+
# Get a node's arguments as an array of suggestions. The node's type must
|
531
|
+
# be a method (:def or :defs).
|
532
|
+
#
|
533
|
+
# @param node [AST::Node]
|
534
|
+
# @return [Array<Suggestion>]
|
471
535
|
def get_method_arguments_from node
|
536
|
+
return [] unless node.type == :def or node.type == :defs
|
472
537
|
param_hash = {}
|
473
538
|
cmnt = api_map.get_comment_for(node)
|
474
539
|
unless cmnt.nil?
|
@@ -77,7 +77,7 @@ module Solargraph
|
|
77
77
|
param_tags = documentation.tags(:param)
|
78
78
|
unless param_tags.empty?
|
79
79
|
param_tags.each do |t|
|
80
|
-
txt = t.name
|
80
|
+
txt = t.name.to_s
|
81
81
|
txt += " [#{t.types.join(',')}]" unless t.types.nil? or t.types.empty?
|
82
82
|
txt += " #{t.text}" unless t.text.nil? or t.text.empty?
|
83
83
|
@params.push txt
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -314,11 +314,13 @@ module Solargraph
|
|
314
314
|
end
|
315
315
|
|
316
316
|
def find_first_resolved_namespace yard, namespace, scope
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
317
|
+
unless scope.nil?
|
318
|
+
parts = scope.split('::')
|
319
|
+
while parts.length > 0
|
320
|
+
ns = yard.resolve(P(parts.join('::')), namespace, true)
|
321
|
+
return ns unless ns.nil?
|
322
|
+
parts.pop
|
323
|
+
end
|
322
324
|
end
|
323
325
|
yard.at(namespace)
|
324
326
|
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.10.
|
4
|
+
version: 0.10.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-08-
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|