Class: RubyLsp::RbsRails::Addon

Inherits:
Addon
  • Object
show all
Includes:
LanguageServer::Protocol::Constant
Defined in:
lib/ruby_lsp/rbs_rails/addon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#global_stateObject (readonly)

: GlobalState



14
15
16
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 14

def global_state
  @global_state
end

#loggerObject (readonly)

: Logger



15
16
17
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 15

def logger
  @logger
end

Instance Method Details

#activate(global_state, message_queue) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 19

def activate(global_state, message_queue) #: void
  @global_state = global_state
  @logger = Logger.new(message_queue)

  load_application
  load_rbs_rails_config
rescue LoadError
  logger.info("Rails application not found. Skip to activate rbs_rails addon.")
end

#deactivateObject

: void



29
30
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 29

def deactivate #: void
end

#nameObject

: String



32
33
34
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 32

def name #: String
  "ruby-lsp-rbs_rails"
end

#versionObject

: String



36
37
38
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 36

def version #: String
  VERSION
end

#workspace_did_change_watched_files(changes) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby_lsp/rbs_rails/addon.rb', line 41

def workspace_did_change_watched_files(changes) #: void
  return unless defined?(::Rails)

  ::Rails.application.reloader.wrap do
    changes.each do |change|
      case change[:type]
      when FileChangeType::CREATED, FileChangeType::CHANGED
        generate_signature(change[:uri])
      when FileChangeType::DELETED
        delete_signature(change[:uri])
      end
    end
  end
end