Class: Solargraph::RbsMap
- Inherits:
-
Object
- Object
- Solargraph::RbsMap
- Includes:
- Logging
- Defined in:
- lib/solargraph/rbs_map.rb,
lib/solargraph/rbs_map/core_map.rb,
lib/solargraph/rbs_map/core_fills.rb,
lib/solargraph/rbs_map/stdlib_map.rb,
lib/solargraph/rbs_map/conversions.rb
Direct Known Subclasses
Defined Under Namespace
Modules: CoreFills Classes: Conversions, CoreMap, StdlibMap
Constant Summary collapse
- CACHE_KEY_GEM_EXPORT =
'gem-export'- CACHE_KEY_UNRESOLVED =
'unresolved'- CACHE_KEY_STDLIB =
'stdlib'- CACHE_KEY_LOCAL =
'local'- @@rbs_maps_hash =
{}
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
Returns the value of attribute library.
-
#rbs_collection_config_path ⇒ Object
readonly
Returns the value of attribute rbs_collection_config_path.
-
#rbs_collection_paths ⇒ Object
readonly
Returns the value of attribute rbs_collection_paths.
Class Method Summary collapse
- .from_gemspec(gemspec, rbs_collection_path, rbs_collection_config_path) ⇒ RbsMap
- .load(library) ⇒ RbsMap
-
.rbs_source_desc(cache_key) ⇒ String?
A description of the source of the RBS info.
Instance Method Summary collapse
-
#cache_key ⇒ String
Representing the version of the RBS info fetched for the given library.
-
#initialize(library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: [], out: $stderr) ⇒ RbsMap
constructor
A new instance of RbsMap.
- #loader ⇒ RBS::EnvironmentLoader
-
#path_pin(path, klass = Pin::Base) ⇒ generic<T>?
@sg-ignore Need to be able to resolve generics based on a Class<generic<T>> param.
- #path_pins(path) ⇒ Array<Pin::Base>
- #pins(out: $stderr) ⇒ Array<Pin::Base>
- #repository ⇒ RBS::Repository
- #resolved? ⇒ Boolean
Methods included from Logging
Constructor Details
#initialize(library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: [], out: $stderr) ⇒ RbsMap
Returns a new instance of RbsMap.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/solargraph/rbs_map.rb', line 26 def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: [], out: $stderr if rbs_collection_config_path.nil? && !rbs_collection_paths.empty? raise 'Please provide rbs_collection_config_path if you provide rbs_collection_paths' end @library = library @version = version @rbs_collection_config_path = rbs_collection_config_path @rbs_collection_paths = rbs_collection_paths add_library loader, library, version end |
Instance Attribute Details
#library ⇒ Object (readonly)
Returns the value of attribute library.
19 20 21 |
# File 'lib/solargraph/rbs_map.rb', line 19 def library @library end |
#rbs_collection_config_path ⇒ Object (readonly)
Returns the value of attribute rbs_collection_config_path.
19 20 21 |
# File 'lib/solargraph/rbs_map.rb', line 19 def rbs_collection_config_path @rbs_collection_config_path end |
#rbs_collection_paths ⇒ Object (readonly)
Returns the value of attribute rbs_collection_paths.
19 20 21 |
# File 'lib/solargraph/rbs_map.rb', line 19 def rbs_collection_paths @rbs_collection_paths end |
Class Method Details
.from_gemspec(gemspec, rbs_collection_path, rbs_collection_config_path) ⇒ RbsMap
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/solargraph/rbs_map.rb', line 108 def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path # prefers stdlib RBS if available rbs_map = RbsMap::StdlibMap.new(gemspec.name) return rbs_map if rbs_map.resolved? rbs_map = RbsMap.new(gemspec.name, gemspec.version, rbs_collection_paths: [rbs_collection_path].compact, rbs_collection_config_path: rbs_collection_config_path) return rbs_map if rbs_map.resolved? # try any version of the gem in the collection RbsMap.new(gemspec.name, nil, rbs_collection_paths: [rbs_collection_path].compact, rbs_collection_config_path: rbs_collection_config_path) end |
.load(library) ⇒ RbsMap
168 169 170 |
# File 'lib/solargraph/rbs_map.rb', line 168 def self.load library @@rbs_maps_hash[library] ||= RbsMap.new(library) end |
.rbs_source_desc(cache_key) ⇒ String?
Returns a description of the source of the RBS info.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/solargraph/rbs_map.rb', line 44 def self.rbs_source_desc cache_key case cache_key when CACHE_KEY_GEM_EXPORT 'RBS gem export' when CACHE_KEY_UNRESOLVED nil when CACHE_KEY_STDLIB 'RBS standard library' when CACHE_KEY_LOCAL 'local RBS shims' else 'RBS collection' end end |
Instance Method Details
#cache_key ⇒ String
Returns representing the version of the RBS info fetched for the given library. Must change when the RBS info is updated upstream for the same library and version. May change if the config for where information comes form changes.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/solargraph/rbs_map.rb', line 68 def cache_key return CACHE_KEY_UNRESOLVED unless resolved? @cache_key ||= begin # @type [String, nil] data = nil # @type gem_config [nil, Hash{String => Hash{String => String}}] gem_config = nil if rbs_collection_config_path # @sg-ignore rbs_collection_config_path is not nil here lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path)) if lockfile_path.exist? collection_config = RBS::Collection::Config.from_path lockfile_path gem_config = collection_config.gem(library) data = gem_config&.to_s end end if gem_config.nil? CACHE_KEY_STDLIB else # @type [String] source = gem_config.dig('source', 'type') case source when 'rubygems' CACHE_KEY_GEM_EXPORT when 'local' CACHE_KEY_LOCAL when 'stdlib' CACHE_KEY_STDLIB else Digest::SHA1.hexdigest(data || '') end end end end |
#loader ⇒ RBS::EnvironmentLoader
60 61 62 |
# File 'lib/solargraph/rbs_map.rb', line 60 def loader @loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository) end |
#path_pin(path, klass = Pin::Base) ⇒ generic<T>?
@sg-ignore Need to be able to resolve generics based on a
Class<generic<T>> param
141 142 143 144 |
# File 'lib/solargraph/rbs_map.rb', line 141 def path_pin path, klass = Pin::Base pin = pins.find { |p| p.path == path } pin if pin.is_a?(klass) end |
#path_pins(path) ⇒ Array<Pin::Base>
148 149 150 |
# File 'lib/solargraph/rbs_map.rb', line 148 def path_pins path pins.select { |p| p.path == path } end |
#pins(out: $stderr) ⇒ Array<Pin::Base>
126 127 128 129 130 131 132 |
# File 'lib/solargraph/rbs_map.rb', line 126 def pins out: $stderr @pins ||= if resolved? conversions.pins else [] end end |
#repository ⇒ RBS::Repository
157 158 159 160 161 162 163 164 |
# File 'lib/solargraph/rbs_map.rb', line 157 def repository @repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo| @rbs_collection_paths.each do |dir| dir_path = Pathname.new(dir) repo.add(dir_path) if dir_path.exist? && dir_path.directory? end end end |
#resolved? ⇒ Boolean
152 153 154 |
# File 'lib/solargraph/rbs_map.rb', line 152 def resolved? @resolved end |