Sha256: 67b950bf76ce0a80e112e82df3a8ad87b555f7db9f13dfb7e28c52d6fcde1a02

Contents?: true

Size: 1.89 KB

Versions: 17

Compression:

Stored size: 1.89 KB

Contents

module Steep
  module Server
    class WorkerProcess
      attr_reader :reader
      attr_reader :writer
      attr_reader :stderr

      attr_reader :wait_thread

      def initialize(reader:, writer:, stderr:, wait_thread:)
        @reader = reader
        @writer = writer
        @stderr = stderr
        @wait_thread = wait_thread
      end

      def self.spawn_worker(type, name:, steepfile:)
        log_level = %w(debug info warn error fatal unknown)[Steep.logger.level]
        command = case type
                  when :code
                    ["steep", "worker", "--code", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"]
                  when :signature
                    ["steep", "worker", "--signature", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"]
                  when :interaction
                    ["steep", "worker", "--interaction", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"]
                  else
                    raise
                  end

        stdin, stdout, thread = Open3.popen2(*command, pgroup: true)
        stderr = nil

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

        new(reader: reader, writer: writer, stderr: stderr, wait_thread: thread)
      end

      def self.spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max)
        count.times.map do |i|
          spawn_worker(:code, name: "code@#{i}", steepfile: steepfile)
        end
      end

      def <<(message)
        writer.write(message)
      end

      def read(&block)
        reader.read(&block)
      end

      def shutdown
        self << { method: :shutdown, params: nil }
        self << { method: :exit, params: nil }

        writer.io.close()
        @wait_thread.join()
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
steep-0.29.0 lib/steep/server/worker_process.rb
steep-0.28.0 lib/steep/server/worker_process.rb
steep-0.27.0 lib/steep/server/worker_process.rb
steep-0.25.0 lib/steep/server/worker_process.rb
steep-0.24.0 lib/steep/server/worker_process.rb
steep-0.23.0 lib/steep/server/worker_process.rb
steep-0.22.0 lib/steep/server/worker_process.rb
steep-0.21.0 lib/steep/server/worker_process.rb
steep-0.20.0 lib/steep/server/worker_process.rb
steep-0.19.0 lib/steep/server/worker_process.rb
steep-0.18.0 lib/steep/server/worker_process.rb
steep-0.17.1 lib/steep/server/worker_process.rb
steep-0.17.0 lib/steep/server/worker_process.rb
steep-0.16.3 lib/steep/server/worker_process.rb
steep-0.16.2 lib/steep/server/worker_process.rb
steep-0.16.1 lib/steep/server/worker_process.rb
steep-0.16.0 lib/steep/server/worker_process.rb