class Standard::Lsp::Routes
def self.handle(name, &block)
def self.handle(name, &block) define_method(:"handle_#{name}", &block) end
def diagnostic(file_uri, text)
def diagnostic(file_uri, text) @text_cache[file_uri] = text { method: "textDocument/publishDiagnostics", params: { uri: file_uri, diagnostics: @standardizer.offenses(uri_to_path(file_uri), text) } } end
def for(name)
def for(name) name = "handle_#{name}" if respond_to?(name) method(name) end end
def format_file(file_uri)
def format_file(file_uri) text = @text_cache[file_uri] if text.nil? @logger.puts "Format request arrived before text synchonized; skipping: `#{file_uri}'" [] else new_text = @standardizer.format(uri_to_path(file_uri), text) if new_text == text [] else [{ newText: new_text, range: { start: {line: 0, character: 0}, end: {line: text.count("\n") + 1, character: 0} } }] end end end
def handle_method_missing(request)
def handle_method_missing(request) if request.key?(:id) @writer.write({id: request[:id], result: nil}) end end
def handle_unsupported_method(request, method = request[:method])
def handle_unsupported_method(request, method = request[:method]) @writer.write({id: request[:id], error: Proto::Interface::ResponseError.new( code: Proto::Constant::ErrorCodes::METHOD_NOT_FOUND, message: "Unsupported Method: #{method}" )}) @logger.puts "Unsupported Method: #{method}" end
def initialize(writer, logger, standardizer)
def initialize(writer, logger, standardizer) @writer = writer @logger = logger @standardizer = standardizer @text_cache = {} @kills_server = KillsServer.new end
def uri_to_path(uri)
def uri_to_path(uri) uri.sub(%r{^file://}, "") end