solargraph 0.54.0 → 0.58.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/.github/workflows/linting.yml +127 -0
- data/.github/workflows/plugins.yml +184 -6
- data/.github/workflows/rspec.yml +55 -5
- data/.github/workflows/typecheck.yml +8 -3
- data/.gitignore +7 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +1279 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +171 -0
- data/README.md +20 -6
- data/Rakefile +125 -13
- data/bin/solargraph +8 -5
- data/lib/solargraph/api_map/cache.rb +13 -3
- data/lib/solargraph/api_map/constants.rb +279 -0
- data/lib/solargraph/api_map/index.rb +193 -0
- data/lib/solargraph/api_map/source_to_yard.rb +13 -4
- data/lib/solargraph/api_map/store.rb +207 -132
- data/lib/solargraph/api_map.rb +394 -261
- data/lib/solargraph/bench.rb +18 -1
- data/lib/solargraph/complex_type/type_methods.rb +29 -12
- data/lib/solargraph/complex_type/unique_type.rb +205 -26
- data/lib/solargraph/complex_type.rb +126 -26
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +20 -3
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -0
- data/lib/solargraph/convention/struct_definition.rb +164 -0
- data/lib/solargraph/convention.rb +36 -4
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/doc_map.rb +316 -64
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/equality.rb +34 -0
- data/lib/solargraph/gem_pins.rb +64 -38
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +54 -5
- data/lib/solargraph/language_server/host.rb +36 -18
- data/lib/solargraph/language_server/message/base.rb +20 -12
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
- data/lib/solargraph/language_server/message/extended/document.rb +5 -2
- data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
- data/lib/solargraph/language_server/message/initialize.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +5 -3
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/formatting.rb +23 -2
- data/lib/solargraph/language_server/message/text_document/hover.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +4 -3
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -2
- data/lib/solargraph/language_server/progress.rb +27 -2
- data/lib/solargraph/language_server/request.rb +4 -1
- data/lib/solargraph/library.rb +83 -73
- data/lib/solargraph/location.rb +45 -1
- data/lib/solargraph/logging.rb +12 -2
- data/lib/solargraph/page.rb +3 -0
- data/lib/solargraph/parser/comment_ripper.rb +20 -7
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -0
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +26 -8
- data/lib/solargraph/parser/parser_gem/class_methods.rb +10 -18
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_methods.rb +10 -19
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +26 -20
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +7 -4
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +14 -2
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +16 -6
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +64 -32
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +14 -0
- data/lib/solargraph/parser/region.rb +4 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +3 -5
- data/lib/solargraph/pin/base.rb +417 -42
- data/lib/solargraph/pin/base_variable.rb +21 -12
- data/lib/solargraph/pin/block.rb +9 -26
- data/lib/solargraph/pin/breakable.rb +9 -0
- data/lib/solargraph/pin/callable.rb +231 -0
- data/lib/solargraph/pin/closure.rb +30 -10
- data/lib/solargraph/pin/common.rb +12 -7
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/conversions.rb +3 -2
- data/lib/solargraph/pin/delegated_method.rb +20 -1
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/instance_variable.rb +2 -2
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/local_variable.rb +15 -7
- data/lib/solargraph/pin/method.rb +241 -70
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/namespace.rb +21 -13
- data/lib/solargraph/pin/parameter.rb +94 -32
- data/lib/solargraph/pin/proxy_type.rb +17 -7
- data/lib/solargraph/pin/reference/override.rb +24 -6
- data/lib/solargraph/pin/reference/require.rb +2 -2
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +6 -1
- data/lib/solargraph/pin/signature.rb +39 -121
- data/lib/solargraph/pin/singleton.rb +1 -1
- data/lib/solargraph/pin/symbol.rb +8 -2
- data/lib/solargraph/pin/until.rb +18 -0
- data/lib/solargraph/pin/while.rb +18 -0
- data/lib/solargraph/pin.rb +8 -2
- data/lib/solargraph/pin_cache.rb +245 -0
- data/lib/solargraph/position.rb +19 -0
- data/lib/solargraph/range.rb +23 -4
- data/lib/solargraph/rbs_map/conversions.rb +315 -99
- data/lib/solargraph/rbs_map/core_fills.rb +50 -16
- data/lib/solargraph/rbs_map/core_map.rb +41 -11
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +87 -16
- data/lib/solargraph/shell.rb +117 -17
- data/lib/solargraph/source/chain/array.rb +13 -8
- data/lib/solargraph/source/chain/block_symbol.rb +1 -1
- data/lib/solargraph/source/chain/block_variable.rb +1 -1
- data/lib/solargraph/source/chain/call.rb +135 -66
- data/lib/solargraph/source/chain/constant.rb +3 -66
- data/lib/solargraph/source/chain/hash.rb +9 -3
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +7 -2
- data/lib/solargraph/source/chain/link.rb +38 -6
- data/lib/solargraph/source/chain/literal.rb +27 -2
- data/lib/solargraph/source/chain/or.rb +2 -2
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +140 -63
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +4 -4
- data/lib/solargraph/source/source_chainer.rb +3 -3
- data/lib/solargraph/source.rb +110 -89
- data/lib/solargraph/source_map/clip.rb +22 -28
- data/lib/solargraph/source_map/data.rb +34 -0
- data/lib/solargraph/source_map/mapper.rb +11 -7
- data/lib/solargraph/source_map.rb +50 -43
- data/lib/solargraph/type_checker/checks.rb +4 -0
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +35 -8
- data/lib/solargraph/type_checker.rb +331 -189
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/_method.erb +10 -10
- data/lib/solargraph/views/_namespace.erb +3 -3
- data/lib/solargraph/views/document.erb +10 -10
- data/lib/solargraph/views/environment.erb +3 -5
- data/lib/solargraph/workspace/config.rb +25 -5
- data/lib/solargraph/workspace/require_paths.rb +97 -0
- data/lib/solargraph/workspace.rb +53 -72
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +8 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +55 -19
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +11 -7
- data/lib/solargraph/yard_map/mapper.rb +5 -3
- data/lib/solargraph/yard_map/to_method.rb +6 -3
- data/lib/solargraph/yardoc.rb +45 -10
- data/lib/solargraph.rb +35 -1
- data/rbs/fills/bundler/0/bundler.rbs +4271 -0
- data/rbs/fills/open3/0/open3.rbs +172 -0
- data/rbs/fills/rubygems/0/basic_specification.rbs +326 -0
- data/rbs/fills/rubygems/0/errors.rbs +364 -0
- data/rbs/fills/rubygems/0/spec_fetcher.rbs +107 -0
- data/rbs/fills/rubygems/0/specification.rbs +1753 -0
- data/rbs/fills/tuple/tuple.rbs +149 -0
- data/rbs_collection.yaml +19 -0
- data/sig/shims/ast/0/node.rbs +5 -0
- data/sig/shims/ast/2.4/.rbs_meta.yaml +9 -0
- data/sig/shims/ast/2.4/ast.rbs +73 -0
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/sig/shims/parser/3.2.0.1/manifest.yaml +7 -0
- data/sig/shims/parser/3.2.0.1/parser.rbs +201 -0
- data/sig/shims/parser/3.2.0.1/polyfill.rbs +4 -0
- data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/solargraph.gemspec +32 -10
- metadata +237 -37
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/cache.rb +0 -77
- data/lib/solargraph/parser/node_methods.rb +0 -83
|
@@ -6,7 +6,9 @@ module Solargraph
|
|
|
6
6
|
class RbsMap
|
|
7
7
|
# Functions for converting RBS declarations to Solargraph pins
|
|
8
8
|
#
|
|
9
|
-
|
|
9
|
+
class Conversions
|
|
10
|
+
include Logging
|
|
11
|
+
|
|
10
12
|
# A container for tracking the current context of the RBS conversion
|
|
11
13
|
# process, e.g., what visibility is declared for methods in the current
|
|
12
14
|
# scope
|
|
@@ -20,11 +22,19 @@ module Solargraph
|
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
# @
|
|
24
|
-
def
|
|
25
|
-
@
|
|
25
|
+
# @param loader [RBS::EnvironmentLoader]
|
|
26
|
+
def initialize(loader:)
|
|
27
|
+
@loader = loader
|
|
28
|
+
@pins = []
|
|
29
|
+
load_environment_to_pins(loader)
|
|
26
30
|
end
|
|
27
31
|
|
|
32
|
+
# @return [RBS::EnvironmentLoader]
|
|
33
|
+
attr_reader :loader
|
|
34
|
+
|
|
35
|
+
# @return [Array<Pin::Base>]
|
|
36
|
+
attr_reader :pins
|
|
37
|
+
|
|
28
38
|
private
|
|
29
39
|
|
|
30
40
|
# @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
|
|
@@ -37,9 +47,11 @@ module Solargraph
|
|
|
37
47
|
def load_environment_to_pins(loader)
|
|
38
48
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
|
39
49
|
cursor = pins.length
|
|
50
|
+
if environment.declarations.empty?
|
|
51
|
+
Solargraph.logger.info "No RBS declarations found in environment for core_root #{loader.core_root.inspect}, libraries #{loader.libs} and directories #{loader.dirs}"
|
|
52
|
+
return
|
|
53
|
+
end
|
|
40
54
|
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
|
41
|
-
added_pins = pins[cursor..-1]
|
|
42
|
-
added_pins.each { |pin| pin.source = :rbs }
|
|
43
55
|
end
|
|
44
56
|
|
|
45
57
|
# @param decl [RBS::AST::Declarations::Base]
|
|
@@ -53,6 +65,7 @@ module Solargraph
|
|
|
53
65
|
# STDERR.puts "Skipping interface #{decl.name.relative!}"
|
|
54
66
|
interface_decl_to_pin decl, closure
|
|
55
67
|
when RBS::AST::Declarations::TypeAlias
|
|
68
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
56
69
|
type_aliases[decl.name.to_s] = decl
|
|
57
70
|
when RBS::AST::Declarations::Module
|
|
58
71
|
module_decl_to_pin decl
|
|
@@ -80,10 +93,14 @@ module Solargraph
|
|
|
80
93
|
# @param closure [Pin::Namespace]
|
|
81
94
|
# @return [void]
|
|
82
95
|
def convert_self_type_to_pins decl, closure
|
|
96
|
+
type = build_type(decl.name, decl.args)
|
|
97
|
+
generic_values = type.all_params.map(&:to_s)
|
|
83
98
|
include_pin = Solargraph::Pin::Reference::Include.new(
|
|
84
99
|
name: decl.name.relative!.to_s,
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
101
|
+
generic_values: generic_values,
|
|
102
|
+
closure: closure,
|
|
103
|
+
source: :rbs
|
|
87
104
|
)
|
|
88
105
|
pins.push include_pin
|
|
89
106
|
end
|
|
@@ -92,24 +109,24 @@ module Solargraph
|
|
|
92
109
|
# @param closure [Pin::Namespace]
|
|
93
110
|
# @return [void]
|
|
94
111
|
def convert_members_to_pins decl, closure
|
|
95
|
-
context = Context.new
|
|
112
|
+
context = Conversions::Context.new
|
|
96
113
|
decl.members.each { |m| context = convert_member_to_pin(m, closure, context) }
|
|
97
114
|
end
|
|
98
115
|
|
|
99
116
|
# @param member [RBS::AST::Members::Base,RBS::AST::Declarations::Base]
|
|
100
117
|
# @param closure [Pin::Namespace]
|
|
101
118
|
# @param context [Context]
|
|
102
|
-
# @return [
|
|
119
|
+
# @return [Context]
|
|
103
120
|
def convert_member_to_pin member, closure, context
|
|
104
121
|
case member
|
|
105
122
|
when RBS::AST::Members::MethodDefinition
|
|
106
|
-
method_def_to_pin(member, closure)
|
|
123
|
+
method_def_to_pin(member, closure, context)
|
|
107
124
|
when RBS::AST::Members::AttrReader
|
|
108
|
-
attr_reader_to_pin(member, closure)
|
|
125
|
+
attr_reader_to_pin(member, closure, context)
|
|
109
126
|
when RBS::AST::Members::AttrWriter
|
|
110
|
-
attr_writer_to_pin(member, closure)
|
|
127
|
+
attr_writer_to_pin(member, closure, context)
|
|
111
128
|
when RBS::AST::Members::AttrAccessor
|
|
112
|
-
attr_accessor_to_pin(member, closure)
|
|
129
|
+
attr_accessor_to_pin(member, closure, context)
|
|
113
130
|
when RBS::AST::Members::Include
|
|
114
131
|
include_to_pin(member, closure)
|
|
115
132
|
when RBS::AST::Members::Prepend
|
|
@@ -125,9 +142,9 @@ module Solargraph
|
|
|
125
142
|
when RBS::AST::Members::InstanceVariable
|
|
126
143
|
ivar_to_pin(member, closure)
|
|
127
144
|
when RBS::AST::Members::Public
|
|
128
|
-
return Context.new(
|
|
145
|
+
return Context.new(:public)
|
|
129
146
|
when RBS::AST::Members::Private
|
|
130
|
-
return Context.new(
|
|
147
|
+
return Context.new(:private)
|
|
131
148
|
when RBS::AST::Declarations::Base
|
|
132
149
|
convert_decl_to_pin(member, closure)
|
|
133
150
|
else
|
|
@@ -139,21 +156,39 @@ module Solargraph
|
|
|
139
156
|
# @param decl [RBS::AST::Declarations::Class]
|
|
140
157
|
# @return [void]
|
|
141
158
|
def class_decl_to_pin decl
|
|
159
|
+
generics = decl.type_params.map(&:name).map(&:to_s)
|
|
160
|
+
generic_defaults = {}
|
|
161
|
+
decl.type_params.each do |param|
|
|
162
|
+
if param.default_type
|
|
163
|
+
tag = other_type_to_tag param.default_type
|
|
164
|
+
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
class_name = decl.name.relative!.to_s
|
|
142
168
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
143
169
|
type: :class,
|
|
144
|
-
name:
|
|
170
|
+
name: class_name,
|
|
145
171
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
146
172
|
comments: decl.comment&.string,
|
|
173
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
147
174
|
# @todo some type parameters in core/stdlib have default
|
|
148
175
|
# values; Solargraph doesn't support that yet as so these
|
|
149
176
|
# get treated as undefined if not specified
|
|
150
|
-
generics:
|
|
177
|
+
generics: generics,
|
|
178
|
+
generic_defaults: generic_defaults,
|
|
179
|
+
source: :rbs
|
|
151
180
|
)
|
|
152
181
|
pins.push class_pin
|
|
153
182
|
if decl.super_class
|
|
183
|
+
type = build_type(decl.super_class.name, decl.super_class.args)
|
|
184
|
+
generic_values = type.all_params.map(&:to_s)
|
|
185
|
+
superclass_name = decl.super_class.name.to_s
|
|
154
186
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
|
187
|
+
type_location: location_decl_to_pin_location(decl.super_class.location),
|
|
155
188
|
closure: class_pin,
|
|
156
|
-
|
|
189
|
+
generic_values: generic_values,
|
|
190
|
+
name: superclass_name,
|
|
191
|
+
source: :rbs
|
|
157
192
|
)
|
|
158
193
|
end
|
|
159
194
|
add_mixins decl, class_pin
|
|
@@ -166,13 +201,15 @@ module Solargraph
|
|
|
166
201
|
def interface_decl_to_pin decl, closure
|
|
167
202
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
168
203
|
type: :module,
|
|
204
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
169
205
|
name: decl.name.relative!.to_s,
|
|
170
206
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
171
207
|
comments: decl.comment&.string,
|
|
172
208
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
|
173
209
|
# HACK: Using :hidden to keep interfaces from appearing in
|
|
174
210
|
# autocompletion
|
|
175
|
-
visibility: :hidden
|
|
211
|
+
visibility: :hidden,
|
|
212
|
+
source: :rbs
|
|
176
213
|
)
|
|
177
214
|
class_pin.docstring.add_tag(YARD::Tags::Tag.new(:abstract, '(RBS interface)'))
|
|
178
215
|
pins.push class_pin
|
|
@@ -185,9 +222,11 @@ module Solargraph
|
|
|
185
222
|
module_pin = Solargraph::Pin::Namespace.new(
|
|
186
223
|
type: :module,
|
|
187
224
|
name: decl.name.relative!.to_s,
|
|
225
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
188
226
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
189
227
|
comments: decl.comment&.string,
|
|
190
228
|
generics: decl.type_params.map(&:name).map(&:to_s),
|
|
229
|
+
source: :rbs
|
|
191
230
|
)
|
|
192
231
|
pins.push module_pin
|
|
193
232
|
convert_self_types_to_pins decl, module_pin
|
|
@@ -199,10 +238,11 @@ module Solargraph
|
|
|
199
238
|
# @param name [String]
|
|
200
239
|
# @param tag [String]
|
|
201
240
|
# @param comments [String]
|
|
241
|
+
# @param decl [RBS::AST::Declarations::ClassAlias, RBS::AST::Declarations::Constant, RBS::AST::Declarations::ModuleAlias]
|
|
202
242
|
# @param base [String, nil] Optional conversion of tag to base<tag>
|
|
203
243
|
#
|
|
204
244
|
# @return [Solargraph::Pin::Constant]
|
|
205
|
-
def create_constant(name, tag, comments, base = nil)
|
|
245
|
+
def create_constant(name, tag, comments, decl, base = nil)
|
|
206
246
|
parts = name.split('::')
|
|
207
247
|
if parts.length > 1
|
|
208
248
|
name = parts.last
|
|
@@ -214,10 +254,13 @@ module Solargraph
|
|
|
214
254
|
constant_pin = Solargraph::Pin::Constant.new(
|
|
215
255
|
name: name,
|
|
216
256
|
closure: closure,
|
|
217
|
-
|
|
257
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
258
|
+
comments: comments,
|
|
259
|
+
source: :rbs
|
|
218
260
|
)
|
|
219
261
|
tag = "#{base}<#{tag}>" if base
|
|
220
|
-
|
|
262
|
+
rooted_tag = ComplexType.parse(tag).force_rooted.rooted_tags
|
|
263
|
+
constant_pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
221
264
|
constant_pin
|
|
222
265
|
end
|
|
223
266
|
|
|
@@ -228,7 +271,7 @@ module Solargraph
|
|
|
228
271
|
new_name = decl.new_name.relative!.to_s
|
|
229
272
|
old_name = decl.old_name.relative!.to_s
|
|
230
273
|
|
|
231
|
-
pins.push create_constant(new_name, old_name, decl.comment&.string, 'Class')
|
|
274
|
+
pins.push create_constant(new_name, old_name, decl.comment&.string, decl, 'Class')
|
|
232
275
|
end
|
|
233
276
|
|
|
234
277
|
# @param decl [RBS::AST::Declarations::ModuleAlias]
|
|
@@ -238,14 +281,14 @@ module Solargraph
|
|
|
238
281
|
new_name = decl.new_name.relative!.to_s
|
|
239
282
|
old_name = decl.old_name.relative!.to_s
|
|
240
283
|
|
|
241
|
-
pins.push create_constant(new_name, old_name, decl.comment&.string, 'Module')
|
|
284
|
+
pins.push create_constant(new_name, old_name, decl.comment&.string, decl, 'Module')
|
|
242
285
|
end
|
|
243
286
|
|
|
244
287
|
# @param decl [RBS::AST::Declarations::Constant]
|
|
245
288
|
# @return [void]
|
|
246
289
|
def constant_decl_to_pin decl
|
|
247
290
|
tag = other_type_to_tag(decl.type)
|
|
248
|
-
pins.push create_constant(decl.name.relative!.to_s, tag, decl.comment&.string)
|
|
291
|
+
pins.push create_constant(decl.name.relative!.to_s, tag, decl.comment&.string, decl)
|
|
249
292
|
end
|
|
250
293
|
|
|
251
294
|
# @param decl [RBS::AST::Declarations::Global]
|
|
@@ -253,35 +296,105 @@ module Solargraph
|
|
|
253
296
|
def global_decl_to_pin decl
|
|
254
297
|
closure = Solargraph::Pin::ROOT_PIN
|
|
255
298
|
name = decl.name.to_s
|
|
256
|
-
tag = other_type_to_tag(decl.type)
|
|
257
299
|
pin = Solargraph::Pin::GlobalVariable.new(
|
|
258
300
|
name: name,
|
|
259
301
|
closure: closure,
|
|
260
302
|
comments: decl.comment&.string,
|
|
303
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
304
|
+
source: :rbs
|
|
261
305
|
)
|
|
262
|
-
|
|
306
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
307
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
263
308
|
pins.push pin
|
|
264
309
|
end
|
|
265
310
|
|
|
311
|
+
|
|
312
|
+
# Visibility overrides that will allow the Solargraph project
|
|
313
|
+
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
|
314
|
+
# so that we can detect any regressions/issues elsewhere in the
|
|
315
|
+
# visibility logic.
|
|
316
|
+
#
|
|
317
|
+
# These should either reflect a bug upstream in the RBS
|
|
318
|
+
# definitions, or include a @todo indicating what needs to be
|
|
319
|
+
# fixed in Solargraph to properly understand it.
|
|
320
|
+
#
|
|
321
|
+
# @todo PR these fixes upstream and list open PRs here above
|
|
322
|
+
# related overrides
|
|
323
|
+
# @todo externalize remaining overrides into yaml file, then
|
|
324
|
+
# allow that to be extended via .solargraph.yml
|
|
325
|
+
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
|
326
|
+
VISIBILITY_OVERRIDE = {
|
|
327
|
+
["Rails::Engine", :instance, "run_tasks_blocks"] => :protected,
|
|
328
|
+
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
|
329
|
+
["Kernel", :instance, "pretty_inspect"] => :private,
|
|
330
|
+
# marked incorrectly in RBS
|
|
331
|
+
["WEBrick::HTTPUtils::FormData", :instance, "next_data"] => :protected,
|
|
332
|
+
["Rails::Command", :class, "command_type"] => :private,
|
|
333
|
+
["Rails::Command", :class, "lookup_paths"] => :private,
|
|
334
|
+
["Rails::Command", :class, "file_lookup_paths"] => :private,
|
|
335
|
+
["Rails::Railtie", :instance, "run_console_blocks"] => :protected,
|
|
336
|
+
["Rails::Railtie", :instance, "run_generators_blocks"] => :protected,
|
|
337
|
+
["Rails::Railtie", :instance, "run_runner_blocks"] => :protected,
|
|
338
|
+
["Rails::Railtie", :instance, "run_tasks_blocks"] => :protected,
|
|
339
|
+
["ActionController::Base", :instance, "_protected_ivars"] => :private,
|
|
340
|
+
["ActionView::Template", :instance, "method_name"] => :public,
|
|
341
|
+
["Module", :instance, "ruby2_keywords"] => :private,
|
|
342
|
+
["Nokogiri::XML::Node", :instance, "coerce"] => :protected,
|
|
343
|
+
["Nokogiri::XML::Document", :class, "empty_doc?"] => :private,
|
|
344
|
+
["Nokogiri::Decorators::Slop", :instance, "respond_to_missing?"] => :public,
|
|
345
|
+
["RuboCop::Cop::RangeHelp", :instance, "source_range"] => :private,
|
|
346
|
+
["AST::Node", :instance, "original_dup"] => :private,
|
|
347
|
+
["Rainbow::Presenter", :instance, "wrap_with_sgr"] => :private,
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor]
|
|
351
|
+
# @param closure [Pin::Closure]
|
|
352
|
+
# @param context [Context]
|
|
353
|
+
# @param scope [Symbol] :instance or :class
|
|
354
|
+
# @param name [String] The name of the method
|
|
355
|
+
# @sg-ignore
|
|
356
|
+
# @return [Symbol]
|
|
357
|
+
def calculate_method_visibility(decl, context, closure, scope, name)
|
|
358
|
+
override_key = [closure.path, scope, name]
|
|
359
|
+
visibility = VISIBILITY_OVERRIDE[override_key]
|
|
360
|
+
simple_override_key = [closure.path, scope]
|
|
361
|
+
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
|
362
|
+
visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(decl.name)
|
|
363
|
+
if decl.kind == :singleton_instance
|
|
364
|
+
# this is a 'module function'
|
|
365
|
+
visibility ||= :private
|
|
366
|
+
end
|
|
367
|
+
visibility ||= decl.visibility
|
|
368
|
+
visibility ||= context.visibility
|
|
369
|
+
visibility ||= :public
|
|
370
|
+
visibility
|
|
371
|
+
end
|
|
372
|
+
|
|
266
373
|
# @param decl [RBS::AST::Members::MethodDefinition]
|
|
267
374
|
# @param closure [Pin::Closure]
|
|
375
|
+
# @param context [Context]
|
|
268
376
|
# @return [void]
|
|
269
|
-
def method_def_to_pin decl, closure
|
|
377
|
+
def method_def_to_pin decl, closure, context
|
|
270
378
|
# there may be edge cases here around different signatures
|
|
271
379
|
# having different type params / orders - we may need to match
|
|
272
380
|
# this data model and have generics live in signatures to
|
|
273
381
|
# handle those correctly
|
|
274
382
|
generics = decl.overloads.map(&:method_type).flat_map(&:type_params).map(&:name).map(&:to_s).uniq
|
|
383
|
+
|
|
275
384
|
if decl.instance?
|
|
385
|
+
name = decl.name.to_s
|
|
386
|
+
final_scope = :instance
|
|
387
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
276
388
|
pin = Solargraph::Pin::Method.new(
|
|
277
|
-
name:
|
|
389
|
+
name: name,
|
|
278
390
|
closure: closure,
|
|
391
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
279
392
|
comments: decl.comment&.string,
|
|
280
|
-
scope:
|
|
393
|
+
scope: final_scope,
|
|
281
394
|
signatures: [],
|
|
282
395
|
generics: generics,
|
|
283
|
-
|
|
284
|
-
|
|
396
|
+
visibility: visibility,
|
|
397
|
+
source: :rbs
|
|
285
398
|
)
|
|
286
399
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
|
287
400
|
pins.push pin
|
|
@@ -291,13 +404,19 @@ module Solargraph
|
|
|
291
404
|
end
|
|
292
405
|
end
|
|
293
406
|
if decl.singleton?
|
|
407
|
+
final_scope = :class
|
|
408
|
+
name = decl.name.to_s
|
|
409
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
294
410
|
pin = Solargraph::Pin::Method.new(
|
|
295
|
-
name:
|
|
411
|
+
name: name,
|
|
296
412
|
closure: closure,
|
|
297
413
|
comments: decl.comment&.string,
|
|
298
|
-
|
|
414
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
415
|
+
visibility: visibility,
|
|
416
|
+
scope: final_scope,
|
|
299
417
|
signatures: [],
|
|
300
|
-
generics: generics
|
|
418
|
+
generics: generics,
|
|
419
|
+
source: :rbs
|
|
301
420
|
)
|
|
302
421
|
pin.signatures.concat method_def_to_sigs(decl, pin)
|
|
303
422
|
pins.push pin
|
|
@@ -308,107 +427,170 @@ module Solargraph
|
|
|
308
427
|
# @param pin [Pin::Method]
|
|
309
428
|
# @return [void]
|
|
310
429
|
def method_def_to_sigs decl, pin
|
|
430
|
+
# @param overload [RBS::AST::Members::MethodDefinition::Overload]
|
|
311
431
|
decl.overloads.map do |overload|
|
|
312
|
-
|
|
313
|
-
|
|
432
|
+
type_location = location_decl_to_pin_location(overload.method_type.location)
|
|
433
|
+
generics = overload.method_type.type_params.map(&:name).map(&:to_s)
|
|
434
|
+
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
|
314
435
|
block = if overload.method_type.block
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
436
|
+
block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin)
|
|
437
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type, source: :rbs,
|
|
438
|
+
type_location: type_location, closure: pin)
|
|
439
|
+
end
|
|
440
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block, source: :rbs,
|
|
441
|
+
type_location: type_location, closure: pin)
|
|
319
442
|
end
|
|
320
443
|
end
|
|
321
444
|
|
|
322
445
|
# @param location [RBS::Location, nil]
|
|
323
446
|
# @return [Solargraph::Location, nil]
|
|
324
|
-
def
|
|
447
|
+
def location_decl_to_pin_location(location)
|
|
325
448
|
return nil if location&.name.nil?
|
|
326
449
|
|
|
327
450
|
start_pos = Position.new(location.start_line - 1, location.start_column)
|
|
328
451
|
end_pos = Position.new(location.end_line - 1, location.end_column)
|
|
329
452
|
range = Range.new(start_pos, end_pos)
|
|
330
|
-
Location.new(location.name, range)
|
|
453
|
+
Location.new(location.name.to_s, range)
|
|
331
454
|
end
|
|
332
455
|
|
|
333
456
|
# @param type [RBS::MethodType,RBS::Types::Block]
|
|
334
457
|
# @param pin [Pin::Method]
|
|
335
|
-
# @return [Array
|
|
458
|
+
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
|
336
459
|
def parts_of_function type, pin
|
|
337
|
-
|
|
460
|
+
type_location = pin.type_location
|
|
461
|
+
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
|
462
|
+
return [
|
|
463
|
+
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs, type_location: type_location)],
|
|
464
|
+
ComplexType.try_parse(method_type_to_tag(type)).force_rooted
|
|
465
|
+
]
|
|
466
|
+
end
|
|
338
467
|
|
|
339
468
|
parameters = []
|
|
340
469
|
arg_num = -1
|
|
341
470
|
type.type.required_positionals.each do |param|
|
|
342
|
-
|
|
343
|
-
|
|
471
|
+
# @sg-ignore RBS generic type understanding issue
|
|
472
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
473
|
+
# @sg-ignore RBS generic type understanding issue
|
|
474
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted, source: :rbs, type_location: type_location)
|
|
344
475
|
end
|
|
345
476
|
type.type.optional_positionals.each do |param|
|
|
346
|
-
|
|
477
|
+
# @sg-ignore RBS generic type understanding issue
|
|
478
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
347
479
|
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
|
348
|
-
|
|
480
|
+
# @sg-ignore RBS generic type understanding issue
|
|
481
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
|
482
|
+
type_location: type_location,
|
|
483
|
+
source: :rbs)
|
|
349
484
|
end
|
|
350
485
|
if type.type.rest_positionals
|
|
351
|
-
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "
|
|
352
|
-
|
|
486
|
+
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
|
487
|
+
inner_rest_positional_type =
|
|
488
|
+
ComplexType.try_parse(other_type_to_tag(type.type.rest_positionals.type))
|
|
489
|
+
rest_positional_type = ComplexType::UniqueType.new('Array',
|
|
490
|
+
[],
|
|
491
|
+
[inner_rest_positional_type],
|
|
492
|
+
rooted: true, parameters_type: :list)
|
|
493
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin,
|
|
494
|
+
source: :rbs, type_location: type_location,
|
|
495
|
+
return_type: rest_positional_type,)
|
|
353
496
|
end
|
|
354
497
|
type.type.trailing_positionals.each do |param|
|
|
355
|
-
|
|
356
|
-
|
|
498
|
+
# @sg-ignore RBS generic type understanding issue
|
|
499
|
+
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
500
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs, type_location: type_location)
|
|
357
501
|
end
|
|
358
502
|
type.type.required_keywords.each do |orig, param|
|
|
359
|
-
|
|
503
|
+
# @sg-ignore RBS generic type understanding issue
|
|
504
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
360
505
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
|
361
|
-
|
|
506
|
+
# @sg-ignore RBS generic type understanding issue
|
|
507
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
|
508
|
+
source: :rbs, type_location: type_location)
|
|
362
509
|
end
|
|
363
510
|
type.type.optional_keywords.each do |orig, param|
|
|
364
|
-
|
|
511
|
+
# @sg-ignore RBS generic type understanding issue
|
|
512
|
+
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
365
513
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
|
366
|
-
|
|
514
|
+
# @sg-ignore RBS generic type understanding issue
|
|
515
|
+
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
|
516
|
+
type_location: type_location,
|
|
517
|
+
source: :rbs)
|
|
367
518
|
end
|
|
368
519
|
if type.type.rest_keywords
|
|
369
|
-
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "
|
|
370
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin
|
|
520
|
+
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
|
521
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin,
|
|
522
|
+
source: :rbs, type_location: type_location)
|
|
371
523
|
end
|
|
372
|
-
|
|
524
|
+
|
|
525
|
+
rooted_tag = method_type_to_tag(type)
|
|
526
|
+
return_type = ComplexType.try_parse(rooted_tag).force_rooted
|
|
373
527
|
[parameters, return_type]
|
|
374
528
|
end
|
|
375
529
|
|
|
376
530
|
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
|
377
531
|
# @param closure [Pin::Namespace]
|
|
532
|
+
# @param context [Context]
|
|
378
533
|
# @return [void]
|
|
379
|
-
def attr_reader_to_pin(decl, closure)
|
|
534
|
+
def attr_reader_to_pin(decl, closure, context)
|
|
535
|
+
name = decl.name.to_s
|
|
536
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
|
537
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
380
538
|
pin = Solargraph::Pin::Method.new(
|
|
381
|
-
name:
|
|
539
|
+
name: name,
|
|
540
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
382
541
|
closure: closure,
|
|
383
542
|
comments: decl.comment&.string,
|
|
384
|
-
scope:
|
|
385
|
-
attribute: true
|
|
543
|
+
scope: final_scope,
|
|
544
|
+
attribute: true,
|
|
545
|
+
visibility: visibility,
|
|
546
|
+
source: :rbs
|
|
386
547
|
)
|
|
387
|
-
|
|
548
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
549
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
550
|
+
logger.debug { "Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}" }
|
|
388
551
|
pins.push pin
|
|
389
552
|
end
|
|
390
553
|
|
|
391
554
|
# @param decl [RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
|
392
555
|
# @param closure [Pin::Namespace]
|
|
556
|
+
# @param context [Context]
|
|
393
557
|
# @return [void]
|
|
394
|
-
def attr_writer_to_pin(decl, closure)
|
|
558
|
+
def attr_writer_to_pin(decl, closure, context)
|
|
559
|
+
final_scope = decl.kind == :instance ? :instance : :class
|
|
560
|
+
name = "#{decl.name.to_s}="
|
|
561
|
+
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
562
|
+
type_location = location_decl_to_pin_location(decl.location)
|
|
395
563
|
pin = Solargraph::Pin::Method.new(
|
|
396
|
-
name:
|
|
564
|
+
name: name,
|
|
565
|
+
type_location: type_location,
|
|
397
566
|
closure: closure,
|
|
567
|
+
parameters: [],
|
|
398
568
|
comments: decl.comment&.string,
|
|
399
|
-
scope:
|
|
400
|
-
attribute: true
|
|
569
|
+
scope: final_scope,
|
|
570
|
+
attribute: true,
|
|
571
|
+
visibility: visibility,
|
|
572
|
+
source: :rbs
|
|
401
573
|
)
|
|
402
|
-
pin.
|
|
574
|
+
pin.parameters <<
|
|
575
|
+
Solargraph::Pin::Parameter.new(
|
|
576
|
+
name: 'value',
|
|
577
|
+
return_type: ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted,
|
|
578
|
+
source: :rbs,
|
|
579
|
+
closure: pin,
|
|
580
|
+
type_location: type_location
|
|
581
|
+
)
|
|
582
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
583
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
403
584
|
pins.push pin
|
|
404
585
|
end
|
|
405
586
|
|
|
406
587
|
# @param decl [RBS::AST::Members::AttrAccessor]
|
|
407
588
|
# @param closure [Pin::Namespace]
|
|
589
|
+
# @param context [Context]
|
|
408
590
|
# @return [void]
|
|
409
|
-
def attr_accessor_to_pin(decl, closure)
|
|
410
|
-
attr_reader_to_pin(decl, closure)
|
|
411
|
-
attr_writer_to_pin(decl, closure)
|
|
591
|
+
def attr_accessor_to_pin(decl, closure, context)
|
|
592
|
+
attr_reader_to_pin(decl, closure, context)
|
|
593
|
+
attr_writer_to_pin(decl, closure, context)
|
|
412
594
|
end
|
|
413
595
|
|
|
414
596
|
# @param decl [RBS::AST::Members::InstanceVariable]
|
|
@@ -418,9 +600,12 @@ module Solargraph
|
|
|
418
600
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
419
601
|
name: decl.name.to_s,
|
|
420
602
|
closure: closure,
|
|
421
|
-
|
|
603
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
604
|
+
comments: decl.comment&.string,
|
|
605
|
+
source: :rbs
|
|
422
606
|
)
|
|
423
|
-
|
|
607
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
608
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
424
609
|
pins.push pin
|
|
425
610
|
end
|
|
426
611
|
|
|
@@ -432,9 +617,12 @@ module Solargraph
|
|
|
432
617
|
pin = Solargraph::Pin::ClassVariable.new(
|
|
433
618
|
name: name,
|
|
434
619
|
closure: closure,
|
|
435
|
-
comments: decl.comment&.string
|
|
620
|
+
comments: decl.comment&.string,
|
|
621
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
622
|
+
source: :rbs
|
|
436
623
|
)
|
|
437
|
-
|
|
624
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
625
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
438
626
|
pins.push pin
|
|
439
627
|
end
|
|
440
628
|
|
|
@@ -446,9 +634,12 @@ module Solargraph
|
|
|
446
634
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
447
635
|
name: name,
|
|
448
636
|
closure: closure,
|
|
449
|
-
comments: decl.comment&.string
|
|
637
|
+
comments: decl.comment&.string,
|
|
638
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
639
|
+
source: :rbs
|
|
450
640
|
)
|
|
451
|
-
|
|
641
|
+
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
|
642
|
+
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
452
643
|
pins.push pin
|
|
453
644
|
end
|
|
454
645
|
|
|
@@ -456,12 +647,14 @@ module Solargraph
|
|
|
456
647
|
# @param closure [Pin::Namespace]
|
|
457
648
|
# @return [void]
|
|
458
649
|
def include_to_pin decl, closure
|
|
459
|
-
type =
|
|
650
|
+
type = build_type(decl.name, decl.args)
|
|
460
651
|
generic_values = type.all_params.map(&:to_s)
|
|
461
652
|
pins.push Solargraph::Pin::Reference::Include.new(
|
|
462
653
|
name: decl.name.relative!.to_s,
|
|
654
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
463
655
|
generic_values: generic_values,
|
|
464
|
-
closure: closure
|
|
656
|
+
closure: closure,
|
|
657
|
+
source: :rbs
|
|
465
658
|
)
|
|
466
659
|
end
|
|
467
660
|
|
|
@@ -471,7 +664,9 @@ module Solargraph
|
|
|
471
664
|
def prepend_to_pin decl, closure
|
|
472
665
|
pins.push Solargraph::Pin::Reference::Prepend.new(
|
|
473
666
|
name: decl.name.relative!.to_s,
|
|
474
|
-
|
|
667
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
668
|
+
closure: closure,
|
|
669
|
+
source: :rbs
|
|
475
670
|
)
|
|
476
671
|
end
|
|
477
672
|
|
|
@@ -481,7 +676,9 @@ module Solargraph
|
|
|
481
676
|
def extend_to_pin decl, closure
|
|
482
677
|
pins.push Solargraph::Pin::Reference::Extend.new(
|
|
483
678
|
name: decl.name.relative!.to_s,
|
|
484
|
-
|
|
679
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
680
|
+
closure: closure,
|
|
681
|
+
source: :rbs
|
|
485
682
|
)
|
|
486
683
|
end
|
|
487
684
|
|
|
@@ -489,10 +686,14 @@ module Solargraph
|
|
|
489
686
|
# @param closure [Pin::Namespace]
|
|
490
687
|
# @return [void]
|
|
491
688
|
def alias_to_pin decl, closure
|
|
689
|
+
final_scope = decl.singleton? ? :class : :instance
|
|
492
690
|
pins.push Solargraph::Pin::MethodAlias.new(
|
|
493
691
|
name: decl.new_name.to_s,
|
|
692
|
+
type_location: location_decl_to_pin_location(decl.location),
|
|
494
693
|
original: decl.old_name.to_s,
|
|
495
|
-
closure: closure
|
|
694
|
+
closure: closure,
|
|
695
|
+
scope: final_scope,
|
|
696
|
+
source: :rbs,
|
|
496
697
|
)
|
|
497
698
|
end
|
|
498
699
|
|
|
@@ -517,23 +718,23 @@ module Solargraph
|
|
|
517
718
|
# @param type_name [RBS::TypeName]
|
|
518
719
|
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
519
720
|
# @return [ComplexType::UniqueType]
|
|
520
|
-
def
|
|
721
|
+
def build_type(type_name, type_args = [])
|
|
521
722
|
base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
|
|
522
|
-
params = type_args.map { |a| other_type_to_tag(a) }.
|
|
523
|
-
ComplexType.try_parse(t)
|
|
723
|
+
params = type_args.map { |a| other_type_to_tag(a) }.map do |t|
|
|
724
|
+
ComplexType.try_parse(t).force_rooted
|
|
524
725
|
end
|
|
525
726
|
if base == 'Hash' && params.length == 2
|
|
526
727
|
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
|
|
527
728
|
else
|
|
528
|
-
ComplexType::UniqueType.new(base, [], params, rooted: true, parameters_type: :list)
|
|
729
|
+
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: true, parameters_type: :list)
|
|
529
730
|
end
|
|
530
731
|
end
|
|
531
732
|
|
|
532
733
|
# @param type_name [RBS::TypeName]
|
|
533
734
|
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
534
735
|
# @return [String]
|
|
535
|
-
def
|
|
536
|
-
|
|
736
|
+
def type_tag(type_name, type_args = [])
|
|
737
|
+
build_type(type_name, type_args).tags
|
|
537
738
|
end
|
|
538
739
|
|
|
539
740
|
# @param type [RBS::Types::Bases::Base]
|
|
@@ -542,14 +743,13 @@ module Solargraph
|
|
|
542
743
|
if type.is_a?(RBS::Types::Optional)
|
|
543
744
|
"#{other_type_to_tag(type.type)}, nil"
|
|
544
745
|
elsif type.is_a?(RBS::Types::Bases::Any)
|
|
545
|
-
|
|
546
|
-
'BasicObject'
|
|
746
|
+
'undefined'
|
|
547
747
|
elsif type.is_a?(RBS::Types::Bases::Bool)
|
|
548
748
|
'Boolean'
|
|
549
749
|
elsif type.is_a?(RBS::Types::Tuple)
|
|
550
750
|
"Array(#{type.types.map { |t| other_type_to_tag(t) }.join(', ')})"
|
|
551
751
|
elsif type.is_a?(RBS::Types::Literal)
|
|
552
|
-
|
|
752
|
+
type.literal.inspect
|
|
553
753
|
elsif type.is_a?(RBS::Types::Union)
|
|
554
754
|
type.types.map { |t| other_type_to_tag(t) }.join(', ')
|
|
555
755
|
elsif type.is_a?(RBS::Types::Record)
|
|
@@ -564,7 +764,7 @@ module Solargraph
|
|
|
564
764
|
elsif type.is_a?(RBS::Types::Variable)
|
|
565
765
|
"#{Solargraph::ComplexType::GENERIC_TAG_NAME}<#{type.name}>"
|
|
566
766
|
elsif type.is_a?(RBS::Types::ClassInstance) #&& !type.args.empty?
|
|
567
|
-
|
|
767
|
+
type_tag(type.name, type.args)
|
|
568
768
|
elsif type.is_a?(RBS::Types::Bases::Instance)
|
|
569
769
|
'self'
|
|
570
770
|
elsif type.is_a?(RBS::Types::Bases::Top)
|
|
@@ -581,8 +781,18 @@ module Solargraph
|
|
|
581
781
|
type.types.map { |member| other_type_to_tag(member) }.join(', ')
|
|
582
782
|
elsif type.is_a?(RBS::Types::Proc)
|
|
583
783
|
'Proc'
|
|
584
|
-
elsif type.
|
|
585
|
-
|
|
784
|
+
elsif type.is_a?(RBS::Types::Alias)
|
|
785
|
+
# type-level alias use - e.g., 'bool' in "type bool = true | false"
|
|
786
|
+
# @todo ensure these get resolved after processing all aliases
|
|
787
|
+
# @todo handle recursive aliases
|
|
788
|
+
type_tag(type.name, type.args)
|
|
789
|
+
elsif type.is_a?(RBS::Types::Interface)
|
|
790
|
+
# represents a mix-in module which can be considered a
|
|
791
|
+
# subtype of a consumer of it
|
|
792
|
+
type_tag(type.name, type.args)
|
|
793
|
+
elsif type.is_a?(RBS::Types::ClassSingleton)
|
|
794
|
+
# e.g., singleton(String)
|
|
795
|
+
type_tag(type.name)
|
|
586
796
|
else
|
|
587
797
|
Solargraph.logger.warn "Unrecognized RBS type: #{type.class} at #{type.location}"
|
|
588
798
|
'undefined'
|
|
@@ -593,12 +803,18 @@ module Solargraph
|
|
|
593
803
|
# @param namespace [Pin::Namespace]
|
|
594
804
|
# @return [void]
|
|
595
805
|
def add_mixins decl, namespace
|
|
806
|
+
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::Members::Extend, RBS::AST::Members::Members::Prepend]
|
|
596
807
|
decl.each_mixin do |mixin|
|
|
808
|
+
# @todo are we handling prepend correctly?
|
|
597
809
|
klass = mixin.is_a?(RBS::AST::Members::Include) ? Pin::Reference::Include : Pin::Reference::Extend
|
|
810
|
+
type = build_type(mixin.name, mixin.args)
|
|
811
|
+
generic_values = type.all_params.map(&:to_s)
|
|
598
812
|
pins.push klass.new(
|
|
599
813
|
name: mixin.name.relative!.to_s,
|
|
600
|
-
|
|
601
|
-
|
|
814
|
+
type_location: location_decl_to_pin_location(mixin.location),
|
|
815
|
+
generic_values: generic_values,
|
|
816
|
+
closure: namespace,
|
|
817
|
+
source: :rbs
|
|
602
818
|
)
|
|
603
819
|
end
|
|
604
820
|
end
|