Skip to content

Commit a87fd92

Browse files
committed
(GH-141) Update Completion and Hover providers for V4 API Functions
Now that the Sidecar and the Sidecar Protocol have been modified to emit V4 API function metadata the completion and hover providers need to be modified to use it. This commit: * Because the concept of Function Type no longer exists (rvalue vs statement) all functions need to be returned when in the root of a document. Therefore the all_statement_functions method is changed into all_functions * The completion resolver is modified to only emit completion information if the function actually has a signature (all functions should have at least one sig). The resulting resolution now returns the function documentation and function signatures in separate fields in the response * The insertion text for the completion item now just emits the function with empty parentheses. This should trigger the Signature Helper, which will be implemented in later commits * The hover provider is modified to remove a todo item because arity no longer exists
1 parent 8cb7f05 commit a87fd92

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

lib/puppet-languageserver/manifest/completion_provider.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def self.complete(content, line_num, char_num, options = {})
2424
# Add resources
2525
all_resources { |x| items << x }
2626

27-
# Find functions which don't return values i.e. statements
28-
all_statement_functions { |x| items << x }
27+
all_functions { |x| items << x }
2928

3029
response = LSP::CompletionList.new
3130
response.items = items
@@ -170,9 +169,8 @@ def self.all_resources(&block)
170169
end
171170
end
172171

173-
def self.all_statement_functions(&block)
174-
# Find functions which don't return values i.e. statements
175-
PuppetLanguageServer::PuppetHelper.filtered_function_names { |_name, data| data.type == :statement }.each do |name|
172+
def self.all_functions(&block)
173+
PuppetLanguageServer::PuppetHelper.function_names.each do |name|
176174
item = LSP::CompletionItem.new(
177175
'label' => name.to_s,
178176
'kind' => LSP::CompletionItemKind::FUNCTION,
@@ -232,12 +230,12 @@ def self.resolve(completion_item)
232230
item_type = PuppetLanguageServer::PuppetHelper.function(data['name'])
233231
return result if item_type.nil?
234232
result.documentation = item_type.doc unless item_type.doc.nil?
235-
result.insertText = "#{data['name']}(${1:value}"
236-
(2..item_type.arity).each do |index|
237-
result.insertText += ", ${#{index}:value}"
233+
unless item_type.nil? || item_type.signatures.count.zero?
234+
result.detail = item_type.signatures.map(&:key).join("\n\n")
235+
# The signature provider should handle suggestions after this, so just place the cursor ready for an opening bracket
236+
result.insertText = data['name'].to_s
237+
result.insertTextFormat = LSP::InsertTextFormat::PLAINTEXT
238238
end
239-
result.insertText += ')'
240-
result.insertTextFormat = LSP::InsertTextFormat::SNIPPET
241239

242240
when 'resource_type'
243241
item_type = PuppetLanguageServer::PuppetHelper.get_type(data['name'])

lib/puppet-languageserver/manifest/hover_provider.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def self.get_call_named_function_expression_content(item)
142142
func_info = PuppetLanguageServer::PuppetHelper.function(func_name)
143143
raise "Function #{func_name} does not exist" if func_info.nil?
144144

145-
# TODO: what about rvalue?
146-
content = "**#{func_name}** Function" # TODO: Do I add in the params from the arity number?
145+
content = "**#{func_name}** Function"
147146
content += "\n\n" + func_info.doc unless func_info.doc.nil?
148147

149148
content

spec/languageserver/integration/puppet-languageserver/manifest/completion_provider_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ class Alice {
458458
expect(result.documentation).to match(/.+/)
459459
end
460460

461-
it 'should return a text snippet' do
461+
it 'should return plain text' do
462462
result = subject.resolve(@resolve_request)
463463
expect(result.insertText).to match(/.+/)
464-
expect(result.insertTextFormat).to eq(LSP::InsertTextFormat::SNIPPET)
464+
expect(result.insertTextFormat).to eq(LSP::InsertTextFormat::PLAINTEXT)
465465
end
466466
end
467467
end

0 commit comments

Comments
 (0)