solargraph 0.24.1 → 0.25.0
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 +93 -46
- data/lib/solargraph/api_map/cache.rb +51 -0
- data/lib/solargraph/api_map/probe.rb +23 -12
- data/lib/solargraph/api_map/source_to_yard.rb +2 -2
- data/lib/solargraph/api_map/store.rb +20 -9
- data/lib/solargraph/complex_type.rb +10 -1
- data/lib/solargraph/diagnostics/require_not_found.rb +1 -1
- data/lib/solargraph/diagnostics/rubocop.rb +35 -27
- data/lib/solargraph/diagnostics/type_not_defined.rb +10 -13
- data/lib/solargraph/language_server/host.rb +11 -11
- data/lib/solargraph/language_server/message.rb +0 -1
- data/lib/solargraph/language_server/message/base.rb +24 -4
- data/lib/solargraph/language_server/message/text_document/completion.rb +9 -16
- data/lib/solargraph/language_server/message/text_document/did_change.rb +0 -2
- data/lib/solargraph/language_server/message/text_document/formatting.rb +1 -10
- data/lib/solargraph/language_server/transport/socket.rb +0 -1
- data/lib/solargraph/language_server/transport/stdio.rb +0 -1
- data/lib/solargraph/pin.rb +1 -1
- data/lib/solargraph/pin/attribute.rb +4 -7
- data/lib/solargraph/pin/base.rb +113 -8
- data/lib/solargraph/pin/base_variable.rb +17 -25
- data/lib/solargraph/pin/block.rb +2 -2
- data/lib/solargraph/pin/block_parameter.rb +8 -10
- data/lib/solargraph/pin/constant.rb +2 -2
- data/lib/solargraph/pin/conversions.rb +8 -0
- data/lib/solargraph/pin/documenting.rb +2 -2
- data/lib/solargraph/pin/duck_method.rb +0 -1
- data/lib/solargraph/pin/local_variable.rb +8 -2
- data/lib/solargraph/pin/method.rb +26 -16
- data/lib/solargraph/pin/method_parameter.rb +15 -8
- data/lib/solargraph/pin/namespace.rb +2 -2
- data/lib/solargraph/pin/reference.rb +7 -0
- data/lib/solargraph/pin/yard_pin.rb +10 -0
- data/lib/solargraph/pin/yard_pin/constant.rb +14 -0
- data/lib/solargraph/pin/yard_pin/method.rb +35 -0
- data/lib/solargraph/pin/yard_pin/namespace.rb +27 -0
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +18 -0
- data/lib/solargraph/source.rb +59 -15
- data/lib/solargraph/source/mapper.rb +46 -99
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace.rb +11 -2
- data/lib/solargraph/workspace/config.rb +47 -1
- data/lib/solargraph/yard_map.rb +103 -278
- data/lib/solargraph/yard_map/cache.rb +13 -38
- metadata +7 -3
- data/lib/solargraph/pin/yard_object.rb +0 -119
@@ -4,19 +4,26 @@ module Solargraph
|
|
4
4
|
def return_complex_types
|
5
5
|
if @return_complex_types.nil?
|
6
6
|
@return_complex_types = []
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
found = p
|
13
|
-
end
|
14
|
-
@return_complex_types.concat ComplexType.parse(*found.types) unless found.nil? or found.types.nil?
|
7
|
+
found = nil
|
8
|
+
params = block.docstring.tags(:param)
|
9
|
+
params.each do |p|
|
10
|
+
next unless p.name == name
|
11
|
+
found = p
|
15
12
|
end
|
13
|
+
@return_complex_types.concat ComplexType.parse(*found.types) unless found.nil? or found.types.nil?
|
16
14
|
end
|
17
15
|
super
|
18
16
|
@return_complex_types
|
19
17
|
end
|
18
|
+
|
19
|
+
def try_merge! pin
|
20
|
+
return false unless super
|
21
|
+
# @todo This is a little expensive, but it's necessary because
|
22
|
+
# parameter data depends on the method's docstring.
|
23
|
+
@return_complex_types = pin.return_complex_types
|
24
|
+
reset_conversions
|
25
|
+
true
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -8,8 +8,8 @@ module Solargraph
|
|
8
8
|
# @return [Pin::Reference]
|
9
9
|
attr_reader :superclass_reference
|
10
10
|
|
11
|
-
def initialize location, namespace, name,
|
12
|
-
super(location, namespace, name,
|
11
|
+
def initialize location, namespace, name, comments, type, visibility, superclass
|
12
|
+
super(location, namespace, name, comments)
|
13
13
|
@type = type
|
14
14
|
@visibility = visibility
|
15
15
|
# @superclass_reference = Reference.new(self, superclass) unless superclass.nil?
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
module YardPin
|
4
|
+
autoload :YardMixin, 'solargraph/pin/yard_pin/yard_mixin'
|
5
|
+
autoload :Constant, 'solargraph/pin/yard_pin/constant'
|
6
|
+
autoload :Method, 'solargraph/pin/yard_pin/method'
|
7
|
+
autoload :Namespace, 'solargraph/pin/yard_pin/namespace'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
module YardPin
|
4
|
+
class Constant < Pin::Constant
|
5
|
+
include YardMixin
|
6
|
+
|
7
|
+
def initialize code_object, location
|
8
|
+
super(location, code_object.namespace.to_s, code_object.name.to_s, comments_from(code_object), nil, nil, nil, code_object.visibility)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
map = Solargraph::ApiMap.new
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
module YardPin
|
4
|
+
class Method < Pin::Method
|
5
|
+
include YardMixin
|
6
|
+
|
7
|
+
def initialize code_object, location
|
8
|
+
comments = (code_object.docstring ? code_object.docstring.all : nil)
|
9
|
+
super(location, code_object.namespace.to_s, code_object.name.to_s, comments, code_object.scope, code_object.visibility, get_parameters(code_object))
|
10
|
+
end
|
11
|
+
|
12
|
+
def return_complex_types
|
13
|
+
@return_complex_types ||= Solargraph::ComplexType.parse(Solargraph::CoreFills::CUSTOM_RETURN_TYPES[path]) if Solargraph::CoreFills::CUSTOM_RETURN_TYPES.has_key?(path)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_parameters code_object
|
20
|
+
return [] unless code_object.kind_of?(YARD::CodeObjects::MethodObject)
|
21
|
+
args = []
|
22
|
+
code_object.parameters.each do |a|
|
23
|
+
p = a[0]
|
24
|
+
unless a[1].nil?
|
25
|
+
p += ' =' unless p.end_with?(':')
|
26
|
+
p += " #{a[1]}"
|
27
|
+
end
|
28
|
+
args.push p
|
29
|
+
end
|
30
|
+
args
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
module YardPin
|
4
|
+
class Namespace < Pin::Namespace
|
5
|
+
include YardMixin
|
6
|
+
|
7
|
+
def initialize code_object, location
|
8
|
+
superclass = nil
|
9
|
+
superclass = code_object.superclass.to_s if code_object.is_a?(YARD::CodeObjects::ClassObject) and code_object.superclass
|
10
|
+
super(location, code_object.namespace.to_s, code_object.name.to_s, comments_from(code_object), namespace_type(code_object), code_object.visibility, superclass)
|
11
|
+
# code_object.class_mixins.each do |m|
|
12
|
+
# extend_references.push Pin::Reference.new(location, path, m.path)
|
13
|
+
# end
|
14
|
+
# code_object.instance_mixins.each do |m|
|
15
|
+
# include_references.push Pin::Reference.new(location, path, m.path)
|
16
|
+
# end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def namespace_type code_object
|
22
|
+
code_object.is_a?(YARD::CodeObjects::ClassObject) ? :class : :module
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
module YardPin
|
4
|
+
module YardMixin
|
5
|
+
def yard_pin?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def comments_from code_object
|
12
|
+
return nil if code_object.docstring.nil?
|
13
|
+
code_object.docstring.all
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/solargraph/source.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'parser/current'
|
2
2
|
require 'time'
|
3
|
+
require 'yard'
|
3
4
|
|
4
5
|
module Solargraph
|
5
6
|
class Source
|
@@ -63,6 +64,7 @@ module Solargraph
|
|
63
64
|
@fixed = code
|
64
65
|
@filename = filename
|
65
66
|
@version = 0
|
67
|
+
@domains = []
|
66
68
|
begin
|
67
69
|
parse
|
68
70
|
rescue Parser::SyntaxError, EncodingError
|
@@ -315,9 +317,9 @@ module Solargraph
|
|
315
317
|
def hard_fix_node
|
316
318
|
@fixed = @code.gsub(/[^\s]/, '_')
|
317
319
|
node, comments = inner_parse(@fixed, filename)
|
320
|
+
process_parsed node, comments
|
318
321
|
@node = node
|
319
322
|
@comments = comments
|
320
|
-
process_parsed node, comments
|
321
323
|
@parsed = false
|
322
324
|
end
|
323
325
|
|
@@ -335,24 +337,66 @@ module Solargraph
|
|
335
337
|
synchronize_mapped *new_map_data
|
336
338
|
end
|
337
339
|
|
338
|
-
def synchronize_mapped new_pins, new_locals, new_requires, new_symbols
|
339
|
-
|
340
|
-
@pins.nil? or
|
341
|
-
@locals.nil? or
|
342
|
-
@pins[1..-1] != new_pins[1..-1] or
|
343
|
-
@locals != new_locals
|
344
|
-
# @requires != new_requires or
|
345
|
-
# @path_macros != new_path_macros or
|
346
|
-
# @new_domains != new_domains
|
347
|
-
)
|
340
|
+
def synchronize_mapped new_pins, new_locals, new_requires, new_symbols #, new_path_macros, new_domains
|
341
|
+
return if @requires == new_requires and @symbols == new_symbols and try_merge(new_pins, new_locals)
|
348
342
|
@pins = new_pins
|
349
343
|
@locals = new_locals
|
350
344
|
@requires = new_requires
|
351
345
|
@symbols = new_symbols
|
352
|
-
@
|
353
|
-
@
|
354
|
-
|
355
|
-
@
|
346
|
+
@domains = []
|
347
|
+
@path_macros = {}
|
348
|
+
dirpins = []
|
349
|
+
@pins.select(&:maybe_directives?).each do |pin|
|
350
|
+
dirpins.push pin unless pin.directives.empty?
|
351
|
+
end
|
352
|
+
process_directives dirpins
|
353
|
+
@stime = Time.now
|
354
|
+
end
|
355
|
+
|
356
|
+
# @param new_pins [Array<Solargraph::Pin::Base>]
|
357
|
+
# @param new_locals [Array<Solargraph::Pin::Base>]
|
358
|
+
# @return [Boolean]
|
359
|
+
def try_merge new_pins, new_locals
|
360
|
+
return false if @pins.nil? or @locals.nil? or new_pins.length != @pins.length or new_locals.length != @locals.length
|
361
|
+
new_pins.each_index do |i|
|
362
|
+
return false unless @pins[i].try_merge!(new_pins[i])
|
363
|
+
end
|
364
|
+
new_locals.each_index do |i|
|
365
|
+
return false unless @locals[i].try_merge!(new_locals[i])
|
366
|
+
end
|
367
|
+
true
|
368
|
+
end
|
369
|
+
|
370
|
+
# @return [void]
|
371
|
+
def process_directives pins
|
372
|
+
pins.each do |pin|
|
373
|
+
pin.directives.each do |d|
|
374
|
+
# ns = namespace_for(k.node)
|
375
|
+
ns = (pin.kind == Pin::NAMESPACE ? pin.path : pin.namespace)
|
376
|
+
docstring = YARD::Docstring.parser.parse(d.tag.text).to_docstring
|
377
|
+
if d.tag.tag_name == 'attribute'
|
378
|
+
t = (d.tag.types.nil? || d.tag.types.empty?) ? nil : d.tag.types.flatten.join('')
|
379
|
+
if t.nil? or t.include?('r')
|
380
|
+
# location, namespace, name, docstring, access
|
381
|
+
@pins.push Solargraph::Pin::Attribute.new(pin.location, pin.path, d.tag.name, docstring.all, :reader, :instance)
|
382
|
+
end
|
383
|
+
if t.nil? or t.include?('w')
|
384
|
+
@pins.push Solargraph::Pin::Attribute.new(pin.location, pin.path, "#{d.tag.name}=", docstring.all, :writer, :instance)
|
385
|
+
end
|
386
|
+
elsif d.tag.tag_name == 'method'
|
387
|
+
gen_src = Source.new("def #{d.tag.name};end", filename)
|
388
|
+
gen_pin = gen_src.pins.last # Method is last pin after root namespace
|
389
|
+
# next if ns.nil? or ns.empty? # @todo Add methods to global namespace?
|
390
|
+
@pins.push Solargraph::Pin::Method.new(pin.location, pin.path, gen_pin.name, docstring.all, :instance, :public, [])
|
391
|
+
elsif d.tag.tag_name == 'macro'
|
392
|
+
@path_macros[pin.path] = d
|
393
|
+
elsif d.tag.tag_name == 'domain'
|
394
|
+
@domains.push d.tag.text
|
395
|
+
else
|
396
|
+
# STDERR.puts "Nothing to do for directive: #{d}"
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
356
400
|
end
|
357
401
|
|
358
402
|
class << self
|
@@ -20,25 +20,24 @@ module Solargraph
|
|
20
20
|
@node = node
|
21
21
|
@node_stack = []
|
22
22
|
@directives = {}
|
23
|
-
@
|
24
|
-
# @todo Stuff that needs to be resolved
|
25
|
-
@variables = []
|
26
|
-
@path_macros = {}
|
27
|
-
@domains = []
|
28
|
-
|
23
|
+
@node_comments = associate_comments(node, comments)
|
29
24
|
@pins = []
|
30
25
|
@requires = []
|
31
26
|
@symbols = []
|
32
27
|
@locals = []
|
33
28
|
|
29
|
+
@used_comment_locs = []
|
30
|
+
|
34
31
|
# HACK make sure the first node gets processed
|
35
32
|
root = AST::Node.new(:source, [filename])
|
36
33
|
root = root.append node
|
37
34
|
# @todo Is the root namespace a class or a module? Assuming class for now.
|
38
35
|
@pins.push Pin::Namespace.new(get_node_location(nil), '', '', nil, :class, :public, nil)
|
39
36
|
process root
|
40
|
-
|
41
|
-
|
37
|
+
@node_comments.reject{|k, v| @used_comment_locs.include?(k)}.each do |k, v|
|
38
|
+
@pins.first.comments.concat v
|
39
|
+
end
|
40
|
+
[@pins, @locals, @requires, @symbols]
|
42
41
|
end
|
43
42
|
|
44
43
|
class << self
|
@@ -83,7 +82,7 @@ module Solargraph
|
|
83
82
|
if node.type == :class and !node.children[1].nil?
|
84
83
|
sc = unpack_name(node.children[1])
|
85
84
|
end
|
86
|
-
pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s,
|
85
|
+
pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s, comments_for(node), node.type, visibility, sc)
|
87
86
|
end
|
88
87
|
file = filename
|
89
88
|
node.children.each do |c|
|
@@ -95,18 +94,17 @@ module Solargraph
|
|
95
94
|
ora = find_parent(stack, :or_asgn)
|
96
95
|
unless ora.nil?
|
97
96
|
u = c.updated(:ivasgn, c.children + ora.children[1..-1], nil)
|
98
|
-
|
99
|
-
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, docstring_for(u), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), context)
|
97
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, comments_for(u), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), context)
|
100
98
|
if visibility == :module_function and context.kind == Pin::METHOD
|
101
99
|
other = pins.select{|pin| pin.path == "#{context.namespace}.#{context.name}"}.first
|
102
|
-
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(u), fqn || '', c.children[0].to_s,
|
100
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, comments_for(u), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), other) unless other.nil?
|
103
101
|
end
|
104
102
|
end
|
105
103
|
else
|
106
|
-
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(c), fqn || '',c.children[0].to_s,
|
104
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(c), fqn || '',c.children[0].to_s, comments_for(c), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), context)
|
107
105
|
if visibility == :module_function and context.kind == Pin::METHOD
|
108
106
|
other = pins.select{|pin| pin.path == "#{context.namespace}.#{context.name}"}.first
|
109
|
-
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(c), fqn || '',c.children[0].to_s,
|
107
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(c), fqn || '',c.children[0].to_s, comments_for(c), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), other)
|
110
108
|
end
|
111
109
|
end
|
112
110
|
elsif c.type == :cvasgn
|
@@ -116,11 +114,10 @@ module Solargraph
|
|
116
114
|
ora = find_parent(stack, :or_asgn)
|
117
115
|
unless ora.nil?
|
118
116
|
u = c.updated(:cvasgn, c.children + ora.children[1..-1], nil)
|
119
|
-
|
120
|
-
pins.push Solargraph::Pin::ClassVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, docstring_for(u), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), context)
|
117
|
+
pins.push Solargraph::Pin::ClassVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, comments_for(u), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), context)
|
121
118
|
end
|
122
119
|
else
|
123
|
-
pins.push Solargraph::Pin::ClassVariable.new(get_node_location(c), fqn || '', c.children[0].to_s,
|
120
|
+
pins.push Solargraph::Pin::ClassVariable.new(get_node_location(c), fqn || '', c.children[0].to_s, comments_for(c), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), context)
|
124
121
|
end
|
125
122
|
elsif c.type == :lvasgn
|
126
123
|
here = get_node_start_position(c)
|
@@ -131,31 +128,29 @@ module Solargraph
|
|
131
128
|
ora = find_parent(stack, :or_asgn)
|
132
129
|
unless ora.nil?
|
133
130
|
u = c.updated(:lvasgn, c.children + ora.children[1..-1], nil)
|
134
|
-
@
|
135
|
-
@locals.push Solargraph::Pin::LocalVariable.new(get_node_location(u), fqn, u.children[0].to_s, docstring_for(u), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), context, block, presence)
|
131
|
+
@locals.push Solargraph::Pin::LocalVariable.new(get_node_location(u), fqn, u.children[0].to_s, comments_for(ora), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), context, block, presence)
|
136
132
|
end
|
137
133
|
else
|
138
|
-
@locals.push Solargraph::Pin::LocalVariable.new(get_node_location(c), fqn, c.children[0].to_s,
|
134
|
+
@locals.push Solargraph::Pin::LocalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), context, block, presence)
|
139
135
|
end
|
140
136
|
elsif c.type == :gvasgn
|
141
|
-
pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, c.children[0].to_s,
|
137
|
+
pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), resolve_node_signature(c.children[1]), infer_literal_node_type(c.children[1]), @pins.first)
|
142
138
|
elsif c.type == :sym
|
143
139
|
@symbols.push Solargraph::Pin::Symbol.new(get_node_location(c), ":#{c.children[0]}")
|
144
140
|
elsif c.type == :casgn
|
145
141
|
here = get_node_start_position(c)
|
146
142
|
block = get_block_pin(here)
|
147
|
-
pins.push Solargraph::Pin::Constant.new(get_node_location(c), fqn, c.children[1].to_s,
|
143
|
+
pins.push Solargraph::Pin::Constant.new(get_node_location(c), fqn, c.children[1].to_s, comments_for(c), resolve_node_signature(c.children[2]), infer_literal_node_type(c.children[2]), block, :public)
|
148
144
|
elsif c.type == :def
|
149
|
-
methpin = Solargraph::Pin::Method.new(get_node_location(c), fqn || '', c.children[(c.type == :def ? 0 : 1)].to_s,
|
145
|
+
methpin = Solargraph::Pin::Method.new(get_node_location(c), fqn || '', c.children[(c.type == :def ? 0 : 1)].to_s, comments_for(c), scope, visibility, get_method_args(c))
|
150
146
|
if methpin.name == 'initialize' and methpin.scope == :instance
|
151
|
-
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, 'new', methpin.
|
147
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, 'new', methpin.comments, :class, :public, methpin.parameters)
|
152
148
|
# @todo Smelly instance variable access.
|
153
|
-
# pins.last.instance_variable_set(:@return_type, methpin.namespace)
|
154
149
|
pins.last.instance_variable_set(:@return_complex_types, ComplexType.parse(methpin.namespace))
|
155
|
-
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.
|
150
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, methpin.scope, :private, methpin.parameters)
|
156
151
|
elsif visibility == :module_function
|
157
|
-
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.
|
158
|
-
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.
|
152
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :class, :public, methpin.parameters)
|
153
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :instance, :private, methpin.parameters)
|
159
154
|
else
|
160
155
|
pins.push methpin
|
161
156
|
end
|
@@ -168,7 +163,7 @@ module Solargraph
|
|
168
163
|
dfqn = unpack_name(c.children[0])
|
169
164
|
end
|
170
165
|
unless dfqn.nil?
|
171
|
-
pins.push Solargraph::Pin::Method.new(get_node_location(c), dfqn, "#{c.children[(node.type == :def ? 0 : 1)]}",
|
166
|
+
pins.push Solargraph::Pin::Method.new(get_node_location(c), dfqn, "#{c.children[(node.type == :def ? 0 : 1)]}", comments_for(c), :class, s_visi, get_method_args(c))
|
172
167
|
process c, tree, scope, :class, dfqn, stack
|
173
168
|
end
|
174
169
|
next
|
@@ -179,7 +174,7 @@ module Solargraph
|
|
179
174
|
ref = pins.select{|p| p.namespace == (fqn || '') and p.name == c.children[2].children[0].to_s}.first
|
180
175
|
unless ref.nil?
|
181
176
|
pins.delete ref
|
182
|
-
pins.push Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.
|
177
|
+
pins.push Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, ref.scope, :private, ref.parameters)
|
183
178
|
end
|
184
179
|
else
|
185
180
|
process c, tree, :private, :class, fqn, stack
|
@@ -194,15 +189,14 @@ module Solargraph
|
|
194
189
|
pins.delete ref
|
195
190
|
# Might be either a namespace or constant
|
196
191
|
if ref.kind == Pin::CONSTANT
|
197
|
-
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.
|
192
|
+
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.signature, ref.return_type, ref.context, :private)
|
198
193
|
else
|
199
|
-
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.
|
194
|
+
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
|
200
195
|
end
|
201
196
|
end
|
202
197
|
end
|
203
198
|
next
|
204
199
|
elsif c.type == :send and c.children[1] == :module_function
|
205
|
-
# @todo Handle module_function
|
206
200
|
if c.children[2].nil?
|
207
201
|
visibility = :module_function
|
208
202
|
elsif c.children[2].type == :sym or c.children[2].type == :str
|
@@ -212,13 +206,13 @@ module Solargraph
|
|
212
206
|
ref = pins.select{|p| p.namespace == (fqn || '') and p.name == cn}.first
|
213
207
|
unless ref.nil?
|
214
208
|
pins.delete ref
|
215
|
-
mm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.
|
216
|
-
cm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.
|
209
|
+
mm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :class, :public, ref.parameters)
|
210
|
+
cm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :instance, :private, ref.parameters)
|
217
211
|
pins.push mm, cm
|
218
212
|
pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context == ref}.each do |ivar|
|
219
213
|
pins.delete ivar
|
220
|
-
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.
|
221
|
-
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.
|
214
|
+
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), mm)
|
215
|
+
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), cm)
|
222
216
|
end
|
223
217
|
end
|
224
218
|
end
|
@@ -259,10 +253,10 @@ module Solargraph
|
|
259
253
|
elsif c.type == :send and [:attr_reader, :attr_writer, :attr_accessor].include?(c.children[1])
|
260
254
|
c.children[2..-1].each do |a|
|
261
255
|
if c.children[1] == :attr_reader or c.children[1] == :attr_accessor
|
262
|
-
pins.push Solargraph::Pin::Attribute.new(get_node_location(c), fqn || '', "#{a.children[0]}",
|
256
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(c), fqn || '', "#{a.children[0]}", comments_for(c), :reader, scope)
|
263
257
|
end
|
264
258
|
if c.children[1] == :attr_writer or c.children[1] == :attr_accessor
|
265
|
-
pins.push Solargraph::Pin::Attribute.new(get_node_location(c), fqn || '', "#{a.children[0]}=",
|
259
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(c), fqn || '', "#{a.children[0]}=", comments_for(c), :writer, scope)
|
266
260
|
end
|
267
261
|
end
|
268
262
|
elsif c.type == :sclass and c.children[0].type == :self
|
@@ -270,35 +264,29 @@ module Solargraph
|
|
270
264
|
next
|
271
265
|
elsif c.type == :send and c.children[1] == :require
|
272
266
|
if c.children[2].kind_of?(AST::Node) and c.children[2].type == :str
|
273
|
-
# @requires.push c.children[2].children[0].to_s
|
274
267
|
@requires.push Solargraph::Pin::Reference.new(get_node_location(c), fqn, c.children[2].children[0].to_s)
|
275
268
|
end
|
276
269
|
elsif c.type == :args
|
277
270
|
if @node_stack.first.type == :block
|
278
271
|
pi = 0
|
279
272
|
c.children.each do |u|
|
280
|
-
# @todo Fix this
|
281
|
-
# pins.push Solargraph::Pin::BlockParameter.new(self, u, fqn || '', @node_stack.clone, pi)
|
282
273
|
here = get_node_start_position(c)
|
283
274
|
blk = get_block_pin(here)
|
284
|
-
@locals.push Solargraph::Pin::BlockParameter.new(get_node_location(u), fqn || '', "#{u.children[0]}",
|
275
|
+
@locals.push Solargraph::Pin::BlockParameter.new(get_node_location(u), fqn || '', "#{u.children[0]}", comments_for(c), blk)
|
285
276
|
blk.parameters.push @locals.push.last
|
286
277
|
pi += 1
|
287
278
|
end
|
288
279
|
else
|
289
280
|
c.children.each do |u|
|
290
|
-
# here = get_node_start_position(c)
|
291
|
-
# blk = get_block_pin(here)
|
292
|
-
# @locals.push Solargraph::Pin::MethodParameter.new(get_node_location(u), fqn || '', "#{u.children[0]}", docstring_for(c), blk)
|
293
281
|
here = get_node_start_position(u)
|
294
282
|
context = get_named_path_pin(here)
|
295
283
|
block = get_block_pin(here)
|
296
284
|
presence = Source::Range.new(here, block.location.range.ending)
|
297
|
-
@locals.push Solargraph::Pin::MethodParameter.new(get_node_location(u), fqn, u.children[0].to_s,
|
285
|
+
@locals.push Solargraph::Pin::MethodParameter.new(get_node_location(u), fqn, u.children[0].to_s, comments_for(c), resolve_node_signature(u.children[1]), infer_literal_node_type(u.children[1]), context, block, presence)
|
298
286
|
end
|
299
287
|
end
|
300
288
|
elsif c.type == :block
|
301
|
-
@pins.push Solargraph::Pin::Block.new(get_node_location(c), fqn || '', '',
|
289
|
+
@pins.push Solargraph::Pin::Block.new(get_node_location(c), fqn || '', '', comments_for(c), resolve_node_signature(c.children[0]))
|
302
290
|
end
|
303
291
|
process c, tree, visibility, scope, fqn, stack
|
304
292
|
end
|
@@ -326,10 +314,12 @@ module Solargraph
|
|
326
314
|
@pins.select{|pin| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(position)}.last
|
327
315
|
end
|
328
316
|
|
329
|
-
# @return [
|
330
|
-
def
|
331
|
-
|
332
|
-
nil
|
317
|
+
# @return [String]
|
318
|
+
def comments_for node
|
319
|
+
result = @node_comments[node.loc]
|
320
|
+
return nil if result.nil?
|
321
|
+
@used_comment_locs.push node.loc
|
322
|
+
result
|
333
323
|
end
|
334
324
|
|
335
325
|
# @param node [Parser::AST::Node]
|
@@ -352,7 +342,7 @@ module Solargraph
|
|
352
342
|
def associate_comments node, comments
|
353
343
|
return nil if comments.nil?
|
354
344
|
comment_hash = Parser::Source::Comment.associate_locations(node, comments)
|
355
|
-
|
345
|
+
result_hash = {}
|
356
346
|
comment_hash.each_pair { |k, v|
|
357
347
|
ctxt = ''
|
358
348
|
num = nil
|
@@ -367,18 +357,11 @@ module Solargraph
|
|
367
357
|
cur = p.index(/[^ ]/)
|
368
358
|
num = cur if cur < num
|
369
359
|
end
|
370
|
-
if started
|
371
|
-
ctxt += "#{p[num..-1]}\n"
|
372
|
-
end
|
360
|
+
ctxt += "#{p[num..-1]}\n" if started
|
373
361
|
}
|
374
|
-
|
375
|
-
unless parse.directives.empty?
|
376
|
-
@directives[k] ||= []
|
377
|
-
@directives[k].concat parse.directives
|
378
|
-
end
|
379
|
-
yard_hash[k] = parse.to_docstring
|
362
|
+
result_hash[k] = ctxt
|
380
363
|
}
|
381
|
-
|
364
|
+
result_hash
|
382
365
|
end
|
383
366
|
|
384
367
|
# @param node [Parser::AST::Node]
|
@@ -388,42 +371,6 @@ module Solargraph
|
|
388
371
|
@pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.location.range.contain?(position)}.last
|
389
372
|
end
|
390
373
|
|
391
|
-
# @return [void]
|
392
|
-
def process_directives
|
393
|
-
@directives.each_pair do |k, v|
|
394
|
-
v.each do |d|
|
395
|
-
ns = namespace_for(k.node)
|
396
|
-
docstring = YARD::Docstring.parser.parse(d.tag.text).to_docstring
|
397
|
-
if d.tag.tag_name == 'attribute'
|
398
|
-
t = (d.tag.types.nil? || d.tag.types.empty?) ? nil : d.tag.types.flatten.join('')
|
399
|
-
if t.nil? or t.include?('r')
|
400
|
-
# location, namespace, name, docstring, access
|
401
|
-
pins.push Solargraph::Pin::Attribute.new(get_node_location(k.node), namespace_for(k.node).path, d.tag.name, docstring, :reader, :instance)
|
402
|
-
end
|
403
|
-
if t.nil? or t.include?('w')
|
404
|
-
pins.push Solargraph::Pin::Attribute.new(get_node_location(k.node), namespace_for(k.node).path, "#{d.tag.name}=", docstring, :writer, :instance)
|
405
|
-
end
|
406
|
-
elsif d.tag.tag_name == 'method'
|
407
|
-
gen_src = Source.new("def #{d.tag.name};end", filename)
|
408
|
-
gen_pin = gen_src.pins.last # Method is last pin after root namespace
|
409
|
-
nsp = namespace_for(k.node)
|
410
|
-
next if nsp.nil? # @todo Add methods to global namespace?
|
411
|
-
@pins.push Solargraph::Pin::Method.new(get_node_location(k.node), nsp.path, gen_pin.name, docstring, :instance, :public, [])
|
412
|
-
elsif d.tag.tag_name == 'macro'
|
413
|
-
# @todo Handle various types of macros (attach, new, whatever)
|
414
|
-
# path = path_for(k.node)
|
415
|
-
here = get_node_start_position(k.node)
|
416
|
-
pin = @pins.select{|pin| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(here)}.first
|
417
|
-
@path_macros[pin.path] = v
|
418
|
-
elsif d.tag.tag_name == 'domain'
|
419
|
-
@domains.push d.tag.text
|
420
|
-
else
|
421
|
-
# STDERR.puts "Nothing to do for directive: #{d}"
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
374
|
def find_parent(stack, *types)
|
428
375
|
stack.reverse.each { |p|
|
429
376
|
return p if types.include?(p.type)
|