solargraph 0.18.3 → 0.19.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solargraph/api_map/probe.rb +222 -0
  3. data/lib/solargraph/api_map/source_to_yard.rb +3 -3
  4. data/lib/solargraph/api_map/store.rb +135 -0
  5. data/lib/solargraph/api_map.rb +169 -609
  6. data/lib/solargraph/diagnostics/rubocop.rb +4 -4
  7. data/lib/solargraph/language_server/host.rb +53 -19
  8. data/lib/solargraph/language_server/message/extended/document.rb +1 -1
  9. data/lib/solargraph/language_server/message/extended/search.rb +1 -1
  10. data/lib/solargraph/language_server/message/method_not_found.rb +1 -1
  11. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -15
  12. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -15
  13. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +3 -15
  14. data/lib/solargraph/language_server/message_types.rb +10 -0
  15. data/lib/solargraph/language_server.rb +1 -0
  16. data/lib/solargraph/library.rb +8 -0
  17. data/lib/solargraph/node_methods.rb +6 -1
  18. data/lib/solargraph/page.rb +2 -1
  19. data/lib/solargraph/pin/attribute.rb +8 -12
  20. data/lib/solargraph/pin/base.rb +20 -95
  21. data/lib/solargraph/pin/base_variable.rb +15 -74
  22. data/lib/solargraph/pin/block.rb +21 -0
  23. data/lib/solargraph/pin/block_parameter.rb +30 -44
  24. data/lib/solargraph/pin/class_variable.rb +3 -0
  25. data/lib/solargraph/pin/constant.rb +4 -8
  26. data/lib/solargraph/pin/conversions.rb +4 -3
  27. data/lib/solargraph/pin/documenting.rb +27 -0
  28. data/lib/solargraph/pin/global_variable.rb +3 -0
  29. data/lib/solargraph/pin/instance_variable.rb +5 -4
  30. data/lib/solargraph/pin/local_variable.rb +8 -15
  31. data/lib/solargraph/pin/localized.rb +12 -0
  32. data/lib/solargraph/pin/method.rb +6 -67
  33. data/lib/solargraph/pin/method_parameter.rb +24 -11
  34. data/lib/solargraph/pin/namespace.rb +26 -35
  35. data/lib/solargraph/pin/reference.rb +15 -8
  36. data/lib/solargraph/pin/symbol.rb +34 -3
  37. data/lib/solargraph/pin/yard_object.rb +11 -4
  38. data/lib/solargraph/pin.rb +16 -2
  39. data/lib/solargraph/server.rb +2 -2
  40. data/lib/solargraph/source/change.rb +10 -13
  41. data/lib/solargraph/source/fragment.rb +42 -94
  42. data/lib/solargraph/source/location.rb +13 -0
  43. data/lib/solargraph/source/mapper.rb +426 -0
  44. data/lib/solargraph/source/position.rb +1 -0
  45. data/lib/solargraph/source/range.rb +11 -3
  46. data/lib/solargraph/source.rb +93 -284
  47. data/lib/solargraph/version.rb +1 -1
  48. data/lib/solargraph/views/_method.erb +59 -60
  49. data/lib/solargraph/views/_name_type_tag.erb +10 -0
  50. data/lib/solargraph/views/_namespace.erb +26 -26
  51. data/lib/solargraph/views/document.erb +23 -16
  52. data/lib/solargraph/views/layout.erb +38 -10
  53. data/lib/solargraph/views/search.erb +12 -11
  54. data/lib/solargraph/workspace/config.rb +27 -6
  55. data/lib/solargraph/workspace.rb +10 -2
  56. data/lib/solargraph.rb +10 -2
  57. data/lib/yard-solargraph.rb +3 -0
  58. metadata +25 -20
  59. data/lib/solargraph/pin/directed/attribute.rb +0 -20
  60. data/lib/solargraph/pin/directed/method.rb +0 -22
  61. data/lib/solargraph/pin/directed.rb +0 -9
  62. data/lib/solargraph/pin/parameter.rb +0 -23
