solargraph 0.39.14 → 0.40.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -8
- data/CHANGELOG.md +988 -0
- data/Rakefile +12 -1
- data/SPONSORS.md +1 -0
- data/lib/solargraph.rb +2 -4
- data/lib/solargraph/api_map.rb +75 -74
- data/lib/solargraph/api_map/cache.rb +2 -2
- data/lib/solargraph/api_map/store.rb +4 -8
- data/lib/solargraph/{bundle.rb → bench.rb} +6 -2
- data/lib/solargraph/compat.rb +14 -0
- data/lib/solargraph/complex_type.rb +2 -2
- data/lib/solargraph/convention.rb +13 -4
- data/lib/solargraph/convention/base.rb +16 -8
- data/lib/solargraph/convention/gemfile.rb +2 -5
- data/lib/solargraph/convention/gemspec.rb +3 -6
- data/lib/solargraph/convention/rspec.rb +3 -6
- data/lib/solargraph/documentor.rb +2 -0
- data/lib/solargraph/environ.rb +11 -6
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +6 -1
- data/lib/solargraph/language_server/message/text_document/definition.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/formatting.rb +17 -19
- data/lib/solargraph/library.rb +8 -10
- data/lib/solargraph/parser/legacy/node_chainer.rb +7 -7
- data/lib/solargraph/parser/legacy/node_methods.rb +5 -0
- data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +1 -1
- data/lib/solargraph/parser/legacy/node_processors/send_node.rb +36 -23
- data/lib/solargraph/parser/node_processor/base.rb +3 -0
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +9 -9
- data/lib/solargraph/parser/rubyvm/node_methods.rb +11 -1
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +1 -1
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +1 -1
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +40 -29
- data/lib/solargraph/pin.rb +0 -3
- data/lib/solargraph/pin/common.rb +1 -1
- data/lib/solargraph/pin/conversions.rb +3 -4
- data/lib/solargraph/pin/documenting.rb +3 -9
- data/lib/solargraph/pin/method.rb +141 -7
- data/lib/solargraph/pin/method_alias.rb +1 -1
- data/lib/solargraph/position.rb +2 -14
- data/lib/solargraph/shell.rb +1 -1
- data/lib/solargraph/source.rb +10 -6
- data/lib/solargraph/source/chain.rb +18 -5
- data/lib/solargraph/source_map.rb +4 -1
- data/lib/solargraph/source_map/clip.rb +3 -2
- data/lib/solargraph/source_map/mapper.rb +10 -6
- data/lib/solargraph/type_checker.rb +35 -39
- data/lib/solargraph/type_checker/param_def.rb +1 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +40 -47
- data/lib/solargraph/yard_map/core_fills.rb +185 -0
- data/lib/solargraph/yard_map/helpers.rb +16 -0
- data/lib/solargraph/yard_map/mapper.rb +14 -8
- data/lib/solargraph/{pin/yard_pin/constant.rb → yard_map/mapper/to_constant.rb} +6 -6
- data/lib/solargraph/yard_map/mapper/to_method.rb +78 -0
- data/lib/solargraph/{pin/yard_pin/namespace.rb → yard_map/mapper/to_namespace.rb} +6 -6
- data/lib/solargraph/yard_map/rdoc_to_yard.rb +1 -1
- data/lib/solargraph/yard_map/stdlib_fills.rb +43 -0
- data/lib/solargraph/yard_map/to_method.rb +79 -0
- data/solargraph.gemspec +4 -4
- metadata +20 -34
- data/lib/solargraph/core_fills.rb +0 -160
- data/lib/solargraph/pin/attribute.rb +0 -49
- data/lib/solargraph/pin/base_method.rb +0 -141
- data/lib/solargraph/pin/yard_pin.rb +0 -12
- data/lib/solargraph/pin/yard_pin/method.rb +0 -80
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +0 -20
- data/lib/solargraph/stdlib_fills.rb +0 -40
- data/travis-bundler.rb +0 -11
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -10,11 +10,15 @@ module Solargraph
|
|
10
10
|
# stdlib, and gems.
|
11
11
|
#
|
12
12
|
class YardMap
|
13
|
-
autoload :Cache,
|
14
|
-
autoload :CoreDocs,
|
15
|
-
autoload :CoreGen,
|
16
|
-
autoload :Mapper,
|
17
|
-
autoload :RdocToYard,
|
13
|
+
autoload :Cache, 'solargraph/yard_map/cache'
|
14
|
+
autoload :CoreDocs, 'solargraph/yard_map/core_docs'
|
15
|
+
autoload :CoreGen, 'solargraph/yard_map/core_gen'
|
16
|
+
autoload :Mapper, 'solargraph/yard_map/mapper'
|
17
|
+
autoload :RdocToYard, 'solargraph/yard_map/rdoc_to_yard'
|
18
|
+
autoload :CoreFills, 'solargraph/yard_map/core_fills'
|
19
|
+
autoload :StdlibFills, 'solargraph/yard_map/stdlib_fills'
|
20
|
+
autoload :Helpers, 'solargraph/yard_map/helpers'
|
21
|
+
autoload :ToMethod, 'solargraph/yard_map/to_method'
|
18
22
|
|
19
23
|
CoreDocs.require_minimum
|
20
24
|
|
@@ -50,6 +54,8 @@ module Solargraph
|
|
50
54
|
def initialize(required: [], gemset: {}, with_dependencies: true)
|
51
55
|
# HACK: YardMap needs its own copy of this array
|
52
56
|
@required = required.clone
|
57
|
+
# HACK: Hardcoded YAML handling
|
58
|
+
@required.push 'psych' if @required.include?('yaml')
|
53
59
|
@with_dependencies = with_dependencies
|
54
60
|
@gem_paths = {}
|
55
61
|
@stdlib_namespaces = []
|
@@ -74,6 +80,8 @@ module Solargraph
|
|
74
80
|
# @param new_gemset [Hash{String => String}]
|
75
81
|
# @return [Boolean]
|
76
82
|
def change new_requires, new_gemset, source_gems = []
|
83
|
+
# HACK: Hardcoded YAML handling
|
84
|
+
new_requires.push 'psych' if new_requires.include?('yaml')
|
77
85
|
if new_requires.uniq.sort == required.uniq.sort && new_gemset == gemset && @source_gems.uniq.sort == source_gems.uniq.sort
|
78
86
|
false
|
79
87
|
else
|
@@ -131,7 +139,7 @@ module Solargraph
|
|
131
139
|
# @param path [String]
|
132
140
|
# @return [Pin::Base]
|
133
141
|
def path_pin path
|
134
|
-
pins.select{ |p| p.path == path }.first
|
142
|
+
pins.select { |p| p.path == path }.first
|
135
143
|
end
|
136
144
|
|
137
145
|
# Get the location of a file referenced by a require path.
|
@@ -151,6 +159,10 @@ module Solargraph
|
|
151
159
|
nil
|
152
160
|
end
|
153
161
|
|
162
|
+
def stdlib_pins
|
163
|
+
@stdlib_pins ||= []
|
164
|
+
end
|
165
|
+
|
154
166
|
private
|
155
167
|
|
156
168
|
# @return [YardMap::Cache]
|
@@ -158,10 +170,12 @@ module Solargraph
|
|
158
170
|
@cache ||= YardMap::Cache.new
|
159
171
|
end
|
160
172
|
|
173
|
+
# @return [Hash]
|
161
174
|
def pin_class_hash
|
162
175
|
@pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
|
163
176
|
end
|
164
177
|
|
178
|
+
# @return [Array<Pin::Base>]
|
165
179
|
def pins_by_class klass
|
166
180
|
@pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
|
167
181
|
end
|
@@ -179,12 +193,13 @@ module Solargraph
|
|
179
193
|
|
180
194
|
# @return [void]
|
181
195
|
def process_requires
|
182
|
-
pins.
|
196
|
+
pins.replace core_pins
|
183
197
|
unresolved_requires.clear
|
184
|
-
|
198
|
+
stdlib_pins.clear
|
199
|
+
environ = Convention.for_global(self)
|
185
200
|
done = []
|
186
201
|
from_std = []
|
187
|
-
required.each do |r|
|
202
|
+
(required + environ.requires).each do |r|
|
188
203
|
next if r.nil? || r.empty? || done.include?(r)
|
189
204
|
done.push r
|
190
205
|
cached = cache.get_path_pins(r)
|
@@ -209,7 +224,6 @@ module Solargraph
|
|
209
224
|
yardocs.unshift yd
|
210
225
|
result.concat process_yardoc yd, spec
|
211
226
|
result.concat add_gem_dependencies(spec) if with_dependencies?
|
212
|
-
stdlib_fill r, result
|
213
227
|
end
|
214
228
|
rescue Gem::LoadError => e
|
215
229
|
base = r.split('/').first
|
@@ -219,7 +233,7 @@ module Solargraph
|
|
219
233
|
if stdtmp.empty?
|
220
234
|
unresolved_requires.push r
|
221
235
|
else
|
222
|
-
|
236
|
+
stdlib_pins.concat stdtmp
|
223
237
|
result.concat stdtmp
|
224
238
|
end
|
225
239
|
end
|
@@ -229,7 +243,13 @@ module Solargraph
|
|
229
243
|
pins.concat result
|
230
244
|
end
|
231
245
|
end
|
232
|
-
|
246
|
+
if required.include?('yaml') && required.include?('psych')
|
247
|
+
# HACK: Hardcoded YAML handling
|
248
|
+
# @todo Why can't this be handled with an override or a virtual pin?
|
249
|
+
pin = path_pin('YAML')
|
250
|
+
pin.instance_variable_set(:@return_type, ComplexType.parse('Module<Psych>')) unless pin.nil?
|
251
|
+
end
|
252
|
+
pins.concat environ.pins
|
233
253
|
end
|
234
254
|
|
235
255
|
# @param spec [Gem::Specification]
|
@@ -327,22 +347,6 @@ module Solargraph
|
|
327
347
|
spec
|
328
348
|
end
|
329
349
|
|
330
|
-
# @param path [String]
|
331
|
-
# @param pins [Array<Pin::Base>]
|
332
|
-
# @return [void]
|
333
|
-
def stdlib_fill path, pins
|
334
|
-
StdlibFills.get(path).each do |ovr|
|
335
|
-
pin = pins.select { |p| p.path == ovr.name }.first
|
336
|
-
next if pin.nil?
|
337
|
-
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
338
|
-
pin.docstring.delete_tags tag.to_sym
|
339
|
-
end
|
340
|
-
ovr.tags.each do |tag|
|
341
|
-
pin.docstring.add_tag(tag)
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
350
|
def load_core_pins
|
347
351
|
yd = CoreDocs.yardoc_file
|
348
352
|
ser = File.join(File.dirname(yd), 'core.ser')
|
@@ -360,23 +364,7 @@ module Solargraph
|
|
360
364
|
else
|
361
365
|
read_core_and_save_cache(yd, ser)
|
362
366
|
end
|
363
|
-
|
364
|
-
errno = result.select{ |pin| pin.path == 'Errno' }.first
|
365
|
-
Errno.constants.each do |const|
|
366
|
-
result.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
|
367
|
-
result.push Solargraph::Pin::Reference::Superclass.new(closure: result.last, name: 'SystemCallError')
|
368
|
-
end
|
369
|
-
CoreFills::OVERRIDES.each do |ovr|
|
370
|
-
pin = result.select { |p| p.path == ovr.name }.first
|
371
|
-
next if pin.nil?
|
372
|
-
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
373
|
-
pin.docstring.delete_tags tag.to_sym
|
374
|
-
end
|
375
|
-
ovr.tags.each do |tag|
|
376
|
-
pin.docstring.add_tag(tag)
|
377
|
-
end
|
378
|
-
end
|
379
|
-
result
|
367
|
+
ApiMap::Store.new(result + CoreFills::ALL).pins.reject { |pin| pin.is_a?(Pin::Reference::Override) }
|
380
368
|
end
|
381
369
|
|
382
370
|
def read_core_and_save_cache yd, ser
|
@@ -384,7 +372,7 @@ module Solargraph
|
|
384
372
|
load_yardoc yd
|
385
373
|
result.concat Mapper.new(YARD::Registry.all).map
|
386
374
|
# HACK: Assume core methods with a single `args` parameter accept restarg
|
387
|
-
result.select { |pin| pin.is_a?(Solargraph::Pin::
|
375
|
+
result.select { |pin| pin.is_a?(Solargraph::Pin::Method )}.each do |pin|
|
388
376
|
if pin.parameters.length == 1 && pin.parameters.first.name == 'args' && pin.parameters.first.decl == :arg
|
389
377
|
# @todo Smelly instance variable access
|
390
378
|
pin.parameters.first.instance_variable_set(:@decl, :restarg)
|
@@ -403,7 +391,7 @@ module Solargraph
|
|
403
391
|
|
404
392
|
def load_stdlib_pins base
|
405
393
|
ser = File.join(File.dirname(CoreDocs.yardoc_stdlib_file), "#{base}.ser")
|
406
|
-
if File.file?(ser)
|
394
|
+
result = if File.file?(ser)
|
407
395
|
Solargraph.logger.info "Loading #{base} stdlib from cache"
|
408
396
|
file = File.open(ser, 'rb')
|
409
397
|
dump = file.read
|
@@ -418,6 +406,11 @@ module Solargraph
|
|
418
406
|
else
|
419
407
|
read_stdlib_and_save_cache(base, ser)
|
420
408
|
end
|
409
|
+
fills = StdlibFills.get(base)
|
410
|
+
unless fills.empty?
|
411
|
+
result = ApiMap::Store.new(result + fills).pins.reject { |pin| pin.is_a?(Pin::Reference::Override) }
|
412
|
+
end
|
413
|
+
result
|
421
414
|
end
|
422
415
|
|
423
416
|
def read_stdlib_and_save_cache base, ser
|
@@ -0,0 +1,185 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class YardMap
|
3
|
+
module CoreFills
|
4
|
+
Override = Pin::Reference::Override
|
5
|
+
|
6
|
+
KEYWORDS = [
|
7
|
+
'__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
|
8
|
+
'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
|
9
|
+
'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
|
10
|
+
'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
|
11
|
+
'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
|
12
|
+
].map { |k| Pin::Keyword.new(k) }
|
13
|
+
|
14
|
+
methods_with_yieldparam_subtypes = %w[
|
15
|
+
Array#each Array#map Array#map! Array#any? Array#all? Array#index
|
16
|
+
Array#keep_if Array#delete_if
|
17
|
+
Enumerable#each_entry Enumerable#map Enumerable#any? Enumerable#all?
|
18
|
+
Enumerable#select Enumerable#reject
|
19
|
+
Set#each
|
20
|
+
]
|
21
|
+
|
22
|
+
OVERRIDES = [
|
23
|
+
Override.method_return('Array#concat', 'Array'),
|
24
|
+
Override.method_return('Array#keep_if', 'self'),
|
25
|
+
Override.method_return('Array#delete_if', 'self'),
|
26
|
+
Override.from_comment('Array#map', %(
|
27
|
+
@overload map(&block)
|
28
|
+
@return [Array]
|
29
|
+
@overload map()
|
30
|
+
@return [Enumerator]
|
31
|
+
)),
|
32
|
+
Override.from_comment('Array#reject', %(
|
33
|
+
@overload reject(&block)
|
34
|
+
@return [self]
|
35
|
+
@overload reject()
|
36
|
+
@return [Enumerator]
|
37
|
+
)),
|
38
|
+
Override.method_return('Array#reverse', 'self', delete: ['overload']),
|
39
|
+
Override.from_comment('Array#select', %(
|
40
|
+
@overload select(&block)
|
41
|
+
@return [self]
|
42
|
+
@overload select()
|
43
|
+
@return [Enumerator]
|
44
|
+
)),
|
45
|
+
Override.from_comment('Array#[]', %(
|
46
|
+
@overload [](range)
|
47
|
+
@param range [Range]
|
48
|
+
@return [self]
|
49
|
+
@overload [](num1, num2)
|
50
|
+
@param num1 [Integer]
|
51
|
+
@param num2 [Integer]
|
52
|
+
@return [self]
|
53
|
+
@overload [](num)
|
54
|
+
@param num [Integer]
|
55
|
+
@return_single_parameter
|
56
|
+
@return_single_parameter
|
57
|
+
)),
|
58
|
+
Override.from_comment('Array#first', %(
|
59
|
+
@overload first(num)
|
60
|
+
@param num [Integer]
|
61
|
+
@return [self]
|
62
|
+
@return_single_parameter
|
63
|
+
)),
|
64
|
+
Override.from_comment('Array#last', %(
|
65
|
+
@overload last(num)
|
66
|
+
@param num [Integer]
|
67
|
+
@return [self]
|
68
|
+
@return_single_parameter
|
69
|
+
)),
|
70
|
+
Override.method_return('Array#map', 'Array'),
|
71
|
+
Override.method_return('Array#uniq', 'self'),
|
72
|
+
Override.method_return('Array#zip', 'Array, nil'),
|
73
|
+
|
74
|
+
Override.from_comment('BasicObject#==', %(
|
75
|
+
@param other [BasicObject]
|
76
|
+
@return [Boolean]
|
77
|
+
)),
|
78
|
+
Override.method_return('BasicObject#initialize', 'void'),
|
79
|
+
|
80
|
+
Override.method_return('Class#new', 'self'),
|
81
|
+
Override.method_return('Class.new', 'Class<Object>'),
|
82
|
+
Override.method_return('Class#allocate', 'self'),
|
83
|
+
Override.method_return('Class.allocate', 'Class<Object>'),
|
84
|
+
|
85
|
+
Override.method_return('Enumerable#select', 'self'),
|
86
|
+
|
87
|
+
Override.method_return('File.absolute_path', 'String'),
|
88
|
+
Override.method_return('File.basename', 'String'),
|
89
|
+
Override.method_return('File.dirname', 'String'),
|
90
|
+
Override.method_return('File.extname', 'String'),
|
91
|
+
Override.method_return('File.join', 'String'),
|
92
|
+
|
93
|
+
Override.from_comment('Float#+', %(
|
94
|
+
@param y [Numeric]
|
95
|
+
@return [Numeric]
|
96
|
+
)),
|
97
|
+
|
98
|
+
Override.from_comment('Hash#[]', %(
|
99
|
+
@return_value_parameter
|
100
|
+
)),
|
101
|
+
|
102
|
+
# @todo This override isn't robust enough. It needs to allow for
|
103
|
+
# parameterized Hash types, e.g., [Hash{Symbol => String}].
|
104
|
+
Override.from_comment('Hash#[]=', %(
|
105
|
+
@param_tuple
|
106
|
+
)),
|
107
|
+
|
108
|
+
Override.method_return('Hash#merge', 'Hash'),
|
109
|
+
|
110
|
+
Override.from_comment('Integer#+', %(
|
111
|
+
@param y [Numeric]
|
112
|
+
@return [Numeric]
|
113
|
+
)),
|
114
|
+
|
115
|
+
Override.method_return('Kernel#puts', 'nil'),
|
116
|
+
|
117
|
+
Override.from_comment('Numeric#+', %(
|
118
|
+
@param y [Numeric]
|
119
|
+
@return [Numeric]
|
120
|
+
)),
|
121
|
+
|
122
|
+
Override.method_return('Object#!', 'Boolean'),
|
123
|
+
Override.method_return('Object#clone', 'self', delete: [:overload]),
|
124
|
+
Override.method_return('Object#dup', 'self', delete: [:overload]),
|
125
|
+
Override.method_return('Object#freeze', 'self', delete: [:overload]),
|
126
|
+
Override.method_return('Object#inspect', 'String'),
|
127
|
+
Override.method_return('Object#taint', 'self'),
|
128
|
+
Override.method_return('Object#to_s', 'String'),
|
129
|
+
Override.method_return('Object#untaint', 'self'),
|
130
|
+
Override.from_comment('Object#tap', %(
|
131
|
+
@return [self]
|
132
|
+
@yieldparam [self]
|
133
|
+
)),
|
134
|
+
|
135
|
+
Override.from_comment('STDERR', %(
|
136
|
+
@type [IO]
|
137
|
+
)),
|
138
|
+
|
139
|
+
Override.from_comment('STDIN', %(
|
140
|
+
@type [IO]
|
141
|
+
)),
|
142
|
+
|
143
|
+
Override.from_comment('STDOUT', %(
|
144
|
+
@type [IO]
|
145
|
+
)),
|
146
|
+
|
147
|
+
Override.method_return('String#freeze', 'self'),
|
148
|
+
Override.method_return('String#split', 'Array<String>'),
|
149
|
+
Override.method_return('String#lines', 'Array<String>'),
|
150
|
+
Override.from_comment('String#each_line', %(
|
151
|
+
@yieldparam [String]
|
152
|
+
)),
|
153
|
+
Override.from_comment('String.new', %(
|
154
|
+
@overload new(*)
|
155
|
+
@return [self]
|
156
|
+
))
|
157
|
+
].concat(
|
158
|
+
methods_with_yieldparam_subtypes.map do |path|
|
159
|
+
Override.from_comment(path, %(
|
160
|
+
@yieldparam_single_parameter
|
161
|
+
))
|
162
|
+
end
|
163
|
+
)
|
164
|
+
|
165
|
+
PINS = [
|
166
|
+
Pin::Reference::Superclass.new(closure: Pin::Namespace.new(name: 'File'), name: 'IO'),
|
167
|
+
Pin::Reference::Superclass.new(closure: Pin::Namespace.new(name: 'Integer'), name: 'Numeric'),
|
168
|
+
Pin::Reference::Superclass.new(closure: Pin::Namespace.new(name: 'Float'), name: 'Numeric')
|
169
|
+
].concat(
|
170
|
+
# HACK: Add Errno exception classes
|
171
|
+
begin
|
172
|
+
errno = Solargraph::Pin::Namespace.new(name: 'Errno')
|
173
|
+
result = []
|
174
|
+
Errno.constants.each do |const|
|
175
|
+
result.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
|
176
|
+
result.push Solargraph::Pin::Reference::Superclass.new(closure: result.last, name: 'SystemCallError')
|
177
|
+
end
|
178
|
+
result
|
179
|
+
end
|
180
|
+
)
|
181
|
+
|
182
|
+
ALL = KEYWORDS + PINS + OVERRIDES
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class YardMap
|
3
|
+
module Helpers
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# @param code_object [YARD::CodeObjects::Base]
|
7
|
+
# @param spec [Gem::Specification]
|
8
|
+
# @return [Solargraph::Location, nil]
|
9
|
+
def object_location code_object, spec
|
10
|
+
return nil if spec.nil? || code_object.nil? || code_object.file.nil? || code_object.line.nil?
|
11
|
+
file = File.join(spec.full_gem_path, code_object.file)
|
12
|
+
Solargraph::Location.new(file, Solargraph::Range.from_to(code_object.line - 1, 0, code_object.line - 1, 0))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,6 +3,10 @@
|
|
3
3
|
module Solargraph
|
4
4
|
class YardMap
|
5
5
|
class Mapper
|
6
|
+
autoload :ToMethod, 'solargraph/yard_map/mapper/to_method'
|
7
|
+
autoload :ToNamespace, 'solargraph/yard_map/mapper/to_namespace'
|
8
|
+
autoload :ToConstant, 'solargraph/yard_map/mapper/to_constant'
|
9
|
+
|
6
10
|
# @param code_objects [Array<YARD::CodeObjects::Base>]
|
7
11
|
# @param spec [Gem::Specification]
|
8
12
|
def initialize code_objects, spec = nil
|
@@ -23,22 +27,24 @@ module Solargraph
|
|
23
27
|
@pins
|
24
28
|
end
|
25
29
|
|
30
|
+
private
|
31
|
+
|
26
32
|
# @param code_object [YARD::CodeObjects::Base]
|
27
33
|
# @return [Array<Pin::Base>]
|
28
34
|
def generate_pins code_object
|
29
35
|
result = []
|
30
36
|
if code_object.is_a?(YARD::CodeObjects::NamespaceObject)
|
31
|
-
nspin =
|
37
|
+
nspin = ToNamespace.make(code_object, @spec, @namespace_pins[code_object.namespace.to_s])
|
32
38
|
@namespace_pins[code_object.path] = nspin
|
33
39
|
result.push nspin
|
34
40
|
if code_object.is_a?(YARD::CodeObjects::ClassObject) and !code_object.superclass.nil?
|
35
41
|
# This method of superclass detection is a bit of a hack. If
|
36
42
|
# the superclass is a Proxy, it is assumed to be undefined in its
|
37
43
|
# yardoc and converted to a fully qualified namespace.
|
38
|
-
if code_object.superclass.is_a?(YARD::CodeObjects::Proxy)
|
39
|
-
|
44
|
+
superclass = if code_object.superclass.is_a?(YARD::CodeObjects::Proxy)
|
45
|
+
"::#{code_object.superclass}"
|
40
46
|
else
|
41
|
-
|
47
|
+
code_object.superclass.to_s
|
42
48
|
end
|
43
49
|
result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin)
|
44
50
|
end
|
@@ -55,14 +61,14 @@ module Solargraph
|
|
55
61
|
closure = @namespace_pins[code_object.namespace.to_s]
|
56
62
|
if code_object.name == :initialize && code_object.scope == :instance
|
57
63
|
# @todo Check the visibility of <Class>.new
|
58
|
-
result.push
|
59
|
-
result.push
|
64
|
+
result.push ToMethod.make(code_object, 'new', :class, :public, closure, @spec)
|
65
|
+
result.push ToMethod.make(code_object, 'initialize', :instance, :private, closure, @spec)
|
60
66
|
else
|
61
|
-
result.push
|
67
|
+
result.push ToMethod.make(code_object, nil, nil, nil, closure, @spec)
|
62
68
|
end
|
63
69
|
elsif code_object.is_a?(YARD::CodeObjects::ConstantObject)
|
64
70
|
closure = @namespace_pins[code_object.namespace]
|
65
|
-
result.push
|
71
|
+
result.push ToConstant.make(code_object, closure, @spec)
|
66
72
|
end
|
67
73
|
result
|
68
74
|
end
|