puppetlabs / puppet-editor-services

Puppet Language Server for editors
Apache License 2.0
46 stars 21 forks source link

(GH-306) Add a syntax aware code folding provider #302

Closed glennsarti closed 3 years ago

glennsarti commented 3 years ago

Fixes #306

Previously the Puppet Lexer ignored whitespace and comments and did not generate any token information. This meant it could not be used for code formatting purposes. This commit adds a new lexer which sub-classes the original and emits tokens for comments. Later commits can use this lexer for operations like code folding and as-you-type formatting.

This commit also memoizes the tokens in the document store so documents do not need to be lexed multiple times for the same version.


Previously the Language Server dod not provide code folding hints, and the client was left to use its defauly, typically indentation based. This commit:

Now that there is a Puppet Manifest Folding provider available, the server capabilities need to be updated so that clients know to use it. This commit:

Adds many tests for the message handler and language client for the new provider


Task list

glennsarti commented 3 years ago
Before After
image image
glennsarti commented 3 years ago

This adds two new settings

puppet.editorService.foldingRange.enable : Turns on or off the syntax folding provider. Supports dynamic registration (No restart required). Defaults to True

puppet.editorService.foldingRange.showLastLine : Whether to show the last line in the folding range. Some people like the whole range hidden. Some people want to see the trailing line. Defaults to True which is the VSCode default

glennsarti commented 3 years ago

Requires Puppet 6.3.0 or above to work due to the needed Lexer methods. Silently disables if it encounters it.

This also sets up the work to move off of the puppet-lint lexer for the hash rock alignment.

glennsarti commented 3 years ago

@jpogran Ready for review.

jpogran commented 3 years ago