Skip to content

add elixirFunctionCall #521

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

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions spec/syntax/alias_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
str = "Enum.empty?(...)"
expect(str).to include_elixir_syntax('elixirAlias', 'Enum')
expect(str).to include_elixir_syntax('elixirOperator', '\.')
expect(str).to include_elixir_syntax('elixirId', 'empty?')
expect(str).to include_elixir_syntax('elixirFunctionCall', 'empty?')
end

it 'colorize the module alias even if it starts with `!`' do
Expand Down Expand Up @@ -43,6 +43,6 @@
expect(str).to include_elixir_syntax('elixirAlias', '\.\(Baz\)\@=')
expect(str).to include_elixir_syntax('elixirAlias', 'Baz')
expect(str).to include_elixir_syntax('elixirOperator', '\.\(fun\)\@=')
expect(str).to include_elixir_syntax('elixirId', 'fun')
expect(str).to include_elixir_syntax('elixirFunctionCall', 'fun')
end
end
112 changes: 111 additions & 1 deletion spec/syntax/function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe 'function syntax' do
it 'doesnt treat underscored functions like unsued variables' do
expect(<<~EOF).to include_elixir_syntax('elixirId', '__ensure_defimpl__')
expect(<<~EOF).to include_elixir_syntax('elixirFunctionCall', '__ensure_defimpl__')
defp derive(protocol, for, struct, opts, env) do
# ... code ...
__ensure_defimpl__(protocol, for, env)
Expand All @@ -17,4 +17,114 @@
__ensure_defimpl__(protocol, for, env)
EOF
end

it 'matches top-level macros as elixirKeyword' do
expect(<<~EOF).to include_elixir_syntax('elixirKeyword', 'quote')
quote do
# ... code ...
end
EOF

expect(<<~EOF).to include_elixir_syntax('elixirKeyword', 'quote')
quote(do: '')
EOF
end

it 'detects higher order function calls' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func.()
EOF
end

it 'detects function calls with parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func()
EOF
end

it 'detects function calls with bangs' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func!')
func!()
EOF
end

it 'detects function calls with question marks' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func?')
func?()
EOF
end

it 'detects function calls appended by module with parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
Mod.func()
EOF
end

it 'detects function calls appended by atom with parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
:mod.func()
EOF
end

it 'detects function calls appended by module without parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
Mod.func
EOF
end

it 'detects function calls appended by atom without parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
:mod.func
EOF
end

it 'detects function calls without parenthesis that contain paramenters' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func 1
EOF
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func [1]
EOF
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func :atom
EOF
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func "string"
EOF
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
func 'a'
EOF
end

it 'does not highlight function calls without parenthesis that does not contain paramenters' do
expect(<<~'EOF').not_to include_elixir_syntax('elixirFunctionCall', 'func')
func
EOF
end

it 'does not detect calls to function with invalid names' do
expect(<<~'EOF').not_to include_elixir_syntax('elixirFunctionCall', '2fast2func')
2fast2func()
EOF
end

it 'ignores spacing between module and function names' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
Module . func
EOF
end

it 'detects piped functions with parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
one_func()
|> func()
EOF
end

it 'detects piped functions without parenthesis' do
expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func')
one_func()
|> func
EOF
end
end
4 changes: 2 additions & 2 deletions spec/syntax/module_function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

describe 'Module function syntax' do
it 'for used as module function' do
expect(<<~EOF).to include_elixir_syntax('elixirId', 'for')
expect(<<~EOF).to include_elixir_syntax('elixirFunctionCall', 'for')
OverridesDefault.for
EOF
end

it 'case used as module function' do
expect(<<~EOF).to include_elixir_syntax('elixirId', 'case')
expect(<<~EOF).to include_elixir_syntax('elixirFunctionCall', 'case')
OverridesDefault.case
EOF
end
Expand Down
4 changes: 4 additions & 0 deletions syntax/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ syn keyword elixirTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained

syn match elixirId '\<[_a-zA-Z]\w*[!?]\?\>' contains=elixirUnusedVariable

syn match elixirFunctionCall '\<[a-z_]\w*[!?]\?\(\s*\.\?\s*(\|\s\+[a-zA-Z0-9@:\'\"\[]\)\@='
syn match elixirFunctionCall '\(:\w\+\s*\.\s*\|[A-Z]\w*\s*\.\s*\)\@<=[a-z_]\w*[!?]\?'
syn match elixirFunctionCall '\(>\s+\)\<[a-z_]\w*[!?]\?'

syn match elixirKeyword '\(\.\)\@<!\<\(for\|case\|when\|with\|cond\|if\|unless\|try\|receive\|after\|raise\|rescue\|catch\|else\|quote\|unquote\|super\|unquote_splicing\)\>:\@!'

syn keyword elixirInclude import require alias use
Expand Down