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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bdbd6d7185bb73e6b6514f5e544c78319643d3e
4
- data.tar.gz: 2d11a5b505c083281d39315b49c4dc984c8ece8f
3
+ metadata.gz: 973c57ed92c49cbc1c242f26d30660a0260329c3
4
+ data.tar.gz: 0f4313ae7372cac8995a78f23992cc2c91c58d85
5
5
  SHA512:
6
- metadata.gz: c20907913080fd29e47bd66218f4b44736985424a128e13e49ea595154ff6b4673a103fa29a97629fb0fb7f6081873d0f1a53737c377a861c76efcdfe527d2dc
7
- data.tar.gz: 37091d44a903d2c0d9edf994e90b771465bfc5c8a464bb310c73f5cfa66231d274c6ccaf5959ac8fbd38cb0164d8fecf83bad8ec8bf7474a619dcf5d48951aa7
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
- method_pins.push Solargraph::Pin::Method.new(source, c, fqn || '', :class, :public)
274
- inner_map_node c, tree, :public, :class, fqn, stack
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 == :class
27
- code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(code_object_at(pin.namespace), pin.name)
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(code_object_at(pin.namespace), pin.name)
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
@@ -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
- result.concat inner_get_constants(pin.path, skip, true)
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
- type = cache.get_assignment_node_type(node, namespace)
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
- cmnt = get_docstring_for(node)
352
- if cmnt.nil?
353
- name_i = (node.type == :casgn ? 1 : 0)
354
- sig_i = (node.type == :casgn ? 2 : 1)
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
- result.push pin_to_suggestion(pin)
876
- if deep
877
- get_include_strings_from(pin.node).each do |i|
878
- result.concat inner_get_constants(i, skip, false)
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
@@ -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
- result.uniq{|s| s.path}.sort{|a,b| a.label <=> b.label}
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
@@ -133,10 +133,6 @@ module Solargraph
133
133
  erb :document
134
134
  end
135
135
 
136
- post '/shutdown' do
137
- exit
138
- end
139
-
140
136
  # @return [Solargraph::ApiMap]
141
137
  def self.get_api_map workspace
142
138
  api_map = nil
@@ -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 = 'Class'
7
+ CLASS = 'Class'
7
8
  CONSTANT = 'Constant'
8
- FIELD = 'Field'
9
- KEYWORD = 'Keyword'
10
- METHOD = 'Method'
11
- MODULE = 'Module'
9
+ FIELD = 'Field'
10
+ KEYWORD = 'Keyword'
11
+ METHOD = 'Method'
12
+ MODULE = 'Module'
12
13
  PROPERTY = 'Property'
13
- SNIPPET = '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
- def inject_detail
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
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.15.2'
2
+ VERSION = '0.15.3'
3
3
  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.15.2
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-05 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser