Skip to content

Commit 672bdad

Browse files
committed
(GH-181) Refactor resource-like class detection
This commit refactors the resource-like class detection to reduce duplicated code and adds more comments on this pseudo resource.
1 parent 90fbee9 commit 672bdad

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/puppet-languageserver/manifest/completion_provider.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ def self.complete(content, line_num, char_num, options = {})
5555
# properities and parameters.
5656

5757
# Try Types first
58-
if item.type_name.value == 'class'
59-
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.bodies[0].title.value)
60-
item_value = item.bodies[0].title.value
61-
else
62-
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.type_name.value)
63-
item_value = item.type_name.value
64-
end
65-
58+
# The `class` pseudo resource type is actually used to set properties/params for the puppet type
59+
# specified in the resource title.
60+
# Ref: https://puppet.com/docs/puppet/5.3/lang_classes.html#using-resource-like-declarations
61+
item_value = item.type_name.value == 'class' && item.bodies.length == 1 ? item.bodies[0].title.value : item.type_name.value
62+
item_object = PuppetLanguageServer::PuppetHelper.get_type(item_value)
6663
unless item_object.nil?
6764
# Add Parameters
6865
item_object.attributes.select { |_name, data| data[:type] == :param }.each_key do |name|

0 commit comments

Comments
 (0)