Class: Solargraph::LanguageServer::Message::Extended::CheckGemVersion
- 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.
Instance Attribute Summary
Attributes inherited from Base
#error, #host, #id, #method, #params, #request, #result
Instance Method Summary collapse
Methods inherited from Base
#initialize, #post_initialize, #send_response, #set_error, #set_result
Constructor Details
This class inherits a constructor from Solargraph::LanguageServer::Message::Base
Instance Method Details
#process ⇒ Object
12 13 14 15 16 17 18 19 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 47 48 |
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 12 def process begin fetcher = Gem::SpecFetcher.new tuple = fetcher.search_for_dependency(Gem::Dependency.new('solargraph')).flatten.first if tuple.nil? msg = "An error occurred checking the Solargraph gem version." STDERR.puts msg host.(msg, MessageTypes::ERROR) if params['verbose'] else available = Gem::Version.new(tuple.version) current = Gem::Version.new(Solargraph::VERSION) if available > current host. "Solagraph gem version #{available} is available.", LanguageServer::MessageTypes::INFO, ['Update now'] do |result| break unless result == 'Update now' o, s = Open3.capture2("gem update solargraph") if s == 0 host. 'Successfully updated the Solargraph gem.', LanguageServer::MessageTypes::INFO else host. 'An error occurred while updating the gem.', LanguageServer::MessageTypes::ERROR end end elsif params['verbose'] host. "The Solargraph gem is up to date (version #{Solargraph::VERSION})." end set_result({ installed: current, available: available }) end rescue Errno::EADDRNOTAVAIL => e msg = "Unable to connect to gem source: #{e.}" STDERR.puts msg host.(msg, MessageTypes::ERROR) if params['verbose'] end end |