Skip to content

Commit 80e03f7

Browse files
latortugatpope
authored andcommitted
Expand syntax highlighting and path recognition for ActiveJob (tpope#468)
- Highlight AJ-specific API for AJ classes queue_as, rescue_from, and lifecycle callback hooks - Add path recognition for jobs
1 parent f35e426 commit 80e03f7

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

autoload/rails.vim

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,16 @@ function! s:readable_controller_name(...) dict abort
370370
return s:sub(f,'.*<app/mailers/(.{-})\.rb$','\1')
371371
elseif f =~ '\<app/apis/.*_api\.rb$'
372372
return s:sub(f,'.*<app/apis/(.{-})_api\.rb$','\1')
373+
elseif f =~ '\<app/jobs/.*\.rb$'
374+
return s:sub(f,'.*<app/jobs/(.{-})%(_job)=\.rb$','\1')
373375
elseif f =~ '\<test/\%(functional\|controllers\)/.*_test\.rb$'
374376
return s:sub(f,'.*<test/%(functional|controllers)/(.{-})%(_controller)=_test\.rb$','\1')
375377
elseif f =~ '\<test/\%(unit/\)\?helpers/.*_helper_test\.rb$'
376378
return s:sub(f,'.*<test/%(unit/)?helpers/(.{-})_helper_test\.rb$','\1')
377379
elseif f =~ '\<spec/controllers/.*_spec\.rb$'
378380
return s:sub(f,'.*<spec/controllers/(.{-})%(_controller)=_spec\.rb$','\1')
381+
elseif f =~ '\<spec/jobs/.*_spec\.rb$'
382+
return s:sub(f,'.*<spec/jobs/(.{-})%(_job)=_spec\.rb$','\1')
379383
elseif f =~ '\<spec/helpers/.*_helper_spec\.rb$'
380384
return s:sub(f,'.*<spec/helpers/(.{-})_helper_spec\.rb$','\1')
381385
elseif f =~ '\<spec/views/.*/\w\+_view_spec\.rb$'
@@ -723,6 +727,8 @@ function! s:readable_calculate_file_type() dict abort
723727
let r = "helper"
724728
elseif f =~ '\<app/mailers/.*\.rb'
725729
let r = "mailer"
730+
elseif f =~ '\<app/jobs/.*\.rb'
731+
let r = "job"
726732
elseif f =~ '\<app/models/'
727733
let top = "\n".join(s:readfile(full_path,50),"\n")
728734
let class = matchstr(top,"\n".'class\s\+\S\+\s*<\s*\<\zs\S\+\>')
@@ -744,7 +750,7 @@ function! s:readable_calculate_file_type() dict abort
744750
let r = "view-layout-" . e
745751
elseif f =~ '\<app/views\>.*\.'
746752
let r = "view-" . e
747-
elseif f =~ '\<test/\%(unit\|models\|helpers\)/.*_test\.rb$'
753+
elseif f =~ '\<test/\%(unit\|models\|helpers\|jobs\)/.*_test\.rb$'
748754
let r = "test-unit"
749755
elseif f =~ '\<test/\%(functional\|controllers\)/.*_test\.rb$'
750756
let r = "test-functional"
@@ -1400,7 +1406,7 @@ function! s:readable_default_rake_task(...) dict abort
14001406
let opts = ' TESTOPTS=-n'.method
14011407
endif
14021408
endif
1403-
if test =~# '^test/\%(unit\|models\)\>'
1409+
if test =~# '^test/\%(unit\|models\|jobs\)\>'
14041410
return 'test:units TEST='.s:rquote(test).opts
14051411
elseif test =~# '^test/\%(functional\|controllers\)\>'
14061412
return 'test:functionals TEST='.s:rquote(test).opts
@@ -1647,7 +1653,7 @@ function! s:app_generators() dict abort
16471653
let paths += map(gems, 'v:val . "/lib"')
16481654
let builtin = []
16491655
else
1650-
let builtin = ['assets', 'controller', 'generator', 'helper', 'integration_test', 'jbuilder', 'jbuilder_scaffold_controller', 'mailer', 'migration', 'model', 'resource', 'scaffold', 'scaffold_controller', 'task']
1656+
let builtin = ['assets', 'controller', 'generator', 'helper', 'integration_test', 'jbuilder', 'jbuilder_scaffold_controller', 'mailer', 'migration', 'model', 'resource', 'scaffold', 'scaffold_controller', 'task', 'job']
16511657
endif
16521658
let generators = s:split(globpath(s:pathjoin(paths), 'generators/**/*_generator.rb'))
16531659
call map(generators, 's:sub(v:val,"^.*[\\\\/]generators[\\\\/]\\ze.","")')
@@ -3715,6 +3721,7 @@ function! s:app_user_classes() dict
37153721
call map(controllers,'v:val == "application" ? v:val."_controller" : v:val')
37163722
let classes =
37173723
\ self.relglob("app/models/","**/*",".rb") +
3724+
\ self.relglob("app/jobs/","**/*",".rb") +
37183725
\ controllers +
37193726
\ self.relglob("app/helpers/","**/*",".rb") +
37203727
\ self.relglob("lib/","**/*",".rb")
@@ -3773,6 +3780,10 @@ function! rails#buffer_syntax()
37733780
syn keyword rubyRailsRenderMethod mail render
37743781
syn keyword rubyRailsControllerMethod attachments default helper helper_attr helper_method layout
37753782
endif
3783+
if buffer.type_name('job')
3784+
syn keyword rubyRailsAPIMethod queue_as rescue_from
3785+
syn keyword rubyRailsARCallbackMethod before_enqueue around_enqueue after_enqueue before_perform around_perform after_perform
3786+
endif
37763787
if buffer.type_name('helper','view')
37773788
syn keyword rubyRailsViewMethod polymorphic_path polymorphic_url
37783789
exe "syn keyword rubyRailsHelperMethod ".s:gsub(s:helpermethods(),'<%(content_for|select)\s+','')
@@ -4542,6 +4553,7 @@ let s:default_projections = {
45424553
\ "type": "helper"
45434554
\ },
45444555
\ "app/jobs/*_job.rb": {
4556+
\ "affinity": "model",
45454557
\ "template": ["class {camelcase|capitalize|colons}Job < ActiveJob::Base", "end"],
45464558
\ "type": "job"
45474559
\ },
@@ -4717,6 +4729,16 @@ let s:has_projections = {
47174729
\ ],
47184730
\ "type": "unit test"
47194731
\ },
4732+
\ "test/jobs/*_test.rb": {
4733+
\ "affinity": "job",
4734+
\ "template": [
4735+
\ "require 'test_helper'",
4736+
\ "",
4737+
\ "class {camelcase|capitalize|colons}Test < ActiveJob::TestCase",
4738+
\ "end"
4739+
\ ],
4740+
\ "type": "unit test"
4741+
\ },
47204742
\ "test/test_helper.rb": {"type": "integration test"},
47214743
\ "test/unit/*_test.rb": {
47224744
\ "affinity": "model",
@@ -4933,7 +4955,7 @@ function! s:SetBasePath() abort
49334955
let path = ['lib', 'vendor']
49344956
let path += get(g:, 'rails_path_additions', [])
49354957
let path += get(g:, 'rails_path', [])
4936-
let path += ['app/models/concerns', 'app/controllers/concerns', 'app/controllers', 'app/helpers', 'app/mailers', 'app/models']
4958+
let path += ['app/models/concerns', 'app/controllers/concerns', 'app/controllers', 'app/helpers', 'app/mailers', 'app/models', 'app/jobs']
49374959

49384960
let true = get(v:, 'true', 1)
49394961
for [key, projection] in items(self.app().projections())
@@ -4949,10 +4971,10 @@ function! s:SetBasePath() abort
49494971
let path += ['app/views/'.self.controller_name(), 'app/views/application', 'public']
49504972
endif
49514973
if self.app().has('test')
4952-
let path += ['test', 'test/unit', 'test/functional', 'test/integration', 'test/controllers', 'test/helpers', 'test/mailers', 'test/models']
4974+
let path += ['test', 'test/unit', 'test/functional', 'test/integration', 'test/controllers', 'test/helpers', 'test/mailers', 'test/models', 'test/jobs']
49534975
endif
49544976
if self.app().has('spec')
4955-
let path += ['spec', 'spec/controllers', 'spec/helpers', 'spec/mailers', 'spec/models', 'spec/views', 'spec/lib', 'spec/features', 'spec/requests', 'spec/integration']
4977+
let path += ['spec', 'spec/controllers', 'spec/helpers', 'spec/mailers', 'spec/models', 'spec/views', 'spec/lib', 'spec/features', 'spec/requests', 'spec/integration', 'spec/jobs']
49564978
endif
49574979
if self.app().has('cucumber')
49584980
let path += ['features']

0 commit comments

Comments
 (0)