solargraph 0.58.3 → 0.60.3
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/.envrc +3 -0
- data/.github/workflows/linting.yml +12 -5
- data/.github/workflows/plugins.yml +54 -34
- data/.github/workflows/rspec.yml +18 -28
- data/.github/workflows/typecheck.yml +6 -3
- data/.rubocop.yml +39 -6
- data/.rubocop_todo.yml +53 -966
- data/CHANGELOG.md +57 -0
- data/Gemfile +6 -1
- data/README.md +3 -3
- data/Rakefile +26 -23
- data/bin/solargraph +2 -1
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -4
- data/lib/solargraph/api_map/index.rb +42 -20
- data/lib/solargraph/api_map/source_to_yard.rb +22 -9
- data/lib/solargraph/api_map/store.rb +61 -36
- data/lib/solargraph/api_map.rb +191 -78
- data/lib/solargraph/bench.rb +2 -3
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +31 -18
- data/lib/solargraph/complex_type/unique_type.rb +225 -63
- data/lib/solargraph/complex_type.rb +177 -59
- data/lib/solargraph/convention/active_support_concern.rb +111 -111
- data/lib/solargraph/convention/base.rb +50 -50
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -1
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
- data/lib/solargraph/convention/data_definition.rb +5 -2
- data/lib/solargraph/convention/gemfile.rb +1 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/rakefile.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
- data/lib/solargraph/convention/struct_definition.rb +8 -4
- data/lib/solargraph/convention.rb +2 -2
- data/lib/solargraph/converters/dd.rb +2 -0
- data/lib/solargraph/converters/dl.rb +2 -0
- data/lib/solargraph/converters/dt.rb +2 -0
- data/lib/solargraph/converters/misc.rb +2 -0
- data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +11 -10
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/diagnostics/type_check.rb +11 -10
- data/lib/solargraph/diagnostics/update_errors.rb +4 -8
- data/lib/solargraph/diagnostics.rb +55 -55
- data/lib/solargraph/doc_map.rb +39 -39
- data/lib/solargraph/environ.rb +52 -52
- data/lib/solargraph/equality.rb +4 -4
- data/lib/solargraph/gem_pins.rb +4 -15
- data/lib/solargraph/language_server/error_codes.rb +10 -10
- data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
- data/lib/solargraph/language_server/host/dispatch.rb +3 -3
- data/lib/solargraph/language_server/host/message_worker.rb +4 -3
- data/lib/solargraph/language_server/host/sources.rb +2 -1
- data/lib/solargraph/language_server/host.rb +35 -28
- data/lib/solargraph/language_server/message/base.rb +1 -1
- data/lib/solargraph/language_server/message/client/register_capability.rb +1 -3
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +6 -8
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +12 -18
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +7 -7
- data/lib/solargraph/language_server/message/extended/download_core.rb +2 -1
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
- data/lib/solargraph/language_server/message/extended/search.rb +1 -1
- data/lib/solargraph/language_server/message/initialize.rb +20 -14
- data/lib/solargraph/language_server/message/initialized.rb +28 -28
- data/lib/solargraph/language_server/message/text_document/completion.rb +10 -8
- data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +17 -10
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -19
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
- data/lib/solargraph/language_server/message/text_document/hover.rb +5 -5
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +13 -6
- data/lib/solargraph/language_server/message/text_document/references.rb +17 -10
- data/lib/solargraph/language_server/message/text_document/rename.rb +20 -13
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +3 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
- data/lib/solargraph/language_server/message/text_document.rb +28 -28
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +34 -28
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +38 -30
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +23 -17
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
- data/lib/solargraph/language_server/message.rb +1 -1
- data/lib/solargraph/language_server/progress.rb +143 -143
- data/lib/solargraph/language_server/request.rb +4 -2
- data/lib/solargraph/language_server/transport/adapter.rb +68 -68
- data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
- data/lib/solargraph/language_server/uri_helpers.rb +2 -2
- data/lib/solargraph/language_server.rb +20 -20
- data/lib/solargraph/library.rb +63 -40
- data/lib/solargraph/location.rb +17 -14
- data/lib/solargraph/logging.rb +22 -4
- data/lib/solargraph/page.rb +1 -1
- data/lib/solargraph/parser/comment_ripper.rb +19 -4
- data/lib/solargraph/parser/flow_sensitive_typing.rb +324 -108
- data/lib/solargraph/parser/node_processor/base.rb +34 -4
- data/lib/solargraph/parser/node_processor.rb +8 -7
- data/lib/solargraph/parser/parser_gem/class_methods.rb +30 -14
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +51 -25
- data/lib/solargraph/parser/parser_gem/node_methods.rb +222 -72
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +11 -12
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +9 -8
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +64 -40
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
- data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +20 -20
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -1
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +2 -0
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +3 -1
- data/lib/solargraph/parser.rb +2 -0
- data/lib/solargraph/pin/base.rb +157 -85
- data/lib/solargraph/pin/base_variable.rb +273 -24
- data/lib/solargraph/pin/block.rb +29 -6
- data/lib/solargraph/pin/breakable.rb +7 -1
- data/lib/solargraph/pin/callable.rb +67 -23
- data/lib/solargraph/pin/closure.rb +7 -10
- data/lib/solargraph/pin/common.rb +36 -6
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +3 -5
- data/lib/solargraph/pin/conversions.rb +10 -4
- data/lib/solargraph/pin/delegated_method.rb +19 -8
- data/lib/solargraph/pin/documenting.rb +4 -2
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +15 -59
- data/lib/solargraph/pin/method.rb +203 -111
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +19 -12
- data/lib/solargraph/pin/parameter.rb +102 -36
- data/lib/solargraph/pin/proxy_type.rb +4 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/require.rb +14 -14
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference/type_alias.rb +16 -0
- data/lib/solargraph/pin/reference.rb +20 -0
- data/lib/solargraph/pin/search.rb +8 -7
- data/lib/solargraph/pin/signature.rb +15 -12
- data/lib/solargraph/pin/singleton.rb +11 -11
- data/lib/solargraph/pin/symbol.rb +2 -1
- data/lib/solargraph/pin/until.rb +2 -4
- data/lib/solargraph/pin/while.rb +2 -4
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +22 -19
- data/lib/solargraph/position.rb +17 -10
- data/lib/solargraph/range.rb +16 -15
- data/lib/solargraph/rbs_map/conversions.rb +227 -238
- data/lib/solargraph/rbs_map/core_fills.rb +18 -11
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
- data/lib/solargraph/rbs_map.rb +76 -32
- data/lib/solargraph/rbs_translator.rb +206 -0
- data/lib/solargraph/server_methods.rb +1 -1
- data/lib/solargraph/shell.rb +330 -71
- data/lib/solargraph/source/chain/array.rb +3 -12
- data/lib/solargraph/source/chain/block_symbol.rb +13 -13
- data/lib/solargraph/source/chain/block_variable.rb +13 -13
- data/lib/solargraph/source/chain/call.rb +92 -120
- data/lib/solargraph/source/chain/class_variable.rb +1 -1
- data/lib/solargraph/source/chain/constant.rb +5 -1
- data/lib/solargraph/source/chain/global_variable.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +8 -5
- data/lib/solargraph/source/chain/head.rb +19 -19
- data/lib/solargraph/source/chain/if.rb +12 -10
- data/lib/solargraph/source/chain/instance_variable.rb +19 -1
- data/lib/solargraph/source/chain/link.rb +12 -22
- data/lib/solargraph/source/chain/literal.rb +22 -15
- data/lib/solargraph/source/chain/or.rb +10 -4
- data/lib/solargraph/source/chain/q_call.rb +2 -0
- data/lib/solargraph/source/chain/variable.rb +3 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -3
- data/lib/solargraph/source/chain.rb +51 -38
- data/lib/solargraph/source/change.rb +12 -5
- data/lib/solargraph/source/cursor.rb +33 -18
- data/lib/solargraph/source/encoding_fixes.rb +6 -7
- data/lib/solargraph/source/source_chainer.rb +56 -32
- data/lib/solargraph/source/updater.rb +5 -1
- data/lib/solargraph/source.rb +71 -43
- data/lib/solargraph/source_map/clip.rb +54 -30
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +30 -133
- data/lib/solargraph/source_map.rb +35 -9
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +81 -8
- data/lib/solargraph/type_checker.rb +208 -125
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +14 -11
- data/lib/solargraph/workspace/gemspecs.rb +373 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +50 -28
- data/lib/solargraph/yard_map/cache.rb +25 -25
- data/lib/solargraph/yard_map/directives/attribute_directive.rb +65 -0
- data/lib/solargraph/yard_map/directives/domain_directive.rb +30 -0
- data/lib/solargraph/yard_map/directives/method_directive.rb +51 -0
- data/lib/solargraph/yard_map/directives/override_directive.rb +30 -0
- data/lib/solargraph/yard_map/directives/parse_directive.rb +53 -0
- data/lib/solargraph/yard_map/directives/visibility_directive.rb +70 -0
- data/lib/solargraph/yard_map/directives.rb +35 -0
- data/lib/solargraph/yard_map/helpers.rb +8 -3
- data/lib/solargraph/yard_map/macro.rb +113 -0
- data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
- data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
- data/lib/solargraph/yard_map/mapper.rb +31 -8
- data/lib/solargraph/yard_map.rb +19 -18
- data/lib/solargraph/yard_tags.rb +2 -2
- data/lib/solargraph/yardoc.rb +7 -4
- data/lib/solargraph.rb +34 -10
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/shims/ast/0/node.rbs +1 -1
- data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
- data/solargraph.gemspec +39 -35
- metadata +77 -41
- data/lib/solargraph/type_checker/checks.rb +0 -124
- data/lib/solargraph/type_checker/param_def.rb +0 -37
- data/lib/solargraph/yard_map/to_method.rb +0 -89
- data/rbs/fills/tuple/tuple.rbs +0 -149
|
@@ -23,7 +23,7 @@ module Solargraph
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
# @param loader [RBS::EnvironmentLoader]
|
|
26
|
-
def initialize
|
|
26
|
+
def initialize loader:
|
|
27
27
|
@loader = loader
|
|
28
28
|
@pins = []
|
|
29
29
|
load_environment_to_pins(loader)
|
|
@@ -37,18 +37,15 @@ module Solargraph
|
|
|
37
37
|
|
|
38
38
|
private
|
|
39
39
|
|
|
40
|
-
# @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
|
|
41
|
-
def type_aliases
|
|
42
|
-
@type_aliases ||= {}
|
|
43
|
-
end
|
|
44
|
-
|
|
45
40
|
# @param loader [RBS::EnvironmentLoader]
|
|
41
|
+
#
|
|
46
42
|
# @return [void]
|
|
47
|
-
def load_environment_to_pins
|
|
43
|
+
def load_environment_to_pins loader
|
|
48
44
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
|
49
|
-
cursor = pins.length
|
|
50
45
|
if environment.declarations.empty?
|
|
51
|
-
Solargraph.logger.info
|
|
46
|
+
Solargraph.logger.info 'No RBS declarations found in environment for core_root ' \
|
|
47
|
+
"#{loader.core_root.inspect}, libraries #{loader.libs} and " \
|
|
48
|
+
"directories #{loader.dirs}"
|
|
52
49
|
return
|
|
53
50
|
end
|
|
54
51
|
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
|
@@ -60,22 +57,61 @@ module Solargraph
|
|
|
60
57
|
def convert_decl_to_pin decl, closure
|
|
61
58
|
case decl
|
|
62
59
|
when RBS::AST::Declarations::Class
|
|
60
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
61
|
+
unless closure.name == '' || decl.name.absolute?
|
|
62
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on class #{decl.inspect}")
|
|
63
|
+
end
|
|
63
64
|
class_decl_to_pin decl
|
|
64
65
|
when RBS::AST::Declarations::Interface
|
|
65
|
-
#
|
|
66
|
-
|
|
66
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
67
|
+
unless closure.name == '' || decl.name.absolute?
|
|
68
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on interface #{decl.inspect}")
|
|
69
|
+
end
|
|
70
|
+
interface_decl_to_pin decl
|
|
67
71
|
when RBS::AST::Declarations::TypeAlias
|
|
68
|
-
# @sg-ignore
|
|
69
|
-
|
|
72
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
73
|
+
unless closure.name == '' || decl.name.absolute?
|
|
74
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
75
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
76
|
+
"Ignoring closure #{closure.inspect} on alias type name #{decl.name}")
|
|
77
|
+
end
|
|
78
|
+
pins.push(
|
|
79
|
+
# @sg-ignore Wrong argument type for Solargraph::Pin::Reference::TypeAlias.new: return_type expected Solargraph::ComplexType, received Solargraph::ComplexType::UniqueType, Solargraph::ComplexType
|
|
80
|
+
Solargraph::Pin::Reference::TypeAlias.new(
|
|
81
|
+
# @sg-ignore Unresolved calls to name, type, type_location; return_type type mismatch
|
|
82
|
+
name: ComplexType.try_parse(decl.name.to_s).to_s, return_type: RbsTranslator.to_complex_type(decl.type).force_rooted, closure: closure, source: :rbs, type_location: location_decl_to_pin_location(decl.location)
|
|
83
|
+
)
|
|
84
|
+
)
|
|
70
85
|
when RBS::AST::Declarations::Module
|
|
86
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
87
|
+
unless closure.name == '' || decl.name.absolute?
|
|
88
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
89
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
90
|
+
"Ignoring closure #{closure.inspect} on alias type name #{decl.name}")
|
|
91
|
+
end
|
|
71
92
|
module_decl_to_pin decl
|
|
72
93
|
when RBS::AST::Declarations::Constant
|
|
94
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
95
|
+
unless closure.name == '' || decl.name.absolute?
|
|
96
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on constant #{decl.inspect}")
|
|
97
|
+
end
|
|
73
98
|
constant_decl_to_pin decl
|
|
74
99
|
when RBS::AST::Declarations::ClassAlias
|
|
100
|
+
# @sg-ignore flow sensitive typing should support case/when
|
|
101
|
+
unless closure.name == '' || decl.new_name.absolute?
|
|
102
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on class alias #{decl.inspect}")
|
|
103
|
+
end
|
|
75
104
|
class_alias_decl_to_pin decl
|
|
76
105
|
when RBS::AST::Declarations::ModuleAlias
|
|
106
|
+
unless closure.name == ''
|
|
107
|
+
Solargraph.assert_or_log(:rbs_closure,
|
|
108
|
+
"Ignoring closure #{closure.inspect} on module alias #{decl.inspect}")
|
|
109
|
+
end
|
|
77
110
|
module_alias_decl_to_pin decl
|
|
78
111
|
when RBS::AST::Declarations::Global
|
|
112
|
+
unless closure.name == ''
|
|
113
|
+
Solargraph.assert_or_log(:rbs_closure, "Ignoring closure #{closure.inspect} on global decl #{decl.inspect}")
|
|
114
|
+
end
|
|
79
115
|
global_decl_to_pin decl
|
|
80
116
|
else
|
|
81
117
|
Solargraph.logger.warn "Skipping declaration #{decl.class}"
|
|
@@ -86,7 +122,41 @@ module Solargraph
|
|
|
86
122
|
# @param module_pin [Pin::Namespace]
|
|
87
123
|
# @return [void]
|
|
88
124
|
def convert_self_types_to_pins decl, module_pin
|
|
89
|
-
decl.self_types.each { |self_type|
|
|
125
|
+
decl.self_types.each { |self_type| convert_self_type_to_pins(self_type, module_pin) }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @type [Hash{String => String}]
|
|
129
|
+
RBS_TO_CLASS = {
|
|
130
|
+
'bool' => 'Boolean',
|
|
131
|
+
'string' => 'String',
|
|
132
|
+
'int' => 'Integer'
|
|
133
|
+
}.freeze
|
|
134
|
+
private_constant :RBS_TO_CLASS
|
|
135
|
+
|
|
136
|
+
# rooted names (namespaces) use the prefix of :: when they are
|
|
137
|
+
# relative to the root namespace, or not if they are relative to
|
|
138
|
+
# the current namespace.
|
|
139
|
+
#
|
|
140
|
+
# @param type_name [RBS::TypeName]
|
|
141
|
+
#
|
|
142
|
+
# @return [String]
|
|
143
|
+
def rooted_name type_name
|
|
144
|
+
name = type_name.to_s
|
|
145
|
+
RBS_TO_CLASS.fetch(name, name)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# fqns names are implicitly fully qualified - they are relative
|
|
149
|
+
# to the root namespace and are not prefixed with ::
|
|
150
|
+
#
|
|
151
|
+
# @param type_name [RBS::TypeName]
|
|
152
|
+
#
|
|
153
|
+
# @return [String]
|
|
154
|
+
def fqns type_name
|
|
155
|
+
unless type_name.absolute?
|
|
156
|
+
Solargraph.assert_or_log(:rbs_fqns, "Received unexpected unqualified type name: #{type_name}")
|
|
157
|
+
end
|
|
158
|
+
ns = type_name.relative!.to_s
|
|
159
|
+
RBS_TO_CLASS.fetch(ns, ns)
|
|
90
160
|
end
|
|
91
161
|
|
|
92
162
|
# @param decl [RBS::AST::Declarations::Module::Self]
|
|
@@ -120,32 +190,44 @@ module Solargraph
|
|
|
120
190
|
def convert_member_to_pin member, closure, context
|
|
121
191
|
case member
|
|
122
192
|
when RBS::AST::Members::MethodDefinition
|
|
193
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
123
194
|
method_def_to_pin(member, closure, context)
|
|
124
195
|
when RBS::AST::Members::AttrReader
|
|
196
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
125
197
|
attr_reader_to_pin(member, closure, context)
|
|
126
198
|
when RBS::AST::Members::AttrWriter
|
|
199
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
127
200
|
attr_writer_to_pin(member, closure, context)
|
|
128
201
|
when RBS::AST::Members::AttrAccessor
|
|
202
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
129
203
|
attr_accessor_to_pin(member, closure, context)
|
|
130
204
|
when RBS::AST::Members::Include
|
|
205
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
131
206
|
include_to_pin(member, closure)
|
|
132
207
|
when RBS::AST::Members::Prepend
|
|
208
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
133
209
|
prepend_to_pin(member, closure)
|
|
134
210
|
when RBS::AST::Members::Extend
|
|
211
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
135
212
|
extend_to_pin(member, closure)
|
|
136
213
|
when RBS::AST::Members::Alias
|
|
214
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
137
215
|
alias_to_pin(member, closure)
|
|
138
216
|
when RBS::AST::Members::ClassInstanceVariable
|
|
217
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
139
218
|
civar_to_pin(member, closure)
|
|
140
219
|
when RBS::AST::Members::ClassVariable
|
|
220
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
141
221
|
cvar_to_pin(member, closure)
|
|
142
222
|
when RBS::AST::Members::InstanceVariable
|
|
223
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
143
224
|
ivar_to_pin(member, closure)
|
|
144
225
|
when RBS::AST::Members::Public
|
|
145
226
|
return Context.new(:public)
|
|
146
227
|
when RBS::AST::Members::Private
|
|
147
228
|
return Context.new(:private)
|
|
148
229
|
when RBS::AST::Declarations::Base
|
|
230
|
+
# @sg-ignore flow based typing needs to understand case when class pattern
|
|
149
231
|
convert_decl_to_pin(member, closure)
|
|
150
232
|
else
|
|
151
233
|
Solargraph.logger.warn "Skipping member type #{member.class}"
|
|
@@ -153,18 +235,34 @@ module Solargraph
|
|
|
153
235
|
context
|
|
154
236
|
end
|
|
155
237
|
|
|
238
|
+
# Pull the name of type variables for a generic - not the
|
|
239
|
+
# values, the names (e.g., T, U, V). As such, "rooting" isn't a
|
|
240
|
+
# thing, these are all in the global namespace.
|
|
241
|
+
#
|
|
242
|
+
# @param decl [RBS::AST::Declarations::Class, RBS::AST::Declarations::Interface,
|
|
243
|
+
# RBS::AST::Declarations::Module, RBS::MethodType]
|
|
244
|
+
#
|
|
245
|
+
# @return [Array<String>]
|
|
246
|
+
def type_parameter_names decl
|
|
247
|
+
decl.type_params.map(&:name).map(&:to_s)
|
|
248
|
+
end
|
|
249
|
+
|
|
156
250
|
# @param decl [RBS::AST::Declarations::Class]
|
|
157
251
|
# @return [void]
|
|
158
252
|
def class_decl_to_pin decl
|
|
159
|
-
|
|
253
|
+
# @type [Hash{String => ComplexType, ComplexType::UniqueType}]
|
|
160
254
|
generic_defaults = {}
|
|
161
255
|
decl.type_params.each do |param|
|
|
162
256
|
if param.default_type
|
|
163
|
-
|
|
164
|
-
generic_defaults[param.name.to_s] =
|
|
257
|
+
complex_type = RbsTranslator.to_complex_type(param.default_type).force_rooted
|
|
258
|
+
generic_defaults[param.name.to_s] = complex_type
|
|
165
259
|
end
|
|
166
260
|
end
|
|
167
|
-
|
|
261
|
+
|
|
262
|
+
class_name = fqns(decl.name)
|
|
263
|
+
|
|
264
|
+
generics = type_parameter_names(decl)
|
|
265
|
+
|
|
168
266
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
169
267
|
type: :class,
|
|
170
268
|
name: class_name,
|
|
@@ -187,7 +285,7 @@ module Solargraph
|
|
|
187
285
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
|
188
286
|
closure: class_pin,
|
|
189
287
|
generic_values: generic_values,
|
|
190
|
-
name:
|
|
288
|
+
name: type.rooted_name, # reference pins use rooted names
|
|
191
289
|
source: :rbs
|
|
192
290
|
)
|
|
193
291
|
end
|
|
@@ -196,16 +294,15 @@ module Solargraph
|
|
|
196
294
|
end
|
|
197
295
|
|
|
198
296
|
# @param decl [RBS::AST::Declarations::Interface]
|
|
199
|
-
# @param closure [Pin::Closure]
|
|
200
297
|
# @return [void]
|
|
201
|
-
def interface_decl_to_pin decl
|
|
298
|
+
def interface_decl_to_pin decl
|
|
202
299
|
class_pin = Solargraph::Pin::Namespace.new(
|
|
203
300
|
type: :module,
|
|
204
301
|
type_location: location_decl_to_pin_location(decl.location),
|
|
205
302
|
name: decl.name.relative!.to_s,
|
|
206
303
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
207
304
|
comments: decl.comment&.string,
|
|
208
|
-
generics: decl
|
|
305
|
+
generics: type_parameter_names(decl),
|
|
209
306
|
# HACK: Using :hidden to keep interfaces from appearing in
|
|
210
307
|
# autocompletion
|
|
211
308
|
visibility: :hidden,
|
|
@@ -225,41 +322,50 @@ module Solargraph
|
|
|
225
322
|
type_location: location_decl_to_pin_location(decl.location),
|
|
226
323
|
closure: Solargraph::Pin::ROOT_PIN,
|
|
227
324
|
comments: decl.comment&.string,
|
|
228
|
-
generics: decl
|
|
325
|
+
generics: type_parameter_names(decl),
|
|
229
326
|
source: :rbs
|
|
230
327
|
)
|
|
231
328
|
pins.push module_pin
|
|
232
329
|
convert_self_types_to_pins decl, module_pin
|
|
233
330
|
convert_members_to_pins decl, module_pin
|
|
234
331
|
|
|
332
|
+
raise "Invalid type for module declaration: #{module_pin.class}" unless module_pin.is_a?(Pin::Namespace)
|
|
333
|
+
|
|
235
334
|
add_mixins decl, module_pin.closure
|
|
236
335
|
end
|
|
237
336
|
|
|
238
|
-
# @param
|
|
239
|
-
# @param
|
|
240
|
-
# @param comments [String]
|
|
241
|
-
# @param decl [RBS::AST::Declarations::ClassAlias,
|
|
242
|
-
#
|
|
337
|
+
# @param fqns [String]
|
|
338
|
+
# @param type [ComplexType, ComplexType::UniqueType]
|
|
339
|
+
# @param comments [String, nil]
|
|
340
|
+
# @param decl [RBS::AST::Declarations::ClassAlias,
|
|
341
|
+
# RBS::AST::Declarations::Constant,
|
|
342
|
+
# RBS::AST::Declarations::ModuleAlias]
|
|
343
|
+
# @param base [String, nil] Optional conversion of tag to
|
|
344
|
+
# base<tag> - valid values are Class and Module
|
|
243
345
|
#
|
|
244
346
|
# @return [Solargraph::Pin::Constant]
|
|
245
|
-
def create_constant
|
|
246
|
-
parts =
|
|
347
|
+
def create_constant fqns, type, comments, decl, base = nil
|
|
348
|
+
parts = fqns.split('::')
|
|
247
349
|
if parts.length > 1
|
|
248
|
-
|
|
350
|
+
fqns = parts.last
|
|
351
|
+
# @sg-ignore Need to add nil check here
|
|
249
352
|
closure = pins.select { |pin| pin && pin.path == parts[0..-2].join('::') }.first
|
|
250
353
|
else
|
|
251
|
-
|
|
354
|
+
fqns = parts.first
|
|
252
355
|
closure = Solargraph::Pin::ROOT_PIN
|
|
253
356
|
end
|
|
254
357
|
constant_pin = Solargraph::Pin::Constant.new(
|
|
255
|
-
name:
|
|
358
|
+
name: fqns,
|
|
256
359
|
closure: closure,
|
|
257
360
|
type_location: location_decl_to_pin_location(decl.location),
|
|
258
361
|
comments: comments,
|
|
259
362
|
source: :rbs
|
|
260
363
|
)
|
|
261
|
-
|
|
262
|
-
rooted_tag =
|
|
364
|
+
rooted_tag = type.rooted_tags
|
|
365
|
+
rooted_tag = "#{base}<#{rooted_tag}>" if base
|
|
366
|
+
# @todo alt version
|
|
367
|
+
# tag = "#{base}<#{tag}>" if base
|
|
368
|
+
# rooted_tag = ComplexType.parse(tag).force_rooted.rooted_tags
|
|
263
369
|
constant_pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
264
370
|
constant_pin
|
|
265
371
|
end
|
|
@@ -268,26 +374,25 @@ module Solargraph
|
|
|
268
374
|
# @return [void]
|
|
269
375
|
def class_alias_decl_to_pin decl
|
|
270
376
|
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ClassAlias
|
|
271
|
-
new_name = decl.new_name
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
pins.push create_constant(new_name, old_name, decl.comment&.string, decl, 'Class')
|
|
377
|
+
new_name = fqns(decl.new_name)
|
|
378
|
+
old_type = build_type(decl.old_name)
|
|
379
|
+
pins.push create_constant(new_name, old_type, decl.comment&.string, decl, '::Class')
|
|
275
380
|
end
|
|
276
381
|
|
|
277
382
|
# @param decl [RBS::AST::Declarations::ModuleAlias]
|
|
278
383
|
# @return [void]
|
|
279
384
|
def module_alias_decl_to_pin decl
|
|
280
385
|
# See https://www.rubydoc.info/gems/rbs/3.4.3/RBS/AST/Declarations/ModuleAlias
|
|
281
|
-
new_name = decl.new_name
|
|
282
|
-
|
|
386
|
+
new_name = fqns(decl.new_name)
|
|
387
|
+
old_type = build_type(decl.old_name)
|
|
283
388
|
|
|
284
|
-
pins.push create_constant(new_name,
|
|
389
|
+
pins.push create_constant(new_name, old_type, decl.comment&.string, decl, '::Module')
|
|
285
390
|
end
|
|
286
391
|
|
|
287
392
|
# @param decl [RBS::AST::Declarations::Constant]
|
|
288
393
|
# @return [void]
|
|
289
394
|
def constant_decl_to_pin decl
|
|
290
|
-
tag =
|
|
395
|
+
tag = RbsTranslator.to_complex_type(decl.type)
|
|
291
396
|
pins.push create_constant(decl.name.relative!.to_s, tag, decl.comment&.string, decl)
|
|
292
397
|
end
|
|
293
398
|
|
|
@@ -303,12 +408,11 @@ module Solargraph
|
|
|
303
408
|
type_location: location_decl_to_pin_location(decl.location),
|
|
304
409
|
source: :rbs
|
|
305
410
|
)
|
|
306
|
-
rooted_tag =
|
|
411
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
307
412
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
308
413
|
pins.push pin
|
|
309
414
|
end
|
|
310
415
|
|
|
311
|
-
|
|
312
416
|
# Visibility overrides that will allow the Solargraph project
|
|
313
417
|
# and plugins to pass typechecking using SOLARGRAPH_ASSERTS=on,
|
|
314
418
|
# so that we can detect any regressions/issues elsewhere in the
|
|
@@ -324,42 +428,47 @@ module Solargraph
|
|
|
324
428
|
# allow that to be extended via .solargraph.yml
|
|
325
429
|
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
|
326
430
|
VISIBILITY_OVERRIDE = {
|
|
327
|
-
[
|
|
431
|
+
['Rails::Engine', :instance, 'run_tasks_blocks'] => :protected,
|
|
328
432
|
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
|
329
|
-
[
|
|
433
|
+
['Kernel', :instance, 'pretty_inspect'] => :private,
|
|
330
434
|
# marked incorrectly in RBS
|
|
331
|
-
[
|
|
332
|
-
[
|
|
333
|
-
[
|
|
334
|
-
[
|
|
335
|
-
[
|
|
336
|
-
[
|
|
337
|
-
[
|
|
338
|
-
[
|
|
339
|
-
[
|
|
340
|
-
[
|
|
341
|
-
[
|
|
342
|
-
[
|
|
343
|
-
[
|
|
344
|
-
[
|
|
345
|
-
[
|
|
346
|
-
[
|
|
347
|
-
[
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
435
|
+
['WEBrick::HTTPUtils::FormData', :instance, 'next_data'] => :protected,
|
|
436
|
+
['Rails::Command', :class, 'command_type'] => :private,
|
|
437
|
+
['Rails::Command', :class, 'lookup_paths'] => :private,
|
|
438
|
+
['Rails::Command', :class, 'file_lookup_paths'] => :private,
|
|
439
|
+
['Rails::Railtie', :instance, 'run_console_blocks'] => :protected,
|
|
440
|
+
['Rails::Railtie', :instance, 'run_generators_blocks'] => :protected,
|
|
441
|
+
['Rails::Railtie', :instance, 'run_runner_blocks'] => :protected,
|
|
442
|
+
['Rails::Railtie', :instance, 'run_tasks_blocks'] => :protected,
|
|
443
|
+
['ActionController::Base', :instance, '_protected_ivars'] => :private,
|
|
444
|
+
['ActionView::Template', :instance, 'method_name'] => :public,
|
|
445
|
+
['Module', :instance, 'ruby2_keywords'] => :private,
|
|
446
|
+
['Nokogiri::XML::Node', :instance, 'coerce'] => :protected,
|
|
447
|
+
['Nokogiri::XML::Document', :class, 'empty_doc?'] => :private,
|
|
448
|
+
['Nokogiri::Decorators::Slop', :instance, 'respond_to_missing?'] => :public,
|
|
449
|
+
['RuboCop::Cop::RangeHelp', :instance, 'source_range'] => :private,
|
|
450
|
+
['AST::Node', :instance, 'original_dup'] => :private,
|
|
451
|
+
['Rainbow::Presenter', :instance, 'wrap_with_sgr'] => :private
|
|
452
|
+
}.freeze
|
|
453
|
+
private_constant :VISIBILITY_OVERRIDE
|
|
454
|
+
|
|
455
|
+
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader,
|
|
456
|
+
# RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
|
351
457
|
# @param closure [Pin::Closure]
|
|
352
458
|
# @param context [Context]
|
|
353
459
|
# @param scope [Symbol] :instance or :class
|
|
354
460
|
# @param name [String] The name of the method
|
|
355
|
-
# @sg-ignore
|
|
356
461
|
# @return [Symbol]
|
|
357
|
-
|
|
462
|
+
# @sg-ignore Declared return type ::Symbol does not match inferred type
|
|
463
|
+
# ::Symbol, :public, :private, nil for Solargraph::RbsMap::Conversions#calculate_method_visibility
|
|
464
|
+
def calculate_method_visibility decl, context, closure, scope, name
|
|
358
465
|
override_key = [closure.path, scope, name]
|
|
359
466
|
visibility = VISIBILITY_OVERRIDE[override_key]
|
|
360
467
|
simple_override_key = [closure.path, scope]
|
|
361
468
|
visibility ||= VISIBILITY_OVERRIDE[simple_override_key]
|
|
362
|
-
|
|
469
|
+
if closure.path == 'Kernel' && Kernel.private_method_defined?(decl.name, false)
|
|
470
|
+
visibility ||= :private
|
|
471
|
+
end
|
|
363
472
|
if decl.kind == :singleton_instance
|
|
364
473
|
# this is a 'module function'
|
|
365
474
|
visibility ||= :private
|
|
@@ -379,7 +488,9 @@ module Solargraph
|
|
|
379
488
|
# having different type params / orders - we may need to match
|
|
380
489
|
# this data model and have generics live in signatures to
|
|
381
490
|
# handle those correctly
|
|
382
|
-
generics = decl.overloads.map(&:method_type).
|
|
491
|
+
generics = decl.overloads.map(&:method_type).map do |method_type|
|
|
492
|
+
type_parameter_names method_type
|
|
493
|
+
end
|
|
383
494
|
|
|
384
495
|
if decl.instance?
|
|
385
496
|
name = decl.name.to_s
|
|
@@ -427,13 +538,16 @@ module Solargraph
|
|
|
427
538
|
# @param pin [Pin::Method]
|
|
428
539
|
# @return [void]
|
|
429
540
|
def method_def_to_sigs decl, pin
|
|
541
|
+
# rubocop:disable Style/SafeNavigationChainLength
|
|
542
|
+
implicit_nil = decl.overloads.first&.annotations&.map(&:string)&.include?('implicitly-returns-nil') || false
|
|
543
|
+
# rubocop:enable Style/SafeNavigationChainLength
|
|
430
544
|
# @param overload [RBS::AST::Members::MethodDefinition::Overload]
|
|
431
545
|
decl.overloads.map do |overload|
|
|
432
546
|
type_location = location_decl_to_pin_location(overload.method_type.location)
|
|
433
547
|
generics = overload.method_type.type_params.map(&:name).map(&:to_s)
|
|
434
|
-
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
|
548
|
+
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin, implicit_nil)
|
|
435
549
|
block = if overload.method_type.block
|
|
436
|
-
block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin)
|
|
550
|
+
block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin, implicit_nil)
|
|
437
551
|
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type, source: :rbs,
|
|
438
552
|
type_location: type_location, closure: pin)
|
|
439
553
|
end
|
|
@@ -455,83 +569,20 @@ module Solargraph
|
|
|
455
569
|
|
|
456
570
|
# @param type [RBS::MethodType,RBS::Types::Block]
|
|
457
571
|
# @param pin [Pin::Method]
|
|
572
|
+
# @param implicit_nil [Boolean]
|
|
458
573
|
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
|
459
|
-
def parts_of_function type, pin
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
ComplexType.try_parse(method_type_to_tag(type)).force_rooted
|
|
465
|
-
]
|
|
466
|
-
end
|
|
467
|
-
|
|
468
|
-
parameters = []
|
|
469
|
-
arg_num = -1
|
|
470
|
-
type.type.required_positionals.each do |param|
|
|
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)
|
|
475
|
-
end
|
|
476
|
-
type.type.optional_positionals.each do |param|
|
|
477
|
-
# @sg-ignore RBS generic type understanding issue
|
|
478
|
-
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
|
479
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
|
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)
|
|
484
|
-
end
|
|
485
|
-
if type.type.rest_positionals
|
|
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,)
|
|
496
|
-
end
|
|
497
|
-
type.type.trailing_positionals.each do |param|
|
|
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)
|
|
501
|
-
end
|
|
502
|
-
type.type.required_keywords.each do |orig, param|
|
|
503
|
-
# @sg-ignore RBS generic type understanding issue
|
|
504
|
-
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
505
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
|
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)
|
|
509
|
-
end
|
|
510
|
-
type.type.optional_keywords.each do |orig, param|
|
|
511
|
-
# @sg-ignore RBS generic type understanding issue
|
|
512
|
-
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
|
513
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
|
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)
|
|
518
|
-
end
|
|
519
|
-
if type.type.rest_keywords
|
|
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)
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
rooted_tag = method_type_to_tag(type)
|
|
526
|
-
return_type = ComplexType.try_parse(rooted_tag).force_rooted
|
|
527
|
-
[parameters, return_type]
|
|
574
|
+
def parts_of_function type, pin, implicit_nil
|
|
575
|
+
[
|
|
576
|
+
RbsTranslator.to_parameter_pins(type, pin, pin.parameter_names),
|
|
577
|
+
extract_method_type_return_type(type, implicit_nil).force_rooted
|
|
578
|
+
]
|
|
528
579
|
end
|
|
529
580
|
|
|
530
581
|
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
|
531
582
|
# @param closure [Pin::Namespace]
|
|
532
583
|
# @param context [Context]
|
|
533
584
|
# @return [void]
|
|
534
|
-
def attr_reader_to_pin
|
|
585
|
+
def attr_reader_to_pin decl, closure, context
|
|
535
586
|
name = decl.name.to_s
|
|
536
587
|
final_scope = decl.kind == :instance ? :instance : :class
|
|
537
588
|
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
@@ -545,9 +596,11 @@ module Solargraph
|
|
|
545
596
|
visibility: visibility,
|
|
546
597
|
source: :rbs
|
|
547
598
|
)
|
|
548
|
-
rooted_tag =
|
|
599
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
549
600
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
550
|
-
logger.debug
|
|
601
|
+
logger.debug do
|
|
602
|
+
"Conversions#attr_reader_to_pin(name=#{name.inspect}, visibility=#{visibility.inspect}) => #{pin.inspect}"
|
|
603
|
+
end
|
|
551
604
|
pins.push pin
|
|
552
605
|
end
|
|
553
606
|
|
|
@@ -555,9 +608,9 @@ module Solargraph
|
|
|
555
608
|
# @param closure [Pin::Namespace]
|
|
556
609
|
# @param context [Context]
|
|
557
610
|
# @return [void]
|
|
558
|
-
def attr_writer_to_pin
|
|
611
|
+
def attr_writer_to_pin decl, closure, context
|
|
559
612
|
final_scope = decl.kind == :instance ? :instance : :class
|
|
560
|
-
name = "#{decl.name
|
|
613
|
+
name = "#{decl.name}="
|
|
561
614
|
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
|
562
615
|
type_location = location_decl_to_pin_location(decl.location)
|
|
563
616
|
pin = Solargraph::Pin::Method.new(
|
|
@@ -574,12 +627,12 @@ module Solargraph
|
|
|
574
627
|
pin.parameters <<
|
|
575
628
|
Solargraph::Pin::Parameter.new(
|
|
576
629
|
name: 'value',
|
|
577
|
-
return_type:
|
|
630
|
+
return_type: RbsTranslator.to_complex_type(decl.type).force_rooted,
|
|
578
631
|
source: :rbs,
|
|
579
632
|
closure: pin,
|
|
580
633
|
type_location: type_location
|
|
581
634
|
)
|
|
582
|
-
rooted_tag =
|
|
635
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
583
636
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
|
584
637
|
pins.push pin
|
|
585
638
|
end
|
|
@@ -588,7 +641,7 @@ module Solargraph
|
|
|
588
641
|
# @param closure [Pin::Namespace]
|
|
589
642
|
# @param context [Context]
|
|
590
643
|
# @return [void]
|
|
591
|
-
def attr_accessor_to_pin
|
|
644
|
+
def attr_accessor_to_pin decl, closure, context
|
|
592
645
|
attr_reader_to_pin(decl, closure, context)
|
|
593
646
|
attr_writer_to_pin(decl, closure, context)
|
|
594
647
|
end
|
|
@@ -596,7 +649,7 @@ module Solargraph
|
|
|
596
649
|
# @param decl [RBS::AST::Members::InstanceVariable]
|
|
597
650
|
# @param closure [Pin::Namespace]
|
|
598
651
|
# @return [void]
|
|
599
|
-
def ivar_to_pin
|
|
652
|
+
def ivar_to_pin decl, closure
|
|
600
653
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
601
654
|
name: decl.name.to_s,
|
|
602
655
|
closure: closure,
|
|
@@ -604,7 +657,7 @@ module Solargraph
|
|
|
604
657
|
comments: decl.comment&.string,
|
|
605
658
|
source: :rbs
|
|
606
659
|
)
|
|
607
|
-
rooted_tag =
|
|
660
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
608
661
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
609
662
|
pins.push pin
|
|
610
663
|
end
|
|
@@ -612,7 +665,7 @@ module Solargraph
|
|
|
612
665
|
# @param decl [RBS::AST::Members::ClassVariable]
|
|
613
666
|
# @param closure [Pin::Namespace]
|
|
614
667
|
# @return [void]
|
|
615
|
-
def cvar_to_pin
|
|
668
|
+
def cvar_to_pin decl, closure
|
|
616
669
|
name = decl.name.to_s
|
|
617
670
|
pin = Solargraph::Pin::ClassVariable.new(
|
|
618
671
|
name: name,
|
|
@@ -621,7 +674,7 @@ module Solargraph
|
|
|
621
674
|
type_location: location_decl_to_pin_location(decl.location),
|
|
622
675
|
source: :rbs
|
|
623
676
|
)
|
|
624
|
-
rooted_tag =
|
|
677
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
625
678
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
626
679
|
pins.push pin
|
|
627
680
|
end
|
|
@@ -629,7 +682,7 @@ module Solargraph
|
|
|
629
682
|
# @param decl [RBS::AST::Members::ClassInstanceVariable]
|
|
630
683
|
# @param closure [Pin::Namespace]
|
|
631
684
|
# @return [void]
|
|
632
|
-
def civar_to_pin
|
|
685
|
+
def civar_to_pin decl, closure
|
|
633
686
|
name = decl.name.to_s
|
|
634
687
|
pin = Solargraph::Pin::InstanceVariable.new(
|
|
635
688
|
name: name,
|
|
@@ -638,7 +691,7 @@ module Solargraph
|
|
|
638
691
|
type_location: location_decl_to_pin_location(decl.location),
|
|
639
692
|
source: :rbs
|
|
640
693
|
)
|
|
641
|
-
rooted_tag =
|
|
694
|
+
rooted_tag = RbsTranslator.to_complex_type(decl.type).force_rooted.rooted_tags
|
|
642
695
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:type, '', rooted_tag))
|
|
643
696
|
pins.push pin
|
|
644
697
|
end
|
|
@@ -662,6 +715,8 @@ module Solargraph
|
|
|
662
715
|
# @param closure [Pin::Namespace]
|
|
663
716
|
# @return [void]
|
|
664
717
|
def prepend_to_pin decl, closure
|
|
718
|
+
type = build_type(decl.name, decl.args)
|
|
719
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
665
720
|
pins.push Solargraph::Pin::Reference::Prepend.new(
|
|
666
721
|
name: decl.name.relative!.to_s,
|
|
667
722
|
type_location: location_decl_to_pin_location(decl.location),
|
|
@@ -674,6 +729,8 @@ module Solargraph
|
|
|
674
729
|
# @param closure [Pin::Namespace]
|
|
675
730
|
# @return [void]
|
|
676
731
|
def extend_to_pin decl, closure
|
|
732
|
+
type = build_type(decl.name, decl.args)
|
|
733
|
+
generic_values = type.all_params.map(&:rooted_tags)
|
|
677
734
|
pins.push Solargraph::Pin::Reference::Extend.new(
|
|
678
735
|
name: decl.name.relative!.to_s,
|
|
679
736
|
type_location: location_decl_to_pin_location(decl.location),
|
|
@@ -693,7 +750,7 @@ module Solargraph
|
|
|
693
750
|
original: decl.old_name.to_s,
|
|
694
751
|
closure: closure,
|
|
695
752
|
scope: final_scope,
|
|
696
|
-
source: :rbs
|
|
753
|
+
source: :rbs
|
|
697
754
|
)
|
|
698
755
|
end
|
|
699
756
|
|
|
@@ -704,15 +761,18 @@ module Solargraph
|
|
|
704
761
|
'untyped' => '',
|
|
705
762
|
'NilClass' => 'nil'
|
|
706
763
|
}
|
|
764
|
+
private_constant :RBS_TO_YARD_TYPE
|
|
707
765
|
|
|
766
|
+
# Extract a ComplexType from a MethodType's return type.
|
|
767
|
+
#
|
|
768
|
+
# This method will convert type aliases to concrete types.
|
|
769
|
+
#
|
|
708
770
|
# @param type [RBS::MethodType]
|
|
709
|
-
# @return [
|
|
710
|
-
def
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
other_type_to_tag type.type.return_type
|
|
715
|
-
end
|
|
771
|
+
# @return [ComplexType]
|
|
772
|
+
def extract_method_type_return_type type, implicit_nil
|
|
773
|
+
tag = RbsTranslator.to_complex_type(type.type.return_type)
|
|
774
|
+
return ComplexType.parse("#{tag}, nil") if tag && implicit_nil
|
|
775
|
+
tag
|
|
716
776
|
end
|
|
717
777
|
|
|
718
778
|
# @param type_name [RBS::TypeName]
|
|
@@ -720,9 +780,7 @@ module Solargraph
|
|
|
720
780
|
# @return [ComplexType::UniqueType]
|
|
721
781
|
def build_type(type_name, type_args = [])
|
|
722
782
|
base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
|
|
723
|
-
params = type_args.map { |
|
|
724
|
-
ComplexType.try_parse(t).force_rooted
|
|
725
|
-
end
|
|
783
|
+
params = type_args.map { |arg| RbsTranslator.to_complex_type(arg).force_rooted }
|
|
726
784
|
if base == 'Hash' && params.length == 2
|
|
727
785
|
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
|
|
728
786
|
else
|
|
@@ -730,80 +788,11 @@ module Solargraph
|
|
|
730
788
|
end
|
|
731
789
|
end
|
|
732
790
|
|
|
733
|
-
# @param type_name [RBS::TypeName]
|
|
734
|
-
# @param type_args [Enumerable<RBS::Types::Bases::Base>]
|
|
735
|
-
# @return [String]
|
|
736
|
-
def type_tag(type_name, type_args = [])
|
|
737
|
-
build_type(type_name, type_args).tags
|
|
738
|
-
end
|
|
739
|
-
|
|
740
|
-
# @param type [RBS::Types::Bases::Base]
|
|
741
|
-
# @return [String]
|
|
742
|
-
def other_type_to_tag type
|
|
743
|
-
if type.is_a?(RBS::Types::Optional)
|
|
744
|
-
"#{other_type_to_tag(type.type)}, nil"
|
|
745
|
-
elsif type.is_a?(RBS::Types::Bases::Any)
|
|
746
|
-
'undefined'
|
|
747
|
-
elsif type.is_a?(RBS::Types::Bases::Bool)
|
|
748
|
-
'Boolean'
|
|
749
|
-
elsif type.is_a?(RBS::Types::Tuple)
|
|
750
|
-
"Array(#{type.types.map { |t| other_type_to_tag(t) }.join(', ')})"
|
|
751
|
-
elsif type.is_a?(RBS::Types::Literal)
|
|
752
|
-
type.literal.inspect
|
|
753
|
-
elsif type.is_a?(RBS::Types::Union)
|
|
754
|
-
type.types.map { |t| other_type_to_tag(t) }.join(', ')
|
|
755
|
-
elsif type.is_a?(RBS::Types::Record)
|
|
756
|
-
# @todo Better record support
|
|
757
|
-
'Hash'
|
|
758
|
-
elsif type.is_a?(RBS::Types::Bases::Nil)
|
|
759
|
-
'nil'
|
|
760
|
-
elsif type.is_a?(RBS::Types::Bases::Self)
|
|
761
|
-
'self'
|
|
762
|
-
elsif type.is_a?(RBS::Types::Bases::Void)
|
|
763
|
-
'void'
|
|
764
|
-
elsif type.is_a?(RBS::Types::Variable)
|
|
765
|
-
"#{Solargraph::ComplexType::GENERIC_TAG_NAME}<#{type.name}>"
|
|
766
|
-
elsif type.is_a?(RBS::Types::ClassInstance) #&& !type.args.empty?
|
|
767
|
-
type_tag(type.name, type.args)
|
|
768
|
-
elsif type.is_a?(RBS::Types::Bases::Instance)
|
|
769
|
-
'self'
|
|
770
|
-
elsif type.is_a?(RBS::Types::Bases::Top)
|
|
771
|
-
# top is the most super superclass
|
|
772
|
-
'BasicObject'
|
|
773
|
-
elsif type.is_a?(RBS::Types::Bases::Bottom)
|
|
774
|
-
# bottom is used in contexts where nothing will ever return
|
|
775
|
-
# - e.g., it could be the return type of 'exit()' or 'raise'
|
|
776
|
-
#
|
|
777
|
-
# @todo define a specific bottom type and use it to
|
|
778
|
-
# determine dead code
|
|
779
|
-
'undefined'
|
|
780
|
-
elsif type.is_a?(RBS::Types::Intersection)
|
|
781
|
-
type.types.map { |member| other_type_to_tag(member) }.join(', ')
|
|
782
|
-
elsif type.is_a?(RBS::Types::Proc)
|
|
783
|
-
'Proc'
|
|
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)
|
|
796
|
-
else
|
|
797
|
-
Solargraph.logger.warn "Unrecognized RBS type: #{type.class} at #{type.location}"
|
|
798
|
-
'undefined'
|
|
799
|
-
end
|
|
800
|
-
end
|
|
801
|
-
|
|
802
791
|
# @param decl [RBS::AST::Declarations::Class, RBS::AST::Declarations::Module]
|
|
803
|
-
# @param namespace [Pin::Namespace]
|
|
792
|
+
# @param namespace [Pin::Namespace, nil]
|
|
804
793
|
# @return [void]
|
|
805
794
|
def add_mixins decl, namespace
|
|
806
|
-
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::
|
|
795
|
+
# @param mixin [RBS::AST::Members::Include, RBS::AST::Members::Extend, RBS::AST::Members::Prepend]
|
|
807
796
|
decl.each_mixin do |mixin|
|
|
808
797
|
# @todo are we handling prepend correctly?
|
|
809
798
|
klass = mixin.is_a?(RBS::AST::Members::Include) ? Pin::Reference::Include : Pin::Reference::Extend
|