项目作者: puppetlabs

项目描述 :
Puppet Language Server for editors
高级语言: Ruby
项目地址: git://github.com/puppetlabs/puppet-editor-services.git
创建时间: 2018-03-27T01:39:56Z
项目社区:https://github.com/puppetlabs/puppet-editor-services

开源协议:Apache License 2.0

下载


Puppet Editor Services

Code Owners
ci
GitHub release (latest by date)

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 8 or above

  • Ruby 3.1 or above

Setting up editor services for development

  • Ensure a modern ruby is installed (3.1+)

    The editor services support Puppet 8.0.0 and above

  • Clone this repository

  1. > git clone https://github.com/puppetlabs/puppet-editor-services.git
  2. > cd puppet-editor-services
  • Bundle the development gems
  1. > bundle install
  2. ... < lots of text >
  • Installed vendored gems
  1. > bundle exec rake gem_revendor
  2. ... < 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

  1. > bundle exec ruby ./puppet-languageserver --debug=stdout
  2. I, [2018-12-05T15:19:51.853802 #28756] INFO -- : Language Server is v0.16.0
  3. I, [2018-12-05T15:19:51.854809 #28756] INFO -- : Using Puppet v5.5.8
  4. D, [2018-12-05T15:19:51.856726 #28756] DEBUG -- : Detected additional puppet settings []
  5. I, [2018-12-05T15:19:51.867798 #28756] INFO -- : Initializing Puppet Helper...
  6. D, [2018-12-05T15:19:51.867798 #28756] DEBUG -- : Initializing Document Store...
  7. I, [2018-12-05T15:19:51.868726 #28756] INFO -- : Initializing settings...
  8. I, [2018-12-05T15:19:51.870728 #28756] INFO -- : Starting RPC Server...
  9. D, [2018-12-05T15:19:51.870728 #28756] DEBUG -- : Using Simple TCP
  10. I, [2018-12-05T15:19:51.871729 #28756] INFO -- : Using Facter v2.5.1
  11. I, [2018-12-05T15:19:51.871729 #28756] INFO -- : Preloading Puppet Types (Async)...
  12. I, [2018-12-05T15:19:51.872728 #28756] INFO -- : Preloading Facter (Async)...
  13. I, [2018-12-05T15:19:51.873727 #28756] INFO -- : Preloading Functions (Async)...
  14. I, [2018-12-05T15:19:51.876727 #28756] INFO -- : Preloading Classes (Async)...
  15. D, [2018-12-05T15:19:51.876727 #28756] DEBUG -- : SidecarQueue Thread: Running sidecar ["ruby", "C:/Source/puppet-editor-services/puppet-languageserver-sidecar", "--action", "default_types", "--feature-flags="]
  16. D, [2018-12-05T15:19:51.899795 #28756] DEBUG -- : SidecarQueue Thread: Running sidecar ["ruby", "C:/Source/puppet-editor-services/puppet-languageserver-sidecar", "--action", "default_functions", "--feature-flags="]
  17. D, [2018-12-05T15:19:51.919794 #28756] DEBUG -- : TCPSRV: Services running. Press ^C to stop
  18. D, [2018-12-05T15:19:51.920795 #28756] DEBUG -- : TCPSRV: Will stop the server in 10 seconds if no connection is made.
  19. D, [2018-12-05T15:19:51.921809 #28756] DEBUG -- : TCPSRV: Will stop the server when client disconnects
  20. LANGUAGE SERVER RUNNING localhost:55087
  21. D, [2018-12-05T15:19:51.923800 #28756] DEBUG -- : TCPSRV: Started listening on localhost:55087.
  22. A, [2018-12-05T15:19:54.520501 #28756] ANY -- : SidecarQueue Thread: Calling sidecar with --action default_functions --feature-flags= returned exitcode 0,
  23. D, [2018-12-05T15:19:54.532525 #28756] DEBUG -- : SidecarQueue Thread: default_functions returned 270 items
  24. D, [2018-12-05T15:19:54.533522 #28756] DEBUG -- : SidecarQueue Thread: Running sidecar ["ruby", "C:/Source/puppet-editor-services/puppet-languageserver-sidecar", "--action", "default_classes", "--feature-flags="]
  25. A, [2018-12-05T15:19:54.576503 #28756] ANY -- : SidecarQueue Thread: Calling sidecar with --action default_types --feature-flags= returned exitcode 0,
  26. D, [2018-12-05T15:19:54.638503 #28756] DEBUG -- : SidecarQueue Thread: default_types returned 81 items
  27. A, [2018-12-05T15:19:56.732112 #28756] ANY -- : SidecarQueue Thread: Calling sidecar with --action default_classes --feature-flags= returned exitcode 0,
  28. D, [2018-12-05T15:19:56.732112 #28756] DEBUG -- : SidecarQueue Thread: default_classes returned 0 items
  29. ...
  30. D, [2018-12-05T15:20:03.319045 #28756] DEBUG -- : TCPSRV: No connection has been received in 10 seconds. Shutting down server.
  31. D, [2018-12-05T15:20:03.320049 #28756] DEBUG -- : TCPSRV: Stopping services
  32. D, [2018-12-05T15:20:03.377052 #28756] DEBUG -- : TCPSRV: Stopped listening on localhost:55087
  33. D, [2018-12-05T15:20:03.377052 #28756] DEBUG -- : TCPSRV: Started shutdown process. Press ^C to force quit.
  34. D, [2018-12-05T15:20:03.378052 #28756] DEBUG -- : TCPSRV: Stopping services
  35. D, [2018-12-05T15:20:03.379050 #28756] DEBUG -- : TCPSRV: Waiting for workers to cycle down
  36. I, [2018-12-05T15:20:03.632011 #28756] INFO -- : Language Server exited.

To make the server run continuously add --timeout=0 and --no-stop to the command line. For example;

  1. > bundle exec ruby ./puppet-languageserver --debug=stdout --timeout=0 --no-stop
  2. I, [2018-12-05T15:20:56.302414 #29752] INFO -- : Language Server is v0.16.0
  3. I, [2018-12-05T15:20:56.303391 #29752] INFO -- : Using Puppet v5.5.8
  4. D, [2018-12-05T15:20:56.306343 #29752] DEBUG -- : Detected additional puppet settings []
  5. I, [2018-12-05T15:20:56.318333 #29752] INFO -- : Initializing Puppet Helper...
  6. D, [2018-12-05T15:20:56.318333 #29752] DEBUG -- : Initializing Document Store...
  7. I, [2018-12-05T15:20:56.319346 #29752] INFO -- : Initializing settings...
  8. I, [2018-12-05T15:20:56.321337 #29752] INFO -- : Starting RPC Server...
  9. D, [2018-12-05T15:20:56.321337 #29752] DEBUG -- : Using Simple TCP
  10. I, [2018-12-05T15:20:56.322332 #29752] INFO -- : Using Facter v2.5.1
  11. I, [2018-12-05T15:20:56.323335 #29752] INFO -- : Preloading Puppet Types (Async)...
  12. I, [2018-12-05T15:20:56.325337 #29752] INFO -- : Preloading Facter (Async)...
  13. I, [2018-12-05T15:20:56.326335 #29752] INFO -- : Preloading Functions (Async)...
  14. I, [2018-12-05T15:20:56.327333 #29752] INFO -- : Preloading Classes (Async)...
  15. ...
  16. D, [2018-12-05T15:20:56.365334 #29752] DEBUG -- : TCPSRV: Services running. Press ^C to stop
  17. LANGUAGE SERVER RUNNING localhost:55180
  18. D, [2018-12-05T15:20:56.374333 #29752] DEBUG -- : TCPSRV: Started listening on localhost:55180.
  19. ...

How to run the Language Server in Production

  • Ensure that Puppet Agent is installed

  • Run the puppet-languageserver with ruby

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.

  1. > ruby puppet-languageserver
  2. 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;

  1. > 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

  1. Usage: puppet-languageserver.rb [options]
  2. -p, --port=PORT TCP Port to listen on. Default is random port
  3. -i, --ip=ADDRESS IP Address to listen on (0.0.0.0 for all interfaces). Default is localhost
  4. -c, --no-stop Do not stop the language server once a client disconnects. Default is to stop
  5. -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
  6. -d, --no-preload ** DEPRECATED ** Do not preload Puppet information when the language server starts. Default is to preload
  7. --debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
  8. -s, --slow-start Delay starting the Language Server until Puppet initialisation has completed. Default is to start fast
  9. --stdio Runs the server in stdio mode, without a TCP listener
  10. --enable-file-cache ** DEPRECATED ** Enables the file system cache for Puppet Objects (types, class etc.)
  11. --[no-]cache Enable or disable all caching inside the sidecar. By default caching is enabled.
  12. --feature-flags=FLAGS A list of comma delimited feature flags
  13. --puppet-settings=TEXT Comma delimited list of settings to pass into Puppet e.g. --vardir,/opt/test-fixture
  14. --local-workspace=PATH The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path.
  15. -h, --help Prints this help
  16. -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.

  1. > bundle exec ruby ./puppet-languageserver-sidecar --action=noop
  2. []

Output all default Puppet Types

  1. > bundle exec ruby ./puppet-languageserver-sidecar --action=default_types
  2. [{"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

  1. > bundle exec ruby ./puppet-languageserver-sidecar --action=default_types --puppet-settings=--vardir,./test/vardir,--confdir,./test/confdir --debug=STDOUT
  2. I, [2018-12-05T15:42:56.679837 #51864] INFO -- : Language Server Sidecar is v0.16.0
  3. I, [2018-12-05T15:42:56.679837 #51864] INFO -- : Using Puppet v5.5.8
  4. D, [2018-12-05T15:42:56.680820 #51864] DEBUG -- : Detected additional puppet settings ["--vardir", "./test/vardir", "--confdir", "./test/confdir"]
  5. D, [2018-12-05T15:42:56.690876 #51864] DEBUG -- : [PuppetHelper::load_functions] Starting
  6. D, [2018-12-05T15:42:56.752804 #51864] DEBUG -- : [PuppetLanguageServerSidecar::load] Loading lib/puppet/parser/functions/assert_type.rb from cache
  7. ...
  8. [{"key":"debug","calling_source":"lib/puppet/parser/functions.rb", ...

Output all Puppet Classes in a workspace directory

  1. > bundle exec ruby ./puppet-languageserver-sidecar --action=workspace_classes --local-workspace=C:\source\puppetlabs-sqlserver
  2. [{"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

  1. Usage: puppet-languageserver-sidecar.rb [options]
  2. -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"]
  3. -c, --action-parameters=JSON JSON Encoded string containing the parameters for the sidecar action
  4. -w, --local-workspace=PATH The workspace or file path that will be used to provide module-specific functionality. Default is no workspace path
  5. -o, --output=PATH The file to save the output from the sidecar. Default is output to STDOUT
  6. -p, --puppet-settings=TEXT Comma delimited list of settings to pass into Puppet e.g. --vardir,/opt/test-fixture
  7. -f, --feature-flags=FLAGS A list of comma delimited feature flags to pass the the sidecar
  8. -n, --[no-]cache Enable or disable all caching inside the sidecar. By default caching is enabled.
  9. --debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
  10. -h, --help Prints this help
  11. -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

  1. > bundle exec ruby ./puppet-debugserver --debug=stdout
  2. I, [2018-04-17T14:19:24.131869 #6940] INFO -- : Debug Server is v0.10.0
  3. I, [2018-04-17T14:19:24.132871 #6940] INFO -- : Starting RPC Server...
  4. D, [2018-04-17T14:19:24.135373 #6940] DEBUG -- : TCPSRV: Services running. Press ^C to stop
  5. D, [2018-04-17T14:19:24.135870 #6940] DEBUG -- : TCPSRV: Will stop the server in 10 seconds if no connection is made.
  6. D, [2018-04-17T14:19:24.135870 #6940] DEBUG -- : TCPSRV: Will stop the server when client disconnects
  7. DEBUG SERVER RUNNING 127.0.0.1:8082
  8. D, [2018-04-17T14:19:24.136871 #6940] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8082.
  9. D, [2018-04-17T14:19:34.140900 #6940] DEBUG -- : TCPSRV: No connection has been received in 10 seconds. Shutting down server.
  10. D, [2018-04-17T14:19:34.140900 #6940] DEBUG -- : TCPSRV: Stopping services
  11. D, [2018-04-17T14:19:34.141400 #6940] DEBUG -- : TCPSRV: Stopped listening on 127.0.0.1:8082
  12. D, [2018-04-17T14:19:34.141900 #6940] DEBUG -- : TCPSRV: Started shutdown process. Press ^C to force quit.
  13. D, [2018-04-17T14:19:34.141900 #6940] DEBUG -- : TCPSRV: Stopping services
  14. D, [2018-04-17T14:19:34.142401 #6940] DEBUG -- : TCPSRV: Waiting for workers to cycle down
  15. I, [2018-04-17T14:19:34.150402 #6940] INFO -- : Debug Server exited.

To make the server run continuously add --timeout=0 to the command line. For example;

  1. > bundle exec ruby ./puppet-debugserver --debug=stdout --timeout=0
  2. I, [2018-04-17T14:21:10.542332 #12424] INFO -- : Debug Server is v0.10.0
  3. I, [2018-04-17T14:21:10.543334 #12424] INFO -- : Starting RPC Server...
  4. D, [2018-04-17T14:21:10.545836 #12424] DEBUG -- : TCPSRV: Services running. Press ^C to stop
  5. D, [2018-04-17T14:21:10.546336 #12424] DEBUG -- : TCPSRV: Will stop the server when client disconnects
  6. DEBUG SERVER RUNNING 127.0.0.1:8082
  7. D, [2018-04-17T14:21:10.546834 #12424] DEBUG -- : TCPSRV: Started listening on 127.0.0.1:8082.
  8. ...

How to run the Debug Server for Production

  • Ensure that Puppet Agent is installed

  • Run the puppet-debugserver with ruby

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.

  1. > ruby puppet-debugserver
  2. 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

  1. Usage: puppet-debugserver.rb [options]
  2. -p, --port=PORT TCP Port to listen on. Default is random port}
  3. -i, --ip=ADDRESS IP Address to listen on (0.0.0.0 for all interfaces). Default is localhost
  4. -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
  5. --debug=DEBUG Output debug information. Either specify a filename or 'STDOUT'. Default is no debug output
  6. -h, --help Prints this help
  7. -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.