Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Improving indent file to more indent scenarios if there is a rule line above #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions indent/cucumber.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ function! s:syn(lnum)
return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
endfunction

" Search if we are under the scope of a rule.
" Return 1 if there is a rule above the given line number... Till we find a feature heading or the start of the file.
" Return 0 otherwise.
function! s:hasRuleAbove(lnum)
let lnum = a:lnum
let line = getline(lnum)
while lnum > 0 && line !~# '^\s*Feature:'
if line =~# '^\s*Rule:'
return 1
endif
let lnum -= 1
let line = getline(lnum)
endwhile
return 0
endfunction

function! GetCucumberIndent()
let line = getline(prevnonblank(v:lnum-1))
let cline = getline(v:lnum)
Expand All @@ -31,15 +47,19 @@ function! GetCucumberIndent()
let syn = s:syn(prevnonblank(v:lnum-1))
let csyn = s:syn(v:lnum)
let nsyn = s:syn(nextnonblank(v:lnum+1))
let hasRuleAbove = s:hasRuleAbove(v:lnum)
if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
" feature heading
return 0
elseif csyn ==# 'cucumberRule' || cline =~# '^\s*Rule:'
" rule heading
return sw
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
" examples heading
return 2 * sw
return (hasRuleAbove ? 3 : 2) * sw
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" background, scenario or outline heading
return sw
return (hasRuleAbove ? 2 : 1) * sw
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
" line after feature heading
return sw
Expand All @@ -48,7 +68,7 @@ function! GetCucumberIndent()
return 3 * sw
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
" line after background, scenario or outline heading
return 2 * sw
return (hasRuleAbove ? 3 : 2) * sw
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
" tag or comment before a feature heading
return 0
Expand Down