solargraph 0.39.13 → 0.40.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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -7
- data/CHANGELOG.md +984 -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 +14 -5
- 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/library.rb +7 -7
- data/lib/solargraph/parser/legacy/node_chainer.rb +7 -7
- 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 +1 -1
- data/lib/solargraph/parser/rubyvm/node_processors.rb +1 -0
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +35 -11
- 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 -0
- 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 -159
- 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
@@ -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
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Solargraph
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class YardMap
|
5
|
+
class Mapper
|
6
|
+
module ToConstant
|
7
|
+
extend YardMap::Helpers
|
8
8
|
|
9
|
-
def
|
9
|
+
def self.make code_object, closure = nil, spec = nil
|
10
10
|
closure ||= Solargraph::Pin::Namespace.new(
|
11
11
|
name: code_object.namespace.to_s,
|
12
12
|
gates: [code_object.namespace.to_s]
|
13
13
|
)
|
14
|
-
|
14
|
+
Pin::Constant.new(
|
15
15
|
location: object_location(code_object, spec),
|
16
16
|
closure: closure,
|
17
17
|
name: code_object.name.to_s,
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class YardMap
|
5
|
+
class Mapper
|
6
|
+
module ToMethod
|
7
|
+
extend YardMap::Helpers
|
8
|
+
|
9
|
+
def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
|
10
|
+
closure ||= Solargraph::Pin::Namespace.new(
|
11
|
+
name: code_object.namespace.to_s,
|
12
|
+
gates: [code_object.namespace.to_s]
|
13
|
+
)
|
14
|
+
location = object_location(code_object, spec)
|
15
|
+
comments = code_object.docstring ? code_object.docstring.all.to_s : ''
|
16
|
+
Pin::Method.new(
|
17
|
+
location: location,
|
18
|
+
closure: closure,
|
19
|
+
name: name || code_object.name.to_s,
|
20
|
+
comments: comments,
|
21
|
+
scope: scope || code_object.scope,
|
22
|
+
visibility: visibility || code_object.visibility,
|
23
|
+
parameters: get_parameters(code_object, location, comments),
|
24
|
+
explicit: code_object.is_explicit?
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
private
|
30
|
+
|
31
|
+
# @param code_object [YARD::CodeObjects::Base]
|
32
|
+
# @return [Array<Solargraph::Pin::Parameter>]
|
33
|
+
def get_parameters code_object, location, comments
|
34
|
+
return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
|
35
|
+
# HACK: Skip `nil` and `self` parameters that are sometimes emitted
|
36
|
+
# for methods defined in C
|
37
|
+
# See https://github.com/castwide/solargraph/issues/345
|
38
|
+
code_object.parameters.select { |a| a[0] && a[0] != 'self' }.map do |a|
|
39
|
+
Solargraph::Pin::Parameter.new(
|
40
|
+
location: location,
|
41
|
+
closure: self,
|
42
|
+
comments: comments,
|
43
|
+
name: arg_name(a),
|
44
|
+
presence: nil,
|
45
|
+
decl: arg_type(a),
|
46
|
+
asgn_code: a[1]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param a [Array]
|
52
|
+
# @return [String]
|
53
|
+
def arg_name a
|
54
|
+
a[0].gsub(/[^a-z0-9_]/i, '')
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param a [Array]
|
58
|
+
# @return [::Symbol]
|
59
|
+
def arg_type a
|
60
|
+
if a[0].start_with?('**')
|
61
|
+
:kwrestarg
|
62
|
+
elsif a[0].start_with?('*')
|
63
|
+
:restarg
|
64
|
+
elsif a[0].start_with?('&')
|
65
|
+
:blockarg
|
66
|
+
elsif a[0].end_with?(':')
|
67
|
+
a[1] ? :kwoptarg : :kwarg
|
68
|
+
elsif a[1]
|
69
|
+
:optarg
|
70
|
+
else
|
71
|
+
:arg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Solargraph
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class YardMap
|
5
|
+
class Mapper
|
6
|
+
module ToNamespace
|
7
|
+
extend YardMap::Helpers
|
8
8
|
|
9
|
-
def
|
9
|
+
def self.make code_object, spec, closure = nil
|
10
10
|
closure ||= Solargraph::Pin::Namespace.new(
|
11
11
|
name: code_object.namespace.to_s,
|
12
12
|
closure: Pin::ROOT_PIN,
|
13
13
|
gates: [code_object.namespace.to_s]
|
14
14
|
)
|
15
|
-
|
15
|
+
Pin::Namespace.new(
|
16
16
|
location: object_location(code_object, spec),
|
17
17
|
name: code_object.name.to_s,
|
18
18
|
comments: code_object.docstring ? code_object.docstring.all.to_s : '',
|
@@ -63,7 +63,7 @@ module Solargraph
|
|
63
63
|
name_hash[mod.full_name] = namepin
|
64
64
|
# @param met [RDoc::AnyMethod]
|
65
65
|
mod.each_method do |met|
|
66
|
-
pin = Solargraph::SourceMap.load_string("def Object.tmp#{met.param_seq};end").first_pin('Object.tmp') || Solargraph::Pin::
|
66
|
+
pin = Solargraph::SourceMap.load_string("def Object.tmp#{met.param_seq};end").first_pin('Object.tmp') || Solargraph::Pin::Method.new
|
67
67
|
pins.push Solargraph::Pin::Method.new(
|
68
68
|
name: met.name,
|
69
69
|
closure: namepin,
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class YardMap
|
3
|
+
module StdlibFills
|
4
|
+
Override = Pin::Reference::Override
|
5
|
+
|
6
|
+
LIBS = {
|
7
|
+
'benchmark' => [
|
8
|
+
Override.method_return('Benchmark.measure', 'Benchmark::Tms')
|
9
|
+
],
|
10
|
+
|
11
|
+
'pathname' => [
|
12
|
+
Override.method_return('Pathname#join', 'Pathname'),
|
13
|
+
Override.method_return('Pathname#basename', 'Pathname'),
|
14
|
+
Override.method_return('Pathname#dirname', 'Pathname'),
|
15
|
+
Override.method_return('Pathname#cleanpath', 'Pathname'),
|
16
|
+
Override.method_return('Pathname#children', 'Array<Pathname>'),
|
17
|
+
Override.method_return('Pathname#entries', 'Array<Pathname>')
|
18
|
+
],
|
19
|
+
|
20
|
+
'set' => [
|
21
|
+
Override.method_return('Enumerable#to_set', 'Set'),
|
22
|
+
Override.method_return('Set#add', 'self'),
|
23
|
+
Override.method_return('Set#add?', 'self, nil'),
|
24
|
+
Override.method_return('Set#classify', 'Hash'),
|
25
|
+
Override.from_comment('Set#each', '@yieldparam_single_parameter'),
|
26
|
+
],
|
27
|
+
|
28
|
+
'tempfile' => [
|
29
|
+
Override.from_comment('Tempfile.open', %(
|
30
|
+
@yieldparam [Tempfile]
|
31
|
+
@return [Tempfile]
|
32
|
+
))
|
33
|
+
]
|
34
|
+
}.freeze
|
35
|
+
|
36
|
+
# @param path [String]
|
37
|
+
# @return [Array<Pin::Reference::Override>]
|
38
|
+
def self.get path
|
39
|
+
LIBS[path] || []
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class YardMap
|
5
|
+
class ToMethod
|
6
|
+
module InnerMethods
|
7
|
+
module_function
|
8
|
+
|
9
|
+
# @param code_object [YARD::CodeObjects::Base]
|
10
|
+
# @return [Array<Solargraph::Pin::Parameter>]
|
11
|
+
def get_parameters code_object, location, comments
|
12
|
+
return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
|
13
|
+
# HACK: Skip `nil` and `self` parameters that are sometimes emitted
|
14
|
+
# for methods defined in C
|
15
|
+
# See https://github.com/castwide/solargraph/issues/345
|
16
|
+
code_object.parameters.select { |a| a[0] && a[0] != 'self' }.map do |a|
|
17
|
+
Solargraph::Pin::Parameter.new(
|
18
|
+
location: location,
|
19
|
+
closure: self,
|
20
|
+
comments: comments,
|
21
|
+
name: arg_name(a),
|
22
|
+
presence: nil,
|
23
|
+
decl: arg_type(a),
|
24
|
+
asgn_code: a[1]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param a [Array]
|
30
|
+
# @return [String]
|
31
|
+
def arg_name a
|
32
|
+
a[0].gsub(/[^a-z0-9_]/i, '')
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param a [Array]
|
36
|
+
# @return [::Symbol]
|
37
|
+
def arg_type a
|
38
|
+
if a[0].start_with?('**')
|
39
|
+
:kwrestarg
|
40
|
+
elsif a[0].start_with?('*')
|
41
|
+
:restarg
|
42
|
+
elsif a[0].start_with?('&')
|
43
|
+
:blockarg
|
44
|
+
elsif a[0].end_with?(':')
|
45
|
+
a[1] ? :kwoptarg : :kwarg
|
46
|
+
elsif a[1]
|
47
|
+
:optarg
|
48
|
+
else
|
49
|
+
:arg
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
private_constant :InnerMethods
|
54
|
+
|
55
|
+
# include YardMixin
|
56
|
+
# extend YardMixin
|
57
|
+
extend Helpers
|
58
|
+
|
59
|
+
def make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
|
60
|
+
closure ||= Solargraph::Pin::Namespace.new(
|
61
|
+
name: code_object.namespace.to_s,
|
62
|
+
gates: [code_object.namespace.to_s]
|
63
|
+
)
|
64
|
+
location = object_location(code_object, spec)
|
65
|
+
comments = code_object.docstring ? code_object.docstring.all.to_s : ''
|
66
|
+
Pin::Method.new(
|
67
|
+
location: location,
|
68
|
+
closure: closure,
|
69
|
+
name: name || code_object.name.to_s,
|
70
|
+
comments: comments,
|
71
|
+
scope: scope || code_object.scope,
|
72
|
+
visibility: visibility || code_object.visibility,
|
73
|
+
parameters: InnerMethods.get_parameters(code_object, location, comments),
|
74
|
+
explicit: code_object.is_explicit?
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|