Skip to content

Commit 83e1767

Browse files
committed
Tighten syn match declarations
References: vim-ruby/vim-ruby#452
1 parent 6030099 commit 83e1767

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

after/syntax/ruby/rails.vim

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ endif
9292
if s:path =~# '/app/controllers/.*\.rb$'
9393
syn keyword rubyHelper params request response session headers cookies flash
9494
syn keyword rubyMacro protect_from_forgery skip_forgery_protection http_basic_authenticate_with
95-
syn match rubyMacro '\<respond_to\>\ze[( ] *[:*]'
96-
syn match rubyResponse '\<respond_to\>\ze[( ] *\%([&{]\|do\>\)'
95+
syn match rubyMacro '\v<respond_to>\ze[( ] *[:*]'
96+
syn match rubyResponse '\v<respond_to>\ze +%([&{]|do>)'
9797
syn keyword rubyResponse render head redirect_to redirect_back respond_with send_data send_file
9898
syn keyword rubyResponse authenticate_or_request_with_http_basic authenticate_with_http_basic http_basic_authenticate_or_request_with request_http_basic_authentication
9999
endif
@@ -108,8 +108,8 @@ endif
108108

109109
if s:path =~# '/app/mailers/.*\.rb$\|/app/models/.*_mailer\.rb$'
110110
syn keyword rubyResponse mail render
111-
syn match rubyResponse "\<headers\>"
112-
syn match rubyHelper "\<headers\[\@="
111+
syn match rubyResponse '\v<headers>[!?:]@!'
112+
syn match rubyHelper '\v<headers\[@='
113113
syn keyword rubyHelper params attachments
114114
syn keyword rubyMacro default
115115
syn keyword rubyMacro register_interceptor register_interceptors register_observer register_observers
@@ -119,7 +119,7 @@ if s:path =~# '/app/\w\+/concerns/.*\.rb$'
119119
syn keyword rubyMacro included class_methods
120120
endif
121121

122-
if s:path =~# '\v/app/%(controllers|helpers|mailers)/.*\.rb$|/app/views/|/test/(controllers|integration|system)/.*_test\.rb$|/spec/(features|requests)/.*_spec\.rb'
122+
if s:path =~# '\v/app/%(controllers|helpers|mailers)/.*\.rb$|/app/views/|/test/(controllers|integration|system)/.*_test\.rb$|/spec/(features|requests)/.*_spec\.rb$'
123123
syn keyword rubyUrlHelper url_for polymorphic_path polymorphic_url edit_polymorphic_path edit_polymorphic_url new_polymorphic_path new_polymorphic_url
124124
endif
125125

@@ -136,7 +136,7 @@ if s:path =~# '/db/migrate/.*\.rb$\|/db/schema\.rb$'
136136
endif
137137

138138
if s:path =~# '\.rake$\|/Rakefile[^/]*$'
139-
syn match rubyRakeMacro '^\s*\zs\%(task\|file\|namespace\|desc\)\>\%(\s*=\)\@!'
139+
syn match rubyRakeMacro '\v^\s*\zs%(task|file|namespace|desc)>%([!?:]|\s*[=])@!'
140140
endif
141141

142142
if s:path =~# '/config/routes\>.*\.rb$'
@@ -159,9 +159,9 @@ if s:path =~# '/test\%(/\|/.*/\)test_[^\/]*\.rb$\|/test/.*_test\.rb$\|/features/
159159
endif
160160

161161
if s:path =~# '/spec/.*_spec\.rb$'
162-
syn match rubyTestHelper '\<subject\>'
163-
syn match rubyTestMacro '\<\%(let\|given\)\>!\='
164-
syn match rubyTestMacro '\<subject\>!\=\ze\s*\%([({&:]\|do\>\)'
162+
syn match rubyTestHelper '\v<subject>[!?:]@!'
163+
syn match rubyTestMacro '\v<%(let|given)!=[[:keyword:]!?:]@!'
164+
syn match rubyTestMacro '\v<subject>!=\ze%(\s*[(]|\s+[{&:]|\s+do\>)'
165165
syn keyword rubyTestMacro before after around background setup teardown
166166
syn keyword rubyTestMacro context describe feature shared_context shared_examples shared_examples_for containedin=rubyKeywordAsMethod
167167
syn keyword rubyTestMacro it example specify scenario include_examples include_context it_should_behave_like it_behaves_like
@@ -180,7 +180,7 @@ endif
180180