@@ -5,13 +5,13 @@ module Solargraph
5
5
  attr_reader :start
6
6
 
7
7
  # @return [Position]
8
- attr_reader :end
8
+ attr_reader :ending
9
9
 
10
10
  # @param start [Position]
11
11
  # @param ending [Position]
12
12
  def initialize start, ending
13
13
  @start = start
14
- @end = ending
14
+ @ending = ending
15
15
  end
16
16
 
17
17
  # Get a hash of the range. This representation is suitable for use in
@@ -20,10 +20,18 @@ module Solargraph
20
20
  def to_hash
21
21
  {
22
22
  start: start.to_hash,
23
- end: self.end.to_hash
23
+ end: ending.to_hash
24
24
  }
25
25
  end
26
26
 
27
+ def contain? position
28
+ return false if position.line < start.line
29
+ return false if position.line == start.line and position.character < start.character
30
+ return false if position.line > ending.line
31
+ return false if position.line == ending.line and position.character > ending.character
32
+ true
33
+ end
34
+
27
35
  # Create a range from a pair of lines and characters.
28
36
  #
29
37
  # @param l1 [Integer] Starting line
@@ -7,8 +7,10 @@ module Solargraph
7
7
  autoload :Fragment, 'solargraph/source/fragment'
8
8
  autoload :Position, 'solargraph/source/position'
9
9
  autoload :Range, 'solargraph/source/range'
10
+ autoload :Location, 'solargraph/source/location'
10
11
  autoload :Updater, 'solargraph/source/updater'
11
12
  autoload :Change, 'solargraph/source/change'
13
+ autoload :Mapper, 'solargraph/source/mapper'
12
14
 
13
15
  # @return [String]
14
16
  attr_reader :code
@@ -38,6 +40,12 @@ module Solargraph
38
40
  # @return [Time]
39
41
  attr_reader :stime
40
42
 
43
+ attr_reader :pins
44
+
45
+ attr_reader :requires
46
+
47
+ attr_reader :locals
48
+
41
49
  include NodeMethods
42
50
 
43
51
  def initialize code, filename = nil
@@ -57,78 +65,93 @@ module Solargraph
57
65
  @path_macros[path]
58
66
  end
59
67
 
68
+ # @todo Temporary blank
69
+ def path_macros
70
+ @path_macros ||= {}
71
+ end
72
+
73
+ # @todo Name problem
74
+ def required
75
+ requires
76
+ end
77
+
60
78
  # @return [Array<String>]
61
79
  def namespaces
62
- @namespaces ||= namespace_pin_map.keys
63
- end
64
-
65
- def qualify(signature, fqns)
66
- return signature if signature.nil? or signature.empty?
67
- base, rest = signature.split('.', 2)
68
- parts = fqns.split('::')
69
- until parts.empty?
70
- here = parts.join('::')
71
- parts.pop
72
- name = "#{here}::#{base}"
73
- next if namespace_pins(name).empty?
74
- base = name
75
- break
76
- end
77
- base + (rest.nil? ? '' : ".#{rest}")
80
+ # @namespaces ||= namespace_pin_map.keys
81
+ @namespaces ||= pins.select{|pin| pin.kind == Pin::NAMESPACE}.map(&:path)
78
82
  end
79
83
 
80
84
  # @param fqns [String] The namespace (nil for all)
81
85
  # @return [Array<Solargraph::Pin::Namespace>]
82
86
  def namespace_pins fqns = nil
83
- return namespace_pin_map.values.flatten if fqns.nil?
84
- namespace_pin_map[fqns] || []
87
+ pins.select{|pin| pin.kind == Pin::NAMESPACE}
85
88
  end
86
89
 
87
90
  # @param fqns [String] The namespace (nil for all)
88
91
  # @return [Array<Solargraph::Pin::Method>]
89
92
  def method_pins fqns = nil
90
- return method_pin_map.values.flatten if fqns.nil?
91
- method_pin_map[fqns] || []
93
+ pins.select{|pin| pin.kind == Solargraph::Pin::METHOD}
92
94
  end
