2
Cannot find type `Sinatra::Base`

红宝石文件

class StaticApp < Sinatra::Base
end  

.rbs 文件

class StaticApp < Sinatra::Base
end  

bundle exec steep check --log-level=fatal

结果

[error] Cannot find type `Sinatra::Base`
Diagnostic ID: RBS::UnknownTypeName 

我用steep宝石。似乎需要一些文件。但

library 'sinatra' 

不起作用。

#<RBS::EnvironmentLoader::UnknownLibraryError: Cannot find type definitions for library: sinatra ([nil])>

我错了什么?谢谢。

4

1 回答 1

0

但是library 'sinatra'不行。。 RBS::EnvironmentLoader::UnknownLibraryError

简短的回答

# Steepfile
target :app do
  repo_path 'vendor/rbs'

创建一个目录结构,如vendor/rbs/sinatra/0/sinatra.rbs.

您如何编写或生成内容sinatra.rbs超出了此答案的范围,但请查看gem_rbs_collection。Rails 人,请参阅rbs_rails

长答案

陡峭正在使用RBS::EnvironmentLoader.

# steep-0.47.0/lib/steep/project/target.rb:54
loader = RBS::EnvironmentLoader.new(core_root: core_root_path, repository: repo)
options.libraries.each do |lib|
  name, version = lib.split(/:/, 2)
  loader.add(library: name, version: version)
end

可以在其中找到EnvironmentLoader一个(我认为这将是一个分布在 gem 中的文件夹),或者在.librarygem_sig_pathsigrepository

# rbs-1.7.1/lib/rbs/environment_loader.rb:68
def has_library?(library:, version:)
  if self.class.gem_sig_path(library, version) || repository.lookup(library, version)
    true
  else
    false
  end
end

在 中Steepfile,存储库是通过 配置的repo_path

# Steepfile
repo_path 'vendor/rbs'

对于一个仓库的目录结构,我以https://github.com/ruby/rbs/tree/master/stdlib为例。

ls -R vendor/rbs
activesupport

vendor/rbs/activesupport:
0

vendor/rbs/activesupport/0:
activesupport.rbs
于 2021-12-12T05:59:06.027 回答