vim-ansible-yaml icon indicating copy to clipboard operation
vim-ansible-yaml copied to clipboard

Add Jinja highlighting for special Ansible functions

Open chase opened this issue 11 years ago • 9 comments
trafficstars

Strings, encased or otherwise, should be highlighted as if they were between Jinja variable blocks for the following keys:

  • when
  • changed_when
  • with_*

There are probably more, but they can be added later.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1446702-add-jinja-highlighting-for-special-ansible-functions?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F509109&utm_medium=issues&utm_source=github).

chase avatar Dec 12 '13 06:12 chase

In this example

- name: silly rule
  command: echo "when {{ when }}"
  when: some_condition

are you saying that you want the second and third "when" to be in the same highlight group? I assume you do not want anything special for the first "when".

Currently, the three "when"s are

  1. yamlString
  2. jinjaVariable
  3. ansibleConditional

benjifisher avatar Nov 30 '14 14:11 benjifisher

You are correct, I want the second and third "when" to be highlighted the same. Essentially all that is required is making it so that the value for the mapping for ansibleRepeat and ansibleConditional is set to be the same as jinjaVarBlock but without the region requirements of {{ and ``}}`.

chase avatar Nov 30 '14 18:11 chase

I am still not sure what you want. If you want the third "when" in the example to be highlighted the same way that the second is now, then all it takes is

:hi link ansibleConditional Normal " or jinjaVariable

and I guess you would do the same for ansibleRepeat.

It looks as though jinjaVariable is explicitly highlighted as Normal, and there is no highlight group defined for jinjaVarBlock.

benjifisher avatar Nov 30 '14 19:11 benjifisher

That's not quite the case. Notice that ansibleRepeat and ansibleConditional are both essentially just keywords.

I do not want to change ansibleRepeat and ansibleConditional, which are syntax items which are contained within yamlKey. What I want is the value, not the key in the mapping of yamlMapping to be the same as the syntax group of jinjaVarBlock. This value is what is after the character :, which is after ansibleRepeat and ansibleConditional.

jinjaVarBlock contains:

  • jinjaStatement
  • jinjaVariable
  • jinjaSpecial
  • jinjaOperator
  • jinjaString
  • jinjaNumber
  • jinjaNested

So making the value use jinjaVariable would not match everything necessary.

For Ansible when, changed_when and with_* statements, the value of the YAML mapping is interpreted exactly the same as a Jinja2 block that goes between {{ .. }}.

chase avatar Nov 30 '14 19:11 chase

I was right about one thing:

I am still not sure what you want.

Please keep the terminology straight: syntax groups and highlight groups are closely related, but they are not the same. :help group-name.

I do not want to change ansibleRepeat and ansibleConditional, which are highlighted as yamlKey

No, this is how they are highlighted:

  HiLink ansibleConditional Statement
  HiLink ansibleRepeat Repeat

(BTW, is there an easy way to generate those links, or do you type in things like #L24-L25 yourself?)

I am pretty sure that my previous comment is completely correct as stated. What may be wrong is the hypothesis:

If you want the third "when" in the example to be highlighted the same way that the second is now ...

If that is the problem, then please be clear about which word you want highlighted differently. Or supply your own example. Here is a screenshot of the example I proposed: silly_rule

benjifisher avatar Nov 30 '14 19:11 benjifisher

Sorry, I did interchange terminology incorrectly. I edited my previous comment in hopes that it is more clear.

Regarding those links with the lines highlighted, when viewing a code file you can click a line number to highlight it. This changes the URL of the current page to correspond to the change. To select a line range, click the first line you want then shift-click the last line you want.

chase avatar Nov 30 '14 22:11 chase

Essentially it is not a single word's highlighting to be changed, otherwise I would have implemented this a long time ago. I want the value of the key-value mapping to be highlighted as I described above.

chase avatar Nov 30 '14 22:11 chase

Thanks for the tip on using GitHub.

Referring to the example, I now think that you want to leave the "when"'s as they are, but change "some_condition" to have the same highlighting as the second "when". In other words, "some_condition" should be part of the jinjaVarBlock syntax group ... or part of a syntax group that behaves just like the jinjaVarBlock syntax group.

benjifisher avatar Nov 30 '14 22:11 benjifisher

Sounds like I finally got my thoughts across properly, haha. Sorry about all the communication issues.

Yes, "some_condition" should be part of a syntax group that behaves just like jinjaVarBlock.

chase avatar Nov 30 '14 22:11 chase