chase / vim-ansible-yaml

Add additional support for Ansible in VIM
449 stars 77 forks source link

YAML highlighting breaks on bar characters #6

Closed ches closed 10 years ago

ches commented 10 years ago

Heya, cool idea for this plugin, thanks for creating it!

I've found that with it installed and the filetype detection correctly working, the bar character is breaking my YAML syntax highlighting. It's a pretty common convention to use bars in task names since some of Ansible's own output formatting uses them too. Here's an example:

- name: Elasticsearch | Set ownership of data directory
  file: path={{ elasticsearch['data_dir'] }} owner=elasticsearch group=elasticsearch
  sudo: true
  tags:
    - elasticsearch

On my setup, the Jinja highlighting is working for the {{ }} (sweet!), but unfortunately everything else after the bar is not highlighted correctly.

I'm not schooled in the arts of Vim syntax definitions, so apologies for not trying to fix -- I'll take a stab if I have some time to learn up. Hopefully the example is enough to reproduce, let me know if any more detail about my setup is helpful.

chase commented 10 years ago

I appreciate the detailed report, @ches! Unfortunately, maintaining this project isn't one of my highest priorities right now. I'm glad you found it useful, but I can't guarantee that I will have this fixed anytime soon.

If you do decide to learn up on the ways of Vim, here are some excellent resources I have used in the past: Vim Docs: Defining a syntax Vim Tips Wiki: Creating your own syntax files

The place you would want to look first to solve your problem would be syntax/include/yaml.vim.

ches commented 10 years ago

No worries, completely understand and appreciate the honesty. I'll give it a look when I have a few minutes, seems like it's probably a pretty simple case, I was just already buried in other documentation and syntax definitions would be a costly context switch at the moment. I'll report back when I can make some headway.

rafi commented 10 years ago

Yep, the pipe character confuses the highlighting. Anyone fixed this?

Screenshot

chase commented 10 years ago

Probably not. After I finish up some other projects this weekend, I might do some syntax fixing :+1:

rafi commented 10 years ago

Thanks, would appreciate it. Tried looking in it myself, but it all looks like Chinese to me..

chase commented 10 years ago

Alright, well it looks like this is caused by the incorrect assumption that anything following a bar character is a scalar block, not just bars at the end of the line. I'll start working on an efficient solution.

On a side note, fixing a syntax file in Vim is kind of like playing tug of war with a rhino.

rafi commented 10 years ago

lol, thanks for doing this :)

rafi commented 10 years ago

Any luck? :cry:

chase commented 10 years ago

It's a work in progress, although as I have stated before: this is a low-priority project of mine. Real work comes first.

So far I've redone the syntax to support key pair recognition, that way values will be recognized appropriately and there won't be mismatches to out-of-pair elements. What I have left to do:

chase commented 10 years ago

@ches @rafi While I'm working on a more proper fix, you can remove scalar highlighting if you wish:

  1. Open vim-ansible-yaml/syntax/include/yaml.vim
  2. Remove line 35 which contains the following:
syn match   yamlScalar          '\(\(|\|>\)\s*\n*\r*\)\@<=\(\s\+\).*\n*\r*\(\(\3\).*\n\)*'
chase commented 10 years ago

Fixed in c6aca1c1938b75b102d9a6fcb9ca98de5a584b9d

ches commented 10 years ago

Thanks!

rafi commented 10 years ago

Thanks for your time!