Skip to content

Commit 03b45fc

Browse files
committed
Change view helper highlighting from "keyword" to "match"
The primary purpose of this change is to avoid false positives in hash keywords, which vim-ruby currently handles, but at great cost. View helpers are a good place to try out this change as they're autogenerated, and this change has the added bonus of simplifying the handling of the "?" helpers. References: vim-ruby/vim-ruby#452
1 parent 0696a04 commit 03b45fc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

after/syntax/ruby/rails.vim

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ if s:path =~# '/app/jobs/.*\.rb$'
5252
endif
5353

5454
if s:path =~# '/app/helpers/.*_helper\.rb$\|/app/views/'
55-
syn keyword rubyViewHelper
55+
let s:autogenerated_helpers = '
5656
\ action_name asset_path asset_url atom_feed audio_path audio_tag audio_url auto_discovery_link_tag
5757
\ button_tag button_to
58-
\ cache cache_fragment_name cache_if cache_unless capture cdata_section check_box check_box_tag collection_check_boxes collection_radio_buttons collection_select color_field color_field_tag compute_asset_extname compute_asset_host compute_asset_path concat content_tag content_tag_for controller controller_name controller_path convert_to_model cookies csp_meta_tag csrf_meta_tag csrf_meta_tags current_cycle cycle
58+
\ cache cache_fragment_name cache_if cache_unless capture cdata_section check_box check_box_tag collection_check_boxes collection_radio_buttons collection_select color_field color_field_tag compute_asset_extname compute_asset_host compute_asset_path concat content_for content_for? content_tag content_tag_for controller controller_name controller_path convert_to_model cookies csp_meta_tag csrf_meta_tag csrf_meta_tags current_cycle current_page? cycle
5959
\ date_field date_field_tag date_select datetime_field datetime_field_tag datetime_local_field datetime_local_field_tag datetime_select debug distance_of_time_in_words distance_of_time_in_words_to_now div_for dom_class dom_id
6060
\ email_field email_field_tag escape_javascript escape_once excerpt
6161
\ favicon_link_tag field_set_tag fields fields_for file_field file_field_tag flash font_path font_url form_for form_tag form_with
@@ -74,13 +74,14 @@ if s:path =~# '/app/helpers/.*_helper\.rb$\|/app/views/'
7474
\ url_field url_field_tag url_for url_to_asset url_to_audio url_to_font url_to_image url_to_javascript url_to_stylesheet url_to_video utf8_enforcer_tag
7575
\ video_path video_tag video_url
7676
\ week_field week_field_tag word_wrap
77-
syn match rubyViewHelper '\<select\>\%(\s*{\|\s*do\>\|\s*(\=\s*&\)\@!'
78-
syn match rubyViewHelper '\<\%(content_for\w\@!?\=\|current_page?\)'
79-
syn match rubyViewHelper '\.\@<!\<\(h\|html_escape\|u\|url_encode\)\>'
80-
syn match rubyViewHelper '\<\%(asset_pack_path\|image_pack_tag\|javascript_pack_tag\|stylesheet_pack_tag\)\>'
81-
syn match rubyViewHelper '\<action_cable_meta_tag\>'
77+
\'[1:-1]
78+
exe 'syn match rubyViewHelper "\v<%(' . escape(tr(s:autogenerated_helpers, ' ', '|'), '?') . ')[[:keyword:]!?:]@!"'
79+
syn match rubyViewHelper '\v<select>%([!?:]|\s*[{]|\s*do>|\s*[(]=\s*[&])@!'
80+
syn match rubyViewHelper '\v\.@<!<%(h|html_escape|u|url_encode)>[!?:]@!'
81+
syn match rubyViewHelper '\v<%(asset_pack_path|image_pack_tag|javascript_pack_tag|stylesheet_pack_tag)>[!?:]@!'
82+
syn match rubyViewHelper '\v<action_cable_meta_tag>[!?:]@!'
8283
if s:path =~# '_[^\/]*$'
83-
syn keyword rubyViewHelper local_assigns
84+
syn match rubyViewHelper '\v<local_assigns>[!?:]@!'
8485
endif
8586
endif
8687

0 commit comments

Comments
 (0)