Sha256: 6d076e558536cf496ec5d40d22c63c3633ac325c698d99d802051ae0769e81f8

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Steep
  module Server
    class BaseWorker
      LSP = LanguageServer::Protocol

      include Utils

      attr_reader :project
      attr_reader :reader, :writer

      def initialize(project:, reader:, writer:)
        @project = project
        @reader = reader
        @writer = writer
        @shutdown = false
      end

      def handle_request(request)
        # process request
      end

      def handle_job(job)
        # process async job
      end

      def run
        tags = Steep.logger.formatter.current_tags.dup
        thread = Thread.new do
          Steep.logger.formatter.push_tags(*tags)
          Steep.logger.tagged "background" do
            while job = queue.pop
              handle_job(job) unless @shutdown
            end
          end
        end

        Steep.logger.tagged "frontend" do
          begin
            reader.read do |request|
              case request[:method]
              when "shutdown"
                @shutdown = true
              when "exit"
                break
              else
                handle_request(request) unless @shutdown
              end
            end
          ensure
            queue << nil
            thread.join
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
steep-0.27.0 lib/steep/server/base_worker.rb