Module: PuppetLanguageServer::PuppetHelper

Defined in:
lib/puppet-languageserver/puppet_helper.rb

Class Method Summary collapse

Class Method Details

.class_names(session_state) ⇒ Object



76
77
78
# File 'lib/puppet-languageserver/puppet_helper.rb', line 76

def self.class_names(session_state)
  session_state.object_cache.object_names_by_section(:class).map(&:to_s)
end

.datatype(session_state, name, tasks_mode = false) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/puppet-languageserver/puppet_helper.rb', line 80

def self.datatype(session_state, name, tasks_mode = false)
  exclude_origins = tasks_mode ? [] : [:bolt]
  session_state.object_cache.object_by_name(
    :datatype,
    name,
    fuzzy_match: true,
    exclude_origins: exclude_origins
  )
end

.function(session_state, name, tasks_mode = false) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/puppet-languageserver/puppet_helper.rb', line 57

def self.function(session_state, name, tasks_mode = false)
  exclude_origins = tasks_mode ? [] : [:bolt]
  session_state.object_cache.object_by_name(
    :function,
    name,
    fuzzy_match: true,
    exclude_origins: exclude_origins
  )
end

.function_names(session_state, tasks_mode = false) ⇒ Object



67
68
69
70
# File 'lib/puppet-languageserver/puppet_helper.rb', line 67

def self.function_names(session_state, tasks_mode = false)
  exclude_origins = tasks_mode ? [] : [:bolt]
  session_state.object_cache.object_names_by_section(:function, exclude_origins: exclude_origins).map(&:to_s)
end

.get_class(session_state, name) ⇒ Object



72
73
74
# File 'lib/puppet-languageserver/puppet_helper.rb', line 72

def self.get_class(session_state, name)
  session_state.object_cache.object_by_name(:class, name)
end

.get_node_graph(session_state, content, local_workspace) ⇒ Object

Node Graph



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet-languageserver/puppet_helper.rb', line 26

def self.get_node_graph(session_state, content, local_workspace)
  with_temporary_file(content) do |filepath|
    ap = PuppetLanguageServer::Sidecar::Protocol::ActionParams.new
    ap['source'] = filepath

    args = ["--action-parameters=#{ap.to_json}"]
    args << "--local-workspace=#{local_workspace}" unless local_workspace.nil?

    sidecar_queue.execute('node_graph', args, false, session_state.connection_id)
  end
end

.get_puppet_resource(session_state, typename, title, local_workspace) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/puppet-languageserver/puppet_helper.rb', line 38

def self.get_puppet_resource(session_state, typename, title, local_workspace)
  ap = PuppetLanguageServer::Sidecar::Protocol::ActionParams.new
  ap['typename'] = typename
  ap['title'] = title unless title.nil?

  args = ["--action-parameters=#{ap.to_json}"]
  args << "--local-workspace=#{local_workspace}" unless local_workspace.nil?

  sidecar_queue.execute('resource_list', args, false, session_state.connection_id)
end

.get_type(session_state, name) ⇒ Object



49
50
51
# File 'lib/puppet-languageserver/puppet_helper.rb', line 49

def self.get_type(session_state, name)
  session_state.object_cache.object_by_name(:type, name)
end

.module_pathObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet-languageserver/puppet_helper.rb', line 10

def self.module_path
  return @module_path unless @module_path.nil?

  # TODO: It would be nice if this wasn't using the whole puppet environment to calculate the modulepath directoties
  # In the meantime memoize it. Currently you can't change the modulepath mid-process.
  begin
    env = Puppet.lookup(:environments).get!(Puppet.settings[:environment])
  rescue Puppet::Environments::EnvironmentNotFound, StandardError
    env = Puppet.lookup(:current_environment)
  end
  return [] if env.nil?

  @module_path = env.modulepath
end

.sidecar_queueObject



90
91
92
# File 'lib/puppet-languageserver/puppet_helper.rb', line 90

def self.sidecar_queue
  PuppetLanguageServer::GlobalQueues.sidecar_queue
end

.type_names(session_state) ⇒ Object



53
54
55
# File 'lib/puppet-languageserver/puppet_helper.rb', line 53

def self.type_names(session_state)
  session_state.object_cache.object_names_by_section(:type).map(&:to_s)
end