93
95
 
94
96
  # @return [Array<Solargraph::Pin::Attribute>]
95
97
  def attribute_pins
96
- @attribute_pins ||= []
98
+ pins.select{|pin| pin.kind == Pin::ATTRIBUTE}
97
99
  end
98
100
 
99
101
  # @return [Array<Solargraph::Pin::InstanceVariable>]
100
102
  def instance_variable_pins
101
- @instance_variable_pins ||= []
103
+ pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE}
102
104
  end
103
105
 
104
106
  # @return [Array<Solargraph::Pin::ClassVariable>]
105
107
  def class_variable_pins
106
- @class_variable_pins ||= []
108
+ pins.select{|pin| pin.kind == Pin::CLASS_VARIABLE}
107
109
  end
108
110
 
109
- # @return [Array<Solargraph::Pin::LocalVariable>]
110
- def local_variable_pins
111
- @local_variable_pins ||= []
111
+ def locals
112
+ @locals
112
113
  end
113
114
 
114
115
  # @return [Array<Solargraph::Pin::GlobalVariable>]
115
116
  def global_variable_pins
116
- @global_variable_pins ||= []
117
+ pins.select{|pin| pin.kind == Pin::GLOBAL_VARIABLE}
117
118
  end
118
119
 
119
120
  # @return [Array<Solargraph::Pin::Constant>]
120
121
  def constant_pins
121
- @constant_pins ||= []
122
+ pins.select{|pin| pin.kind == Pin::CONSTANT}
122
123
  end
123
124
 
124
125
  # @return [Array<Solargraph::Pin::Symbol>]
125
126
  def symbol_pins
126
- @symbol_pins ||= []
127
+ @symbols
127
128
  end
128
129
 
129
- # @return [Array<String>]
130
- def required
131
- @required ||= []
130
+ def symbols
131
+ symbol_pins
132
+ end
133
+
134
+ def locate_named_path_pin line, character
135
+ _locate_pin line, character, Pin::NAMESPACE, Pin::METHOD
136
+ end
137
+
138
+ def locate_namespace_pin line, character
139
+ _locate_pin line, character, Pin::NAMESPACE
140
+ end
141
+
142
+ def locate_block_pin line, character
143
+ _locate_pin line, character, Pin::NAMESPACE, Pin::METHOD, Pin::BLOCK
144
+ end
145
+
146
+ def _locate_pin line, character, *kinds
147
+ position = Solargraph::Source::Position.new(line, character)
148
+ found = nil
149
+ pins.each do |pin|
150
+ found = pin if (kinds.empty? or kinds.include?(pin.kind)) and pin.location.range.contain?(position)
151
+ break if pin.location.range.start.line > line
152
+ end
153
+ # @todo Assuming the root pin is always valid
154
+ found || pins.first
132
155
  end
133
156
 
134
157
  # @return [YARD::Docstring]
@@ -158,28 +181,35 @@ module Solargraph
158
181
  tree_at(line, column).first
159
182
  end
160
183
 
184
+ def string_at?(line, column)
185
+ node = node_at(line, column)
186
+ # @todo raise InvalidOffset or InvalidRange or something?
187
+ return false if node.nil?
188
+ node.type == :str or node.type == :dstr
189
+ end
190
+
161
191
  # Get an array of nodes containing the specified index, starting with the
162
192
  # nearest node and ending with the root.
163
193
  #
164
194
  # @param index [Integer]
165
195
  # @return [Array<AST::Node>]
166
196
  def tree_at(line, column)
167
- # offset = get_parsed_offset(line, column)
168
197
  offset = Position.line_char_to_offset(@code, line, column)
