solargraph 0.58.3 → 0.59.0.dev.1
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 +4 -5
- data/.github/workflows/plugins.yml +41 -38
- data/.github/workflows/rspec.yml +45 -13
- data/.github/workflows/typecheck.yml +2 -2
- data/.gitignore +0 -1
- data/.rubocop_todo.yml +27 -49
- data/CHANGELOG.md +1 -10
- data/README.md +3 -3
- data/Rakefile +1 -0
- data/lib/solargraph/api_map/cache.rb +3 -3
- data/lib/solargraph/api_map/constants.rb +13 -3
- data/lib/solargraph/api_map/index.rb +22 -11
- data/lib/solargraph/api_map/source_to_yard.rb +13 -1
- data/lib/solargraph/api_map/store.rb +11 -8
- data/lib/solargraph/api_map.rb +105 -50
- data/lib/solargraph/bench.rb +45 -45
- data/lib/solargraph/complex_type/conformance.rb +176 -0
- data/lib/solargraph/complex_type/type_methods.rb +16 -2
- data/lib/solargraph/complex_type/unique_type.rb +170 -20
- data/lib/solargraph/complex_type.rb +119 -14
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +3 -1
- data/lib/solargraph/convention/data_definition.rb +4 -1
- data/lib/solargraph/convention/gemfile.rb +15 -15
- data/lib/solargraph/convention/gemspec.rb +23 -23
- data/lib/solargraph/convention/rakefile.rb +17 -17
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +1 -0
- data/lib/solargraph/convention/struct_definition.rb +5 -1
- data/lib/solargraph/convention.rb +78 -78
- data/lib/solargraph/converters/dd.rb +17 -17
- data/lib/solargraph/converters/dl.rb +15 -15
- data/lib/solargraph/converters/dt.rb +15 -15
- data/lib/solargraph/converters/misc.rb +1 -1
- data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop.rb +1 -0
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
- data/lib/solargraph/diagnostics/type_check.rb +1 -0
- data/lib/solargraph/diagnostics/update_errors.rb +41 -41
- data/lib/solargraph/doc_map.rb +134 -373
- data/lib/solargraph/equality.rb +1 -1
- data/lib/solargraph/gem_pins.rb +14 -15
- data/lib/solargraph/language_server/error_codes.rb +20 -20
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +1 -0
- data/lib/solargraph/language_server/host/message_worker.rb +2 -1
- data/lib/solargraph/language_server/host/sources.rb +1 -0
- data/lib/solargraph/language_server/host.rb +6 -1
- data/lib/solargraph/language_server/message/base.rb +97 -97
- data/lib/solargraph/language_server/message/client/register_capability.rb +15 -15
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +60 -60
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -7
- data/lib/solargraph/language_server/message/extended/document.rb +1 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
- data/lib/solargraph/language_server/message/extended/download_core.rb +19 -19
- data/lib/solargraph/language_server/message/extended/search.rb +20 -20
- data/lib/solargraph/language_server/message/initialize.rb +191 -191
- data/lib/solargraph/language_server/message/text_document/completion.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -16
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -11
- data/lib/solargraph/language_server/message/text_document/references.rb +16 -16
- data/lib/solargraph/language_server/message/text_document/rename.rb +19 -19
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -0
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +35 -35
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -40
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +26 -26
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -0
- data/lib/solargraph/language_server/message.rb +94 -94
- data/lib/solargraph/language_server/request.rb +27 -27
- data/lib/solargraph/language_server/transport/data_reader.rb +74 -74
- data/lib/solargraph/language_server/uri_helpers.rb +49 -49
- data/lib/solargraph/library.rb +59 -13
- data/lib/solargraph/location.rb +9 -4
- data/lib/solargraph/logging.rb +21 -1
- data/lib/solargraph/page.rb +92 -92
- data/lib/solargraph/parser/comment_ripper.rb +7 -0
- data/lib/solargraph/parser/flow_sensitive_typing.rb +330 -102
- data/lib/solargraph/parser/node_processor/base.rb +32 -2
- data/lib/solargraph/parser/node_processor.rb +7 -6
- data/lib/solargraph/parser/parser_gem/class_methods.rb +28 -10
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +31 -6
- data/lib/solargraph/parser/parser_gem/node_methods.rb +27 -7
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +2 -0
- 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 -11
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +7 -0
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +37 -37
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +3 -2
- 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/opasgn_node.rb +2 -2
- 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 +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +12 -7
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +5 -1
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/parser_gem.rb +12 -12
- data/lib/solargraph/parser/region.rb +9 -3
- data/lib/solargraph/parser/snippet.rb +1 -1
- data/lib/solargraph/parser.rb +23 -23
- data/lib/solargraph/pin/base.rb +53 -21
- data/lib/solargraph/pin/base_variable.rb +312 -20
- data/lib/solargraph/pin/block.rb +26 -4
- data/lib/solargraph/pin/breakable.rb +5 -1
- data/lib/solargraph/pin/callable.rb +50 -3
- data/lib/solargraph/pin/closure.rb +2 -6
- data/lib/solargraph/pin/common.rb +20 -5
- data/lib/solargraph/pin/compound_statement.rb +55 -0
- data/lib/solargraph/pin/constant.rb +45 -45
- data/lib/solargraph/pin/conversions.rb +2 -1
- data/lib/solargraph/pin/delegated_method.rb +15 -4
- data/lib/solargraph/pin/documenting.rb +1 -0
- data/lib/solargraph/pin/instance_variable.rb +5 -1
- data/lib/solargraph/pin/keyword.rb +0 -4
- data/lib/solargraph/pin/local_variable.rb +13 -57
- data/lib/solargraph/pin/method.rb +90 -42
- data/lib/solargraph/pin/method_alias.rb +8 -0
- data/lib/solargraph/pin/namespace.rb +7 -1
- data/lib/solargraph/pin/parameter.rb +76 -13
- data/lib/solargraph/pin/proxy_type.rb +2 -1
- data/lib/solargraph/pin/reference/override.rb +1 -1
- data/lib/solargraph/pin/reference/superclass.rb +2 -0
- data/lib/solargraph/pin/reference.rb +2 -0
- data/lib/solargraph/pin/search.rb +1 -0
- data/lib/solargraph/pin/signature.rb +8 -0
- data/lib/solargraph/pin/symbol.rb +1 -1
- data/lib/solargraph/pin/until.rb +1 -1
- data/lib/solargraph/pin/while.rb +1 -1
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/pin_cache.rb +477 -57
- data/lib/solargraph/position.rb +12 -26
- data/lib/solargraph/range.rb +6 -6
- data/lib/solargraph/rbs_map/conversions.rb +33 -10
- data/lib/solargraph/rbs_map/core_fills.rb +84 -84
- data/lib/solargraph/rbs_map/core_map.rb +24 -17
- data/lib/solargraph/rbs_map/stdlib_map.rb +34 -5
- data/lib/solargraph/rbs_map.rb +74 -20
- data/lib/solargraph/server_methods.rb +16 -16
- data/lib/solargraph/shell.rb +73 -39
- data/lib/solargraph/source/chain/array.rb +37 -37
- data/lib/solargraph/source/chain/call.rb +52 -17
- data/lib/solargraph/source/chain/class_variable.rb +13 -13
- data/lib/solargraph/source/chain/constant.rb +2 -0
- data/lib/solargraph/source/chain/global_variable.rb +13 -13
- data/lib/solargraph/source/chain/hash.rb +1 -0
- data/lib/solargraph/source/chain/if.rb +1 -0
- data/lib/solargraph/source/chain/instance_variable.rb +22 -1
- data/lib/solargraph/source/chain/link.rb +109 -109
- data/lib/solargraph/source/chain/literal.rb +5 -0
- data/lib/solargraph/source/chain/or.rb +9 -1
- data/lib/solargraph/source/chain/q_call.rb +11 -11
- data/lib/solargraph/source/chain/variable.rb +13 -13
- data/lib/solargraph/source/chain/z_super.rb +30 -30
- data/lib/solargraph/source/chain.rb +25 -22
- data/lib/solargraph/source/change.rb +9 -2
- data/lib/solargraph/source/cursor.rb +7 -1
- data/lib/solargraph/source/source_chainer.rb +13 -3
- data/lib/solargraph/source/updater.rb +4 -0
- data/lib/solargraph/source.rb +33 -7
- data/lib/solargraph/source_map/clip.rb +13 -2
- data/lib/solargraph/source_map/data.rb +4 -1
- data/lib/solargraph/source_map/mapper.rb +24 -1
- data/lib/solargraph/source_map.rb +14 -6
- data/lib/solargraph/type_checker/problem.rb +3 -1
- data/lib/solargraph/type_checker/rules.rb +75 -2
- data/lib/solargraph/type_checker.rb +111 -30
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +3 -1
- data/lib/solargraph/workspace/gemspecs.rb +367 -0
- data/lib/solargraph/workspace/require_paths.rb +1 -0
- data/lib/solargraph/workspace.rb +158 -16
- data/lib/solargraph/yard_map/helpers.rb +2 -1
- data/lib/solargraph/yard_map/mapper/to_method.rb +5 -1
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -0
- data/lib/solargraph/yard_map/mapper.rb +5 -0
- data/lib/solargraph/yard_tags.rb +20 -20
- data/lib/solargraph/yardoc.rb +33 -23
- data/lib/solargraph.rb +24 -3
- data/rbs/fills/rubygems/0/dependency.rbs +193 -0
- data/rbs/fills/tuple/tuple.rbs +28 -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 +2 -1
- metadata +12 -7
- 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
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class Source
|
|
5
|
-
class Chain
|
|
6
|
-
class Link
|
|
7
|
-
include Equality
|
|
8
|
-
|
|
9
|
-
# @return [String]
|
|
10
|
-
attr_reader :word
|
|
11
|
-
|
|
12
|
-
# @return [Pin::Base]
|
|
13
|
-
attr_accessor :last_context
|
|
14
|
-
|
|
15
|
-
# @param word [String]
|
|
16
|
-
def initialize word = '<undefined>'
|
|
17
|
-
@word = word
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @sg-ignore two problems - Declared return type
|
|
21
|
-
# ::Solargraph::Source::Chain::Array does not match inferred
|
|
22
|
-
# type ::Array(::Class<::Solargraph::Source::Chain::Link>,
|
|
23
|
-
# ::String) for
|
|
24
|
-
# Solargraph::Source::Chain::Link#equality_fields
|
|
25
|
-
# and
|
|
26
|
-
# Not enough arguments to Module#protected
|
|
27
|
-
protected def equality_fields
|
|
28
|
-
[self.class, word]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def undefined?
|
|
32
|
-
word == '<undefined>'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def constant?
|
|
36
|
-
is_a?(Chain::Constant)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @param api_map [ApiMap]
|
|
40
|
-
# @param name_pin [Pin::Base]
|
|
41
|
-
# @param locals [::Array<Pin::Base>]
|
|
42
|
-
# @return [::Array<Pin::Base>]
|
|
43
|
-
def resolve api_map, name_pin, locals
|
|
44
|
-
[]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# debugging description of contents; not for machine use
|
|
48
|
-
# @return [String]
|
|
49
|
-
def desc
|
|
50
|
-
word
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def to_s
|
|
54
|
-
desc
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def inspect
|
|
58
|
-
"#<#{self.class} - `#{self.desc}`>"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def head?
|
|
62
|
-
@head ||= false
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Make a copy of this link marked as the head of a chain
|
|
66
|
-
#
|
|
67
|
-
# @return [self]
|
|
68
|
-
def clone_head
|
|
69
|
-
clone.mark_head(true)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Make a copy of this link unmarked as the head of a chain
|
|
73
|
-
#
|
|
74
|
-
# @return [self]
|
|
75
|
-
def clone_body
|
|
76
|
-
clone.mark_head(false)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def nullable?
|
|
80
|
-
false
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# debugging description of contents; not for machine use
|
|
84
|
-
#
|
|
85
|
-
# @return [String]
|
|
86
|
-
def desc
|
|
87
|
-
word
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def inspect
|
|
91
|
-
"#<#{self.class} - `#{self.desc}`>"
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
include Logging
|
|
95
|
-
|
|
96
|
-
protected
|
|
97
|
-
|
|
98
|
-
# Mark whether this link is the head of a chain
|
|
99
|
-
#
|
|
100
|
-
# @param bool [Boolean]
|
|
101
|
-
# @return [self]
|
|
102
|
-
def mark_head bool
|
|
103
|
-
@head = bool
|
|
104
|
-
self
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class Source
|
|
5
|
+
class Chain
|
|
6
|
+
class Link
|
|
7
|
+
include Equality
|
|
8
|
+
|
|
9
|
+
# @return [String]
|
|
10
|
+
attr_reader :word
|
|
11
|
+
|
|
12
|
+
# @return [Pin::Base]
|
|
13
|
+
attr_accessor :last_context
|
|
14
|
+
|
|
15
|
+
# @param word [String]
|
|
16
|
+
def initialize word = '<undefined>'
|
|
17
|
+
@word = word
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @sg-ignore two problems - Declared return type
|
|
21
|
+
# ::Solargraph::Source::Chain::Array does not match inferred
|
|
22
|
+
# type ::Array(::Class<::Solargraph::Source::Chain::Link>,
|
|
23
|
+
# ::String) for
|
|
24
|
+
# Solargraph::Source::Chain::Link#equality_fields
|
|
25
|
+
# and
|
|
26
|
+
# Not enough arguments to Module#protected
|
|
27
|
+
protected def equality_fields
|
|
28
|
+
[self.class, word]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def undefined?
|
|
32
|
+
word == '<undefined>'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def constant?
|
|
36
|
+
is_a?(Chain::Constant)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @param api_map [ApiMap]
|
|
40
|
+
# @param name_pin [Pin::Base]
|
|
41
|
+
# @param locals [::Array<Pin::Base>]
|
|
42
|
+
# @return [::Array<Pin::Base>]
|
|
43
|
+
def resolve api_map, name_pin, locals
|
|
44
|
+
[]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# debugging description of contents; not for machine use
|
|
48
|
+
# @return [String]
|
|
49
|
+
def desc
|
|
50
|
+
word
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_s
|
|
54
|
+
desc
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def inspect
|
|
58
|
+
"#<#{self.class} - `#{self.desc}`>"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def head?
|
|
62
|
+
@head ||= false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Make a copy of this link marked as the head of a chain
|
|
66
|
+
#
|
|
67
|
+
# @return [self]
|
|
68
|
+
def clone_head
|
|
69
|
+
clone.mark_head(true)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Make a copy of this link unmarked as the head of a chain
|
|
73
|
+
#
|
|
74
|
+
# @return [self]
|
|
75
|
+
def clone_body
|
|
76
|
+
clone.mark_head(false)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def nullable?
|
|
80
|
+
false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# debugging description of contents; not for machine use
|
|
84
|
+
#
|
|
85
|
+
# @return [String]
|
|
86
|
+
def desc
|
|
87
|
+
word
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def inspect
|
|
91
|
+
"#<#{self.class} - `#{self.desc}`>"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
include Logging
|
|
95
|
+
|
|
96
|
+
protected
|
|
97
|
+
|
|
98
|
+
# Mark whether this link is the head of a chain
|
|
99
|
+
#
|
|
100
|
+
# @param bool [Boolean]
|
|
101
|
+
# @return [self]
|
|
102
|
+
def mark_head bool
|
|
103
|
+
@head = bool
|
|
104
|
+
self
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -16,11 +16,15 @@ module Solargraph
|
|
|
16
16
|
# @param node [Parser::AST::Node, Object]
|
|
17
17
|
def initialize type, node
|
|
18
18
|
if node.is_a?(::Parser::AST::Node)
|
|
19
|
+
# @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
|
|
19
20
|
if node.type == :true
|
|
20
21
|
@value = true
|
|
22
|
+
# @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
|
|
21
23
|
elsif node.type == :false
|
|
22
24
|
@value = false
|
|
25
|
+
# @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
|
|
23
26
|
elsif [:int, :sym].include?(node.type)
|
|
27
|
+
# @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
|
|
24
28
|
@value = node.children.first
|
|
25
29
|
end
|
|
26
30
|
end
|
|
@@ -31,6 +35,7 @@ module Solargraph
|
|
|
31
35
|
|
|
32
36
|
# @sg-ignore Fix "Not enough arguments to Module#protected"
|
|
33
37
|
protected def equality_fields
|
|
38
|
+
# @sg-ignore literal arrays in this module turn into ::Solargraph::Source::Chain::Array
|
|
34
39
|
super + [@value, @type, @literal_type, @complex_type]
|
|
35
40
|
end
|
|
36
41
|
|
|
@@ -8,6 +8,8 @@ module Solargraph
|
|
|
8
8
|
'<or>'
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
attr_reader :links
|
|
12
|
+
|
|
11
13
|
# @param links [::Array<Chain>]
|
|
12
14
|
def initialize links
|
|
13
15
|
@links = links
|
|
@@ -15,7 +17,13 @@ module Solargraph
|
|
|
15
17
|
|
|
16
18
|
def resolve api_map, name_pin, locals
|
|
17
19
|
types = @links.map { |link| link.infer(api_map, name_pin, locals) }
|
|
18
|
-
|
|
20
|
+
combined_type = Solargraph::ComplexType.new(types)
|
|
21
|
+
unless types.all?(&:nullable?)
|
|
22
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
23
|
+
combined_type = combined_type.without_nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[Solargraph::Pin::ProxyType.anonymous(combined_type, source: :chain)]
|
|
19
27
|
end
|
|
20
28
|
end
|
|
21
29
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module Solargraph
|
|
2
|
-
class Source
|
|
3
|
-
class Chain
|
|
4
|
-
class QCall < Call
|
|
5
|
-
def nullable?
|
|
6
|
-
true
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
1
|
+
module Solargraph
|
|
2
|
+
class Source
|
|
3
|
+
class Chain
|
|
4
|
+
class QCall < Call
|
|
5
|
+
def nullable?
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class Source
|
|
5
|
-
class Chain
|
|
6
|
-
class Variable < Link
|
|
7
|
-
def resolve api_map, name_pin, locals
|
|
8
|
-
api_map.get_instance_variable_pins(name_pin.context.namespace, name_pin.context.scope).select{|p| p.name == word}
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class Source
|
|
5
|
+
class Chain
|
|
6
|
+
class Variable < Link
|
|
7
|
+
def resolve api_map, name_pin, locals
|
|
8
|
+
api_map.get_instance_variable_pins(name_pin.context.namespace, name_pin.context.scope).select{|p| p.name == word}
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class Source
|
|
5
|
-
class Chain
|
|
6
|
-
class ZSuper < Call
|
|
7
|
-
# @return [String]
|
|
8
|
-
attr_reader :word
|
|
9
|
-
|
|
10
|
-
# @return [::Array<Chain>]
|
|
11
|
-
attr_reader :arguments
|
|
12
|
-
|
|
13
|
-
# @param word [String]
|
|
14
|
-
# @param arguments [::Array<Chain>]
|
|
15
|
-
# @param with_block [Boolean] True if the chain is inside a block
|
|
16
|
-
# @param head [Boolean] True if the call is the start of its chain
|
|
17
|
-
def initialize word, with_block = false
|
|
18
|
-
super(word, nil, [], with_block)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# @param api_map [ApiMap]
|
|
22
|
-
# @param name_pin [Pin::Base]
|
|
23
|
-
# @param locals [::Array<Pin::Base>]
|
|
24
|
-
def resolve api_map, name_pin, locals
|
|
25
|
-
return super_pins(api_map, name_pin)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class Source
|
|
5
|
+
class Chain
|
|
6
|
+
class ZSuper < Call
|
|
7
|
+
# @return [String]
|
|
8
|
+
attr_reader :word
|
|
9
|
+
|
|
10
|
+
# @return [::Array<Chain>]
|
|
11
|
+
attr_reader :arguments
|
|
12
|
+
|
|
13
|
+
# @param word [String]
|
|
14
|
+
# @param arguments [::Array<Chain>]
|
|
15
|
+
# @param with_block [Boolean] True if the chain is inside a block
|
|
16
|
+
# @param head [Boolean] True if the call is the start of its chain
|
|
17
|
+
def initialize word, with_block = false
|
|
18
|
+
super(word, nil, [], with_block)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param api_map [ApiMap]
|
|
22
|
+
# @param name_pin [Pin::Base]
|
|
23
|
+
# @param locals [::Array<Pin::Base>]
|
|
24
|
+
def resolve api_map, name_pin, locals
|
|
25
|
+
return super_pins(api_map, name_pin)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -71,6 +71,7 @@ module Solargraph
|
|
|
71
71
|
|
|
72
72
|
# @return [Chain]
|
|
73
73
|
def base
|
|
74
|
+
# @sg-ignore Need to add nil check here
|
|
74
75
|
@base ||= Chain.new(links[0..-2])
|
|
75
76
|
end
|
|
76
77
|
|
|
@@ -78,25 +79,25 @@ module Solargraph
|
|
|
78
79
|
#
|
|
79
80
|
# @param api_map [ApiMap]
|
|
80
81
|
#
|
|
81
|
-
# @param name_pin [Pin::Base] A pin
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
82
|
+
# @param name_pin [Pin::Base] A pin representing the closure in
|
|
83
|
+
# which expression is evaluated (e.g., a Method pin, or a
|
|
84
|
+
# Module or Class pin if not run within a method - both in
|
|
85
|
+
# terms of the closure around the chain, as well as the self
|
|
86
|
+
# type used for any method calls in head position.
|
|
86
87
|
#
|
|
87
88
|
# Requirements for name_pin:
|
|
88
89
|
#
|
|
89
90
|
# * name_pin.context: This should be a type representing the
|
|
90
|
-
# namespace where we can look up non-local variables
|
|
91
|
-
#
|
|
92
|
-
#
|
|
91
|
+
# namespace where we can look up non-local variables. If
|
|
92
|
+
# it is a Class<X>, we will look up :class scoped
|
|
93
|
+
# instance variables.
|
|
93
94
|
#
|
|
94
95
|
# * name_pin.binder: Used for method call lookups only
|
|
95
96
|
# (Chain::Call links). For method calls as the first
|
|
96
97
|
# element in the chain, 'name_pin.binder' should be the
|
|
97
98
|
# same as name_pin.context above. For method calls later
|
|
98
|
-
# in the chain (e.g., 'b' in a.b.c
|
|
99
|
-
# 'a'.
|
|
99
|
+
# in the chain, it changes. (e.g., for 'b' in a.b.c, it
|
|
100
|
+
# should represent the type of 'a').
|
|
100
101
|
#
|
|
101
102
|
# @param locals [::Array<Pin::LocalVariable>] Any local
|
|
102
103
|
# variables / method parameters etc visible by the statement
|
|
@@ -113,6 +114,7 @@ module Solargraph
|
|
|
113
114
|
#
|
|
114
115
|
# @todo ProxyType uses 'type' for the binder, but '
|
|
115
116
|
working_pin = name_pin
|
|
117
|
+
# @sg-ignore Need to add nil check here
|
|
116
118
|
links[0..-2].each do |link|
|
|
117
119
|
pins = link.resolve(api_map, working_pin, locals)
|
|
118
120
|
type = infer_from_definitions(pins, working_pin, api_map, locals)
|
|
@@ -138,7 +140,8 @@ module Solargraph
|
|
|
138
140
|
# @return [ComplexType]
|
|
139
141
|
# @sg-ignore
|
|
140
142
|
def infer api_map, name_pin, locals
|
|
141
|
-
|
|
143
|
+
# includes binder as it is mutable in Pin::Block
|
|
144
|
+
cache_key = [node, node&.location, links, name_pin&.return_type, name_pin&.binder, locals]
|
|
142
145
|
if @@inference_invalidation_key == api_map.hash
|
|
143
146
|
cached = @@inference_cache[cache_key]
|
|
144
147
|
return cached if cached
|
|
@@ -154,7 +157,7 @@ module Solargraph
|
|
|
154
157
|
# @param api_map [ApiMap]
|
|
155
158
|
# @param name_pin [Pin::Base]
|
|
156
159
|
# @param locals [::Array<Pin::LocalVariable>]
|
|
157
|
-
# @return [ComplexType]
|
|
160
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
158
161
|
def infer_uncached api_map, name_pin, locals
|
|
159
162
|
pins = define(api_map, name_pin, locals)
|
|
160
163
|
if pins.empty?
|
|
@@ -209,12 +212,12 @@ module Solargraph
|
|
|
209
212
|
private
|
|
210
213
|
|
|
211
214
|
# @param pins [::Array<Pin::Base>]
|
|
212
|
-
# @param
|
|
215
|
+
# @param name_pin [Pin::Base]
|
|
213
216
|
# @param api_map [ApiMap]
|
|
214
217
|
# @param locals [::Enumerable<Pin::LocalVariable>]
|
|
215
|
-
# @return [ComplexType]
|
|
216
|
-
def infer_from_definitions pins,
|
|
217
|
-
# @type [::Array<ComplexType>]
|
|
218
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
219
|
+
def infer_from_definitions pins, name_pin, api_map, locals
|
|
220
|
+
# @type [::Array<ComplexType, ComplexType::UniqueType>]
|
|
218
221
|
types = []
|
|
219
222
|
unresolved_pins = []
|
|
220
223
|
# @todo this param tag shouldn't be needed to probe the type
|
|
@@ -232,7 +235,8 @@ module Solargraph
|
|
|
232
235
|
# @todo even at strong, no typechecking complaint
|
|
233
236
|
# happens when a [Pin::Base,nil] is passed into a method
|
|
234
237
|
# that accepts only [Pin::Namespace] as an argument
|
|
235
|
-
|
|
238
|
+
# @sg-ignore Need to add nil check here
|
|
239
|
+
type = type.resolve_generics(pin.closure, name_pin.binder)
|
|
236
240
|
end
|
|
237
241
|
types << type
|
|
238
242
|
else
|
|
@@ -271,16 +275,15 @@ module Solargraph
|
|
|
271
275
|
else
|
|
272
276
|
ComplexType.new(types)
|
|
273
277
|
end
|
|
274
|
-
if
|
|
278
|
+
if name_pin.nil? || name_pin.context.undefined?
|
|
275
279
|
# up to downstream to resolve self type
|
|
276
280
|
return type
|
|
277
281
|
end
|
|
278
|
-
|
|
279
|
-
type.self_to_type(context.return_type)
|
|
282
|
+
type.self_to_type(name_pin.context)
|
|
280
283
|
end
|
|
281
284
|
|
|
282
|
-
# @param type [ComplexType]
|
|
283
|
-
# @return [ComplexType]
|
|
285
|
+
# @param type [ComplexType, ComplexType::UniqueType]
|
|
286
|
+
# @return [ComplexType, ComplexType::UniqueType]
|
|
284
287
|
def maybe_nil type
|
|
285
288
|
return type if type.undefined? || type.void? || type.nullable?
|
|
286
289
|
return type unless nullable?
|
|
@@ -7,13 +7,13 @@ module Solargraph
|
|
|
7
7
|
class Change
|
|
8
8
|
include EncodingFixes
|
|
9
9
|
|
|
10
|
-
# @return [Range]
|
|
10
|
+
# @return [Range, nil]
|
|
11
11
|
attr_reader :range
|
|
12
12
|
|
|
13
13
|
# @return [String]
|
|
14
14
|
attr_reader :new_text
|
|
15
15
|
|
|
16
|
-
# @param range [Range] The starting and ending positions of the change.
|
|
16
|
+
# @param range [Range, nil] The starting and ending positions of the change.
|
|
17
17
|
# If nil, the original text will be overwritten.
|
|
18
18
|
# @param new_text [String] The text to be changed.
|
|
19
19
|
def initialize range, new_text
|
|
@@ -31,9 +31,11 @@ module Solargraph
|
|
|
31
31
|
if nullable and !range.nil? and new_text.match(/[.\[{(@$:]$/)
|
|
32
32
|
[':', '@'].each do |dupable|
|
|
33
33
|
next unless new_text == dupable
|
|
34
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
34
35
|
offset = Position.to_offset(text, range.start)
|
|
35
36
|
if text[offset - 1] == dupable
|
|
36
37
|
p = Position.from_offset(text, offset - 1)
|
|
38
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
37
39
|
r = Change.new(Range.new(p, range.start), ' ')
|
|
38
40
|
text = r.write(text)
|
|
39
41
|
end
|
|
@@ -58,9 +60,12 @@ module Solargraph
|
|
|
58
60
|
fixed
|
|
59
61
|
else
|
|
60
62
|
result = commit text, fixed
|
|
63
|
+
# @sg-ignore flow sensitive typing needs to handle attrs
|
|
61
64
|
off = Position.to_offset(text, range.start)
|
|
65
|
+
# @sg-ignore Need to add nil check here
|
|
62
66
|
match = result[0, off].match(/[.:]+\z/)
|
|
63
67
|
if match
|
|
68
|
+
# @sg-ignore flow sensitive typing should be able to handle redefinition
|
|
64
69
|
result = result[0, off].sub(/#{match[0]}\z/, ' ' * match[0].length) + result[off..-1]
|
|
65
70
|
end
|
|
66
71
|
result
|
|
@@ -73,7 +78,9 @@ module Solargraph
|
|
|
73
78
|
# @param insert [String]
|
|
74
79
|
# @return [String]
|
|
75
80
|
def commit text, insert
|
|
81
|
+
# @sg-ignore Need to add nil check here
|
|
76
82
|
start_offset = Position.to_offset(text, range.start)
|
|
83
|
+
# @sg-ignore Need to add nil check here
|
|
77
84
|
end_offset = Position.to_offset(text, range.ending)
|
|
78
85
|
(start_offset == 0 ? '' : text[0..start_offset-1].to_s) + normalize(insert) + text[end_offset..-1].to_s
|
|
79
86
|
end
|
|
@@ -19,7 +19,7 @@ module Solargraph
|
|
|
19
19
|
@position = Position.normalize(position)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# @return [String]
|
|
22
|
+
# @return [String, nil]
|
|
23
23
|
def filename
|
|
24
24
|
source.filename
|
|
25
25
|
end
|
|
@@ -35,12 +35,14 @@ module Solargraph
|
|
|
35
35
|
# The part of the word before the current position. Given the text
|
|
36
36
|
# `foo.bar`, the start_of_word at position(0, 6) is `ba`.
|
|
37
37
|
#
|
|
38
|
+
# @sg-ignore Need to add nil check here
|
|
38
39
|
# @return [String]
|
|
39
40
|
def start_of_word
|
|
40
41
|
@start_of_word ||= begin
|
|
41
42
|
match = source.code[0..offset-1].to_s.match(start_word_pattern)
|
|
42
43
|
result = (match ? match[0] : '')
|
|
43
44
|
# Including the preceding colon if the word appears to be a symbol
|
|
45
|
+
# @sg-ignore Need to add nil check here
|
|
44
46
|
result = ":#{result}" if source.code[0..offset-result.length-1].end_with?(':') and !source.code[0..offset-result.length-1].end_with?('::')
|
|
45
47
|
result
|
|
46
48
|
end
|
|
@@ -50,6 +52,7 @@ module Solargraph
|
|
|
50
52
|
# `foo.bar`, the end_of_word at position (0,6) is `r`.
|
|
51
53
|
#
|
|
52
54
|
# @return [String]
|
|
55
|
+
# @sg-ignore Need to add nil check here
|
|
53
56
|
def end_of_word
|
|
54
57
|
@end_of_word ||= begin
|
|
55
58
|
match = source.code[offset..-1].to_s.match(end_word_pattern)
|
|
@@ -110,6 +113,7 @@ module Solargraph
|
|
|
110
113
|
def recipient
|
|
111
114
|
@recipient ||= begin
|
|
112
115
|
node = recipient_node
|
|
116
|
+
# @sg-ignore Need to add nil check here
|
|
113
117
|
node ? Cursor.new(source, Range.from_node(node).ending) : nil
|
|
114
118
|
end
|
|
115
119
|
end
|
|
@@ -124,8 +128,10 @@ module Solargraph
|
|
|
124
128
|
def node_position
|
|
125
129
|
@node_position ||= begin
|
|
126
130
|
if start_of_word.empty?
|
|
131
|
+
# @sg-ignore Need to add nil check here
|
|
127
132
|
match = source.code[0, offset].match(/\s*(\.|:+)\s*$/)
|
|
128
133
|
if match
|
|
134
|
+
# @sg-ignore Need to add nil check here
|
|
129
135
|
Position.from_offset(source.code, offset - match[0].length)
|
|
130
136
|
else
|
|
131
137
|
position
|
|
@@ -33,25 +33,29 @@ module Solargraph
|
|
|
33
33
|
def chain
|
|
34
34
|
# Special handling for files that end with an integer and a period
|
|
35
35
|
return Chain.new([Chain::Literal.new('Integer', Integer(phrase[0..-2])), Chain::UNDEFINED_CALL]) if phrase =~ /^[0-9]+\.$/
|
|
36
|
+
# @sg-ignore Need to add nil check here
|
|
36
37
|
return Chain.new([Chain::Literal.new('Symbol', phrase[1..].to_sym)]) if phrase.start_with?(':') && !phrase.start_with?('::')
|
|
37
38
|
return SourceChainer.chain(source, Position.new(position.line, position.character + 1)) if end_of_phrase.strip == '::' && source.code[Position.to_offset(source.code, position)].to_s.match?(/[a-z]/i)
|
|
38
39
|
begin
|
|
39
40
|
return Chain.new([]) if phrase.end_with?('..')
|
|
41
|
+
# @type [::Parser::AST::Node, nil]
|
|
40
42
|
node = nil
|
|
43
|
+
# @type [::Parser::AST::Node, nil]
|
|
41
44
|
parent = nil
|
|
42
45
|
if !source.repaired? && source.parsed? && source.synchronized?
|
|
43
46
|
tree = source.tree_at(position.line, position.column)
|
|
44
47
|
node, parent = tree[0..2]
|
|
45
48
|
elsif source.parsed? && source.repaired? && end_of_phrase == '.'
|
|
46
49
|
node, parent = source.tree_at(fixed_position.line, fixed_position.column)[0..2]
|
|
47
|
-
|
|
50
|
+
# provide filename and line so that we can look up local variables there later
|
|
51
|
+
node = Parser.parse(fixed_phrase, source.filename, fixed_position.line) if node.nil?
|
|
48
52
|
elsif source.repaired?
|
|
49
|
-
node = Parser.parse(fixed_phrase)
|
|
53
|
+
node = Parser.parse(fixed_phrase, source.filename, fixed_position.line)
|
|
50
54
|
else
|
|
51
55
|
node, parent = source.tree_at(fixed_position.line, fixed_position.column)[0..2] unless source.error_ranges.any?{|r| r.nil? || r.include?(fixed_position)}
|
|
52
56
|
# Exception for positions that chain literal nodes in unsynchronized sources
|
|
53
57
|
node = nil unless source.synchronized? || !Parser.infer_literal_node_type(node).nil?
|
|
54
|
-
node = Parser.parse(fixed_phrase) if node.nil?
|
|
58
|
+
node = Parser.parse(fixed_phrase, source.filename, fixed_position.line) if node.nil?
|
|
55
59
|
end
|
|
56
60
|
rescue Parser::SyntaxError
|
|
57
61
|
return Chain.new([Chain::UNDEFINED_CALL])
|
|
@@ -79,11 +83,13 @@ module Solargraph
|
|
|
79
83
|
# @return [Solargraph::Source]
|
|
80
84
|
attr_reader :source
|
|
81
85
|
|
|
86
|
+
# @sg-ignore Need to add nil check here
|
|
82
87
|
# @return [String]
|
|
83
88
|
def phrase
|
|
84
89
|
@phrase ||= source.code[signature_data..offset-1]
|
|
85
90
|
end
|
|
86
91
|
|
|
92
|
+
# @sg-ignore Need to add nil check here
|
|
87
93
|
# @return [String]
|
|
88
94
|
def fixed_phrase
|
|
89
95
|
@fixed_phrase ||= phrase[0..-(end_of_phrase.length+1)]
|
|
@@ -95,6 +101,7 @@ module Solargraph
|
|
|
95
101
|
end
|
|
96
102
|
|
|
97
103
|
# @return [String]
|
|
104
|
+
# @sg-ignore Need to add nil check here
|
|
98
105
|
def end_of_phrase
|
|
99
106
|
@end_of_phrase ||= begin
|
|
100
107
|
match = phrase.match(/\s*(\.{1}|::)\s*$/)
|
|
@@ -149,9 +156,12 @@ module Solargraph
|
|
|
149
156
|
in_whitespace = true
|
|
150
157
|
else
|
|
151
158
|
if brackets.zero? and parens.zero? and squares.zero? and in_whitespace
|
|
159
|
+
# @sg-ignore Need to add nil check here
|
|
152
160
|
unless char == '.' or @source.code[index+1..-1].strip.start_with?('.')
|
|
153
161
|
old = @source.code[index+1..-1]
|
|
162
|
+
# @sg-ignore Need to add nil check here
|
|
154
163
|
nxt = @source.code[index+1..-1].lstrip
|
|
164
|
+
# @sg-ignore Need to add nil check here
|
|
155
165
|
index += (@source.code[index+1..-1].length - @source.code[index+1..-1].lstrip.length)
|
|
156
166
|
break
|
|
157
167
|
end
|