Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Add Jinja highlighting for special Ansible functions #2

Open
chase opened this issue Dec 12, 2013 · 9 comments
Open

Add Jinja highlighting for special Ansible functions #2

chase opened this issue Dec 12, 2013 · 9 comments

Comments

@chase
Copy link
Owner

chase commented Dec 12, 2013

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 chase changed the title Add Jinja highlighting for special Ansible functions Add Jinja highlighting for special Ansible functions Mar 23, 2014
@chase chase closed this as completed Jun 28, 2014
@chase chase reopened this Jun 28, 2014
@benjifisher
Copy link
Contributor

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

@chase
Copy link
Owner Author

chase commented Nov 30, 2014

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 ``}}`.

@benjifisher
Copy link
Contributor

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.

@chase
Copy link
Owner Author

chase commented Nov 30, 2014

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 {{ .. }}.

@benjifisher
Copy link
Contributor

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

@chase
Copy link
Owner Author

chase commented Nov 30, 2014

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
Copy link
Owner Author

chase commented Nov 30, 2014

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.

@benjifisher
Copy link
Contributor

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.

@chase
Copy link
Owner Author

chase commented Nov 30, 2014

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.

benjifisher added a commit that referenced this issue Dec 1, 2014
Add this cluster, then replace a bunch of
containedin=jinjaVarBlock,jinjaNested clauses with
contains=@jinjaNestedElement on the jinjaVarBlock and jinjaNested syntax
groups.
benjifisher added a commit that referenced this issue Dec 1, 2014
These replace the jinja variants for mappings where the key is one of
the Ansible keywords when, changed_when, or with_*. The ansibleVarBlock
item can contain exactly the same things as the jinjaVarBlock element,
namely the @jinjaNestedElement syntax cluster.
benjifisher added a commit that referenced this issue Dec 23, 2014
Add this cluster, then replace a bunch of
containedin=jinjaVarBlock,jinjaNested clauses with
contains=@jinjaNestedElement on the jinjaVarBlock and jinjaNested syntax
groups.
benjifisher added a commit that referenced this issue Dec 23, 2014
These replace the jinja variants for mappings where the key is one of
the Ansible keywords when, changed_when, or with_*. The ansibleVarBlock
item can contain exactly the same things as the jinjaVarBlock element,
namely the @jinjaNestedElement syntax cluster.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants