class RuboCop::LSP::Routes
Routes
for Language Server
Protocol of RuboCop
. @api private
Constants
- CONFIGURATION_FILE_PATTERNS
Public Class Methods
Source
# File lib/rubocop/lsp/routes.rb, line 30 def initialize(server) @server = server @text_cache = {} end
Private Class Methods
Source
# File lib/rubocop/lsp/routes.rb, line 24 def self.handle(name, &block) define_method(:"handle_#{name}", &block) end
Public Instance Methods
Source
# File lib/rubocop/lsp/routes.rb, line 36 def for(name) name = "handle_#{name}" return unless respond_to?(name) method(name) end
Source
# File lib/rubocop/lsp/routes.rb, line 172 def handle_method_missing(request) return unless request.key?(:id) @server.write(id: request[:id], result: nil) end
Source
# File lib/rubocop/lsp/routes.rb, line 161 def handle_unsupported_method(request, method = request[:method]) @server.write( id: request[:id], error: LanguageServer::Protocol::Interface::ResponseError.new( code: LanguageServer::Protocol::Constant::ErrorCodes::METHOD_NOT_FOUND, message: "Unsupported Method: #{method}" ) ) Logger.log("Unsupported Method: #{method}") end
Private Instance Methods
Source
# File lib/rubocop/lsp/routes.rb, line 210 def diagnostic(file_uri, text) @text_cache[file_uri] = text { method: 'textDocument/publishDiagnostics', params: { uri: file_uri, diagnostics: @server.offenses(remove_file_protocol_from(file_uri), text) } } end
Source
# File lib/rubocop/lsp/routes.rb, line 180 def extract_initialization_options_from(request) safe_autocorrect = request.dig(:params, :initializationOptions, :safeAutocorrect) { safe_autocorrect: safe_autocorrect.nil? || safe_autocorrect == true, lint_mode: request.dig(:params, :initializationOptions, :lintMode) == true, layout_mode: request.dig(:params, :initializationOptions, :layoutMode) == true } end
Source
# File lib/rubocop/lsp/routes.rb, line 190 def format_file(file_uri, command: nil) unless (text = @text_cache[file_uri]) Logger.log("Format request arrived before text synchronized; skipping: `#{file_uri}'") return [] end new_text = @server.format(remove_file_protocol_from(file_uri), text, command: command) return [] if new_text == text [ newText: new_text, range: { start: { line: 0, character: 0 }, end: { line: text.count("\n") + 1, character: 0 } } ] end
Source
# File lib/rubocop/lsp/routes.rb, line 222 def remove_file_protocol_from(uri) uri.delete_prefix('file://') end