@@ -44,29 +44,26 @@ def self.complete(content, line_num, char_num)
4444 # We are inside a resource definition. Should display all available
4545 # properities and parameters.
4646
47- # TODO: Should really cache all of the resources and params/props for quick
48- # searching and then only actually instatiate when needed. For the moment,
49- # instantiate all the things!
50-
51- item_type = Puppet ::Type . type ( item . type_name . value )
47+ item_type = PuppetLanguageServer ::PuppetHelper . get_type ( item . type_name . value )
5248 # Add Parameters
53- item_type . parameters . each do |param |
54- items << LanguageServer ::CompletionItem . create ( 'label' => param . to_s ,
49+ item_type . parameters . each_key do |name |
50+ items << LanguageServer ::CompletionItem . create ( 'label' => name . to_s ,
5551 'kind' => LanguageServer ::COMPLETIONITEMKIND_PROPERTY ,
5652 'detail' => 'Parameter' ,
5753 'data' => { 'type' => 'resource_parameter' ,
58- 'param' => param . to_s ,
54+ 'param' => name . to_s ,
5955 'resource_type' => item . type_name . value } )
6056 end
6157 # Add Properties
62- item_type . properties . each do |prop |
63- items << LanguageServer ::CompletionItem . create ( 'label' => prop . name . to_s ,
58+ item_type . properties . each_key do |name |
59+ items << LanguageServer ::CompletionItem . create ( 'label' => name . to_s ,
6460 'kind' => LanguageServer ::COMPLETIONITEMKIND_PROPERTY ,
6561 'detail' => 'Property' ,
6662 'data' => { 'type' => 'resource_property' ,
67- 'prop' => prop . name . to_s ,
63+ 'prop' => name . to_s ,
6864 'resource_type' => item . type_name . value } )
6965 end
66+ # TODO: What about meta parameters?
7067 end
7168
7269 LanguageServer ::CompletionList . create ( 'isIncomplete' => incomplete ,
@@ -110,12 +107,12 @@ def self.all_resources(&block)
110107
111108 def self . all_statement_functions ( &block )
112109 # Find functions which don't return values i.e. statements
113- PuppetLanguageServer ::PuppetHelper . functions . select { |_key , obj | obj [ : type] == :statement } . each_key do |key |
114- item = LanguageServer ::CompletionItem . create ( 'label' => key . to_s ,
110+ PuppetLanguageServer ::PuppetHelper . filtered_function_names { |_name , data | data . type == :statement } . each do |name |
111+ item = LanguageServer ::CompletionItem . create ( 'label' => name . to_s ,
115112 'kind' => LanguageServer ::COMPLETIONITEMKIND_FUNCTION ,
116113 'detail' => 'Function' ,
117114 'data' => { 'type' => 'function' ,
118- 'name' => key . to_s } )
115+ 'name' => name . to_s } )
119116 block . call ( item ) if block
120117 end
121118 end
@@ -162,32 +159,36 @@ def self.resolve(completion_item)
162159
163160 when 'function'
164161 item_type = PuppetLanguageServer ::PuppetHelper . function ( data [ 'name' ] )
165- completion_item [ 'documentation' ] = item_type [ : doc] unless item_type [ : doc] . nil?
162+ completion_item [ 'documentation' ] = item_type . doc unless item_type . doc . nil?
166163 completion_item [ 'insertText' ] = "#{ data [ 'name' ] } (${1:value}"
167- ( 2 ..item_type [ : arity] ) . each do |index |
164+ ( 2 ..item_type . arity ) . each do |index |
168165 completion_item [ 'insertText' ] += ", ${#{ index } :value}"
169166 end
170167 completion_item [ 'insertText' ] += ')'
171168 completion_item [ 'insertTextFormat' ] = LanguageServer ::INSERTTEXTFORMAT_SNIPPET
172169
173170 when 'resource_type'
174- item_type = Puppet :: Type . type ( data [ 'name' ] )
171+ item_type = PuppetLanguageServer :: PuppetHelper . get_type ( data [ 'name' ] )
175172 # TODO: More things?
176173 completion_item [ 'documentation' ] = item_type . doc unless item_type . doc . nil?
177174 completion_item [ 'insertText' ] = "#{ data [ 'name' ] } { '${1:title}':\n \t ensure => '${2:present}'\n }"
178175 completion_item [ 'insertTextFormat' ] = LanguageServer ::INSERTTEXTFORMAT_SNIPPET
179176 when 'resource_parameter'
180- item_type = Puppet ::Type . type ( data [ 'resource_type' ] )
181- param_type = item_type . attrclass ( data [ 'param' ] . intern )
182- # TODO: More things?
183- completion_item [ 'documentation' ] = param_type . doc unless param_type . doc . nil?
184- completion_item [ 'insertText' ] = "#{ data [ 'param' ] } => "
177+ item_type = PuppetLanguageServer ::PuppetHelper . get_type ( data [ 'resource_type' ] )
178+ param_type = item_type . parameters [ data [ 'param' ] . intern ]
179+ unless param_type . nil?
180+ # TODO: More things?
181+ completion_item [ 'documentation' ] = param_type [ :doc ] unless param_type [ :doc ] . nil?
182+ completion_item [ 'insertText' ] = "#{ data [ 'param' ] } => "
183+ end
185184 when 'resource_property'
186- item_type = Puppet ::Type . type ( data [ 'resource_type' ] )
187- prop_type = item_type . attrclass ( data [ 'prop' ] . intern )
188- # TODO: More things?
189- completion_item [ 'documentation' ] = prop_type . doc unless prop_type . doc . nil?
190- completion_item [ 'insertText' ] = "#{ data [ 'prop' ] } => "
185+ item_type = PuppetLanguageServer ::PuppetHelper . get_type ( data [ 'resource_type' ] )
186+ prop_type = item_type . properties [ data [ 'prop' ] . intern ]
187+ unless prop_type . nil?
188+ # TODO: More things?
189+ completion_item [ 'documentation' ] = prop_type [ :doc ] unless prop_type [ :doc ] . nil?
190+ completion_item [ 'insertText' ] = "#{ data [ 'prop' ] } => "
191+ end
191192 end
192193
193194 LanguageServer ::CompletionItem . create ( completion_item )
0 commit comments