Class: RubyLsp::Typeprof::Addon

Inherits:
Addon
  • Object
show all
Defined in:
lib/ruby_lsp/ruby_lsp_typeprof/addon.rb

Instance Method Summary collapse

Constructor Details

#initializeAddon

Returns a new instance of Addon.



12
13
14
15
16
17
# File 'lib/ruby_lsp/ruby_lsp_typeprof/addon.rb', line 12

def initialize
  super
  @service = nil
  @mutex = Mutex.new
  @code_lens_enabled = true
end

Instance Method Details

#activate(global_state, _outgoing_queue) ⇒ Object



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

def activate(global_state, _outgoing_queue)
  require "typeprof"

  settings = global_state.settings_for_addon(name)
  @code_lens_enabled = settings&.dig(:enableCodeLens) != false
  @service = build_service(global_state.workspace_path)
rescue StandardError => e
  warn "ruby-lsp-typeprof: Failed to activate: #{e.message}"
end

#create_code_lens_listener(response_builder, uri, dispatcher) ⇒ Object



41
42
43
44
45
46
# File 'lib/ruby_lsp/ruby_lsp_typeprof/addon.rb', line 41

def create_code_lens_listener(response_builder, uri, dispatcher)
  return unless @service
  return unless @code_lens_enabled

  CodeLensListener.new(response_builder, uri, dispatcher, @service, @mutex)
end

#deactivateObject



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

def deactivate
  @service = nil
end

#nameObject



33
34
35
# File 'lib/ruby_lsp/ruby_lsp_typeprof/addon.rb', line 33

def name
  "TypeProf"
end

#versionObject



37
38
39
# File 'lib/ruby_lsp/ruby_lsp_typeprof/addon.rb', line 37

def version
  VERSION
end

#workspace_did_change_watched_files(changes) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/ruby_lsp/ruby_lsp_typeprof/addon.rb', line 48

def workspace_did_change_watched_files(changes)
  return unless @service

  @mutex.synchronize do
    changes.each { |change| update_changed_file(change) }
  end
end