5
Cannot find type `Sinatra::Base`

ruby file

class StaticApp < Sinatra::Base
end  

rbs file

class StaticApp < Sinatra::Base
end  

run

bundle exec steep check --log-level=fatal

result

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

I use steep gem. It seems it is needed to require some files. But

library 'sinatra' 

doesn't work.

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

What do I wrong? Thanks.

Jared Beck
  • 16,796
  • 9
  • 72
  • 97
gayavat
  • 18,910
  • 11
  • 45
  • 55
  • When creating a new tag, would you mind also providing a [guidance and tag wiki](https://stackoverflow.com/edit-tag-wiki/152892) for it? Esp. since "steep" can have various meanings. – Gert Arnold Sep 22 '21 at 19:07
  • @GertArnold, done. https://stackoverflow.com/edit-tag-wiki/152892 But it seems cached – gayavat Sep 23 '21 at 05:44

1 Answers1

3

But library 'sinatra' doesn't work .. RBS::EnvironmentLoader::UnknownLibraryError

Short answer

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

Create a directory structure like vendor/rbs/sinatra/0/sinatra.rbs.

How you write or generate the contents of sinatra.rbs is out of the scope of this answer, but check out:

Long answer

Steep is using an 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

The EnvironmentLoader can find a library in either gem_sig_path (I think this would be a sig folder distributed in the gem), or in a repository.

# 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

In a Steepfile, repositories are configured via repo_path.

# Steepfile
repo_path 'vendor/rbs'

For the directory structure of a repository, I took https://github.com/ruby/rbs/tree/master/stdlib as an example.

ls -R vendor/rbs
activesupport

vendor/rbs/activesupport:
0

vendor/rbs/activesupport/0:
activesupport.rbs
Jared Beck
  • 16,796
  • 9
  • 72
  • 97