solargraph 0.39.16 → 0.40.3
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 +998 -0
- data/SPONSORS.md +1 -0
- data/lib/solargraph.rb +2 -4
- data/lib/solargraph/api_map.rb +61 -63
- data/lib/solargraph/api_map/cache.rb +2 -2
- data/lib/solargraph/api_map/store.rb +3 -7
- data/lib/solargraph/{bundle.rb → bench.rb} +6 -2
- data/lib/solargraph/compat.rb +14 -0
- 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/diagnostics/rubocop_helpers.rb +1 -20
- data/lib/solargraph/environ.rb +11 -6
- data/lib/solargraph/language_server/host.rb +5 -0
- 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 +47 -20
- data/lib/solargraph/library.rb +6 -8
- data/lib/solargraph/parser/legacy/node_methods.rb +9 -0
- data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +1 -1
- data/lib/solargraph/parser/legacy/node_processors/send_node.rb +34 -22
- data/lib/solargraph/parser/node_processor/base.rb +3 -0
- data/lib/solargraph/parser/rubyvm/node_methods.rb +18 -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 +38 -28
- data/lib/solargraph/pin.rb +0 -3
- data/lib/solargraph/pin/common.rb +1 -1
- data/lib/solargraph/pin/conversions.rb +1 -1
- 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/source.rb +10 -6
- data/lib/solargraph/source/chain.rb +3 -3
- 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 +50 -44
- data/lib/solargraph/type_checker/checks.rb +5 -1
- data/lib/solargraph/type_checker/param_def.rb +1 -1
- data/lib/solargraph/type_checker/rules.rb +5 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +15 -0
- data/lib/solargraph/yard_map.rb +38 -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 +11 -5
- 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/{pin/yard_pin/method.rb → yard_map/to_method.rb} +29 -30
- data/solargraph.gemspec +5 -5
- metadata +22 -36
- data/lib/solargraph/core_fills.rb +0 -164
- data/lib/solargraph/pin/attribute.rb +0 -49
- data/lib/solargraph/pin/base_method.rb +0 -149
- data/lib/solargraph/pin/yard_pin.rb +0 -12
- 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
@@ -1,12 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class TypeChecker
|
5
|
+
# Definitions of type checking rules to be performed at various levels
|
6
|
+
#
|
3
7
|
class Rules
|
4
8
|
LEVELS = {
|
5
9
|
normal: 0,
|
6
10
|
typed: 1,
|
7
11
|
strict: 2,
|
8
12
|
strong: 3
|
9
|
-
}
|
13
|
+
}.freeze
|
10
14
|
|
11
15
|
# @return [Symbol]
|
12
16
|
attr_reader :level
|
data/lib/solargraph/version.rb
CHANGED
@@ -85,6 +85,13 @@ module Solargraph
|
|
85
85
|
raw_data['reporters']
|
86
86
|
end
|
87
87
|
|
88
|
+
# A hash of options supported by the formatter
|
89
|
+
#
|
90
|
+
# @return [Hash]
|
91
|
+
def formatter
|
92
|
+
raw_data['formatter']
|
93
|
+
end
|
94
|
+
|
88
95
|
# An array of plugins to require.
|
89
96
|
#
|
90
97
|
# @return [Array<String>]
|
@@ -144,6 +151,14 @@ module Solargraph
|
|
144
151
|
'require' => [],
|
145
152
|
'domains' => [],
|
146
153
|
'reporters' => %w[rubocop require_not_found],
|
154
|
+
'formatter' => {
|
155
|
+
'rubocop' => {
|
156
|
+
'cops' => 'safe',
|
157
|
+
'except' => [],
|
158
|
+
'only' => [],
|
159
|
+
'extra_args' =>[]
|
160
|
+
}
|
161
|
+
},
|
147
162
|
'require_paths' => [],
|
148
163
|
'plugins' => [],
|
149
164
|
'max_files' => MAX_FILES
|
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]
|
@@ -181,12 +193,13 @@ module Solargraph
|
|
181
193
|
|
182
194
|
# @return [void]
|
183
195
|
def process_requires
|
184
|
-
pins.
|
196
|
+
pins.replace core_pins
|
185
197
|
unresolved_requires.clear
|
186
|
-
|
198
|
+
stdlib_pins.clear
|
199
|
+
environ = Convention.for_global(self)
|
187
200
|
done = []
|
188
201
|
from_std = []
|
189
|
-
required.each do |r|
|
202
|
+
(required + environ.requires).each do |r|
|
190
203
|
next if r.nil? || r.empty? || done.include?(r)
|
191
204
|
done.push r
|
192
205
|
cached = cache.get_path_pins(r)
|
@@ -211,7 +224,6 @@ module Solargraph
|
|
211
224
|
yardocs.unshift yd
|
212
225
|
result.concat process_yardoc yd, spec
|
213
226
|
result.concat add_gem_dependencies(spec) if with_dependencies?
|
214
|
-
stdlib_fill r, result
|
215
227
|
end
|
216
228
|
rescue Gem::LoadError => e
|
217
229
|
base = r.split('/').first
|
@@ -221,7 +233,7 @@ module Solargraph
|
|
221
233
|
if stdtmp.empty?
|
222
234
|
unresolved_requires.push r
|
223
235
|
else
|
224
|
-
|
236
|
+
stdlib_pins.concat stdtmp
|
225
237
|
result.concat stdtmp
|
226
238
|
end
|
227
239
|
end
|
@@ -231,7 +243,13 @@ module Solargraph
|
|
231
243
|
pins.concat result
|
232
244
|
end
|
233
245
|
end
|
234
|
-
|
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
|
235
253
|
end
|
236
254
|
|
237
255
|
# @param spec [Gem::Specification]
|
@@ -329,22 +347,6 @@ module Solargraph
|
|
329
347
|
spec
|
330
348
|
end
|
331
349
|
|
332
|
-
# @param path [String]
|
333
|
-
# @param pins [Array<Pin::Base>]
|
334
|
-
# @return [void]
|
335
|
-
def stdlib_fill path, pins
|
336
|
-
StdlibFills.get(path).each do |ovr|
|
337
|
-
pin = pins.select { |p| p.path == ovr.name }.first
|
338
|
-
next if pin.nil?
|
339
|
-
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
340
|
-
pin.docstring.delete_tags tag.to_sym
|
341
|
-
end
|
342
|
-
ovr.tags.each do |tag|
|
343
|
-
pin.docstring.add_tag(tag)
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
350
|
def load_core_pins
|
349
351
|
yd = CoreDocs.yardoc_file
|
350
352
|
ser = File.join(File.dirname(yd), 'core.ser')
|
@@ -362,23 +364,7 @@ module Solargraph
|
|
362
364
|
else
|
363
365
|
read_core_and_save_cache(yd, ser)
|
364
366
|
end
|
365
|
-
|
366
|
-
errno = result.select{ |pin| pin.path == 'Errno' }.first
|
367
|
-
Errno.constants.each do |const|
|
368
|
-
result.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno)
|
369
|
-
result.push Solargraph::Pin::Reference::Superclass.new(closure: result.last, name: 'SystemCallError')
|
370
|
-
end
|
371
|
-
CoreFills::OVERRIDES.each do |ovr|
|
372
|
-
pin = result.select { |p| p.path == ovr.name }.first
|
373
|
-
next if pin.nil?
|
374
|
-
(ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
|
375
|
-
pin.docstring.delete_tags tag.to_sym
|
376
|
-
end
|
377
|
-
ovr.tags.each do |tag|
|
378
|
-
pin.docstring.add_tag(tag)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
result
|
367
|
+
ApiMap::Store.new(result + CoreFills::ALL).pins.reject { |pin| pin.is_a?(Pin::Reference::Override) }
|
382
368
|
end
|
383
369
|
|
384
370
|
def read_core_and_save_cache yd, ser
|
@@ -386,7 +372,7 @@ module Solargraph
|
|
386
372
|
load_yardoc yd
|
387
373
|
result.concat Mapper.new(YARD::Registry.all).map
|
388
374
|
# HACK: Assume core methods with a single `args` parameter accept restarg
|
389
|
-
result.select { |pin| pin.is_a?(Solargraph::Pin::
|
375
|
+
result.select { |pin| pin.is_a?(Solargraph::Pin::Method )}.each do |pin|
|
390
376
|
if pin.parameters.length == 1 && pin.parameters.first.name == 'args' && pin.parameters.first.decl == :arg
|
391
377
|
# @todo Smelly instance variable access
|
392
378
|
pin.parameters.first.instance_variable_set(:@decl, :restarg)
|
@@ -405,7 +391,7 @@ module Solargraph
|
|
405
391
|
|
406
392
|
def load_stdlib_pins base
|
407
393
|
ser = File.join(File.dirname(CoreDocs.yardoc_stdlib_file), "#{base}.ser")
|
408
|
-
if File.file?(ser)
|
394
|
+
result = if File.file?(ser)
|
409
395
|
Solargraph.logger.info "Loading #{base} stdlib from cache"
|
410
396
|
file = File.open(ser, 'rb')
|
411
397
|
dump = file.read
|
@@ -420,6 +406,11 @@ module Solargraph
|
|
420
406
|
else
|
421
407
|
read_stdlib_and_save_cache(base, ser)
|
422
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
|
423
414
|
end
|
424
415
|
|
425
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,12 +27,14 @@ 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?
|
@@ -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
|