Puppet Editor Services

A ruby based implementation of a Language Server and Debug Server for the Puppet Language. Integrate this into your editor to benefit from full Puppet Language support, such as syntax hightlighting, linting, hover support and more.
Requirements
-
Puppet 7 or above
-
Ruby 2.7 or above
Setting up editor services for development
> git clone https://github.com/puppetlabs/puppet-editor-services.git
> cd puppet-editor-services
- Bundle the development gems
> bundle install
... < lots of text >
> bundle exec rake gem_revendor
... < lots of text >
Language Server
How to run the Language Server for Development
By default the language server will stop if no connection is made within 10 seconds and will also stop after a client disconnects. Adding --debug=stdout
will log messages to the console
> bundle exec ruby ./puppet-languageserver --debug=stdout
I, [2018-12-05T15:19:51.853802
I, [2018-12-05T15:19:51.854809
D, [2018-12-05T15:19:51.856726
I, [2018-12-05T15:19:51.867798
D, [2018-12-05T15:19:51.867798
I, [2018-12-05T15:19:51.868726
I, [2018-12-05T15:19:51.870728
D, [2018-12-05T15:19:51.870728
I, [2018-12-05T15:19:51.871729
I, [2018-12-05T15:19:51.871729
I, [2018-12-05T15:19:51.872728
I, [2018-12-05T15:19:51.873727
I, [2018-12-05T15:19:51.876727
D, [2018-12-05T15:19:51.876727
D, [2018-12-05T15:19:51.899795
D, [2018-12-05T15:19:51.919794
D, [2018-12-05T15:19:51.920795
D, [2018-12-05T15:19:51.921809
LANGUAGE SERVER RUNNING localhost:55087
D, [2018-12-05T15:19:51.923800
A, [2018-12-05T15:19:54.520501
D, [2018-12-05T15:19:54.532525
D, [2018-12-05T15:19:54.533522
A, [2018-12-05T15:19:54.576503
D, [2018-12-05T15:19:54.638503
A, [2018-12-05T15:19:56.732112
D, [2018-12-05T15:19:56.732112
...
D, [2018-12-05T15:20:03.319045
D, [2018-12-05T15:20:03.320049
D, [2018-12-05T15:20:03.377052
D, [2018-12-05T15:20:03.377052
D, [2018-12-05T15:20:03.378052
D, [2018-12-05T15:20:03.379050
I, [2018-12-05T15:20:03.632011
To make the server run continuously add --timeout=0
and --no-stop
to the command line. For example;
> bundle exec ruby ./puppet-languageserver --debug=stdout --timeout=0 --no-stop
I, [2018-12-05T15:20:56.302414
I, [2018-12-05T15:20:56.303391
D, [2018-12-05T15:20:56.306343
I, [2018-12-05T15:20:56.318333
D, [2018-12-05T15:20:56.318333
I, [2018-12-05T15:20:56.319346
I, [2018-12-05T15:20:56.321337
D, [2018-12-05T15:20:56.321337
I, [2018-12-05T15:20:56.322332
I, [2018-12-05T15:20:56.323335
I, [2018-12-05T15:20:56.325337
I, [2018-12-05T15:20:56.326335
I, [2018-12-05T15:20:56.327333
...
D, [2018-12-05T15:20:56.365334
LANGUAGE SERVER RUNNING localhost:55180
D, [2018-12-05T15:20:56.374333
...
How to run the Language Server in Production
On Windows you need to run ruby with the Puppet Command Prompt
which can be found in the Start Menu. This enables the Puppet Agent ruby environment.
> ruby puppet-languageserver
LANGUAGE SERVER RUNNING 127.0.0.1:55086
Note the language server will stop after 10 seconds if no client connection is made.
Note that the Language Server will use TCP as the default transport on localhost
at a random port. The IP Address and Port can be changed using the --ip
and --port
arguments respectively. For example to listen on all interfaces on port 9000;
> ruby ./puppet-languageserver --ip=0.0.0.0 --port=9000
To change the protocol to STDIO, that is using STDOUT and STDIN, use the --stdio
argument.
Command line arguments
Usage: puppet-languageserver.rb [options]
-p, --port=PORT TCP Port to listen on. Default is random port
-i, --ip=ADDRESS IP Address to listen on (0.0.0.0 for all interfaces). Default is localhost
-c, --no-stop Do not stop the language server once a client disconnects. Default is to stop
-t, --timeout=TIMEOUT Stop the language server if a client does not connection within TIMEOUT seconds. A value of zero will not timeout. Default is 10 seconds
-d, --no-preload ** DEPRECATED ** Do not preload Puppet information when the language server starts. Default is to preload
--debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
-s, --slow-start Delay starting the Language Server until Puppet initialisation has completed. Default is to start fast
--stdio Runs the server in stdio mode, without a TCP listener
--enable-file-cache ** DEPRECATED ** Enables the file system cache for Puppet Objects (types, class etc.)
--[no-]cache Enable or disable all caching inside the sidecar. By default caching is enabled.
--feature-flags=FLAGS A list of comma delimited feature flags
--puppet-settings=TEXT Comma delimited list of settings to pass into Puppet e.g. --vardir,/opt/test-fixture
--local-workspace=PATH The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path.
-h, --help Prints this help
-v, --version Prints the Langauge Server version
Language Server Sidecar
How to run the Language Server for Development
The Language Server Sidecar is a process used by the Language Server to get information about Puppet's environment, for example, all available functions, classes, and custom types. This tool is typically only run by the Language Server itself, but it can be used to diagnose issues.
The sidecar is told to perform an action (using the action
) parameter and then, by default, outputs the JSON encoded result to STDOUT. This can be changed to a text file using the --output=PATH
argument.
Note that using the --debug=STDOUT
option without directing the output to a text file will generate output on STDOUT which cannot be deserialized correctly. Typically this only used by a developer to inspect what the Sidecar is doing.
Example usage
Confirm that the Sidecar loads correctly
The noop
action just outputs an empty JSON array but can be used to confirm that the Sidecar does not error while loading Puppet.
> bundle exec ruby ./puppet-languageserver-sidecar --action=noop
[]
Output all default Puppet Types
> bundle exec ruby ./puppet-languageserver-sidecar --action=default_types
[{"key":"anchor","calling_source":"puppet/cache/lib/puppet/type/anchor.rb","sou ...
Output all default Puppet Functions with a different puppet configuration, and debug information
> bundle exec ruby ./puppet-languageserver-sidecar --action=default_types --puppet-settings=--vardir,./test/vardir,--confdir,./test/confdir --debug=STDOUT
I, [2018-12-05T15:42:56.679837
I, [2018-12-05T15:42:56.679837
D, [2018-12-05T15:42:56.680820
D, [2018-12-05T15:42:56.690876
D, [2018-12-05T15:42:56.752804
...
[{"key":"debug","calling_source":"lib/puppet/parser/functions.rb", ...
Output all Puppet Classes in a workspace directory
> bundle exec ruby ./puppet-languageserver-sidecar --action=workspace_classes --local-workspace=C:\source\puppetlabs-sqlserver
[{"key":"sqlserver::config","calling_source":"C:/Source/puppetlabs-sqlserver/manifests/config.pp","source":"C:/Source/puppetlabs-sqlserver/manifests/config.pp","line":25,"ch...
Command line arguments
Usage: puppet-languageserver-sidecar.rb [options]
-a, --action=NAME The action for the sidecar to take. Expected ["noop", "default_classes", "default_functions", "default_types", "node_graph", "resource_list", "workspace_classes", "workspace_functions", "workspace_types"]
-c, --action-parameters=JSON JSON Encoded string containing the parameters for the sidecar action
-w, --local-workspace=PATH The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path
-o, --output=PATH The file to save the output from the sidecar. Default is output to STDOUT
-p, --puppet-settings=TEXT Comma delimited list of settings to pass into Puppet e.g. --vardir,/opt/test-fixture
-f, --feature-flags=FLAGS A list of comma delimited feature flags to pass the the sidecar
-n, --[no-]cache Enable or disable all caching inside the sidecar. By default caching is enabled.
--debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
-h, --help Prints this help
-v, --version Prints the Langauge Server version
Debug Server
How to run the Debug Server for Development
By default the debug server will stop if no connection is made within 10 seconds and will also stop after a client disconnects. Adding --debug=stdout
will log messages to the console
> bundle exec ruby ./puppet-debugserver --debug=stdout
I, [2018-04-17T14:19:24.131869
I, [2018-04-17T14:19:24.132871
D, [2018-04-17T14:19:24.135373
D, [2018-04-17T14:19:24.135870
D, [2018-04-17T14:19:24.135870
DEBUG SERVER RUNNING 127.0.0.1:8082
D, [2018-04-17T14:19:24.136871
D, [2018-04-17T14:19:34.140900
D, [2018-04-17T14:19:34.140900
D, [2018-04-17T14:19:34.141400
D, [2018-04-17T14:19:34.141900
D, [2018-04-17T14:19:34.141900
D, [2018-04-17T14:19:34.142401
I, [2018-04-17T14:19:34.150402
To make the server run continuously add --timeout=0
to the command line. For example;
> bundle exec ruby ./puppet-debugserver --debug=stdout --timeout=0
I, [2018-04-17T14:21:10.542332
I, [2018-04-17T14:21:10.543334
D, [2018-04-17T14:21:10.545836
D, [2018-04-17T14:21:10.546336
DEBUG SERVER RUNNING 127.0.0.1:8082
D, [2018-04-17T14:21:10.546834
...
How to run the Debug Server for Production
On Windows you need to run ruby with the Puppet Command Prompt
which can be found in the Start Menu. This enables the Puppet Agent ruby environment.
> ruby puppet-debugserver
DEBUG SERVER RUNNING 127.0.0.1:8082
Note the debug server will stop after 10 seconds if no client connection is made.
Command line arguments
Usage: puppet-debugserver.rb [options]
-p, --port=PORT TCP Port to listen on. Default is random port}
-i, --ip=ADDRESS IP Address to listen on (0.0.0.0 for all interfaces). Default is localhost
-t, --timeout=TIMEOUT Stop the Debug Server if a client does not connection within TIMEOUT seconds. A value of zero will not timeout. Default is 10 seconds
--debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
-h, --help Prints this help
-v, --version Prints the Debug Server version
License
This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
Other information
Reporting bugs
If you find a bug in puppet-editor-services or its results, please create an issue in the repo issues tracker. Bonus points will be awarded if you also include a patch that fixes the issue.
Development
If you run into an issue with this tool or would like to request a feature you can raise a PR with your suggested changes. Alternatively, you can raise a Github issue with a feature request or to report any bugs. Every other Tuesday the DevX team holds office hours in the Puppet Community Slack, where you can ask questions about this and any other supported tools. This session runs at 15:00 (GMT) for about an hour.
Why are there vendored gems and why only native ruby
When used by editors this language server will be running using the Ruby runtime provided by Puppet Agent. That means no native extensions and no bundler. Also, only the gems provided by Puppet Agent would be available by default. To work around this limitation all runtime dependencies should be re-vendored and then the load path modified appropriately.