Module: Steep::Drivers::Utils::DriverHelper
- Included in:
- Annotations, Check, Checkfile, Init, Langserver, PrintProject, Stats, Watch, Worker
- Defined in:
- lib/steep/drivers/utils/driver_helper.rb
Instance Attribute Summary collapse
-
#disable_install_collection ⇒ Object
Returns the value of attribute disable_install_collection.
-
#steepfile ⇒ Object
Returns the value of attribute steepfile.
Instance Method Summary collapse
- #install_collection(target, config_path) ⇒ Object
- #keep_diagnostic?(diagnostic, severity_level:) ⇒ Boolean
- #load_config(path: steepfile || Pathname("Steepfile")) ⇒ Object
- #request_id ⇒ Object
- #shutdown_exit(writer:, reader:) ⇒ Object
- #wait_for_message(reader:, unknown_messages: :ignore, &block) ⇒ Object
- #wait_for_response_id(reader:, id:, unknown_responses: nil, &block) ⇒ Object
Instance Attribute Details
#disable_install_collection ⇒ Object
Returns the value of attribute disable_install_collection.
6 7 8 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 6 def disable_install_collection @disable_install_collection end |
#steepfile ⇒ Object
Returns the value of attribute steepfile.
5 6 7 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 5 def steepfile @steepfile end |
Instance Method Details
#install_collection(target, config_path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 52 def install_collection(target, config_path) Steep.ui_logger.info { "Installing RBS files for collection: #{config_path}" } lockfile_path = RBS::Collection::Config.to_lockfile_path(config_path) io = StringIO.new begin RBS::Collection::Installer.new(lockfile_path: lockfile_path, stdout: io).install_from_lockfile() target..load_collection_lock(force: true) Steep.ui_logger.debug { "Finished setting up RBS collection: " + io.string } result = target..load_collection_lock(force: true) unless result.is_a?(RBS::Collection::Config::Lockfile) raise "Failed to set up RBS collection: #{result.inspect}" end rescue => exn Steep.ui_logger.error { "Failed to set up RBS collection: #{exn.inspect}" } end end |
#keep_diagnostic?(diagnostic, severity_level:) ⇒ Boolean
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 124 def keep_diagnostic?(diagnostic, severity_level:) severity = diagnostic[:severity] case severity_level when nil, :hint true when :error severity <= LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR when :warning severity <= LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING when :information severity <= LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION end end |
#load_config(path: steepfile || Pathname("Steepfile")) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 8 def load_config(path: steepfile || Pathname("Steepfile")) if path.file? steep_file_path = path.absolute? ? path : Pathname.pwd + path Project.new(steepfile_path: steep_file_path).tap do |project| Project::DSL.parse(project, path.read, filename: path.to_s) end else Steep.ui_logger.error { "Cannot find a configuration at #{path}: `steep init` to scaffold. Using current directory..." } Project.new(steepfile_path: nil, base_dir: Pathname.pwd).tap do |project| Project::DSL.eval(project) do target :'.' do check '.' signature '.' end end end end.tap do |project| project.targets.each do |target| case result = target..load_collection_lock when nil, RBS::Collection::Config::Lockfile # ok when Pathname # File is missing if result == target..collection_config_path # Config file is missing Steep.ui_logger.error { "rbs-collection configuration is missing: `#{result}`" } else # Lockfile is missing Steep.ui_logger.error { "Run `rbs collection install` to generate missing lockfile: `#{result}`" } end when YAML::SyntaxError # File is broken Steep.ui_logger.error { "rbs-collection setup is broken:\nsyntax error #{result.inspect}" } when RBS::Collection::Config::CollectionNotAvailable unless disable_install_collection install_collection(target, target..collection_config_path || raise) else Steep.ui_logger.error { "Run `rbs collection install` to set up RBS files for gems" } end end end end end |
#request_id ⇒ Object
70 71 72 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 70 def request_id SecureRandom.alphanumeric(10) end |
#shutdown_exit(writer:, reader:) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 99 def shutdown_exit(writer:, reader:) request_id().tap do |id| writer.write({ method: :shutdown, id: id }) wait_for_response_id(reader: reader, id: id) end writer.write({ method: :exit }) end |
#wait_for_message(reader:, unknown_messages: :ignore, &block) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 107 def (reader:, unknown_messages: :ignore, &block) reader.read do || if yield() return else case when :ignore # nop when :log Steep.logger.error { "Unexpected message: #{.inspect}" } when :raise raise "Unexpected message: #{.inspect}" end end end end |
#wait_for_response_id(reader:, id:, unknown_responses: nil, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/steep/drivers/utils/driver_helper.rb', line 74 def wait_for_response_id(reader:, id:, unknown_responses: nil, &block) reader.read do || Steep.logger.debug { "Received message waiting for #{id}: #{.inspect}" } response_id = [:id] if response_id == id return end if block yield else case unknown_responses when :ignore, nil # nop when :log Steep.logger.error { "Unexpected message: #{.inspect}" } when :raise raise "Unexpected message: #{.inspect}" end end end end |