169
- @all_nodes.reverse.each do |n|
170
- if n.respond_to?(:loc)
171
- if n.respond_to?(:begin) and n.respond_to?(:end)
172
- if offset >= n.begin.begin_pos and offset < n.end.end_pos
173
- return [n] + @node_tree[n.object_id]
174
- end
175
- elsif !n.loc.expression.nil?
176
- if offset >= n.loc.expression.begin_pos and offset < n.loc.expression.end_pos
177
- return [n] + @node_tree[n.object_id]
178
- end
179
- end
198
+ stack = []
199
+ inner_tree_at @node, offset, stack
200
+ stack
201
+ end
202
+
203
+ def inner_tree_at node, offset, stack
204
+ stack.unshift node
205
+ node.children.each do |c|
206
+ next unless c.is_a?(AST::Node)
207
+ next if c.loc.expression.nil?
208
+ if offset >= c.loc.expression.begin_pos and offset < c.loc.expression.end_pos
209
+ inner_tree_at(c, offset, stack)
210
+ break
180
211
  end
181
212
  end
182
- [@node]
183
213
  end
184
214
 
185
215
  # Find the nearest parent node from the specified index. If one or more
@@ -265,7 +295,7 @@ module Solargraph
265
295
 
266
296
  # @return [Solargraph::Source::Fragment]
267
297
  def fragment_at line, column
268
- Fragment.new(self, line, column, tree_at(line, column))
298
+ Fragment.new(self, line, column)
269
299
  end
270
300
 
271
301
  def fragment_for node
@@ -283,71 +313,33 @@ module Solargraph
283
313
  private
284
314
 
285
315
  def parse
286
- node, comments = Source.parse(@fixed, filename)
316
+ node, comments = inner_parse(@fixed, filename)
317
+ @node = node
318
+ @comments = comments
287
319
  process_parsed node, comments
288
320
  @parsed = true
289
321
  end
290
322
 
291
323
  def hard_fix_node
292
- @fixed = @code.gsub(/[^\s]/, ' ')
293
- node, comments = Source.parse(@fixed, filename)
324
+ @fixed = @code.gsub(/[^\s]/, '_')
325
+ node, comments = inner_parse(@fixed, filename)
326
+ @node = node
327
+ @comments = comments
294
328
  process_parsed node, comments
295
329
  @parsed = false
296
330
  end
297
331
 
332
+ def inner_parse code, filename
333
+ parser = Parser::CurrentRuby.new(FlawedBuilder.new)
334
+ parser.diagnostics.all_errors_are_fatal = true
335
+ parser.diagnostics.ignore_warnings = true
336
+ buffer = Parser::Source::Buffer.new(filename, 1)
337
+ buffer.source = code.force_encoding(Encoding::UTF_8)
338
+ parser.parse_with_comments(buffer)
339
+ end
340
+
298
341
  def process_parsed node, comments
299
- root = AST::Node.new(:source, [filename])
300
- root = root.append node
301
- @node = root
302
- @namespaces = nil
303
- @comments = comments
304
- @directives = {}
305
- @path_macros = {}
306
- @docstring_hash = associate_comments(node, comments)
307
- @mtime = (!filename.nil? and File.exist?(filename) ? File.mtime(filename) : nil)
308
- @all_nodes = []
309
- @node_stack = []
310
- @node_tree = {}
311
- namespace_pin_map.clear
312
- namespace_pin_map[''] = [Solargraph::Pin::Namespace.new(self, @node, '', :public)]
313
- @namespace_pins = nil
314
- instance_variable_pins.clear
315
- class_variable_pins.clear
316
- local_variable_pins.clear
317
- symbol_pins.clear
318
- constant_pins.clear
319
- method_pin_map.clear
320
- # namespace_includes.clear
321
- attribute_pins.clear
322
- @node_object_ids = nil
323
- inner_map_node @node
324
- @directives.each_pair do |k, v|
325
- v.each do |d|
326
- ns = namespace_for(k.node)
327
- docstring = YARD::Docstring.parser.parse(d.tag.text).to_docstring
328
- if d.tag.tag_name == 'attribute'
329
- t = (d.tag.types.nil? || d.tag.types.empty?) ? nil : d.tag.types.flatten.join('')
330
- if t.nil? or t.include?('r')
331
- attribute_pins.push Solargraph::Pin::Directed::Attribute.new(self, k.node, ns, :reader, docstring, d.tag.name)
332
- end
333
- if t.nil? or t.include?('w')
334
- attribute_pins.push Solargraph::Pin::Directed::Attribute.new(self, k.node, ns, :writer, docstring, "#{d.tag.name}=")
335
- end
336
- elsif d.tag.tag_name == 'method'
337
- gen_src = Source.new("def #{d.tag.name};end", filename)
338
- gen_pin = gen_src.method_pins.first
339
- method_pin_map[ns] ||= []
340
- method_pin_map[ns].push Solargraph::Pin::Directed::Method.new(gen_src, gen_pin.node, ns, :instance, :public, docstring, gen_pin.name)
341
- elsif d.tag.tag_name == 'macro'
342
- # @todo Handle various types of macros (attach, new, whatever)
343
- path = path_for(k.node)
344
- @path_macros[path] = v
345
- else
346
- STDERR.puts "Nothing to do for directive: #{d}"
347
- end
348
- end
349
- end
350
- @all_pins = namespace_pin_map.values.flatten + instance_variable_pins + class_variable_pins + local_variable_pins + symbol_pins + constant_pins + method_pins + attribute_pins
342
+ @pins, @locals, @requires, @symbols, @path_macros = Mapper.map filename, code, node, comments
351
343
  @stime = Time.now