181181
if s:path =~# '\v/test/%(channels|controllers|helpers|integration|mailers|models|system)/.*_test\.rb$'
182182
if s:has_app && !empty(rails#app().user_assertions())
183-
exe "syn keyword rubyUserAssertion ".join(rails#app().user_assertions())
183+
exe "syn match rubyUserAssertion '\\v<%(" . escape(join(rails#app().user_assertions(), '|'), '?') . ")[[:keyword:]?!:]@!'"
184184
endif
185185
syn keyword rubyTestMacro test setup teardown
186186
syn keyword rubyAssertion assert_difference assert_no_difference
@@ -205,16 +205,16 @@ if s:path =~# '/test/system/.*_test\.rb$' ||
205205
syn keyword rubyAssertion refute_button refute_checked_field refute_content refute_css refute_current_path refute_field refute_link refute_select refute_selector refute_table refute_text refute_title refute_unchecked_field refute_xpath
206206
endif
207207

208-
if s:path =~# '/spec/controllers/.*_spec.rb'
208+
if s:path =~# '/spec/controllers/.*_spec\.rb$'
209209
syn keyword rubyTestMacro render_views
210210
syn keyword rubyTestHelper assigns
211211
endif
212-
if s:path =~# '/spec/helpers/.*_spec.rb'
212+
if s:path =~# '/spec/helpers/.*_spec\.rb$'
213213
syn keyword rubyTestAction assign
214-
syn match rubyTestHelper '\<helper\>'
215-
syn match rubyTestMacro '\<helper\>!\=\ze\s*\%([({&:]\|do\>\)'
214+
syn match rubyTestHelper '\v<helper>[!?:]@!'
215+
syn match rubyTestMacro '\v<helper>!=\ze%(\s*[(]|\s+[{&:]|\s+do\>)'
216216
endif
217-
if s:path =~# '/spec/views/.*_spec.rb'
217+
if s:path =~# '/spec/views/.*_spec\.rb$'
218218
syn keyword rubyTestAction assign render
219219
syn keyword rubyTestHelper rendered
220220
endif
@@ -224,8 +224,8 @@ if s:has_app && rails#buffer().type_name('test', 'spec')
224224
syn keyword rubyTestHelper file_fixture
225225
endif
226226
if s:path =~# '\v/test/%(controllers|integration)/.*_test\.rb$|/spec/%(controllers|requests)/.*_spec\.rb$'
227-
syn match rubyTestAction '\.\@<!\<\%(get\|post\|put\|patch\|delete\|head\|process\)\>'
228-
syn match rubyTestAction '\<follow_redirect!'
227+
syn match rubyTestAction '\v\.@<!<%(get|post|put|patch|delete|head|process)>[?!:]@!'
228+
syn match rubyTestAction '\v<follow_redirect![[:keyword:]!?:]@!'
229229
syn keyword rubyTestAction get_via_redirect post_via_redirect
230230
syn keyword rubyTestHelper request response flash session cookies fixture_file_upload
231231
endif
@@ -235,7 +235,7 @@ if s:path =~# '/test/system/.*_test\.rb$\|/spec/features/.*_spec\.rb$' ||
235235
syn keyword rubyTestHelper page text
236236
syn keyword rubyTestHelper all field_labeled find find_all find_button find_by_id find_field find_link first
237237
syn keyword rubyTestAction evaluate_script execute_script go_back go_forward open_new_window save_and_open_page save_and_open_screenshot save_page save_screenshot switch_to_frame switch_to_window visit window_opened_by within within_element within_fieldset within_frame within_table within_window
238-
syn match rubyTestAction "\<reset_session!"
238+
syn match rubyTestAction '\v<reset_session![[:keyword:]!?:]@!'
239239
syn keyword rubyTestAction attach_file check choose click_button click_link click_link_or_button click_on fill_in select uncheck unselect
240240
endif
241241

@@ -260,7 +260,7 @@ function! s:highlight(group, ...) abort
260260
call filter(words, 'type(v:val) == type("") && v:val =~# ''^\h\k*[!?]\=[][{}]\=$''')
261261
if !empty(words)
262262
exe 'syn match' a:group substitute(
263-
\ '"\<\%('.join(words, '\|').'\)\%(\k\@<!\|\k\@!:\@!\)"',
263+
\ '"\<\%('.join(words, '\|').'\)[[:keyword:]!?:]\@!"',
264264
\ '[][{}]', '\=get(s:special, submatch(0), submatch(0))', 'g')
265265
endif
266266
endfunction

0 commit comments

Comments
 (0)