@@ -13,15 +13,52 @@ module SorbetHelper
1313
1414 SPOOM_CONTEXT = Spoom ::Context . new ( "." ) #: Spoom::Context
1515
16+ # Represents the `sorbet/config` file, and provides access to its options.
17+ # If the file doesn't exist, this object will still exist, but will return default values for all options.
18+ class SorbetConfig
19+ #: (spoom_context: Spoom::Context) -> void
20+ def initialize ( spoom_context :)
21+ config_path = File . join ( spoom_context . absolute_path , "sorbet" , "config" )
22+ lines = File . exist? ( config_path ) ? File . read ( config_path ) . lines . map ( &:strip ) . reject ( &:empty? ) : [ ]
23+
24+ options = lines . filter_map do |line |
25+ next if line . start_with? ( "#" ) # Skip comments
26+ next unless line . start_with? ( "--" )
27+
28+ key , value = line . split ( "=" , 2 )
29+ key = key #: as !nil
30+
31+ [ key , value ]
32+ end . to_h #: Hash[String, String | bool | nil]
33+
34+ @parser = options [ "--parser" ] == "prism" ? :prism : :original #: Symbol
35+ end
36+
37+ #: Symbol
38+ attr_reader :parser
39+
40+ #: -> bool
41+ def parse_with_prism? = @parser == :prism
42+ end
43+
1644 FEATURE_REQUIREMENTS = {
1745 # feature_name: ::Gem::Requirement.new(">= ___"), # https://github.com/sorbet/sorbet/pull/___
1846 } . freeze #: Hash[Symbol, ::Gem::Requirement]
1947
2048 #: (*String sorbet_args) -> Spoom::ExecResult
2149 def sorbet ( *sorbet_args )
50+ if sorbet_config . parse_with_prism?
51+ sorbet_args << "--parser=prism"
52+ end
53+
2254 SPOOM_CONTEXT . srb ( sorbet_args . join ( " " ) , sorbet_bin : sorbet_path )
2355 end
2456
57+ #: -> SorbetConfig
58+ def sorbet_config
59+ @sorbet_config ||= SorbetConfig . new ( spoom_context : SPOOM_CONTEXT ) #: SorbetConfig?
60+ end
61+
2562 #: -> String
2663 def sorbet_path
2764 sorbet_path = ENV . fetch ( SORBET_EXE_PATH_ENV_VAR , SORBET_BIN )
0 commit comments