352
344
  end
353
345
 
@@ -383,180 +375,6 @@ module Solargraph
383
375
  yard_hash
384
376
  end
385
377
 
386
- def inner_map_node node, tree = [], visibility = :public, scope = :instance, fqn = '', stack = []
387
- stack.push node
388
- source = self
389
- if node.kind_of?(AST::Node)
390
- @all_nodes.push node
391
- @node_stack.unshift node
392
- if node.type == :class or node.type == :module
393
- visibility = :public
394
- if node.children[0].kind_of?(AST::Node) and node.children[0].children[0].kind_of?(AST::Node) and node.children[0].children[0].type == :cbase
395
- tree = pack_name(node.children[0])
396
- else
397
- tree = tree + pack_name(node.children[0])
398
- end
399
- fqn = tree.join('::')
400
- sc = nil
401
- nspin = Solargraph::Pin::Namespace.new(self, node, tree[0..-2].join('::') || '', :public, sc)
402
- if node.type == :class and !node.children[1].nil?
403
- nspin.reference_superclass unpack_name(node.children[1])
404
- end
405
- namespace_pin_map[nspin.path] ||= []
406
- namespace_pin_map[nspin.path].push nspin
407
- end
408
- file = source.filename
409
- node.children.each do |c|
410
- if c.kind_of?(AST::Node)
411
- @node_tree[c.object_id] = @node_stack.clone
412
- if c.type == :ivasgn
413
- par = find_parent(stack, :class, :module, :def, :defs)
414
- local_scope = ( (par.kind_of?(AST::Node) and par.type == :def) ? :instance : :class )
415
- if c.children[1].nil?
416
- ora = find_parent(stack, :or_asgn)
417
- unless ora.nil?
418
- u = c.updated(:ivasgn, c.children + ora.children[1..-1], nil)
419
- @all_nodes.push u
420
- @node_tree[u.object_id] = @node_stack.clone
421
- @docstring_hash[u.loc] = docstring_for(ora)
422
- instance_variable_pins.push Solargraph::Pin::InstanceVariable.new(self, u, fqn || '', local_scope)
423
- end
424
- else
425
- instance_variable_pins.push Solargraph::Pin::InstanceVariable.new(self, c, fqn || '', local_scope)
426
- end
427
- elsif c.type == :cvasgn
428
- if c.children[1].nil?
429
- ora = find_parent(stack, :or_asgn)
430
- unless ora.nil?
431
- u = c.updated(:cvasgn, c.children + ora.children[1..-1], nil)
432
- @node_tree[u.object_id] = @node_stack.clone
433
- @all_nodes.push u
434
- @docstring_hash[u.loc] = docstring_for(ora)
435
- class_variable_pins.push Solargraph::Pin::ClassVariable.new(self, u, fqn || '')
436
- end
437
- else
438
- class_variable_pins.push Solargraph::Pin::ClassVariable.new(self, c, fqn || '')
439
- end
440
- elsif c.type == :lvasgn
441
- if c.children[1].nil?
442
- ora = find_parent(stack, :or_asgn)
443
- unless ora.nil?
444
- u = c.updated(:lvasgn, c.children + ora.children[1..-1], nil)
445
- @all_nodes.push u
446
- @node_tree[u] = @node_stack.clone
447
- @docstring_hash[u.loc] = docstring_for(ora)
448
- local_variable_pins.push Solargraph::Pin::LocalVariable.new(self, u, fqn || '', @node_stack.clone)
449
- end
450
- else
451
- @node_tree[c] = @node_stack.clone
452
- local_variable_pins.push Solargraph::Pin::LocalVariable.new(self, c, fqn || '', @node_stack.clone)
453
- end
454
- elsif c.type == :gvasgn
455
- global_variable_pins.push Solargraph::Pin::GlobalVariable.new(self, c, fqn || '')
456
- elsif c.type == :sym
457
- symbol_pins.push Solargraph::Pin::Symbol.new(self, c, fqn)
458
- elsif c.type == :casgn
459
- constant_pins.push Solargraph::Pin::Constant.new(self, c, fqn, :public)
460
- elsif c.type == :def and c.children[0].to_s[0].match(/[a-z]/i)
461
- method_pin_map[fqn || ''] ||= []
462
- method_pin_map[fqn || ''].push Solargraph::Pin::Method.new(source, c, fqn || '', scope, visibility)
463
- elsif c.type == :defs
464
- s_visi = visibility
465
- s_visi = :public if scope != :class
466
- if c.children[0].is_a?(AST::Node) and c.children[0].type == :self
467
- dfqn = fqn || ''
468
- else
469
- dfqn = unpack_name(c.children[0])
470
- end
471
- unless dfqn.nil?
472
- method_pin_map[dfqn] ||= []
473
- method_pin_map[dfqn].push Solargraph::Pin::Method.new(source, c, dfqn, :class, s_visi)
474
- inner_map_node c, tree, scope, :class, dfqn, stack
475
- end
476
- next
477
- elsif c.type == :send and [:public, :protected, :private].include?(c.children[1])
478
- visibility = c.children[1]
479
- elsif c.type == :send and [:private_class_method].include?(c.children[1]) and c.children[2].kind_of?(AST::Node)
480
- if c.children[2].type == :sym or c.children[2].type == :str
481
- ref = method_pins(fqn || '').select{|p| p.name == c.children[2].children[0].to_s}.first
482
- unless ref.nil?
483
- method_pin_map[fqn || ''].delete ref
484
- method_pin_map[fqn || ''].push Solargraph::Pin::Method.new(ref.source, ref.node, ref.namespace, ref.scope, :private)
485
- end
486
- else
487
- inner_map_node c, tree, :private, :class, fqn, stack
488
- next
489
- end
490
- elsif c.type == :send and [:private_constant].include?(c.children[1]) and c.children[2].kind_of?(AST::Node)
491
- if c.children[2].type == :sym or c.children[2].type == :str
492
- cn = c.children[2].children[0].to_s
493
- ref = constant_pins.select{|p| p.name == cn}.first
494
- if ref.nil?
495
- ref = namespace_pin_map.values.flatten.select{|p| p.name == cn and p.namespace == fqn}.last
496
- unless ref.nil?
497
- namespace_pin_map[ref.path].delete ref
498
- namespace_pin_map[ref.path].push Solargraph::Pin::Namespace.new(ref.source, ref.node, ref.namespace, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
499
- end
500
- else
501
- source.constant_pins.delete ref
502
- source.constant_pins.push Solargraph::Pin::Constant.new(ref.source, ref.node, ref.namespace, :private)
503
- end
504
- end
505
- next
506
- elsif c.type == :send and c.children[1] == :include and c.children[0].nil?
507
- if @node_tree[0].nil? or @node_tree[0].type == :source or @node_tree[0].type == :class or @node_tree[0].type == :module or (@node_tree.length > 1 and @node_tree[0].type == :begin and (@node_tree[1].type == :class or @node_tree[1].type == :module))
508
- if c.children[2].kind_of?(AST::Node) and c.children[2].type == :const
509
- c.children[2..-1].each do |i|
510
- namespace_pins(fqn || '').last.reference_include unpack_name(i)
511
- end
512
- end
513
- end
514
- elsif c.type == :send and c.children[1] == :extend and c.children[0].nil?
515
- if @node_tree[0].nil? or @node_tree[0].type == :source or @node_tree[0].type == :class or @node_tree[0].type == :module or (@node_tree.length > 1 and @node_tree[0].type == :begin and (@node_tree[1].type == :class or @node_tree[1].type == :module))
516
- if c.children[2].kind_of?(AST::Node) and c.children[2].type == :const
517
- # namespace_extends[fqn || ''] ||= []
518
- c.children[2..-1].each do |i|
519
- namespace_pin_map[fqn || ''].last.reference_extend unpack_name(i)
520
- end
521
- end
522
- end
523
- elsif c.type == :send and [:attr_reader, :attr_writer, :attr_accessor].include?(c.children[1])
524
- c.children[2..-1].each do |a|
525
- if c.children[1] == :attr_reader or c.children[1] == :attr_accessor
526
- attribute_pins.push Solargraph::Pin::Attribute.new(self, a, fqn || '', :reader, docstring_for(c)) #AttrPin.new(c)
527
- end
528
- if c.children[1] == :attr_writer or c.children[1] == :attr_accessor
529
- attribute_pins.push Solargraph::Pin::Attribute.new(self, a, fqn || '', :writer, docstring_for(c)) #AttrPin.new(c)
530
- end
531
- end
532
- elsif c.type == :sclass and c.children[0].type == :self
533
- inner_map_node c, tree, :public, :class, fqn || '', stack
534
- next
535
- elsif c.type == :send and c.children[1] == :require
536
- if c.children[2].kind_of?(AST::Node) and c.children[2].type == :str
537
- required.push c.children[2].children[0].to_s
538
- end
539
- elsif c.type == :args
540
- if @node_stack.first.type == :block
541
- pi = 0
542
- c.children.each do |u|
543
- local_variable_pins.push Solargraph::Pin::BlockParameter.new(self, u, fqn || '', @node_stack.clone, pi)
544
- pi += 1
545
- end
546
- else
547
- c.children.each do |u|
548
- local_variable_pins.push Solargraph::Pin::MethodParameter.new(self, u, fqn || '', @node_stack.clone)
549
- end
550
- end
551
- end
552
- inner_map_node c, tree, visibility, scope, fqn, stack
553
- end
554
- end
555
- @node_stack.shift
556
- end
557
- stack.pop
558
- end
559
-
560
378
  def find_parent(stack, *types)
561
379
  stack.reverse.each { |p|
562
380
  return p if types.include?(p.type)
@@ -590,15 +408,6 @@ module Solargraph
590
408
  Source.new code, filename
591
409
  end
592
410
 
593
- def parse code, filename = nil
594
- parser = Parser::CurrentRuby.new(FlawedBuilder.new)
595
- parser.diagnostics.all_errors_are_fatal = true
596
- parser.diagnostics.ignore_warnings = true
597
- buffer = Parser::Source::Buffer.new(filename, 1)
598
- buffer.source = code.force_encoding(Encoding::UTF_8)
599
- parser.parse_with_comments(buffer)
600
- end
601
-
602
411
  def fix code, filename = nil, offset = nil
603
412
  tries = 0
604
413
  offset = Source.get_offset(code, offset[0], offset[1]) if offset.kind_of?(Array)
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.18.3'
2
+ VERSION = '0.19.0'
3
3
  end
@@ -1,60 +1,59 @@
1
- <h2>
2
- Namespace:
3
- </h2>
4
- <p>
5
- <a href="command:solargraph._openDocument?<%= URI.escape "\"solargraph:/document?#{object.namespace}\"" %>"><%= object.namespace %></a>
6
- </p>
7
- <h2>
8
- Overview:
9
- </h2>
10
- <%= htmlify object.docstring %>
11
- <h2>
12
- Parameters:
13
- </h2>
14
- <% if object.parameters.empty? %>
15
- <p>
16
- None
17
- </p>
18
- <% else %>
19
- <ul>
20
- <% object.parameters.each do |p| %>
21
- <li>
22
- <%= p[0] %>
23
- <%= " = #{p[1]}" unless p[1].nil? %>
24
- </li>
25
- <% end %>
26
- </ul>
27
- <% end %>
28
- <h2>
29
- Returns:
30
- </h2>
31
- <% if object.tag(:return).nil? %>
32
- <p>
33
- Undefined/unknown
34
- </p>
35
- <% else %>
36
- <% tag = object.tag(:return) %>
37
- <% unless tag.types.nil? or tag.types.empty? %>
38
- <ul>
39
- <% tag.types.each do |r| %>
40
- <li>
41
- <a href="command:solargraph._openDocument?<%= URI.escape "\"solargraph:/document?#{r}\"" %>"><%= r %></a>
42
- </li>
43
- <% end %>
44
- </ul>
45
- <% end %>
46
- <% unless tag.text.empty? %>
47
- <p>
48
- <%= tag.text %>
49
- </p>
50
- <% end %>
51
- <% end %>
52
- <% examples = object.tags(:example) %>
53
- <% unless examples.nil? %>
54
- <% examples.each do |example| %>
55
- <h2>
56
- Example: <%= example.name %>
57
- </h2>
58
- <%= ruby_to_html example.text.strip %>
59
- <% end %>
60
- <% end %>
1
+ <h2>
2
+ Namespace:
3
+ </h2>
4
+ <p>
5
+ <a href="command:solargraph._openDocument?<%= URI.escape "\"solargraph:/document?query=#{object.namespace}\"" %>"><%= object.namespace %></a>
6
+ </p>
7
+ <h2>
8
+ Overview:
9
+ </h2>
10
+ <%= htmlify object.docstring %>
11
+ <% unless object.tags(:param).empty? %>
12
+ <h2>
13
+ Parameters:
14
+ </h2>
15
+ <ul>
16
+ <% object.tags(:param).each do |tag| %>
17
+ <li>
18
+ <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
19
+ </li>
20
+ <% end %>
21
+ </ul>
22
+ <% end %>
23
+ <% unless object.tags(:raise).empty? %>
24
+ <h2>
25
+ Raises:
26
+ </h2>
27
+ <ul>
28
+ <% object.tags(:raise).each do |tag| %>
29
+ <li>
30
+ <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
31
+ </li>
32
+ <% end %>
33
+ </ul>
34
+ <% end %>
35
+ <h2>
36
+ Returns:
37
+ </h2>
38
+ <% if object.tag(:return).nil? %>
39
+ <p>
40
+ Undefined/unknown
41
+ </p>
42
+ <% else %>
43
+ <ul>
44
+ <% object.tags(:return).each do |tag| %>
45
+ <li>
46
+ <%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
47
+ </li>
48
+ <% end %>
49
+ </ul>
50
+ <% end %>
51
+ <% examples = object.tags(:example) %>
52
+ <% unless examples.nil? %>
53
+ <% examples.each do |example| %>
54
+ <h2>
55
+ Example: <%= example.name %>
56
+ </h2>
57
+ <%= ruby_to_html example.text.strip %>
58
+ <% end %>
59
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%= tag.name %>
2
+ <% unless tag.types.nil? or tag.types.empty? %>
3
+ [<%= tag.types.join(', ') %>]
4
+ <% end %>
5
+ <% unless tag.text.empty? %>
6
+ <% unless (tag.name.nil? or tag.name.empty?) and (tag.types.nil? or tag.types.empty?) %>
7
+ -
8
+ <% end %>
9
+ <%= tag.text %>
10
+ <% end %>