Skip to content

Commit

Permalink
Added completion for resource-like class
Browse files Browse the repository at this point in the history
Modified completion provider to allow completion for resource-like class

link: https://puppet.com/docs/puppet/5.3/lang_classes.html#using-resource-like-declarations

class keyword behave like resource when using a defined class, and name parameter become the class name to lookup by the helper
  • Loading branch information
juliosueiras committed Sep 13, 2019
1 parent f50d75c commit 35822b6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/puppet-languageserver/manifest/completion_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def self.complete(content, line_num, char_num, options = {})
# properities and parameters.

# Try Types first
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.type_name.value)
if item.type_name.value == 'class'
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.bodies[0].title.value)
item_value = item.bodies[0].title.value
else
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.type_name.value)
item_value = item.type_name.value
end

unless item_object.nil?
# Add Parameters
item_object.attributes.select { |_name, data| data[:type] == :param }.each_key do |name|
Expand All @@ -66,7 +73,7 @@ def self.complete(content, line_num, char_num, options = {})
'data' => {
'type' => 'resource_parameter',
'param' => name.to_s,
'resource_type' => item.type_name.value
'resource_type' => item_value
}
)
end
Expand All @@ -79,15 +86,15 @@ def self.complete(content, line_num, char_num, options = {})
'data' => {
'type' => 'resource_property',
'prop' => name.to_s,
'resource_type' => item.type_name.value
'resource_type' => item_value
}
)
end
# TODO: What about meta parameters?
end
if item_object.nil?
# Try Classes/Defined Types
item_object = PuppetLanguageServer::PuppetHelper.get_class(item.type_name.value)
item_object = PuppetLanguageServer::PuppetHelper.get_class(item_value)
unless item_object.nil?
# Add Parameters
item_object.parameters.each_key do |name|
Expand All @@ -98,7 +105,7 @@ def self.complete(content, line_num, char_num, options = {})
'data' => {
'type' => 'resource_class_parameter',
'param' => name.to_s,
'resource_type' => item.type_name.value
'resource_type' => item_value
}
)
end
Expand Down

0 comments on commit 35822b6

Please sign in to comment.