Module: Ibex::CLILSP

Defined in:
lib/ibex/cli/lsp.rb,
sig/ibex/cli/lsp.rbs

Overview

CLI boundary for the stdio-only language server.

Instance Method Summary collapse

Instance Method Details

#lsp_option_parser(settings) ⇒ OptionParser

RBS:

  • (Hash[Symbol, bool] settings) -> OptionParser

Parameters:

  • settings (Hash[Symbol, bool])

Returns:

  • (OptionParser)


25
26
27
28
29
30
31
# File 'lib/ibex/cli/lsp.rb', line 25

def lsp_option_parser(settings)
  OptionParser.new do |options|
    options.banner = "Usage: ibex lsp [--stdio]"
    options.on("--stdio", "use Content-Length framed JSON-RPC on standard IO") { settings[:stdio] = true }
    options.on("--help", "show help") { settings[:help] = true }
  end
end

#run_lsp_command(arguments) ⇒ Integer

RBS:

  • (Array[String] arguments) -> Integer

Parameters:

  • arguments (Array[String])

Returns:

  • (Integer)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ibex/cli/lsp.rb', line 11

def run_lsp_command(arguments)
  settings = { help: false, stdio: false } #: Hash[Symbol, bool]
  remaining = lsp_option_parser(settings).parse(arguments)
  raise Ibex::Error, "(cli):1:1: ibex lsp does not accept file arguments" unless remaining.empty?

  if settings.fetch(:help)
    @stdout.puts(lsp_option_parser(settings))
    return 0
  end

  LSP::Server.new(stdin: @stdin, stdout: @stdout, stderr: @stderr).run
end