Vscode-yaml: Custom tags not working

Created on 16 Nov 2018  路  14Comments  路  Source: redhat-developer/vscode-yaml

I have trouble getting the custom tags working. This are my user settings:

cat ~/.config/Code/User/settings.json

{
    "workbench.editor.enablePreview": false,
    "workbench.editor.enablePreviewFromQuickOpen": false,
    "yaml.customTags": [ "!rampPerSec", "!constantPerSec"]
}

and this is the yaml that fails to be parsed:

foo:
  - !constantPerSec bar: gee

VSCode version: 1.28.2
YAML Support by Red Hat version: 0.1.0
possibly conflicting plugin? Ansible 0.5.2 (extension association is to YAML, not ansible, though).

I'll be grateful for any hints. I've tried restarting VSCode couple of times, or placing the yaml.customTags to workspace settings instead but it did not help. Removing exclamation marks didn't help either. Thank you.

Most helpful comment

I'm was getting a similar problem (Cloudformation yaml tags were causing unknown tag errors), I managed to 'fix' it by:

  • disabling all dependent VSCode extensions (Ansible etc)
  • disabling the YAML extension
  • re-enable the YAML extension

For reference my versions are:

VSCode: 1.30.2
YAML extension: 0.2.1

Here's my yaml.customTags:

"yaml.customTags": [ "!And sequence", "!Equals sequence", "!If sequence", "!Not sequence", "!Or sequence", "!Base64", "!Cidr sequence", "!FindInMap sequence", "!GetAtt", "!GetAZs", "!ImportValue", "!Join sequence", "!Select sequence", "!Split sequence", "!Sub", "!Ref" ]

All 14 comments

What errors are you getting?

!con is underlined with unknown tag <!constantPerSec>
: gee is underlined with bad indentation of sequence entry

I think in this case you would technically need to do:

"yaml.customTags": [
"!constantParSec sequence"
]

However it looks like there are quite a few bugs in custom tags right now anyways so that won't work currently. I'm working on a fix

That gets me only halfway: With !constantPerSec sequence the : gee is underlined with
unacceptable node kind for !<!constantPerSec> tag; it should be "sequence", not "scalar"

When I try !constantPerSec scalar, it complains about indentation...

Do you plan to include 'any' type as well? Or will you make sure that the same tag can be applied to multiple types? Thanks.

Currently, there are no plans to include (the code that has the issue doesn't live here it lives in http://github.com/mulesoft-labs/yaml-ast-parser/issues iirc).

Or will you make sure that the same tag can be applied to multiple types? Thanks.

I hope to do this/someone adds this in the future, it would be very useful.

I'm was getting a similar problem (Cloudformation yaml tags were causing unknown tag errors), I managed to 'fix' it by:

  • disabling all dependent VSCode extensions (Ansible etc)
  • disabling the YAML extension
  • re-enable the YAML extension

For reference my versions are:

VSCode: 1.30.2
YAML extension: 0.2.1

Here's my yaml.customTags:

"yaml.customTags": [ "!And sequence", "!Equals sequence", "!If sequence", "!Not sequence", "!Or sequence", "!Base64", "!Cidr sequence", "!FindInMap sequence", "!GetAtt", "!GetAZs", "!ImportValue", "!Join sequence", "!Select sequence", "!Split sequence", "!Sub", "!Ref" ]

In more news - as soon as I re-enable the Ansible 0.5.2 extension and reload it breaks the yaml custom tags

Same problem here. Looks like Ansible extension breaks YAML custom tags functionality.

The ansible extension uses a fork of this one for some reason :man_shrugging: and because of that we can't actually stop it from showing the error see: https://github.com/redhat-developer/vscode-yaml/issues/178 but it looks like the actual issue was fixed so I'm going to close the issue

I'm not able to get it working even after disabling the Ansible extension unfortunately.

@smiller171 Can you open a new issue with your custom tags and also a picture whats in the text document (similar to what was posted in the issue) and other extensions installed.

I have also tried @AndyJPhillips method above and am not able to get custom tags to work after disabling all extensions and re-enabling just the YAML extension.

I have tried removing all custom tags and just trying one at a time. None are working. I am trying to get the Cloudformation (!Ref, !Sub, etc) custom tags to work.

I've tried with just !Ref, !Sub. I've tried !Sub scalar, !Sub sequence, !Sub mapping. Nothing.

Screen Shot 2019-12-20 at 11 08 38 AM


EDIT:
So apparently not only does the Ansible extension break customTags, also the Cloud Code extension breaks it.

If you copy your "yaml.customTags" in settings and add the same to "cloudcode.yaml.customTags", this fixes it.

Also with the Ansible extension enabled, if you set "ansible.validation": false the customTags will still work as well.

I posted another workaround at https://github.com/VSChina/vscode-ansible/issues/230#issuecomment-561281378.

Or to rephrase this bug is caused by https://github.com/adamvoss/vscode-yaml/issues/16 extension which hijacks yaml customTagsconfig and overrides it for all YAML files, not only for Ansible ones, breaking a huge number of YAML tools.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gauthamp10 picture gauthamp10  路  5Comments

remcohaszing picture remcohaszing  路  4Comments

bfelbo picture bfelbo  路  3Comments

ssbarnea picture ssbarnea  路  3Comments

Chagrilled picture Chagrilled  路  4Comments