@@ -8,7 +8,9 @@ module PuppetHelper
88 @ops_lock_funcs = Mutex . new
99 @types_hash = nil
1010 @function_module = nil
11-
11+ @types_loaded = nil
12+ @functions_loaded = nil
13+
1214 def self . reset
1315 @ops_lock_types . synchronize do
1416 @ops_lock_funcs . synchronize do
@@ -35,6 +37,10 @@ def self.load_types_async
3537 end
3638 end
3739
40+ def self . types_loaded?
41+ @types_loaded . nil? ? false : @types_loaded
42+ end
43+
3844 def self . load_types
3945 @ops_lock_types . synchronize do
4046 _load_types
@@ -43,6 +49,7 @@ def self.load_types
4349
4450 def self . get_type ( name )
4551 result = nil
52+ return result if @types_loaded == false
4653 @ops_lock_types . synchronize do
4754 _load_types if @types_hash . nil?
4855 result = @types_hash [ name . intern ]
@@ -52,6 +59,7 @@ def self.get_type(name)
5259
5360 def self . type_names
5461 result = [ ]
62+ return result if @types_loaded == false
5563 @ops_lock_types . synchronize do
5664 _load_types if @types_hash . nil?
5765 result = @types_hash . keys . map ( &:to_s )
@@ -60,6 +68,10 @@ def self.type_names
6068 end
6169
6270 # Functions
71+ def self . functions_loaded?
72+ @functions_loaded . nil? ? false : @functions_loaded
73+ end
74+
6375 def self . load_functions
6476 @ops_lock_funcs . synchronize do
6577 _load_functions if @function_module . nil?
@@ -74,6 +86,7 @@ def self.load_functions_async
7486
7587 def self . functions
7688 result = [ ]
89+ return result if @functions_loaded == false
7790 @ops_lock_funcs . synchronize do
7891 _load_functions if @function_module . nil?
7992 result = @function_module . all_function_info . dup
@@ -83,6 +96,7 @@ def self.functions
8396
8497 def self . function ( name )
8598 result = nil
99+ return result if @functions_loaded == false
86100 @ops_lock_funcs . synchronize do
87101 _load_functions if @function_module . nil?
88102 result = @function_module . all_function_info [ name . intern ]
@@ -92,6 +106,7 @@ def self.function(name)
92106
93107 def self . function_names
94108 result = [ ]
109+ return result if @functions_loaded == false
95110 @ops_lock_funcs . synchronize do
96111 _load_functions if @function_module . nil?
97112 result = @function_module . all_function_info . keys . map ( &:to_s )
@@ -104,6 +119,8 @@ def self.function_names
104119 def self . _reset
105120 @types_hash = nil
106121 @function_module = nil
122+ @types_loaded = nil
123+ @functions_loaded = nil
107124 end
108125 private_class_method :_reset
109126
@@ -118,6 +135,7 @@ def self.prune_resource_parameters(resources)
118135 private_class_method :prune_resource_parameters
119136
120137 def self . _load_types
138+ @types_loaded = false
121139 @types_hash = { }
122140 # This is an expensive call
123141 # From https://github.com/puppetlabs/puppet/blob/ebd96213cab43bb2a8071b7ac0206c3ed0be8e58/lib/puppet/metatype/manager.rb#L182-L189
@@ -143,11 +161,13 @@ def self._load_types
143161 type_count = @types_hash . count
144162 PuppetLanguageServer . log_message ( :debug , "[PuppetHelper::_load_types] Finished loading #{ type_count } types" )
145163
164+ @types_loaded = true
146165 nil
147166 end
148167 private_class_method :_load_types
149168
150169 def self . _load_functions
170+ @functions_loaded = false
151171 autoloader = Puppet ::Parser ::Functions . autoloader
152172
153173 # This is an expensive call
@@ -165,6 +185,7 @@ def self._load_functions
165185
166186 function_count = @function_module . all_function_info . keys . map ( &:to_s ) . count
167187 PuppetLanguageServer . log_message ( :debug , "[PuppetHelper::_load_functions] Finished loading #{ function_count } functions" )
188+ @functions_loaded = true
168189 nil
169190 end
170191 private_class_method :_load_functions
0 commit comments