Skip to content

Conversation

@glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Jun 10, 2019

Builds on #140

Fixes #141

  • Remove all TODOs
  • What about puppet language functions?

Previously the Sidecar Protocol had the serialisation methods on the
BasePuppetObject however this meant anything that wanted to use the
serialisation methods also inherited the parameters like key and calling_source.

This commit:

  • Moves the serialisation methods (to_json, from_json!) to BaseClass which
    BasePuppetObject now inherits from
  • Adds equality methods on the BaseClass to make it possible to compare
    Sidecar objects correctly. This is mainly required in spec tests to test for
    equality (either == or eql?)
  • Adds a hash method to generate the hash number required when Sidecar objects
    are put into hashtables

Previously the Puppet Function information retrieved over the Sidecar Protocol
only supported the older V3 Function API. This commit updates the Protocol to
now be able to transmit V4 function information. V3 information is expected to
be adapted into its equivalent in V4.

This commit:

  • Removes the deprecated arity and type methods and adds function_version and
    signatures. Where signatures are the function method signatures expressed as
    a PuppetFunctionSignatureList object
  • Adds a PuppetFunctionSignature and PuppetFunctionSignatureList object which
    captures all of the properties of Puppet Function V4 API method signature.
    The PuppetFunctionSignatureList object is a "typed" array of
    PuppetFunctionSignature objects
  • Adds a PuppetFunctionSignatureParameter and
    PuppetFunctionSignatureParameterList object which captures all of the
    properties of Puppet Function V4 API method signature parameter. The
    PuppetFunctionSignatureParameterList object is a "typed" array of
    PuppetFunctionSignatureParameter objects
  • Updates the spec_helper to be able to create mock objects for functions,
    function signatures and function signature parameters
  • Updates the sidecar protocol tests for the modified parameters and newly added
    classes
  • Updates the in-memory cache object tests for the modified parameters of a
    Function.

Previously a Puppet Strings Helper was added however there no tests for the
metadata extraction. This commit:

  • Adds tests to ensure that YARD/Puppet Strings extracts the metadata correctly
  • Converts the Strings Helper module into a class to make it easier to test
  • Updates the Puppet 4 function fixture to be a more complete example

When Puppet Strings extracts the parameter name it differs from how it appears
in the signature key. This makes it hard for clients to determine where in the
signature, the parameter actually is. This commit:

  • Updates the Sidecar Protocol and adds two new methods for the
    PuppetFunctionSignatureParameter class; signature_key_offset and
    signature_key_length. These values will store where in the signature key
    a parameter exists
  • Updates the protocol tests and spec helper for the new methods
  • Updates the Puppet Strings Helper to detect and populate the offset and length
    values for each parameter in a signature
  • Updates the Puppet Strings Helper tests to assert these values are correct for
    bare parameter names, blocks and splattable arguments.

Previously the Sidecar could only emit information in function V3 API format.
Now that the Sidecar Protocol has been changed to emit V4 information, this
commit updates the Sidecar to extact the V4 information.

This commit:

  • Updates the sidecar_protocol_extensions for the Puppet Function object to
    adapt the V3 function information into the V4 version
  • Updates the tests for the sidecar_protocol_extensions for the new parameters
    for the V4 API functions
  • Updates the Puppet Strings Helper to extract the required information from
    YARN in order to populate the V4 API function metadata. In particular the
    concepts of function type and arity no longer apply, and have been replaced
    using Function Signatures.

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

