Class: Steep::Drivers::Langserver

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/langserver.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:) ⇒ Langserver

Returns a new instance of Langserver.



16
17
18
19
20
21
22
23
24
25
# File 'lib/steep/drivers/langserver.rb', line 16

def initialize(stdout:, stderr:, stdin:)
  @stdout = stdout
  @stderr = stderr
  @stdin = stdin
  @write_mutex = Mutex.new
  @type_check_queue = Queue.new
  @jobs_option = Utils::JobsOption.new(jobs_count_modifier: -1)
  @refork = false
  @command_socket = true
end

Instance Attribute Details

#command_socketObject

Returns the value of attribute command_socket.



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

def command_socket
  @command_socket
end

#jobs_optionObject (readonly)

Returns the value of attribute jobs_option.



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

def jobs_option
  @jobs_option
end

#reforkObject

Returns the value of attribute refork.



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

def refork
  @refork
end

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/steep/drivers/langserver.rb', line 5

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

#type_check_queueObject (readonly)

Returns the value of attribute type_check_queue.



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

def type_check_queue
  @type_check_queue
end

#type_check_threadObject (readonly)

Returns the value of attribute type_check_thread.



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

def type_check_thread
  @type_check_thread
end

#write_mutexObject (readonly)

Returns the value of attribute write_mutex.



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

def write_mutex
  @write_mutex
end

Instance Method Details

#projectObject



35
36
37
# File 'lib/steep/drivers/langserver.rb', line 35

def project
  @project or raise "Empty #project"
end

#readerObject



31
32
33
# File 'lib/steep/drivers/langserver.rb', line 31

def reader
  @reader ||= LanguageServer::Protocol::Transport::Io::Reader.new(stdin)
end

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/steep/drivers/langserver.rb', line 39

def run
  @project = load_config()

  interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: project.steepfile_path, steep_command: jobs_option.steep_command)
  typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: project.steepfile_path, args: [], steep_command: jobs_option.steep_command, count: jobs_option.jobs_count_value)

  master = Server::Master.new(
    project: project,
    reader: reader,
    writer: writer,
    interaction_worker: interaction_worker,
    typecheck_workers: typecheck_workers,
    refork: refork,
  )
  master.typecheck_automatically = true

  socket = start_command_socket(master)

  begin
    master.start()
  ensure
    socket&.stop
  end

  0
end

#start_command_socket(master) ⇒ Object

Starts accepting steep query/steep check connections on the UNIX socket

Returns nil when the command socket is disabled, is not supported on the platform, or is already served by another process.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/steep/drivers/langserver.rb', line 71

def start_command_socket(master)
  return nil unless command_socket

  configuration = Daemon::Configuration.new(base_dir: project.base_dir.to_s)
  socket = Server::CommandSocket.new(master: master, configuration: configuration)

  if socket.start
    stderr.puts "Steep command socket is ready: #{configuration.socket_path}"
    socket
  else
    stderr.puts "Steep command socket is not available: #{configuration.socket_path}"
    nil
  end
rescue NotImplementedError, StandardError => error
  Steep.logger.error { "Failed to start command socket: #{error.inspect}" }
  stderr.puts "Failed to start Steep command socket: #{error.message}"
  nil
end

#writerObject



27
28
29
# File 'lib/steep/drivers/langserver.rb', line 27

def writer
  @writer ||= LanguageServer::Protocol::Transport::Io::Writer.new(stdout)
end