Skip to content

Commit 93199cf

Browse files
committed
Fix indentation specs
Remove all indentation before force vim to indent to check if vim indent the code right.
1 parent 56b433c commit 93199cf

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

indent/elixir.vim

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let b:did_indent = 1
1010

1111
setlocal nosmartindent
1212

13-
setlocal indentexpr=GetElixirIndent(v:lnum)
13+
setlocal indentexpr=GetElixirIndent()
1414
setlocal indentkeys+==end,=else:,=match:,=elsif:,=catch:,=after:,=rescue:
1515

1616
if exists("*GetElixirIndent")
@@ -31,7 +31,7 @@ let s:pipeline = '^\s*|>.*$'
3131
let s:indent_keywords = '\<\%(' . s:block_start . '\|' . s:block_middle . '\)$' . '\|' . s:arrow
3232
let s:deindent_keywords = '^\s*\<\%(' . s:block_end . '\|' . s:block_middle . '\)\>' . '\|' . s:arrow
3333

34-
function! GetElixirIndent(...)
34+
function! GetElixirIndent()
3535
let lnum = prevnonblank(v:lnum - 1)
3636
let ind = indent(lnum)
3737

@@ -40,6 +40,14 @@ function! GetElixirIndent(...)
4040
return 0
4141
endif
4242

43+
" TODO: Remove these 2 lines
44+
" I don't know why, but for the test on spec/indent/lists_spec.rb:24.
45+
" Vim is making some mess on parsing the syntax of 'end', it is being
46+
" recognized as 'elixirString' when should be recognized as 'elixirBlock'.
47+
" This forces vim to sync the syntax.
48+
call synID(v:lnum, 1, 1)
49+
syntax sync fromstart
50+
4351
if synIDattr(synID(v:lnum, 1, 1), "name") !~ s:skip_syntax
4452
let current_line = getline(v:lnum)
4553
let last_line = getline(lnum)
@@ -61,7 +69,7 @@ function! GetElixirIndent(...)
6169
if current_line =~ s:pipeline &&
6270
\ last_line =~ '^[^=]\+=.\+$'
6371
let b:old_ind = ind
64-
let ind += round(match(last_line, '=') / &sw) * &sw
72+
let ind = float2nr(matchend(last_line, '=\s*[^ ]') / &sw) * &sw
6573
endif
6674

6775
" if last line starts with pipeline
@@ -78,6 +86,7 @@ function! GetElixirIndent(...)
7886
\ '\<:\@<!' . s:block_end . '\>\zs',
7987
\ 'nbW',
8088
\ s:block_skip )
89+
8190
let ind = indent(bslnum)
8291
endif
8392

spec/indent/pipeline_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ def test do
4242
end
4343
EOF
4444
end
45+
46+
it "using a record with pipeline" do
47+
assert_correct_indenting <<-EOF
48+
defrecord RECORD, field_a: nil, field_b: nil
49+
50+
rec = RECORD.new
51+
|> IO.inspect
52+
EOF
53+
end
4554
end

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ def assert_correct_indenting(string)
66
content = write_file(string)
77

88
@vim.edit file
9+
# remove all indentation
10+
@vim.normal 'ggVG999<<'
11+
# force vim to indent the file
912
@vim.normal 'gg=G'
1013
@vim.write
1114

0 commit comments

Comments
 (0)