@glennsarti glennsarti added enhancement New feature or request Language Server labels Jun 10, 2019
@glennsarti glennsarti added this to the 0.20.0 milestone Jun 10, 2019
@glennsarti glennsarti self-assigned this Jun 10, 2019
@glennsarti glennsarti force-pushed the gh141-pup4-functions branch 5 times, most recently from 69ec36e to 67e317e Compare June 10, 2019 07:35
@glennsarti glennsarti changed the title {WIP}(GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features (GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features Jun 10, 2019
Previously the Sidecar Protocol had the serialisation methods on the
BasePuppetObject however this meant anything that wanted to use the
serialisation methods also inherited the parameters like key and calling_source.

This commit:
* Moves the serialisation methods (to_json, from_json!) to BaseClass which
  BasePuppetObject now inherits from
* Adds equality methods on the BaseClass to make it possible to compare
  Sidecar objects correctly.  This is mainly required in spec tests to test for
  equality (either == or eql?)
* Adds a hash method to generate the hash number required when Sidecar objects
  are put into hashtables

There are no test changes as this is a refactor only.
…upport V4 API

Previously the Puppet Function information retrieved over the Sidecar Protocol
only supported the older V3 Function API.  This commit updates the Protocol to
now be able to transmit V4 function information.  V3 information is expected to
be adapted into its equivalent in V4.

This commit:
* Removes the deprecated arity and type methods and adds function_version and
  signatures.  Where signatures are the function method signatures expressed as
  a PuppetFunctionSignatureList object
* Adds a PuppetFunctionSignature and PuppetFunctionSignatureList object which
  captures all of the properties of Puppet Function V4 API method signature.
  The PuppetFunctionSignatureList object is a "typed" array of
  PuppetFunctionSignature objects
* Adds a PuppetFunctionSignatureParameter and
  PuppetFunctionSignatureParameterList object which captures all of the
  properties of Puppet Function V4 API method signature parameter. The
  PuppetFunctionSignatureParameterList object is a "typed" array of
  PuppetFunctionSignatureParameter objects
* Updates the spec_helper to be able to create mock objects for functions,
  function signatures and function signature parameters
* Updates the sidecar protocol tests for the modified parameters and newly added
  classes
* Updates the in-memory cache object tests for the modified parameters of a
  Function.

At this point the protocol now only accepts V4 Function API information. Later
commits will modify the Sidecar and Language Server to generate and consume the
new information respectively.
@glennsarti glennsarti force-pushed the gh141-pup4-functions branch 4 times, most recently from 8cbc51d to 674cbe0 Compare June 11, 2019 02:45
@glennsarti glennsarti changed the title (GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features {WIP}(GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features Jun 13, 2019
@glennsarti
Copy link
Contributor Author

Found some bugs. Back to WIP

Previously the Sidecar could only emit information in function V3 API format.
Now that the Sidecar Protocol has been changed to emit V4 information, this
commit updates the Sidecar to extact the V4 information.

This commit:
* Updates the sidecar_protocol_extensions for the Puppet Function object to
  adapt the V3 function information into the V4 version
* Updates the tests for the sidecar_protocol_extensions for the new parameters
  for the V4 API functions
* Updates the Puppet Strings Helper to extract the required information from
  YARN in order to populate the V4 API function metadata.  In particular the
  concepts of function type and arity no longer apply, and have been replaced
  using Function Signatures.
Previously the function loader was modified for V4 Function API however there
were no tests for the Puppet based Functions, as opposed to Ruby.  This commit
adds the test fixtures and tests to ensure that Puppet based Functions are
loaded correctly.
@glennsarti glennsarti force-pushed the gh141-pup4-functions branch from 674cbe0 to a87fd92 Compare June 13, 2019 07:55
Previously a Puppet Strings Helper was added however there no tests for the
metadata extraction.  This commit:

* Adds tests to ensure that YARD/Puppet Strings extracts the metadata correctly
* Converts the Strings Helper module into a class to make it easier to test
* Updates the Puppet 4 function fixture to be a more complete example
When Puppet Strings extracts the parameter name it differs from how it appears
in the signature key. This makes it hard for clients to determine where in the
signature, the parameter actually is. This commit:

* Updates the Sidecar Protocol and adds two new methods for the
  PuppetFunctionSignatureParameter class; signature_key_offset and
  signature_key_length.  These values will store where in the signature key
  a parameter exists
* Updates the protocol tests and spec helper for the new methods
* Updates the Puppet Strings Helper to detect and populate the offset and length
  values for each parameter in a signature
* Updates the Puppet Strings Helper tests to assert these values are correct for
  bare parameter names, blocks and splattable arguments.
…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
@glennsarti glennsarti force-pushed the gh141-pup4-functions branch from a87fd92 to 04178c5 Compare June 13, 2019 08:24
There is a state problem when running different combinations of integration
tests whereby the Puppet mode still has tasks enabled, which then breaks
node graph generation. This commit safely modifies the Puppet[:tasks] state
prior to testing and reverts once complete.
@glennsarti glennsarti force-pushed the gh141-pup4-functions branch from 04178c5 to c2aaa5f Compare June 13, 2019 12:29
@glennsarti glennsarti changed the title {WIP}(GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features (GH-141) Modify the Puppet Function loading to use all of the new Puppet 4 API features Jun 13, 2019
@jpogran
Copy link
Contributor

jpogran commented Jun 24, 2019

I'm good to merge this, but feel like I haven't really 'used' it as I don't have examples of these advanced functions and stuff you've exposed. Do you have some examples to use?

@glennsarti
Copy link
Contributor Author

Copy link
Contributor

@jpogran jpogran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpogran jpogran merged commit 31b5c35 into puppetlabs:master Jun 25, 2019
@glennsarti glennsarti deleted the gh141-pup4-functions branch July 28, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Puppet4API Project Task 7] Modify the Puppet Function loading to use all of the new Puppet 4 API features

2 participants