de-jcup / eclipse-yaml-editor

Eclipse YAML editor
https://marketplace.eclipse.org/content/yaml-editor
Apache License 2.0
35 stars 10 forks source link

Support Go Templates #76

Closed teoincontatto closed 5 years ago

teoincontatto commented 5 years ago

I see that when opening template yaml files the editor spawn an validation error. I whould like to being able to disable such validations on a project basis in order to allow use this editor for such templates (actually they a re go templates for helm).

de-jcup commented 5 years ago

Okay, I understand the situation (I have got this too, but currently I rename them ...). Normally I always try to avoid project specific settings, but maybe this is necessary.

What do you think about global path filters - or patterns. So something like disable validation for : "**/templates/*.yaml, template*.yaml" inside preferences?

teoincontatto commented 5 years ago

Global path filters seems good and would allow to have both tamplates and plain yaml files in a project. But I still think an option to disable completely validation it is needed since this is a common case for all eclipse validations. In particular that should integrate better in eclipse validations, seems that the editor is validating only files that are opened instead. Not sure if integration with eclipse validation is the way to go since it is probably too deep bounded with eclipse build cycle but maybe is worth some investigation.

de-jcup commented 5 years ago

I investigated a way to integrate into standard validation inside eclipse some time ago - as far as I remember there is (unfortunately) a strong dependency to WTP (web tools platform). Also an integration to this would be ... not nice.

Wanting my plugins to work with less dependencies as possible (KISS pattern + reduce problems with other dependencies) - so I decided to setup validation in my own preferences.

Writing this... I checked the preferences of the editor... and I have currently not integrated an option to turn off globally validation for yaml files... ups.

Proposal

So I will provide a enable validation [x] inside preferences in combination with filters when validation is enabled.

Would this be suitable for your needs ?

teoincontatto commented 5 years ago

Yeah, that would solve my use case.

de-jcup commented 5 years ago

Hello @teoincontatto .

I tried to disable validation... but...

those failures are are shown, because used YAML parser (snake) complies about invalid yaml (and is right because { and } are normally used as mapping inside yaml.

Using parsed yaml nodes to create the outline ignoring the parse errors would result in empty outline view when at least one parse error occurs, because snake is not able to parse the document, so no AST available.

Another approach: Go Template support

Instead of turning of validation I will provide a "Go template support" option in preferences, which is enabled per default. At parse time the editor will inspect the content of being a go template or not (can be estimated by occurrence of {{ and }} ).

In this case the parser will not validate the origin source, but an replacement which is valid for yaml: {{ will be replaced by (( and }} will be replaced by (( special characters inside will be replaced by _ inside this block.

Also syntax highlighting will be provided for templates

de-jcup commented 5 years ago

Before:

image Also no outline was available.

With last changes Support Go templates is enabled per default inside preferences: image

When this has been enabled the editor file looks now like: image

If the Go template support was doing some changes under the hood to get valid yaml there will be an information marker at the first line of the editor:

image

Inside the outline you will see the changes - so instead of {{ .Release.Name }}-configmap you find a santiized value:

image

de-jcup commented 5 years ago

When no go template parts are detected nothing has been changed and you will get also no such information marker:

image

de-jcup commented 5 years ago

@teoincontatto : I think this is much better. If you have still the need to turn off validation - means parsing at all and so no outline - please create another issue.

teoincontatto commented 5 years ago

I'm impressed! That is way better than the initial solution of disabling validation. I'll let you know if I found any use case that requires disabling validation. Will update the plugin to try the new feature asap :)