Class: PuppetLanguageServer::ClientSessionState

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-languageserver/client_session_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_handler, options = {}) ⇒ ClientSessionState

Returns a new instance of ClientSessionState.



11
12
13
14
15
16
# File 'lib/puppet-languageserver/client_session_state.rb', line 11

def initialize(message_handler, options = {})
  @documents       = options[:documents].nil? ? PuppetLanguageServer::SessionState::DocumentStore.new : options[:documents]
  @language_client = options[:language_client].nil? ? PuppetLanguageServer::SessionState::LanguageClient.new(message_handler) : options[:language_client]
  @object_cache    = options[:object_cache].nil? ? PuppetLanguageServer::SessionState::ObjectCache.new : options[:object_cache]
  @connection_id   = options[:connection_id].nil? ? message_handler.protocol.connection.id : options[:connection_id]
end

Instance Attribute Details

#connection_idObject (readonly)

Returns the value of attribute connection_id.



9
10
11
# File 'lib/puppet-languageserver/client_session_state.rb', line 9

def connection_id
  @connection_id
end

#documentsObject (readonly)

Returns the value of attribute documents.



9
10
11
# File 'lib/puppet-languageserver/client_session_state.rb', line 9

def documents
  @documents
end

#language_clientObject (readonly)

Returns the value of attribute language_client.



9
10
11
# File 'lib/puppet-languageserver/client_session_state.rb', line 9

def language_client
  @language_client
end

#object_cacheObject (readonly)

Returns the value of attribute object_cache.



9
10
11
# File 'lib/puppet-languageserver/client_session_state.rb', line 9

def object_cache
  @object_cache
end

Instance Method Details

#default_classes_loaded?Boolean

Helper methods to know the state of the object cache

Returns:

  • (Boolean)


19
20
21
# File 'lib/puppet-languageserver/client_session_state.rb', line 19

def default_classes_loaded?
  object_cache.section_in_origin_exist?(:class, :default)
end

#default_datatypes_loaded?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/puppet-languageserver/client_session_state.rb', line 23

def default_datatypes_loaded?
  object_cache.section_in_origin_exist?(:datatype, :default)
end

#default_functions_loaded?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/puppet-languageserver/client_session_state.rb', line 27

def default_functions_loaded?
  object_cache.section_in_origin_exist?(:function, :default)
end

#default_types_loaded?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/puppet-languageserver/client_session_state.rb', line 31

def default_types_loaded?
  object_cache.section_in_origin_exist?(:type, :default)
end

#facts_loaded?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/puppet-languageserver/client_session_state.rb', line 35

def facts_loaded?
  object_cache.section_in_origin_exist?(:fact, :default)
end

#load_default_data!(async = true) ⇒ Object

Loaders for object cache information



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet-languageserver/client_session_state.rb', line 44

def load_default_data!(async = true)
  PuppetLanguageServer.log_message(:info, "Loading Default Data via aggregate #{'(Async)' if async}...")
  if async
    sidecar_queue.enqueue('default_aggregate', [], false, connection_id)
    sidecar_queue.enqueue('facts', [], false, connection_id)
  else
    sidecar_queue.execute('default_aggregate', [], false, connection_id)
    sidecar_queue.execute('facts', [], false, connection_id)
  end

  true
end

#load_static_data!(async = true) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet-languageserver/client_session_state.rb', line 57

def load_static_data!(async = true)
  if async
    Thread.new do
      PuppetLanguageServer.log_message(:info, 'Loading static data (Async)...')
      load_static_data_impl
    end
  else
    PuppetLanguageServer.log_message(:info, 'Loading static data...')
    load_static_data_impl
  end

  true
end

#load_workspace_data!(async = true) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet-languageserver/client_session_state.rb', line 71

def load_workspace_data!(async = true)
  return true if documents.store_root_path.nil?

  action_args = ['--local-workspace', documents.store_root_path]
  PuppetLanguageServer.log_message(:info, "Loading Workspace Data via aggregate #{'(Async)' if async}...")
  if async
    sidecar_queue.enqueue('workspace_aggregate', action_args, false, connection_id)
  else
    sidecar_queue.execute('workspace_aggregate', action_args, false, connection_id)
  end

  true
end

#purge_workspace_data!Object



85
86
87
# File 'lib/puppet-languageserver/client_session_state.rb', line 85

def purge_workspace_data!
  object_cache.remove_origin!(:workspace)
end

#static_data_loaded?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/puppet-languageserver/client_session_state.rb', line 39

def static_data_loaded?
  object_cache.origin_exist?(:bolt)
end