Class: Steep::Drivers::Worker

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/worker.rb

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#disable_install_collection, #steepfile

Instance Method Summary collapse

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:, stdin:) ⇒ Worker

Returns a new instance of Worker.



16
17
18
19
20
21
# File 'lib/steep/drivers/worker.rb', line 16

def initialize(stdout:, stderr:, stdin:)
  @stdout = stdout
  @stderr = stderr
  @stdin = stdin
  @commandline_args = []
end

Instance Attribute Details

#commandline_argsObject

Returns the value of attribute commandline_args.



11
12
13
# File 'lib/steep/drivers/worker.rb', line 11

def commandline_args
  @commandline_args
end

#delay_shutdownObject

Returns the value of attribute delay_shutdown.



8
9
10
# File 'lib/steep/drivers/worker.rb', line 8

def delay_shutdown
  @delay_shutdown
end

#indexObject

Returns the value of attribute index.



10
11
12
# File 'lib/steep/drivers/worker.rb', line 10

def index
  @index
end

#io_socketObject

Returns the value of attribute io_socket.



12
13
14
# File 'lib/steep/drivers/worker.rb', line 12

def io_socket
  @io_socket
end

#max_indexObject

Returns the value of attribute max_index.



9
10
11
# File 'lib/steep/drivers/worker.rb', line 9

def max_index
  @max_index
end

#stderrObject (readonly)

Returns the value of attribute stderr.



4
5
6
# File 'lib/steep/drivers/worker.rb', line 4

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



4
5
6
# File 'lib/steep/drivers/worker.rb', line 4

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/steep/drivers/worker.rb', line 4

def stdout
  @stdout
end

#worker_nameObject

Returns the value of attribute worker_name.



7
8
9
# File 'lib/steep/drivers/worker.rb', line 7

def worker_name
  @worker_name
end

#worker_typeObject

Returns the value of attribute worker_type.



6
7
8
# File 'lib/steep/drivers/worker.rb', line 6

def worker_type
  @worker_type
end

Instance Method Details

#runObject



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
51
52
53
54
55
56
57
# File 'lib/steep/drivers/worker.rb', line 23

def run()
  Steep.logger.tagged("#{worker_type}:#{worker_name}") do
    project = load_config()

    reader = LanguageServer::Protocol::Transport::Io::Reader.new(stdin)
    writer = LanguageServer::Protocol::Transport::Io::Writer.new(stdout)

    worker = case worker_type
             when :typecheck
               assignment = Services::PathAssignment.new(max_index: max_index, index: index)
               Server::TypeCheckWorker.new(project: project,
                                           reader: reader,
                                           writer: writer,
                                           io_socket:,
                                           assignment: assignment,
                                           commandline_args: commandline_args)
             when :interaction
               Server::InteractionWorker.new(project: project, reader: reader, writer: writer)
             else
               raise "Unknown worker type: #{worker_type}"
             end

    unless delay_shutdown
      worker.skip_jobs_after_shutdown!
    end

    Steep.logger.info "Starting #{worker_type} worker..."

    worker.run()
  rescue Interrupt
    Steep.logger.info "Shutting down by interrupt..."
  end

  0
end