Skip to content

Commit

Permalink
Merge pull request #47 from glennsarti/gh-46-under-non-root
Browse files Browse the repository at this point in the history
(GH-46) Detect Puppet Environment correctly
  • Loading branch information
James Pogran authored Jul 19, 2018
2 parents e768efc + 6eb083b commit d40aea7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/puppet-languageserver/puppet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ def self.prune_resource_parameters(resources)
end
private_class_method :prune_resource_parameters

def self.current_environment
begin
env = Puppet.lookup(:environments).get!(Puppet.settings[:environment])
return env unless env.nil?
rescue Puppet::Environments::EnvironmentNotFound
PuppetLanguageServer.log_message(:warning, "[PuppetHelper::current_environment] Unable to load environment #{Puppet.settings[:environment]}")
rescue StandardError => ex
PuppetLanguageServer.log_message(:warning, "[PuppetHelper::current_environment] Error loading environment #{Puppet.settings[:environment]}: #{ex}")
end
Puppet.lookup(:current_environment)
end
private_class_method :current_environment

# Class and Defined Type loading
def self._load_default_classes
@default_classes_loaded = false
Expand Down Expand Up @@ -325,7 +338,7 @@ def self._load_default_types

# From https://github.com/puppetlabs/puppet/blob/ebd96213cab43bb2a8071b7ac0206c3ed0be8e58/lib/puppet/metatype/manager.rb#L182-L189
autoloader = Puppet::Util::Autoload.new(self, 'puppet/type')
current_env = Puppet.lookup(:current_environment)
current_env = current_environment
type_count = 0

# This is an expensive call
Expand Down Expand Up @@ -389,7 +402,7 @@ def self._load_default_functions
PuppetLanguageServer.log_message(:debug, '[PuppetHelper::_load_default_functions] Starting')

autoloader = Puppet::Parser::Functions.autoloader
current_env = Puppet.lookup(:current_environment)
current_env = current_environment
function_count = 0

# Functions that are already loaded (e.g. system default functions like alert)
Expand Down

0 comments on commit d40aea7

Please sign in to comment.