Skip to content

Commit

Permalink
(puppetlabsGH-141) Update Completion and Hover providers for V4 API F…
Browse files Browse the repository at this point in the history
…unctions

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
  • Loading branch information
glennsarti committed Jun 10, 2019
1 parent 8ddad4b commit 69ec36e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 8 additions & 10 deletions lib/puppet-languageserver/manifest/completion_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def self.complete(content, line_num, char_num, options = {})
# Add resources
all_resources { |x| items << x }

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

response = LSP::CompletionList.new
response.items = items
Expand Down Expand Up @@ -170,9 +169,8 @@ def self.all_resources(&block)
end
end

def self.all_statement_functions(&block)
# Find functions which don't return values i.e. statements
PuppetLanguageServer::PuppetHelper.filtered_function_names { |_name, data| data.type == :statement }.each do |name|
def self.all_functions(&block)
PuppetLanguageServer::PuppetHelper.function_names.each do |name|
item = LSP::CompletionItem.new(
'label' => name.to_s,
'kind' => LSP::CompletionItemKind::FUNCTION,
Expand Down Expand Up @@ -232,12 +230,12 @@ def self.resolve(completion_item)
item_type = PuppetLanguageServer::PuppetHelper.function(data['name'])
return result if item_type.nil?
result.documentation = item_type.doc unless item_type.doc.nil?
result.insertText = "#{data['name']}(${1:value}"
(2..item_type.arity).each do |index|
result.insertText += ", ${#{index}:value}"
unless item_type.nil? || item_type.signatures.count.zero?
result.detail = item_type.signatures.map(&:key).join("\n\n")
# The signature provider should handle suggestions from here on in, so just place the cusrsor in the brackets
result.insertText = "#{data['name']}($1)" # TODO: How can I get the signature provider to trigger after the insert?
result.insertTextFormat = LSP::InsertTextFormat::SNIPPET
end
result.insertText += ')'
result.insertTextFormat = LSP::InsertTextFormat::SNIPPET

when 'resource_type'
item_type = PuppetLanguageServer::PuppetHelper.get_type(data['name'])
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet-languageserver/manifest/hover_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def self.get_call_named_function_expression_content(item)
func_info = PuppetLanguageServer::PuppetHelper.function(func_name)
raise "Function #{func_name} does not exist" if func_info.nil?

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

content
Expand Down

0 comments on commit 69ec36e

Please sign in to comment.