Module: RuboCop::Server Private

Defined in:
lib/rubocop/server.rb,
lib/rubocop/server/cli.rb,
lib/rubocop/server/core.rb,
lib/rubocop/server/cache.rb,
lib/rubocop/server/errors.rb,
lib/rubocop/server/helper.rb,
lib/rubocop/server/socket_reader.rb,
lib/rubocop/server/client_command.rb,
lib/rubocop/server/server_command.rb,
lib/rubocop/server/client_command/base.rb,
lib/rubocop/server/client_command/exec.rb,
lib/rubocop/server/client_command/stop.rb,
lib/rubocop/server/server_command/base.rb,
lib/rubocop/server/server_command/exec.rb,
lib/rubocop/server/server_command/stop.rb,
lib/rubocop/server/client_command/start.rb,
lib/rubocop/server/client_command/status.rb,
lib/rubocop/server/client_command/restart.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

The bootstrap module for server.

Defined Under Namespace

Modules: ClientCommand, Helper, ServerCommand Classes: CLI, Cache, Core, InvalidTokenError, ServerStopRequest, SocketReader, UnknownServerCommandError

Constant Summary collapse

TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

20
IN_PROCESS_PROTOCOL_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Options that start a long-lived protocol server on stdio in the current process. They must never be forwarded to the server process, which would run them as a lint request and silently produce no protocol response.

%w[--lsp --mcp].freeze

Class Method Summary collapse

Class Method Details

.forward_to_server?(argv = ARGV) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether the invocation should be forwarded to the running server process. --lsp and --mcp always run in the current process even when the server is running: they serve a protocol on stdio, which the server's exec command cannot do.

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/rubocop/server.rb', line 47

def forward_to_server?(argv = ARGV)
  return false unless running?

  (IN_PROCESS_PROTOCOL_OPTIONS & argv).empty?
end

.running?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/rubocop/server.rb', line 38

def running?
  return false unless support_server? # Never running.

  Cache.pid_running?
end

.support_server?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


34
35
36
# File 'lib/rubocop/server.rb', line 34

def support_server?
  RUBY_ENGINE == 'ruby' && !RuboCop::Platform.windows?
end

.wait_for_running_status!(expected) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
59
60
61
62
# File 'lib/rubocop/server.rb', line 53

def wait_for_running_status!(expected)
  start_time = Time.now
  while Server.running? != expected
    sleep 0.1
    next unless Time.now - start_time > TIMEOUT

    warn "running? was not #{expected} after #{TIMEOUT} seconds!"
    exit 1
  end
end