Class: Solargraph::LanguageServer::Message::Extended::CheckGemVersion

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/language_server/message/extended/check_gem_version.rb

Overview

Check if a more recent version of the Solargraph gem is available. Notify the client when an update exists. If the `verbose` parameter is true, notify the client when the gem is up to date.

Constant Summary collapse

GEM_ZERO =
Gem::Version.new('0.0.0')

Instance Attribute Summary

Attributes inherited from Base

#host, #id, #method, #params, #request, #result

Instance Method Summary collapse

Methods inherited from Base

#post_initialize, #send_response, #set_error, #set_result

Constructor Details

#initialize(host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil) ⇒ CheckGemVersion


14
15
16
17
18
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 14

def initialize host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil
  super(host, request)
  @current = current
  @available = available
end

Instance Method Details

#processObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 20

def process
  if available > GEM_ZERO
    if available > current
      host.show_message_request "Solargraph gem version #{available} is available. (Current version: #{current})",
                                LanguageServer::MessageTypes::INFO,
                                ['Update now'] do |result|
                                  next unless result == 'Update now'
                                  o, s = Open3.capture2("gem update solargraph")
                                  if s == 0
                                    host.show_message 'Successfully updated the Solargraph gem.', LanguageServer::MessageTypes::INFO
                                    host.send_notification '$/solargraph/restart', {}
                                  else
                                    host.show_message 'An error occurred while updating the gem.', LanguageServer::MessageTypes::ERROR
                                  end
                                end
    elsif params['verbose']
      host.show_message "The Solargraph gem is up to date (version #{Solargraph::VERSION})."
    end
  elsif fetched?
    Solargraph::Logging.logger.warn error
    host.show_message(error, MessageTypes::ERROR) if params['verbose']
  end
  set_result({
    installed: current,
    available: available
  })
end