solargraph 0.58.1 → 0.58.2
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/.gitignore +1 -0
- data/CHANGELOG.md +7 -1
- data/lib/solargraph/api_map/cache.rb +110 -110
- data/lib/solargraph/api_map/constants.rb +279 -279
- data/lib/solargraph/api_map/index.rb +193 -193
- data/lib/solargraph/api_map/source_to_yard.rb +97 -97
- data/lib/solargraph/api_map/store.rb +384 -384
- data/lib/solargraph/api_map.rb +945 -945
- data/lib/solargraph/complex_type/type_methods.rb +228 -228
- data/lib/solargraph/complex_type/unique_type.rb +482 -482
- data/lib/solargraph/complex_type.rb +444 -444
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -91
- data/lib/solargraph/convention/data_definition.rb +105 -105
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -61
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -102
- data/lib/solargraph/convention/struct_definition.rb +164 -164
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -53
- data/lib/solargraph/diagnostics/rubocop.rb +118 -118
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +68 -68
- data/lib/solargraph/diagnostics/type_check.rb +55 -55
- data/lib/solargraph/doc_map.rb +439 -439
- data/lib/solargraph/equality.rb +34 -34
- data/lib/solargraph/gem_pins.rb +98 -98
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
- data/lib/solargraph/language_server/host/dispatch.rb +130 -130
- data/lib/solargraph/language_server/host/message_worker.rb +112 -112
- data/lib/solargraph/language_server/host/sources.rb +99 -99
- data/lib/solargraph/language_server/host.rb +878 -878
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +114 -114
- data/lib/solargraph/language_server/message/extended/document.rb +23 -23
- data/lib/solargraph/language_server/message/text_document/completion.rb +56 -56
- data/lib/solargraph/language_server/message/text_document/definition.rb +40 -40
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +26 -26
- data/lib/solargraph/language_server/message/text_document/formatting.rb +148 -148
- data/lib/solargraph/language_server/message/text_document/hover.rb +58 -58
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -24
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -25
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -23
- data/lib/solargraph/library.rb +683 -683
- data/lib/solargraph/location.rb +82 -82
- data/lib/solargraph/logging.rb +37 -37
- data/lib/solargraph/parser/comment_ripper.rb +69 -69
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -255
- data/lib/solargraph/parser/node_processor/base.rb +92 -92
- data/lib/solargraph/parser/node_processor.rb +62 -62
- data/lib/solargraph/parser/parser_gem/class_methods.rb +149 -149
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +166 -166
- data/lib/solargraph/parser/parser_gem/node_methods.rb +486 -486
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +15 -15
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +53 -53
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -23
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +40 -40
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +59 -59
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +38 -38
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +52 -52
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +291 -291
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -29
- data/lib/solargraph/parser/parser_gem/node_processors.rb +70 -70
- data/lib/solargraph/parser/region.rb +69 -69
- data/lib/solargraph/parser/snippet.rb +17 -17
- data/lib/solargraph/pin/base.rb +729 -729
- data/lib/solargraph/pin/base_variable.rb +126 -126
- data/lib/solargraph/pin/block.rb +104 -104
- data/lib/solargraph/pin/breakable.rb +9 -9
- data/lib/solargraph/pin/callable.rb +231 -231
- data/lib/solargraph/pin/closure.rb +72 -72
- data/lib/solargraph/pin/common.rb +79 -79
- data/lib/solargraph/pin/conversions.rb +123 -123
- data/lib/solargraph/pin/delegated_method.rb +120 -120
- data/lib/solargraph/pin/documenting.rb +114 -114
- data/lib/solargraph/pin/instance_variable.rb +34 -34
- data/lib/solargraph/pin/keyword.rb +20 -20
- data/lib/solargraph/pin/local_variable.rb +75 -75
- data/lib/solargraph/pin/method.rb +672 -672
- data/lib/solargraph/pin/method_alias.rb +34 -34
- data/lib/solargraph/pin/namespace.rb +115 -115
- data/lib/solargraph/pin/parameter.rb +275 -275
- data/lib/solargraph/pin/proxy_type.rb +39 -39
- data/lib/solargraph/pin/reference/override.rb +47 -47
- data/lib/solargraph/pin/reference/superclass.rb +15 -15
- data/lib/solargraph/pin/reference.rb +39 -39
- data/lib/solargraph/pin/search.rb +61 -61
- data/lib/solargraph/pin/signature.rb +61 -61
- data/lib/solargraph/pin/symbol.rb +53 -53
- data/lib/solargraph/pin/until.rb +18 -18
- data/lib/solargraph/pin/while.rb +18 -18
- data/lib/solargraph/pin.rb +44 -44
- data/lib/solargraph/pin_cache.rb +245 -245
- data/lib/solargraph/position.rb +132 -119
- data/lib/solargraph/range.rb +112 -112
- data/lib/solargraph/rbs_map/conversions.rb +823 -823
- data/lib/solargraph/rbs_map/core_map.rb +58 -58
- data/lib/solargraph/rbs_map/stdlib_map.rb +43 -43
- data/lib/solargraph/rbs_map.rb +163 -163
- data/lib/solargraph/shell.rb +352 -352
- data/lib/solargraph/source/chain/call.rb +337 -337
- data/lib/solargraph/source/chain/constant.rb +26 -26
- data/lib/solargraph/source/chain/hash.rb +34 -34
- data/lib/solargraph/source/chain/if.rb +28 -28
- data/lib/solargraph/source/chain/instance_variable.rb +13 -13
- data/lib/solargraph/source/chain/literal.rb +48 -48
- data/lib/solargraph/source/chain/or.rb +23 -23
- data/lib/solargraph/source/chain.rb +291 -291
- data/lib/solargraph/source/change.rb +82 -82
- data/lib/solargraph/source/cursor.rb +166 -166
- data/lib/solargraph/source/source_chainer.rb +194 -194
- data/lib/solargraph/source/updater.rb +55 -55
- data/lib/solargraph/source.rb +498 -498
- data/lib/solargraph/source_map/clip.rb +226 -226
- data/lib/solargraph/source_map/data.rb +34 -34
- data/lib/solargraph/source_map/mapper.rb +259 -259
- data/lib/solargraph/source_map.rb +212 -212
- data/lib/solargraph/type_checker/checks.rb +124 -124
- data/lib/solargraph/type_checker/param_def.rb +37 -37
- data/lib/solargraph/type_checker/problem.rb +32 -32
- data/lib/solargraph/type_checker/rules.rb +84 -84
- data/lib/solargraph/type_checker.rb +814 -814
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +255 -255
- data/lib/solargraph/workspace/require_paths.rb +97 -97
- data/lib/solargraph/workspace.rb +220 -220
- data/lib/solargraph/yard_map/helpers.rb +44 -44
- data/lib/solargraph/yard_map/mapper/to_method.rb +130 -130
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +31 -31
- data/lib/solargraph/yard_map/mapper.rb +79 -79
- data/lib/solargraph/yard_map/to_method.rb +89 -89
- data/lib/solargraph/yardoc.rb +87 -87
- data/lib/solargraph.rb +105 -105
- data/rbs_collection.yaml +1 -1
- metadata +12 -12
- /data/{sig → rbs}/shims/ast/0/node.rbs +0 -0
- /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
- /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
- /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Solargraph
|
|
4
|
-
class RbsMap
|
|
5
|
-
# Ruby core pins
|
|
6
|
-
#
|
|
7
|
-
class CoreMap
|
|
8
|
-
include Logging
|
|
9
|
-
|
|
10
|
-
def resolved?
|
|
11
|
-
true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
FILLS_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills'))
|
|
15
|
-
|
|
16
|
-
def initialize; end
|
|
17
|
-
|
|
18
|
-
# @return [Enumerable<Pin::Base>]
|
|
19
|
-
def pins
|
|
20
|
-
return @pins if @pins
|
|
21
|
-
|
|
22
|
-
@pins = []
|
|
23
|
-
cache = PinCache.deserialize_core
|
|
24
|
-
if cache
|
|
25
|
-
@pins.replace cache
|
|
26
|
-
else
|
|
27
|
-
@pins.concat conversions.pins
|
|
28
|
-
|
|
29
|
-
# Avoid RBS::DuplicatedDeclarationError by loading in a different EnvironmentLoader
|
|
30
|
-
fill_loader = RBS::EnvironmentLoader.new(core_root: nil, repository: RBS::Repository.new(no_stdlib: false))
|
|
31
|
-
fill_loader.add(path: Pathname(FILLS_DIRECTORY))
|
|
32
|
-
fill_conversions = Conversions.new(loader: fill_loader)
|
|
33
|
-
@pins.concat fill_conversions.pins
|
|
34
|
-
|
|
35
|
-
@pins.concat RbsMap::CoreFills::ALL
|
|
36
|
-
|
|
37
|
-
processed = ApiMap::Store.new(pins).pins.reject { |p| p.is_a?(Solargraph::Pin::Reference::Override) }
|
|
38
|
-
@pins.replace processed
|
|
39
|
-
|
|
40
|
-
PinCache.serialize_core @pins
|
|
41
|
-
end
|
|
42
|
-
@pins
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
private
|
|
46
|
-
|
|
47
|
-
# @return [RBS::EnvironmentLoader]
|
|
48
|
-
def loader
|
|
49
|
-
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# @return [Conversions]
|
|
53
|
-
def conversions
|
|
54
|
-
@conversions ||= Conversions.new(loader: loader)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Solargraph
|
|
4
|
+
class RbsMap
|
|
5
|
+
# Ruby core pins
|
|
6
|
+
#
|
|
7
|
+
class CoreMap
|
|
8
|
+
include Logging
|
|
9
|
+
|
|
10
|
+
def resolved?
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
FILLS_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills'))
|
|
15
|
+
|
|
16
|
+
def initialize; end
|
|
17
|
+
|
|
18
|
+
# @return [Enumerable<Pin::Base>]
|
|
19
|
+
def pins
|
|
20
|
+
return @pins if @pins
|
|
21
|
+
|
|
22
|
+
@pins = []
|
|
23
|
+
cache = PinCache.deserialize_core
|
|
24
|
+
if cache
|
|
25
|
+
@pins.replace cache
|
|
26
|
+
else
|
|
27
|
+
@pins.concat conversions.pins
|
|
28
|
+
|
|
29
|
+
# Avoid RBS::DuplicatedDeclarationError by loading in a different EnvironmentLoader
|
|
30
|
+
fill_loader = RBS::EnvironmentLoader.new(core_root: nil, repository: RBS::Repository.new(no_stdlib: false))
|
|
31
|
+
fill_loader.add(path: Pathname(FILLS_DIRECTORY))
|
|
32
|
+
fill_conversions = Conversions.new(loader: fill_loader)
|
|
33
|
+
@pins.concat fill_conversions.pins
|
|
34
|
+
|
|
35
|
+
@pins.concat RbsMap::CoreFills::ALL
|
|
36
|
+
|
|
37
|
+
processed = ApiMap::Store.new(pins).pins.reject { |p| p.is_a?(Solargraph::Pin::Reference::Override) }
|
|
38
|
+
@pins.replace processed
|
|
39
|
+
|
|
40
|
+
PinCache.serialize_core @pins
|
|
41
|
+
end
|
|
42
|
+
@pins
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# @return [RBS::EnvironmentLoader]
|
|
48
|
+
def loader
|
|
49
|
+
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [Conversions]
|
|
53
|
+
def conversions
|
|
54
|
+
@conversions ||= Conversions.new(loader: loader)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rbs'
|
|
4
|
-
|
|
5
|
-
module Solargraph
|
|
6
|
-
class RbsMap
|
|
7
|
-
# Ruby stdlib pins
|
|
8
|
-
#
|
|
9
|
-
class StdlibMap < RbsMap
|
|
10
|
-
include Logging
|
|
11
|
-
|
|
12
|
-
# @type [Hash{String => RbsMap}]
|
|
13
|
-
@stdlib_maps_hash = {}
|
|
14
|
-
|
|
15
|
-
# @param library [String]
|
|
16
|
-
def initialize library
|
|
17
|
-
cached_pins = PinCache.deserialize_stdlib_require library
|
|
18
|
-
if cached_pins
|
|
19
|
-
@pins = cached_pins
|
|
20
|
-
@resolved = true
|
|
21
|
-
@loaded = true
|
|
22
|
-
logger.debug { "Deserialized #{cached_pins.length} cached pins for stdlib require #{library.inspect}" }
|
|
23
|
-
else
|
|
24
|
-
super
|
|
25
|
-
unless resolved?
|
|
26
|
-
@pins = []
|
|
27
|
-
logger.info { "Could not resolve #{library.inspect}" }
|
|
28
|
-
return
|
|
29
|
-
end
|
|
30
|
-
generated_pins = pins
|
|
31
|
-
logger.debug { "Found #{generated_pins.length} pins for stdlib library #{library}" }
|
|
32
|
-
PinCache.serialize_stdlib_require library, generated_pins
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# @param library [String]
|
|
37
|
-
# @return [StdlibMap]
|
|
38
|
-
def self.load library
|
|
39
|
-
@stdlib_maps_hash[library] ||= StdlibMap.new(library)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rbs'
|
|
4
|
+
|
|
5
|
+
module Solargraph
|
|
6
|
+
class RbsMap
|
|
7
|
+
# Ruby stdlib pins
|
|
8
|
+
#
|
|
9
|
+
class StdlibMap < RbsMap
|
|
10
|
+
include Logging
|
|
11
|
+
|
|
12
|
+
# @type [Hash{String => RbsMap}]
|
|
13
|
+
@stdlib_maps_hash = {}
|
|
14
|
+
|
|
15
|
+
# @param library [String]
|
|
16
|
+
def initialize library
|
|
17
|
+
cached_pins = PinCache.deserialize_stdlib_require library
|
|
18
|
+
if cached_pins
|
|
19
|
+
@pins = cached_pins
|
|
20
|
+
@resolved = true
|
|
21
|
+
@loaded = true
|
|
22
|
+
logger.debug { "Deserialized #{cached_pins.length} cached pins for stdlib require #{library.inspect}" }
|
|
23
|
+
else
|
|
24
|
+
super
|
|
25
|
+
unless resolved?
|
|
26
|
+
@pins = []
|
|
27
|
+
logger.info { "Could not resolve #{library.inspect}" }
|
|
28
|
+
return
|
|
29
|
+
end
|
|
30
|
+
generated_pins = pins
|
|
31
|
+
logger.debug { "Found #{generated_pins.length} pins for stdlib library #{library}" }
|
|
32
|
+
PinCache.serialize_stdlib_require library, generated_pins
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param library [String]
|
|
37
|
+
# @return [StdlibMap]
|
|
38
|
+
def self.load library
|
|
39
|
+
@stdlib_maps_hash[library] ||= StdlibMap.new(library)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/solargraph/rbs_map.rb
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'digest'
|
|
4
|
-
require 'pathname'
|
|
5
|
-
require 'rbs'
|
|
6
|
-
|
|
7
|
-
module Solargraph
|
|
8
|
-
class RbsMap
|
|
9
|
-
autoload :Conversions, 'solargraph/rbs_map/conversions'
|
|
10
|
-
autoload :CoreMap, 'solargraph/rbs_map/core_map'
|
|
11
|
-
autoload :CoreFills, 'solargraph/rbs_map/core_fills'
|
|
12
|
-
autoload :StdlibMap, 'solargraph/rbs_map/stdlib_map'
|
|
13
|
-
|
|
14
|
-
include Logging
|
|
15
|
-
|
|
16
|
-
# @type [Hash{String => RbsMap}]
|
|
17
|
-
@@rbs_maps_hash = {}
|
|
18
|
-
|
|
19
|
-
attr_reader :library
|
|
20
|
-
|
|
21
|
-
attr_reader :rbs_collection_paths
|
|
22
|
-
|
|
23
|
-
attr_reader :rbs_collection_config_path
|
|
24
|
-
|
|
25
|
-
# @param library [String]
|
|
26
|
-
# @param version [String, nil]
|
|
27
|
-
# @param rbs_collection_config_path [String, Pathname, nil]
|
|
28
|
-
# @param rbs_collection_paths [Array<Pathname, String>]
|
|
29
|
-
def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []
|
|
30
|
-
if rbs_collection_config_path.nil? && !rbs_collection_paths.empty?
|
|
31
|
-
raise 'Please provide rbs_collection_config_path if you provide rbs_collection_paths'
|
|
32
|
-
end
|
|
33
|
-
@library = library
|
|
34
|
-
@version = version
|
|
35
|
-
@rbs_collection_config_path = rbs_collection_config_path
|
|
36
|
-
@rbs_collection_paths = rbs_collection_paths
|
|
37
|
-
add_library loader, library, version
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# @return [RBS::EnvironmentLoader]
|
|
41
|
-
def loader
|
|
42
|
-
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# @return [String] representing the version of the RBS info fetched
|
|
46
|
-
# for the given library. Must change when the RBS info is
|
|
47
|
-
# updated upstream for the same library and version. May change
|
|
48
|
-
# if the config for where information comes form changes.
|
|
49
|
-
def cache_key
|
|
50
|
-
@hextdigest ||= begin
|
|
51
|
-
# @type [String, nil]
|
|
52
|
-
data = nil
|
|
53
|
-
if rbs_collection_config_path
|
|
54
|
-
lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path))
|
|
55
|
-
if lockfile_path.exist?
|
|
56
|
-
collection_config = RBS::Collection::Config.from_path lockfile_path
|
|
57
|
-
gem_config = collection_config.gem(library)
|
|
58
|
-
data = gem_config&.to_s
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
if data.nil? || data.empty?
|
|
62
|
-
if resolved?
|
|
63
|
-
# definitely came from the gem itself and not elsewhere -
|
|
64
|
-
# only one version per gem
|
|
65
|
-
'gem-export'
|
|
66
|
-
else
|
|
67
|
-
'unresolved'
|
|
68
|
-
end
|
|
69
|
-
else
|
|
70
|
-
Digest::SHA1.hexdigest(data)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# @param gemspec [Gem::Specification, Bundler::LazySpecification]
|
|
76
|
-
# @param rbs_collection_path [String, Pathname, nil]
|
|
77
|
-
# @param rbs_collection_config_path [String, Pathname, nil]
|
|
78
|
-
# @return [RbsMap]
|
|
79
|
-
def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path
|
|
80
|
-
rbs_map = RbsMap.new(gemspec.name, gemspec.version,
|
|
81
|
-
rbs_collection_paths: [rbs_collection_path].compact,
|
|
82
|
-
rbs_collection_config_path: rbs_collection_config_path)
|
|
83
|
-
return rbs_map if rbs_map.resolved?
|
|
84
|
-
|
|
85
|
-
# try any version of the gem in the collection
|
|
86
|
-
RbsMap.new(gemspec.name, nil,
|
|
87
|
-
rbs_collection_paths: [rbs_collection_path].compact,
|
|
88
|
-
rbs_collection_config_path: rbs_collection_config_path)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# @return [Array<Pin::Base>]
|
|
92
|
-
def pins
|
|
93
|
-
@pins ||= resolved? ? conversions.pins : []
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# @generic T
|
|
97
|
-
# @param path [String]
|
|
98
|
-
# @param klass [Class<generic<T>>]
|
|
99
|
-
# @return [generic<T>, nil]
|
|
100
|
-
def path_pin path, klass = Pin::Base
|
|
101
|
-
pin = pins.find { |p| p.path == path }
|
|
102
|
-
pin if pin&.is_a?(klass)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
# @param path [String]
|
|
106
|
-
# @return [Array<Pin::Base>]
|
|
107
|
-
def path_pins path
|
|
108
|
-
pins.select { |p| p.path == path }
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def resolved?
|
|
112
|
-
@resolved
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# @return [RBS::Repository]
|
|
116
|
-
def repository
|
|
117
|
-
@repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
|
|
118
|
-
@rbs_collection_paths.each do |dir|
|
|
119
|
-
dir_path = Pathname.new(dir)
|
|
120
|
-
repo.add(dir_path) if dir_path.exist? && dir_path.directory?
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# @param library [String]
|
|
126
|
-
# @return [RbsMap]
|
|
127
|
-
def self.load library
|
|
128
|
-
@@rbs_maps_hash[library] ||= RbsMap.new(library)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
private
|
|
132
|
-
|
|
133
|
-
# @return [RBS::EnvironmentLoader]
|
|
134
|
-
def loader
|
|
135
|
-
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# @return [Conversions]
|
|
139
|
-
def conversions
|
|
140
|
-
@conversions ||= Conversions.new(loader: loader)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# @param loader [RBS::EnvironmentLoader]
|
|
144
|
-
# @param library [String]
|
|
145
|
-
# @param version [String, nil]
|
|
146
|
-
# @return [Boolean] true if adding the library succeeded
|
|
147
|
-
def add_library loader, library, version
|
|
148
|
-
@resolved = if loader.has_library?(library: library, version: version)
|
|
149
|
-
loader.add library: library, version: version
|
|
150
|
-
logger.debug { "#{short_name} successfully loaded library #{library}:#{version}" }
|
|
151
|
-
true
|
|
152
|
-
else
|
|
153
|
-
logger.info { "#{short_name} did not find data for library #{library}:#{version}" }
|
|
154
|
-
false
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
# @return [String]
|
|
159
|
-
def short_name
|
|
160
|
-
self.class.name.split('::').last
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
require 'rbs'
|
|
6
|
+
|
|
7
|
+
module Solargraph
|
|
8
|
+
class RbsMap
|
|
9
|
+
autoload :Conversions, 'solargraph/rbs_map/conversions'
|
|
10
|
+
autoload :CoreMap, 'solargraph/rbs_map/core_map'
|
|
11
|
+
autoload :CoreFills, 'solargraph/rbs_map/core_fills'
|
|
12
|
+
autoload :StdlibMap, 'solargraph/rbs_map/stdlib_map'
|
|
13
|
+
|
|
14
|
+
include Logging
|
|
15
|
+
|
|
16
|
+
# @type [Hash{String => RbsMap}]
|
|
17
|
+
@@rbs_maps_hash = {}
|
|
18
|
+
|
|
19
|
+
attr_reader :library
|
|
20
|
+
|
|
21
|
+
attr_reader :rbs_collection_paths
|
|
22
|
+
|
|
23
|
+
attr_reader :rbs_collection_config_path
|
|
24
|
+
|
|
25
|
+
# @param library [String]
|
|
26
|
+
# @param version [String, nil]
|
|
27
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
|
28
|
+
# @param rbs_collection_paths [Array<Pathname, String>]
|
|
29
|
+
def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []
|
|
30
|
+
if rbs_collection_config_path.nil? && !rbs_collection_paths.empty?
|
|
31
|
+
raise 'Please provide rbs_collection_config_path if you provide rbs_collection_paths'
|
|
32
|
+
end
|
|
33
|
+
@library = library
|
|
34
|
+
@version = version
|
|
35
|
+
@rbs_collection_config_path = rbs_collection_config_path
|
|
36
|
+
@rbs_collection_paths = rbs_collection_paths
|
|
37
|
+
add_library loader, library, version
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [RBS::EnvironmentLoader]
|
|
41
|
+
def loader
|
|
42
|
+
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @return [String] representing the version of the RBS info fetched
|
|
46
|
+
# for the given library. Must change when the RBS info is
|
|
47
|
+
# updated upstream for the same library and version. May change
|
|
48
|
+
# if the config for where information comes form changes.
|
|
49
|
+
def cache_key
|
|
50
|
+
@hextdigest ||= begin
|
|
51
|
+
# @type [String, nil]
|
|
52
|
+
data = nil
|
|
53
|
+
if rbs_collection_config_path
|
|
54
|
+
lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path))
|
|
55
|
+
if lockfile_path.exist?
|
|
56
|
+
collection_config = RBS::Collection::Config.from_path lockfile_path
|
|
57
|
+
gem_config = collection_config.gem(library)
|
|
58
|
+
data = gem_config&.to_s
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
if data.nil? || data.empty?
|
|
62
|
+
if resolved?
|
|
63
|
+
# definitely came from the gem itself and not elsewhere -
|
|
64
|
+
# only one version per gem
|
|
65
|
+
'gem-export'
|
|
66
|
+
else
|
|
67
|
+
'unresolved'
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
Digest::SHA1.hexdigest(data)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @param gemspec [Gem::Specification, Bundler::LazySpecification]
|
|
76
|
+
# @param rbs_collection_path [String, Pathname, nil]
|
|
77
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
|
78
|
+
# @return [RbsMap]
|
|
79
|
+
def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path
|
|
80
|
+
rbs_map = RbsMap.new(gemspec.name, gemspec.version,
|
|
81
|
+
rbs_collection_paths: [rbs_collection_path].compact,
|
|
82
|
+
rbs_collection_config_path: rbs_collection_config_path)
|
|
83
|
+
return rbs_map if rbs_map.resolved?
|
|
84
|
+
|
|
85
|
+
# try any version of the gem in the collection
|
|
86
|
+
RbsMap.new(gemspec.name, nil,
|
|
87
|
+
rbs_collection_paths: [rbs_collection_path].compact,
|
|
88
|
+
rbs_collection_config_path: rbs_collection_config_path)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @return [Array<Pin::Base>]
|
|
92
|
+
def pins
|
|
93
|
+
@pins ||= resolved? ? conversions.pins : []
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# @generic T
|
|
97
|
+
# @param path [String]
|
|
98
|
+
# @param klass [Class<generic<T>>]
|
|
99
|
+
# @return [generic<T>, nil]
|
|
100
|
+
def path_pin path, klass = Pin::Base
|
|
101
|
+
pin = pins.find { |p| p.path == path }
|
|
102
|
+
pin if pin&.is_a?(klass)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @param path [String]
|
|
106
|
+
# @return [Array<Pin::Base>]
|
|
107
|
+
def path_pins path
|
|
108
|
+
pins.select { |p| p.path == path }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def resolved?
|
|
112
|
+
@resolved
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @return [RBS::Repository]
|
|
116
|
+
def repository
|
|
117
|
+
@repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
|
|
118
|
+
@rbs_collection_paths.each do |dir|
|
|
119
|
+
dir_path = Pathname.new(dir)
|
|
120
|
+
repo.add(dir_path) if dir_path.exist? && dir_path.directory?
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# @param library [String]
|
|
126
|
+
# @return [RbsMap]
|
|
127
|
+
def self.load library
|
|
128
|
+
@@rbs_maps_hash[library] ||= RbsMap.new(library)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
# @return [RBS::EnvironmentLoader]
|
|
134
|
+
def loader
|
|
135
|
+
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# @return [Conversions]
|
|
139
|
+
def conversions
|
|
140
|
+
@conversions ||= Conversions.new(loader: loader)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @param loader [RBS::EnvironmentLoader]
|
|
144
|
+
# @param library [String]
|
|
145
|
+
# @param version [String, nil]
|
|
146
|
+
# @return [Boolean] true if adding the library succeeded
|
|
147
|
+
def add_library loader, library, version
|
|
148
|
+
@resolved = if loader.has_library?(library: library, version: version)
|
|
149
|
+
loader.add library: library, version: version
|
|
150
|
+
logger.debug { "#{short_name} successfully loaded library #{library}:#{version}" }
|
|
151
|
+
true
|
|
152
|
+
else
|
|
153
|
+
logger.info { "#{short_name} did not find data for library #{library}:#{version}" }
|
|
154
|
+
false
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# @return [String]
|
|
159
|
+
def short_name
|
|
160
|
+
self.class.name.split('::').last
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|