solargraph 0.56.2 → 0.57.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 +125 -0
- data/.github/workflows/plugins.yml +148 -6
- data/.github/workflows/rspec.yml +39 -4
- data/.github/workflows/typecheck.yml +5 -2
- data/.gitignore +5 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +2627 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +42 -0
- data/README.md +8 -4
- data/Rakefile +125 -13
- data/lib/solargraph/api_map/cache.rb +3 -2
- data/lib/solargraph/api_map/constants.rb +218 -0
- data/lib/solargraph/api_map/index.rb +20 -26
- data/lib/solargraph/api_map/source_to_yard.rb +10 -4
- data/lib/solargraph/api_map/store.rb +126 -18
- data/lib/solargraph/api_map.rb +212 -234
- data/lib/solargraph/bench.rb +1 -0
- data/lib/solargraph/complex_type/type_methods.rb +1 -0
- data/lib/solargraph/complex_type/unique_type.rb +7 -7
- data/lib/solargraph/complex_type.rb +5 -1
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +17 -0
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +3 -1
- data/lib/solargraph/convention/data_definition.rb +2 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -1
- data/lib/solargraph/convention/struct_definition.rb +36 -13
- data/lib/solargraph/convention.rb +31 -2
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
- data/lib/solargraph/doc_map.rb +40 -12
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/gem_pins.rb +17 -11
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +3 -0
- data/lib/solargraph/language_server/host.rb +2 -1
- data/lib/solargraph/language_server/message/base.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +1 -0
- data/lib/solargraph/library.rb +8 -15
- data/lib/solargraph/location.rb +2 -0
- data/lib/solargraph/logging.rb +11 -2
- data/lib/solargraph/page.rb +4 -0
- data/lib/solargraph/parser/comment_ripper.rb +8 -1
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -4
- data/lib/solargraph/parser/node_methods.rb +2 -2
- data/lib/solargraph/parser/node_processor/base.rb +1 -1
- data/lib/solargraph/parser/node_processor.rb +6 -2
- data/lib/solargraph/parser/parser_gem/class_methods.rb +1 -1
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_methods.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +2 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +35 -14
- data/lib/solargraph/parser/region.rb +3 -0
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/pin/base.rb +50 -8
- data/lib/solargraph/pin/base_variable.rb +1 -2
- data/lib/solargraph/pin/callable.rb +9 -0
- data/lib/solargraph/pin/closure.rb +2 -0
- data/lib/solargraph/pin/common.rb +6 -2
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/delegated_method.rb +1 -0
- data/lib/solargraph/pin/local_variable.rb +4 -1
- data/lib/solargraph/pin/method.rb +8 -5
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/parameter.rb +18 -8
- data/lib/solargraph/pin/proxy_type.rb +1 -0
- data/lib/solargraph/pin/reference/override.rb +15 -1
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +26 -0
- data/lib/solargraph/pin/search.rb +3 -1
- data/lib/solargraph/pin/signature.rb +2 -0
- data/lib/solargraph/pin/symbol.rb +5 -0
- data/lib/solargraph/pin_cache.rb +64 -4
- data/lib/solargraph/position.rb +2 -0
- data/lib/solargraph/range.rb +1 -0
- data/lib/solargraph/rbs_map/conversions.rb +7 -5
- data/lib/solargraph/rbs_map/core_map.rb +3 -0
- data/lib/solargraph/rbs_map.rb +15 -2
- data/lib/solargraph/shell.rb +3 -0
- data/lib/solargraph/source/chain/link.rb +10 -1
- data/lib/solargraph/source/chain.rb +9 -2
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +2 -3
- data/lib/solargraph/source/source_chainer.rb +1 -1
- data/lib/solargraph/source.rb +5 -2
- data/lib/solargraph/source_map/clip.rb +1 -1
- data/lib/solargraph/source_map/data.rb +4 -0
- data/lib/solargraph/source_map/mapper.rb +4 -2
- data/lib/solargraph/source_map.rb +21 -14
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +8 -0
- data/lib/solargraph/type_checker.rb +173 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +0 -2
- data/lib/solargraph/workspace/require_paths.rb +98 -0
- data/lib/solargraph/workspace.rb +16 -48
- data/lib/solargraph/yard_map/mapper/to_method.rb +2 -2
- data/lib/solargraph/yardoc.rb +16 -3
- data/lib/solargraph.rb +2 -0
- data/rbs/fills/tuple.rbs +2 -3
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -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 +14 -4
- metadata +123 -9
- data/lib/.rubocop.yml +0 -22
@@ -5,6 +5,8 @@ module Solargraph
|
|
5
5
|
class Constant < BaseVariable
|
6
6
|
attr_reader :visibility
|
7
7
|
|
8
|
+
# @param visibility [::Symbol] The visibility of the constant (:public, :protected, or :private)
|
9
|
+
# @param splat [Hash] Additional options supported by superclasses
|
8
10
|
def initialize visibility: :public, **splat
|
9
11
|
super(**splat)
|
10
12
|
@visibility = visibility
|
@@ -51,6 +51,7 @@ module Solargraph
|
|
51
51
|
%i[typify realize infer probe].each do |method|
|
52
52
|
# @param api_map [ApiMap]
|
53
53
|
define_method(method) do |api_map|
|
54
|
+
# @sg-ignore Unresolved call to resolve_method
|
54
55
|
resolve_method(api_map)
|
55
56
|
# @sg-ignore Need to set context correctly in define_method blocks
|
56
57
|
@resolved_method ? @resolved_method.send(method, api_map) : super(api_map)
|
@@ -26,7 +26,10 @@ module Solargraph
|
|
26
26
|
assignment: assert_same(other, :assignment),
|
27
27
|
presence_certain: assert_same(other, :presence_certain?),
|
28
28
|
}.merge(attrs)
|
29
|
-
|
29
|
+
# @sg-ignore Wrong argument type for
|
30
|
+
# Solargraph::Pin::Base#assert_same: other expected
|
31
|
+
# Solargraph::Pin::Base, received self
|
32
|
+
new_attrs[:presence] = assert_same(other, :presence) unless attrs.key?(:presence)
|
30
33
|
|
31
34
|
super(other, new_attrs)
|
32
35
|
end
|
@@ -22,7 +22,8 @@ module Solargraph
|
|
22
22
|
# @param attribute [Boolean]
|
23
23
|
# @param signatures [::Array<Signature>, nil]
|
24
24
|
# @param anon_splat [Boolean]
|
25
|
-
def initialize visibility: :public, explicit: true, block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false,
|
25
|
+
def initialize visibility: :public, explicit: true, block: :undefined, node: nil, attribute: false, signatures: nil, anon_splat: false,
|
26
|
+
**splat
|
26
27
|
super(**splat)
|
27
28
|
@visibility = visibility
|
28
29
|
@explicit = explicit
|
@@ -50,7 +51,7 @@ module Solargraph
|
|
50
51
|
end
|
51
52
|
|
52
53
|
# @param other [Pin::Method]
|
53
|
-
# @return [Symbol]
|
54
|
+
# @return [::Symbol]
|
54
55
|
def combine_visibility(other)
|
55
56
|
if dodgy_visibility_source? && !other.dodgy_visibility_source?
|
56
57
|
other.visibility
|
@@ -76,6 +77,9 @@ module Solargraph
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def combine_with(other, attrs = {})
|
80
|
+
priority_choice = choose_priority(other)
|
81
|
+
return priority_choice unless priority_choice.nil?
|
82
|
+
|
79
83
|
sigs = combine_signatures(other)
|
80
84
|
parameters = if sigs.length > 0
|
81
85
|
[].freeze
|
@@ -301,7 +305,6 @@ module Solargraph
|
|
301
305
|
super
|
302
306
|
end
|
303
307
|
|
304
|
-
# @sg-ignore
|
305
308
|
def documentation
|
306
309
|
if @documentation.nil?
|
307
310
|
method_docs ||= super || ''
|
@@ -425,7 +428,7 @@ module Solargraph
|
|
425
428
|
@resolved_ref_tag = true
|
426
429
|
return self unless docstring.ref_tags.any?
|
427
430
|
docstring.ref_tags.each do |tag|
|
428
|
-
ref = if tag.owner.to_s.start_with?(/[
|
431
|
+
ref = if tag.owner.to_s.start_with?(/[#.]/)
|
429
432
|
api_map.get_methods(namespace)
|
430
433
|
.select { |pin| pin.path.end_with?(tag.owner.to_s) }
|
431
434
|
.first
|
@@ -549,7 +552,7 @@ module Solargraph
|
|
549
552
|
# @param api_map [ApiMap]
|
550
553
|
# @return [ComplexType, nil]
|
551
554
|
def resolve_reference ref, api_map
|
552
|
-
parts = ref.split(/[
|
555
|
+
parts = ref.split(/[.#]/)
|
553
556
|
if parts.first.empty? || parts.one?
|
554
557
|
path = "#{namespace}#{ref}"
|
555
558
|
else
|
@@ -13,6 +13,9 @@ module Solargraph
|
|
13
13
|
# @return [String]
|
14
14
|
attr_reader :original
|
15
15
|
|
16
|
+
# @param scope [::Symbol]
|
17
|
+
# @param original [String, nil] The name of the original method
|
18
|
+
# @param splat [Hash] Additional options supported by superclasses
|
16
19
|
def initialize scope: :instance, original: nil, **splat
|
17
20
|
super(**splat)
|
18
21
|
@scope = scope
|
@@ -105,15 +105,13 @@ module Solargraph
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
# @return [String]
|
109
|
-
|
108
|
+
# @return [String] the full name of the parameter, including any
|
109
|
+
# declarative symbols such as `*` or `:` indicating type of
|
110
|
+
# parameter. This is used in method signatures.
|
111
|
+
def full_name
|
110
112
|
case decl
|
111
|
-
when :
|
112
|
-
"#{name} = #{asgn_code || '?'}"
|
113
|
-
when :kwarg
|
113
|
+
when :kwarg, :kwoptarg
|
114
114
|
"#{name}:"
|
115
|
-
when :kwoptarg
|
116
|
-
"#{name}: #{asgn_code || '?'}"
|
117
115
|
when :restarg
|
118
116
|
"*#{name}"
|
119
117
|
when :kwrestarg
|
@@ -125,6 +123,18 @@ module Solargraph
|
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
126
|
+
# @return [String]
|
127
|
+
def full
|
128
|
+
full_name + case decl
|
129
|
+
when :optarg
|
130
|
+
" = #{asgn_code || '?'}"
|
131
|
+
when :kwoptarg
|
132
|
+
" #{asgn_code || '?'}"
|
133
|
+
else
|
134
|
+
''
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
128
138
|
# @return [ComplexType]
|
129
139
|
def return_type
|
130
140
|
if @return_type.nil?
|
@@ -237,7 +247,7 @@ module Solargraph
|
|
237
247
|
def resolve_reference ref, api_map, skip
|
238
248
|
return nil if skip.include?(ref)
|
239
249
|
skip.push ref
|
240
|
-
parts = ref.split(/[
|
250
|
+
parts = ref.split(/[.#]/)
|
241
251
|
if parts.first.empty?
|
242
252
|
path = "#{namespace}#{ref}"
|
243
253
|
else
|
@@ -4,6 +4,7 @@ module Solargraph
|
|
4
4
|
module Pin
|
5
5
|
class ProxyType < Base
|
6
6
|
# @param return_type [ComplexType]
|
7
|
+
# @param binder [ComplexType, ComplexType::UniqueType, nil]
|
7
8
|
def initialize return_type: ComplexType::UNDEFINED, binder: nil, **splat
|
8
9
|
super(**splat)
|
9
10
|
@return_type = return_type
|
@@ -14,16 +14,30 @@ module Solargraph
|
|
14
14
|
nil
|
15
15
|
end
|
16
16
|
|
17
|
+
# @param location [Location, nil]
|
18
|
+
# @param name [String]
|
19
|
+
# @param tags [::Array<YARD::Tags::Tag>]
|
20
|
+
# @param delete [::Array<Symbol>]
|
21
|
+
# @param splat [Hash]
|
17
22
|
def initialize location, name, tags, delete = [], **splat
|
18
23
|
super(location: location, name: name, **splat)
|
19
24
|
@tags = tags
|
20
25
|
@delete = delete
|
21
26
|
end
|
22
27
|
|
28
|
+
# @param name [String]
|
29
|
+
# @param tags [::Array<String>]
|
30
|
+
# @param delete [::Array<Symbol>]
|
31
|
+
# @param splat [Hash]
|
32
|
+
# @return [Solargraph::Pin::Reference::Override]
|
23
33
|
def self.method_return name, *tags, delete: [], **splat
|
24
|
-
new(nil, name, [YARD::Tags::Tag.new('return',
|
34
|
+
new(nil, name, [YARD::Tags::Tag.new('return', '', tags)], delete, **splat)
|
25
35
|
end
|
26
36
|
|
37
|
+
# @param name [String]
|
38
|
+
# @param comment [String]
|
39
|
+
# @param splat [Hash]
|
40
|
+
# @return [Solargraph::Pin::Reference::Override]
|
27
41
|
def self.from_comment name, comment, **splat
|
28
42
|
new(nil, name, Solargraph::Source.parse_docstring(comment).to_docstring.tags, **splat)
|
29
43
|
end
|
@@ -17,6 +17,32 @@ module Solargraph
|
|
17
17
|
super(**splat)
|
18
18
|
@generic_values = generic_values
|
19
19
|
end
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
def parameter_tag
|
23
|
+
@parameter_tag ||= if generic_values&.any?
|
24
|
+
"<#{generic_values.join(', ')}>"
|
25
|
+
else
|
26
|
+
''
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [ComplexType]
|
31
|
+
def parametrized_tag
|
32
|
+
@parametrized_tag ||= ComplexType.try_parse(
|
33
|
+
name +
|
34
|
+
if generic_values&.length&.> 0
|
35
|
+
"<#{generic_values.join(', ')}>"
|
36
|
+
else
|
37
|
+
''
|
38
|
+
end
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Array<String>]
|
43
|
+
def reference_gates
|
44
|
+
closure.gates
|
45
|
+
end
|
20
46
|
end
|
21
47
|
end
|
22
48
|
end
|
@@ -12,6 +12,8 @@ module Solargraph
|
|
12
12
|
# @return [Pin::Base]
|
13
13
|
attr_reader :pin
|
14
14
|
|
15
|
+
# @param match [Float] The match score for the pin
|
16
|
+
# @param pin [Pin::Base]
|
15
17
|
def initialize match, pin
|
16
18
|
@match = match
|
17
19
|
@pin = pin
|
@@ -48,7 +50,7 @@ module Solargraph
|
|
48
50
|
# @param str2 [String]
|
49
51
|
# @return [Float]
|
50
52
|
def fuzzy_string_match str1, str2
|
51
|
-
return
|
53
|
+
return 1.0 + (str2.length.to_f / str1.length.to_f) if str1.downcase.include?(str2.downcase)
|
52
54
|
JaroWinkler.similarity(str1, str2, ignore_case: true)
|
53
55
|
end
|
54
56
|
end
|
@@ -39,6 +39,8 @@ module Solargraph
|
|
39
39
|
end
|
40
40
|
return ComplexType::UNDEFINED if closure.nil?
|
41
41
|
return ComplexType::UNDEFINED unless closure.is_a?(Pin::Method)
|
42
|
+
# @sg-ignore need is_a? support
|
43
|
+
# @type [Array<Pin::Method>]
|
42
44
|
method_stack = closure.rest_of_stack api_map
|
43
45
|
logger.debug { "Signature#typify(self=#{self}) - method_stack: #{method_stack}" }
|
44
46
|
method_stack.each do |pin|
|
@@ -20,6 +20,10 @@ module Solargraph
|
|
20
20
|
''
|
21
21
|
end
|
22
22
|
|
23
|
+
def closure
|
24
|
+
@closure ||= Pin::ROOT_PIN
|
25
|
+
end
|
26
|
+
|
23
27
|
def completion_item_kind
|
24
28
|
Solargraph::LanguageServer::CompletionItemKinds::KEYWORD
|
25
29
|
end
|
@@ -36,6 +40,7 @@ module Solargraph
|
|
36
40
|
[]
|
37
41
|
end
|
38
42
|
|
43
|
+
# @return [::Symbol]
|
39
44
|
def visibility
|
40
45
|
:public
|
41
46
|
end
|
data/lib/solargraph/pin_cache.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'yard-activesupport-concern'
|
1
2
|
require 'fileutils'
|
2
3
|
require 'rbs'
|
3
4
|
|
@@ -26,98 +27,156 @@ module Solargraph
|
|
26
27
|
File.join(base_dir, "ruby-#{RUBY_VERSION}", "rbs-#{RBS::VERSION}", "solargraph-#{Solargraph::VERSION}")
|
27
28
|
end
|
28
29
|
|
30
|
+
# @param gemspec [Gem::Specification]
|
31
|
+
# @return [String]
|
29
32
|
def yardoc_path gemspec
|
30
|
-
File.join(base_dir,
|
33
|
+
File.join(base_dir,
|
34
|
+
"yard-#{YARD::VERSION}",
|
35
|
+
"yard-activesupport-concern-#{YARD::ActiveSupport::Concern::VERSION}",
|
36
|
+
"#{gemspec.name}-#{gemspec.version}.yardoc")
|
31
37
|
end
|
32
38
|
|
39
|
+
# @return [String]
|
33
40
|
def stdlib_path
|
34
41
|
File.join(work_dir, 'stdlib')
|
35
42
|
end
|
36
43
|
|
44
|
+
# @param require [String]
|
45
|
+
# @return [String]
|
37
46
|
def stdlib_require_path require
|
38
47
|
File.join(stdlib_path, "#{require}.ser")
|
39
48
|
end
|
40
49
|
|
50
|
+
# @param require [String]
|
51
|
+
# @return [Array<Pin::Base>]
|
41
52
|
def deserialize_stdlib_require require
|
42
53
|
load(stdlib_require_path(require))
|
43
54
|
end
|
44
55
|
|
56
|
+
# @param require [String]
|
57
|
+
# @param pins [Array<Pin::Base>]
|
58
|
+
# @return [void]
|
45
59
|
def serialize_stdlib_require require, pins
|
46
60
|
save(stdlib_require_path(require), pins)
|
47
61
|
end
|
48
62
|
|
63
|
+
# @return [String]
|
49
64
|
def core_path
|
50
65
|
File.join(work_dir, 'core.ser')
|
51
66
|
end
|
52
67
|
|
68
|
+
# @return [Array<Pin::Base>]
|
53
69
|
def deserialize_core
|
54
70
|
load(core_path)
|
55
71
|
end
|
56
72
|
|
73
|
+
# @param pins [Array<Pin::Base>]
|
74
|
+
# @return [void]
|
57
75
|
def serialize_core pins
|
58
76
|
save(core_path, pins)
|
59
77
|
end
|
60
78
|
|
79
|
+
# @param gemspec [Gem::Specification]
|
80
|
+
# @return [String]
|
61
81
|
def yard_gem_path gemspec
|
62
82
|
File.join(work_dir, 'yard', "#{gemspec.name}-#{gemspec.version}.ser")
|
63
83
|
end
|
64
84
|
|
85
|
+
# @param gemspec [Gem::Specification]
|
86
|
+
# @return [Array<Pin::Base>]
|
65
87
|
def deserialize_yard_gem(gemspec)
|
66
88
|
load(yard_gem_path(gemspec))
|
67
89
|
end
|
68
90
|
|
91
|
+
# @param gemspec [Gem::Specification]
|
92
|
+
# @param pins [Array<Pin::Base>]
|
93
|
+
# @return [void]
|
69
94
|
def serialize_yard_gem(gemspec, pins)
|
70
95
|
save(yard_gem_path(gemspec), pins)
|
71
96
|
end
|
72
97
|
|
98
|
+
# @param gemspec [Gem::Specification]
|
99
|
+
# @return [Boolean]
|
73
100
|
def has_yard?(gemspec)
|
74
101
|
exist?(yard_gem_path(gemspec))
|
75
102
|
end
|
76
103
|
|
104
|
+
# @param gemspec [Gem::Specification]
|
105
|
+
# @param hash [String, nil]
|
106
|
+
# @return [String]
|
77
107
|
def rbs_collection_path(gemspec, hash)
|
78
108
|
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
|
79
109
|
end
|
80
110
|
|
111
|
+
# @param gemspec [Gem::Specification]
|
112
|
+
# @return [String]
|
81
113
|
def rbs_collection_path_prefix(gemspec)
|
82
114
|
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-")
|
83
115
|
end
|
84
116
|
|
117
|
+
# @param gemspec [Gem::Specification]
|
118
|
+
# @param hash [String, nil]
|
119
|
+
# @return [Array<Pin::Base>]
|
85
120
|
def deserialize_rbs_collection_gem(gemspec, hash)
|
86
121
|
load(rbs_collection_path(gemspec, hash))
|
87
122
|
end
|
88
123
|
|
124
|
+
# @param gemspec [Gem::Specification]
|
125
|
+
# @param hash [String, nil]
|
126
|
+
# @param pins [Array<Pin::Base>]n
|
127
|
+
# @return [void]
|
89
128
|
def serialize_rbs_collection_gem(gemspec, hash, pins)
|
90
129
|
save(rbs_collection_path(gemspec, hash), pins)
|
91
130
|
end
|
92
131
|
|
132
|
+
# @param gemspec [Gem::Specification]
|
133
|
+
# @param hash [String, nil]
|
134
|
+
# @return [String]
|
93
135
|
def combined_path(gemspec, hash)
|
94
136
|
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
|
95
137
|
end
|
96
138
|
|
139
|
+
# @param gemspec [Gem::Specification]
|
140
|
+
# @return [String]
|
97
141
|
def combined_path_prefix(gemspec)
|
98
142
|
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-")
|
99
143
|
end
|
100
144
|
|
145
|
+
# @param gemspec [Gem::Specification]
|
146
|
+
# @param hash [String, nil]
|
147
|
+
# @param pins [Array<Pin::Base>]
|
148
|
+
# @return [void]
|
101
149
|
def serialize_combined_gem(gemspec, hash, pins)
|
102
150
|
save(combined_path(gemspec, hash), pins)
|
103
151
|
end
|
104
152
|
|
153
|
+
# @param gemspec [Gem::Specification]
|
154
|
+
# @param hash [String, nil]
|
155
|
+
# @return [Array<Pin::Base>]
|
105
156
|
def deserialize_combined_gem gemspec, hash
|
106
157
|
load(combined_path(gemspec, hash))
|
107
158
|
end
|
108
159
|
|
160
|
+
# @param gemspec [Gem::Specification]
|
161
|
+
# @param hash [String, nil]
|
162
|
+
# @return [Boolean]
|
109
163
|
def has_rbs_collection?(gemspec, hash)
|
110
164
|
exist?(rbs_collection_path(gemspec, hash))
|
111
165
|
end
|
112
166
|
|
167
|
+
# @return [void]
|
113
168
|
def uncache_core
|
114
169
|
uncache(core_path)
|
115
170
|
end
|
116
171
|
|
172
|
+
# @return [void]
|
117
173
|
def uncache_stdlib
|
118
174
|
uncache(stdlib_path)
|
119
175
|
end
|
120
176
|
|
177
|
+
# @param gemspec [Gem::Specification]
|
178
|
+
# @param out [IO, nil]
|
179
|
+
# @return [void]
|
121
180
|
def uncache_gem(gemspec, out: nil)
|
122
181
|
uncache(yardoc_path(gemspec), out: out)
|
123
182
|
uncache_by_prefix(rbs_collection_path_prefix(gemspec), out: out)
|
@@ -143,11 +202,12 @@ module Solargraph
|
|
143
202
|
nil
|
144
203
|
end
|
145
204
|
|
205
|
+
# @param path [String]
|
146
206
|
def exist? *path
|
147
|
-
File.file? join(*path)
|
207
|
+
File.file? File.join(*path)
|
148
208
|
end
|
149
209
|
|
150
|
-
# @param
|
210
|
+
# @param file [String]
|
151
211
|
# @param pins [Array<Pin::Base>]
|
152
212
|
# @return [void]
|
153
213
|
def save file, pins
|
@@ -158,8 +218,8 @@ module Solargraph
|
|
158
218
|
logger.debug { "Cache#save: Saved #{pins.length} pins to #{file}" }
|
159
219
|
end
|
160
220
|
|
161
|
-
# @return [void]
|
162
221
|
# @param path_segments [Array<String>]
|
222
|
+
# @return [void]
|
163
223
|
def uncache *path_segments, out: nil
|
164
224
|
path = File.join(*path_segments)
|
165
225
|
if File.exist?(path)
|
data/lib/solargraph/position.rb
CHANGED
@@ -26,6 +26,7 @@ module Solargraph
|
|
26
26
|
[line, character]
|
27
27
|
end
|
28
28
|
|
29
|
+
# @param other [Position]
|
29
30
|
def <=>(other)
|
30
31
|
return nil unless other.is_a?(Position)
|
31
32
|
if line == other.line
|
@@ -57,6 +58,7 @@ module Solargraph
|
|
57
58
|
# @return [Integer]
|
58
59
|
def self.to_offset text, position
|
59
60
|
return 0 if text.empty?
|
61
|
+
# @sg-ignore Unresolved call to + on Integer
|
60
62
|
text.lines[0...position.line].sum(&:length) + position.character
|
61
63
|
end
|
62
64
|
|
data/lib/solargraph/range.rb
CHANGED
@@ -163,9 +163,10 @@ module Solargraph
|
|
163
163
|
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
164
164
|
end
|
165
165
|
end
|
166
|
+
class_name = decl.name.relative!.to_s
|
166
167
|
class_pin = Solargraph::Pin::Namespace.new(
|
167
168
|
type: :class,
|
168
|
-
name:
|
169
|
+
name: class_name,
|
169
170
|
closure: Solargraph::Pin::ROOT_PIN,
|
170
171
|
comments: decl.comment&.string,
|
171
172
|
type_location: location_decl_to_pin_location(decl.location),
|
@@ -180,11 +181,12 @@ module Solargraph
|
|
180
181
|
if decl.super_class
|
181
182
|
type = build_type(decl.super_class.name, decl.super_class.args)
|
182
183
|
generic_values = type.all_params.map(&:to_s)
|
184
|
+
superclass_name = decl.super_class.name.to_s
|
183
185
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
184
186
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
185
187
|
closure: class_pin,
|
186
188
|
generic_values: generic_values,
|
187
|
-
name:
|
189
|
+
name: superclass_name,
|
188
190
|
source: :rbs
|
189
191
|
)
|
190
192
|
end
|
@@ -345,7 +347,7 @@ module Solargraph
|
|
345
347
|
}
|
346
348
|
|
347
349
|
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor]
|
348
|
-
# @param closure [Pin::
|
350
|
+
# @param closure [Pin::Closure]
|
349
351
|
# @param context [Context]
|
350
352
|
# @param scope [Symbol] :instance or :class
|
351
353
|
# @param name [String] The name of the method
|
@@ -699,13 +701,13 @@ module Solargraph
|
|
699
701
|
# @return [ComplexType::UniqueType]
|
700
702
|
def build_type(type_name, type_args = [])
|
701
703
|
base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
|
702
|
-
params = type_args.map { |a| other_type_to_tag(a) }.
|
704
|
+
params = type_args.map { |a| other_type_to_tag(a) }.map do |t|
|
703
705
|
ComplexType.try_parse(t).force_rooted
|
704
706
|
end
|
705
707
|
if base == 'Hash' && params.length == 2
|
706
708
|
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
|
707
709
|
else
|
708
|
-
ComplexType::UniqueType.new(base, [], params, rooted: true, parameters_type: :list)
|
710
|
+
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: true, parameters_type: :list)
|
709
711
|
end
|
710
712
|
end
|
711
713
|
|
@@ -14,6 +14,7 @@ module Solargraph
|
|
14
14
|
|
15
15
|
def initialize; end
|
16
16
|
|
17
|
+
# @return [Enumerable<Pin::Base>]
|
17
18
|
def pins
|
18
19
|
return @pins if @pins
|
19
20
|
|
@@ -39,10 +40,12 @@ module Solargraph
|
|
39
40
|
|
40
41
|
private
|
41
42
|
|
43
|
+
# @return [RBS::EnvironmentLoader]
|
42
44
|
def loader
|
43
45
|
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
44
46
|
end
|
45
47
|
|
48
|
+
# @return [Conversions]
|
46
49
|
def conversions
|
47
50
|
@conversions ||= Conversions.new(loader: loader)
|
48
51
|
end
|
data/lib/solargraph/rbs_map.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'digest'
|
3
4
|
require 'pathname'
|
4
5
|
require 'rbs'
|
5
6
|
|
@@ -22,7 +23,8 @@ module Solargraph
|
|
22
23
|
attr_reader :rbs_collection_config_path
|
23
24
|
|
24
25
|
# @param library [String]
|
25
|
-
# @param version [String, nil
|
26
|
+
# @param version [String, nil
|
27
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
26
28
|
# @param rbs_collection_paths [Array<Pathname, String>]
|
27
29
|
def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []
|
28
30
|
if rbs_collection_config_path.nil? && !rbs_collection_paths.empty?
|
@@ -35,16 +37,18 @@ module Solargraph
|
|
35
37
|
add_library loader, library, version
|
36
38
|
end
|
37
39
|
|
40
|
+
# @return [RBS::EnvironmentLoader]
|
38
41
|
def loader
|
39
42
|
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
40
43
|
end
|
41
44
|
|
42
|
-
# @return
|
45
|
+
# @return [String] representing the version of the RBS info fetched
|
43
46
|
# for the given library. Must change when the RBS info is
|
44
47
|
# updated upstream for the same library and version. May change
|
45
48
|
# if the config for where information comes form changes.
|
46
49
|
def cache_key
|
47
50
|
@hextdigest ||= begin
|
51
|
+
# @type [String, nil]
|
48
52
|
data = nil
|
49
53
|
if rbs_collection_config_path
|
50
54
|
lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path))
|
@@ -68,6 +72,10 @@ module Solargraph
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
75
|
+
# @param gemspec [Gem::Specification]
|
76
|
+
# @param rbs_collection_path [String, Pathname, nil]
|
77
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
78
|
+
# @return [RbsMap]
|
71
79
|
def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path
|
72
80
|
rbs_map = RbsMap.new(gemspec.name, gemspec.version,
|
73
81
|
rbs_collection_paths: [rbs_collection_path].compact,
|
@@ -80,6 +88,7 @@ module Solargraph
|
|
80
88
|
rbs_collection_config_path: rbs_collection_config_path)
|
81
89
|
end
|
82
90
|
|
91
|
+
# @return [Array<Pin::Base>]
|
83
92
|
def pins
|
84
93
|
@pins ||= resolved? ? conversions.pins : []
|
85
94
|
end
|
@@ -103,6 +112,7 @@ module Solargraph
|
|
103
112
|
@resolved
|
104
113
|
end
|
105
114
|
|
115
|
+
# @return [RBS::Repository]
|
106
116
|
def repository
|
107
117
|
@repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
|
108
118
|
@rbs_collection_paths.each do |dir|
|
@@ -120,16 +130,19 @@ module Solargraph
|
|
120
130
|
|
121
131
|
private
|
122
132
|
|
133
|
+
# @return [RBS::EnvironmentLoader]
|
123
134
|
def loader
|
124
135
|
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
125
136
|
end
|
126
137
|
|
138
|
+
# @return [Conversions]
|
127
139
|
def conversions
|
128
140
|
@conversions ||= Conversions.new(loader: loader)
|
129
141
|
end
|
130
142
|
|
131
143
|
# @param loader [RBS::EnvironmentLoader]
|
132
144
|
# @param library [String]
|
145
|
+
# @param version [String, nil]
|
133
146
|
# @return [Boolean] true if adding the library succeeded
|
134
147
|
def add_library loader, library, version
|
135
148
|
@resolved = if loader.has_library?(library: library, version: version)
|
data/lib/solargraph/shell.rb
CHANGED
@@ -36,6 +36,7 @@ module Solargraph
|
|
36
36
|
Signal.trap("TERM") do
|
37
37
|
Backport.stop
|
38
38
|
end
|
39
|
+
# @sg-ignore Wrong argument type for Backport.prepare_tcp_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
39
40
|
Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter
|
40
41
|
STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
|
41
42
|
end
|
@@ -52,6 +53,7 @@ module Solargraph
|
|
52
53
|
Signal.trap("TERM") do
|
53
54
|
Backport.stop
|
54
55
|
end
|
56
|
+
# @sg-ignore Wrong argument type for Backport.prepare_stdio_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
55
57
|
Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter
|
56
58
|
STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}"
|
57
59
|
end
|
@@ -258,6 +260,7 @@ module Solargraph
|
|
258
260
|
end
|
259
261
|
|
260
262
|
# @param gemspec [Gem::Specification]
|
263
|
+
# @param api_map [ApiMap]
|
261
264
|
# @return [void]
|
262
265
|
def do_cache gemspec, api_map
|
263
266
|
# @todo if the rebuild: option is passed as a positional arg,
|