solargraph 0.15.2 → 0.15.3
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/source.rb +33 -4
- data/lib/solargraph/api_map/source_to_yard.rb +12 -5
- data/lib/solargraph/api_map.rb +20 -31
- data/lib/solargraph/code_map.rb +2 -1
- data/lib/solargraph/pin/constant.rb +6 -0
- data/lib/solargraph/pin/namespace.rb +7 -0
- data/lib/solargraph/server.rb +0 -4
- data/lib/solargraph/suggestion.rb +27 -10
- 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: 973c57ed92c49cbc1c242f26d30660a0260329c3
|
4
|
+
data.tar.gz: 0f4313ae7372cac8995a78f23992cc2c91c58d85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28dad009825df7ce472a842b134f47eb6341171a176c4ebf88c01f092819d7e1cdf3645c88142e18fbe35c9c811ff022eee4715df47b8a053382158b426fa987
|
7
|
+
data.tar.gz: 86d7d8120d867c48cd2a480b71cc4ee0fd72f39bd2c70cc34ae8a73bbd9706fc031e4b39d522387865f107bba1b43fdd8fae7f9bb3e1a6f849ca0c38077f06ce
|
@@ -210,7 +210,7 @@ module Solargraph
|
|
210
210
|
fqn = tree.join('::')
|
211
211
|
@namespace_nodes[fqn] ||= []
|
212
212
|
@namespace_nodes[fqn].push node
|
213
|
-
namespace_pins.push Solargraph::Pin::Namespace.new(self, node, tree[0..-2].join('::') || '')
|
213
|
+
namespace_pins.push Solargraph::Pin::Namespace.new(self, node, tree[0..-2].join('::') || '', :public)
|
214
214
|
if node.type == :class and !node.children[1].nil?
|
215
215
|
sc = unpack_name(node.children[1])
|
216
216
|
superclasses[fqn] = sc
|
@@ -264,17 +264,46 @@ module Solargraph
|
|
264
264
|
elsif c.type == :sym
|
265
265
|
symbol_pins.push Solargraph::Pin::Symbol.new(self, c, fqn)
|
266
266
|
elsif c.type == :casgn
|
267
|
-
constant_pins.push Solargraph::Pin::Constant.new(self, c, fqn)
|
267
|
+
constant_pins.push Solargraph::Pin::Constant.new(self, c, fqn, :public)
|
268
268
|
else
|
269
269
|
if c.kind_of?(AST::Node)
|
270
270
|
if c.type == :def and c.children[0].to_s[0].match(/[a-z]/i)
|
271
271
|
method_pins.push Solargraph::Pin::Method.new(source, c, fqn || '', scope, visibility)
|
272
272
|
elsif c.type == :defs
|
273
|
-
|
274
|
-
|
273
|
+
s_visi = visibility
|
274
|
+
s_visi = :public if scope != :class
|
275
|
+
method_pins.push Solargraph::Pin::Method.new(source, c, fqn || '', :class, s_visi)
|
276
|
+
inner_map_node c, tree, scope, :class, fqn, stack
|
275
277
|
next
|
276
278
|
elsif c.type == :send and [:public, :protected, :private].include?(c.children[1])
|
277
279
|
visibility = c.children[1]
|
280
|
+
elsif c.type == :send and [:private_class_method].include?(c.children[1]) and c.children[2].kind_of?(AST::Node)
|
281
|
+
if c.children[2].type == :sym or c.children[2].type == :str
|
282
|
+
ref = method_pins.select{|p| p.name == c.children[2].children[0].to_s}.first
|
283
|
+
unless ref.nil?
|
284
|
+
source.method_pins.delete ref
|
285
|
+
source.method_pins.push Solargraph::Pin::Method.new(ref.source, ref.node, ref.namespace, ref.scope, :private)
|
286
|
+
end
|
287
|
+
else
|
288
|
+
inner_map_node c, tree, :private, :class, fqn, stack
|
289
|
+
next
|
290
|
+
end
|
291
|
+
elsif c.type == :send and [:private_constant].include?(c.children[1]) and c.children[2].kind_of?(AST::Node)
|
292
|
+
if c.children[2].type == :sym or c.children[2].type == :str
|
293
|
+
cn = c.children[2].children[0].to_s
|
294
|
+
ref = constant_pins.select{|p| p.name == cn}.first
|
295
|
+
if ref.nil?
|
296
|
+
ref = namespace_pins.select{|p| p.name == cn}.first
|
297
|
+
unless ref.nil?
|
298
|
+
source.namespace_pins.delete ref
|
299
|
+
source.namespace_pins.push Solargraph::Pin::Namespace.new(ref.source, ref.node, ref.namespace, :private)
|
300
|
+
end
|
301
|
+
else
|
302
|
+
source.constant_pins.delete ref
|
303
|
+
source.constant_pins.push Solargraph::Pin::Constant.new(ref.source, ref.node, ref.namespace, :private)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
next
|
278
307
|
elsif c.type == :send and c.children[1] == :include #and node.type == :class
|
279
308
|
namespace_includes[fqn] ||= []
|
280
309
|
c.children[2..-1].each do |i|
|
@@ -2,6 +2,8 @@ module Solargraph
|
|
2
2
|
class ApiMap
|
3
3
|
module SourceToYard
|
4
4
|
|
5
|
+
private
|
6
|
+
|
5
7
|
# Get the YARD CodeObject at the specified path.
|
6
8
|
#
|
7
9
|
# @return [YARD::CodeObjects::Base]
|
@@ -13,22 +15,25 @@ module Solargraph
|
|
13
15
|
code_object_map.keys
|
14
16
|
end
|
15
17
|
|
16
|
-
private
|
17
|
-
|
18
18
|
def code_object_map
|
19
19
|
@code_object_map ||= {}
|
20
20
|
end
|
21
21
|
|
22
|
+
def root_code_object
|
23
|
+
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
24
|
+
end
|
25
|
+
|
22
26
|
def rake_yard sources
|
23
27
|
code_object_map.clear
|
24
28
|
sources.each do |s|
|
25
29
|
s.namespace_pins.each do |pin|
|
26
|
-
if pin.kind ==
|
27
|
-
code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(
|
30
|
+
if pin.kind == Solargraph::Suggestion::CLASS
|
31
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path)
|
28
32
|
else
|
29
|
-
code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(
|
33
|
+
code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path)
|
30
34
|
end
|
31
35
|
code_object_map[pin.path].docstring = pin.docstring unless pin.docstring.nil?
|
36
|
+
code_object_map[pin.path].files.push pin.source.filename
|
32
37
|
end
|
33
38
|
s.namespace_includes.each_pair do |n, i|
|
34
39
|
code_object_map[n].mixins.push code_object_map[i] unless code_object_map[i].nil?
|
@@ -36,11 +41,13 @@ module Solargraph
|
|
36
41
|
s.attribute_pins.each do |pin|
|
37
42
|
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, :instance)
|
38
43
|
code_object_map[pin.path].docstring = pin.docstring unless pin.docstring.nil?
|
44
|
+
code_object_map[pin.path].files.push pin.source.filename
|
39
45
|
#code_object_map[pin.path].parameters = []
|
40
46
|
end
|
41
47
|
s.method_pins.each do |pin|
|
42
48
|
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope)
|
43
49
|
code_object_map[pin.path].docstring = pin.docstring unless pin.docstring.nil?
|
50
|
+
code_object_map[pin.path].files.push pin.source.filename
|
44
51
|
code_object_map[pin.path].parameters = pin.parameters.map do |p|
|
45
52
|
n = p.match(/^[a-z0-9\-]*?:?/i)[0]
|
46
53
|
v = nil
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -181,12 +181,14 @@ module Solargraph
|
|
181
181
|
skip = []
|
182
182
|
fqns = find_fully_qualified_namespace(namespace, root)
|
183
183
|
if fqns.empty?
|
184
|
-
result.concat inner_get_constants('', skip, false)
|
184
|
+
result.concat inner_get_constants('', skip, false, :public)
|
185
185
|
else
|
186
186
|
parts = fqns.split('::')
|
187
187
|
resolved = find_namespace_pins(parts.join('::'))
|
188
188
|
resolved.each do |pin|
|
189
|
-
|
189
|
+
visi = :public
|
190
|
+
visi = :private if root != '' and pin.path == fqns
|
191
|
+
result.concat inner_get_constants(pin.path, skip, true, visi)
|
190
192
|
end
|
191
193
|
end
|
192
194
|
result.concat yard_map.get_constants(fqns)
|
@@ -346,29 +348,14 @@ module Solargraph
|
|
346
348
|
|
347
349
|
# @return [String]
|
348
350
|
def infer_assignment_node_type node, namespace
|
349
|
-
|
351
|
+
name_i = (node.type == :casgn ? 1 : 0)
|
352
|
+
sig_i = (node.type == :casgn ? 2 : 1)
|
353
|
+
type = infer_literal_node_type(node.children[sig_i])
|
350
354
|
if type.nil?
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
type = infer_literal_node_type(node.children[sig_i])
|
356
|
-
if type.nil?
|
357
|
-
sig = resolve_node_signature(node.children[sig_i])
|
358
|
-
# Avoid infinite loops from variable assignments that reference themselves
|
359
|
-
return nil if node.children[name_i].to_s == sig.split('.').first
|
360
|
-
type = infer_signature_type(sig, namespace)
|
361
|
-
end
|
362
|
-
else
|
363
|
-
t = cmnt.tag(:type)
|
364
|
-
if t.nil?
|
365
|
-
sig = resolve_node_signature(node.children[1])
|
366
|
-
type = infer_signature_type(sig, namespace)
|
367
|
-
else
|
368
|
-
type = t.types[0]
|
369
|
-
end
|
370
|
-
end
|
371
|
-
cache.set_assignment_node_type(node, namespace, type)
|
355
|
+
sig = resolve_node_signature(node.children[sig_i])
|
356
|
+
# Avoid infinite loops from variable assignments that reference themselves
|
357
|
+
return nil if node.children[name_i].to_s == sig.split('.').first
|
358
|
+
type = infer_signature_type(sig, namespace)
|
372
359
|
end
|
373
360
|
type
|
374
361
|
end
|
@@ -859,29 +846,31 @@ module Solargraph
|
|
859
846
|
type
|
860
847
|
end
|
861
848
|
|
862
|
-
def inner_get_constants here, skip = [], deep = true
|
849
|
+
def inner_get_constants here, skip = [], deep = true, visibility
|
863
850
|
return [] if skip.include?(here)
|
864
851
|
skip.push here
|
865
852
|
result = []
|
866
853
|
cp = @const_pins[here]
|
867
854
|
unless cp.nil?
|
868
855
|
cp.each do |pin|
|
869
|
-
result.push pin_to_suggestion(pin)
|
856
|
+
result.push pin_to_suggestion(pin) if pin.visibility == :public or visibility == :private
|
870
857
|
end
|
871
858
|
end
|
872
859
|
np = @namespace_pins[here]
|
873
860
|
unless np.nil?
|
874
861
|
np.each do |pin|
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
862
|
+
if pin.visibility == :public || visibility == :private
|
863
|
+
result.push pin_to_suggestion(pin)
|
864
|
+
if deep
|
865
|
+
get_include_strings_from(pin.node).each do |i|
|
866
|
+
result.concat inner_get_constants(i, skip, false, :public)
|
867
|
+
end
|
879
868
|
end
|
880
869
|
end
|
881
870
|
end
|
882
871
|
end
|
883
872
|
get_include_strings_from(*get_namespace_nodes(here)).each do |i|
|
884
|
-
result.concat inner_get_constants(i, skip, false)
|
873
|
+
result.concat inner_get_constants(i, skip, false, :public)
|
885
874
|
end
|
886
875
|
result
|
887
876
|
end
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -246,7 +246,8 @@ module Solargraph
|
|
246
246
|
result.concat api_map.get_instance_methods(type) unless (type == '' and signature.include?('.'))
|
247
247
|
end
|
248
248
|
result = reduce_starting_with(result, word_at(index)) if filtered
|
249
|
-
|
249
|
+
# Use a stable sort to keep the class order (e.g., local methods before superclass methods)
|
250
|
+
result.uniq(&:path).sort_by.with_index{ |x, idx| [x.label, idx] }
|
250
251
|
end
|
251
252
|
|
252
253
|
def signatures_at index
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module Solargraph
|
2
2
|
module Pin
|
3
3
|
class Constant < BaseVariable
|
4
|
+
attr_reader :visibility
|
5
|
+
|
6
|
+
def initialize source, node, namespace, visibility
|
7
|
+
super(source, node, namespace)
|
8
|
+
@visibility = visibility
|
9
|
+
end
|
4
10
|
|
5
11
|
def name
|
6
12
|
@name ||= node.children[1].to_s
|
@@ -3,6 +3,13 @@ module Solargraph
|
|
3
3
|
class Namespace < Pin::Base
|
4
4
|
include Solargraph::NodeMethods
|
5
5
|
|
6
|
+
attr_reader :visibility
|
7
|
+
|
8
|
+
def initialize source, node, namespace, visibility
|
9
|
+
super(source, node, namespace)
|
10
|
+
@visibility = visibility
|
11
|
+
end
|
12
|
+
|
6
13
|
def name
|
7
14
|
@name ||= pack_name(node.children[0]).last.to_s
|
8
15
|
end
|
data/lib/solargraph/server.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module Solargraph
|
4
|
-
|
4
|
+
# Information about a class, module, method, or variable.
|
5
|
+
#
|
5
6
|
class Suggestion
|
6
|
-
CLASS
|
7
|
+
CLASS = 'Class'
|
7
8
|
CONSTANT = 'Constant'
|
8
|
-
FIELD
|
9
|
-
KEYWORD
|
10
|
-
METHOD
|
11
|
-
MODULE
|
9
|
+
FIELD = 'Field'
|
10
|
+
KEYWORD = 'Keyword'
|
11
|
+
METHOD = 'Method'
|
12
|
+
MODULE = 'Module'
|
12
13
|
PROPERTY = 'Property'
|
13
|
-
SNIPPET
|
14
|
+
SNIPPET = 'Snippet'
|
14
15
|
VARIABLE = 'Variable'
|
15
16
|
|
16
17
|
# @return [String]
|
@@ -51,6 +52,14 @@ module Solargraph
|
|
51
52
|
@path = path
|
52
53
|
end
|
53
54
|
|
55
|
+
# The full path of the suggestion.
|
56
|
+
#
|
57
|
+
# Examples:
|
58
|
+
# - MyClass
|
59
|
+
# - MyModule::MyClass
|
60
|
+
# - MyClass#instance_method
|
61
|
+
# - MyModule.singleton_method
|
62
|
+
#
|
54
63
|
# @return [String]
|
55
64
|
def path
|
56
65
|
@path ||= (code_object.nil? ? label : code_object.path)
|
@@ -99,7 +108,13 @@ module Solargraph
|
|
99
108
|
@params
|
100
109
|
end
|
101
110
|
|
102
|
-
|
111
|
+
# True if the suggestion has documentation.
|
112
|
+
# Useful for determining whether a client should resolve a suggestion's
|
113
|
+
# path to retrieve more information about it.
|
114
|
+
#
|
115
|
+
# @return [Boolean]
|
116
|
+
def has_doc?
|
117
|
+
!documentation.empty?
|
103
118
|
end
|
104
119
|
|
105
120
|
def as_json args = {}
|
@@ -112,7 +127,8 @@ module Solargraph
|
|
112
127
|
location: (@location.nil? ? nil : @location.to_s),
|
113
128
|
arguments: @arguments,
|
114
129
|
params: params,
|
115
|
-
return_type: return_type
|
130
|
+
return_type: return_type,
|
131
|
+
has_doc: has_doc?
|
116
132
|
}
|
117
133
|
result[:documentation] = documentation if args[:all]
|
118
134
|
result
|
@@ -122,10 +138,11 @@ module Solargraph
|
|
122
138
|
as_json.to_json(args)
|
123
139
|
end
|
124
140
|
|
141
|
+
# Generate a suggestion from a pin.
|
142
|
+
#
|
125
143
|
# @param pin [Solargraph::Pin::Base]
|
126
144
|
def self.pull pin, return_type = nil
|
127
145
|
Suggestion.new(pin.name, insert: pin.name.gsub(/=/, ' = '), kind: pin.kind, docstring: pin.docstring, detail: pin.namespace, arguments: pin.parameters, path: pin.path, return_type: return_type || pin.return_type, location: pin.location)
|
128
146
|
end
|
129
147
|
end
|
130
|
-
|
131
148
|
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.15.
|
4
|
+
version: 0.15.3
|
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-12-
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|