Class: Steep::Drivers::Stats
- Includes:
- Utils::DriverHelper
- Defined in:
- lib/steep/drivers/stats.rb
Defined Under Namespace
Classes: CSVPrinter, TablePrinter
Instance Attribute Summary collapse
-
#command_line_patterns ⇒ Object
readonly
Returns the value of attribute command_line_patterns.
-
#format ⇒ Object
Returns the value of attribute format.
-
#jobs_option ⇒ Object
readonly
Returns the value of attribute jobs_option.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Attributes included from Utils::DriverHelper
#disable_install_collection, #steepfile
Instance Method Summary collapse
-
#initialize(stdout:, stderr:) ⇒ Stats
constructor
A new instance of Stats.
- #run ⇒ Object
Methods included from Utils::DriverHelper
#install_collection, #keep_diagnostic?, #load_config, #request_id, #shutdown_exit, #wait_for_message, #wait_for_response_id
Constructor Details
#initialize(stdout:, stderr:) ⇒ Stats
Returns a new instance of Stats.
111 112 113 114 115 116 |
# File 'lib/steep/drivers/stats.rb', line 111 def initialize(stdout:, stderr:) @stdout = stdout @stderr = stderr @command_line_patterns = [] @jobs_option = Utils::JobsOption.new() end |
Instance Attribute Details
#command_line_patterns ⇒ Object (readonly)
Returns the value of attribute command_line_patterns.
105 106 107 |
# File 'lib/steep/drivers/stats.rb', line 105 def command_line_patterns @command_line_patterns end |
#format ⇒ Object
Returns the value of attribute format.
106 107 108 |
# File 'lib/steep/drivers/stats.rb', line 106 def format @format end |
#jobs_option ⇒ Object (readonly)
Returns the value of attribute jobs_option.
107 108 109 |
# File 'lib/steep/drivers/stats.rb', line 107 def jobs_option @jobs_option end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
104 105 106 |
# File 'lib/steep/drivers/stats.rb', line 104 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
103 104 105 |
# File 'lib/steep/drivers/stats.rb', line 103 def stdout @stdout end |
Instance Method Details
#run ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/steep/drivers/stats.rb', line 118 def run project = load_config() stderr.puts Rainbow("# Calculating stats:").bold stderr.puts client_read, server_write = IO.pipe server_read, client_write = IO.pipe client_reader = LanguageServer::Protocol::Transport::Io::Reader.new(client_read) client_writer = LanguageServer::Protocol::Transport::Io::Writer.new(client_write) server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read) server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write) typecheck_workers = Server::WorkerProcess.start_typecheck_workers( steepfile: project.steepfile_path, delay_shutdown: true, args: command_line_patterns, steep_command: jobs_option.steep_command, count: jobs_option.jobs_count_value ) master = Server::Master.new( project: project, reader: server_reader, writer: server_writer, interaction_worker: nil, typecheck_workers: typecheck_workers ) master.typecheck_automatically = false master.commandline_args.push(*command_line_patterns) main_thread = Thread.start do Thread.current.abort_on_exception = true master.start() end initialize_id = request_id() client_writer.write({ method: :initialize, id: initialize_id, params: DEFAULT_CLI_LSP_INITIALIZE_PARAMS }) wait_for_response_id(reader: client_reader, id: initialize_id) typecheck_guid = SecureRandom.uuid master.job_queue << -> do Steep.logger.info { "Type checking for stats..." } progress = master.work_done_progress(typecheck_guid) master.start_type_check(last_request: nil, progress: progress, include_unchanged: true, report_progress_threshold: 0, needs_response: true) end (reader: client_reader) do || [:id] == typecheck_guid end Steep.logger.info { "Finished type checking for stats" } stats_id = request_id() client_writer.write(Server::CustomMethods::Stats.request(stats_id)) stats_response = wait_for_response_id(reader: client_reader, id: stats_id) stats_result = stats_response[:result] #: Server::CustomMethods::Stats::result shutdown_exit(reader: client_reader, writer: client_writer) main_thread.join() printer = case format when "csv" CSVPrinter.new(io: stdout) when "table" TablePrinter.new(io: stdout) when nil if stdout.tty? TablePrinter.new(io: stdout) else CSVPrinter.new(io: stdout) end else raise ArgumentError.new("Invalid format: #{format}") end printer.print(stats_result) 0 end |