From 30bd139aaefcf771bf8a048fea2db078645fe23a Mon Sep 17 00:00:00 2001 From: William Sanches Date: Thu, 29 Aug 2019 19:13:53 -0300 Subject: [PATCH 1/6] Add syntax highlight to function calls This supports function calls without parenthesis only if prepended by the module name, otherwise parenthesis are mandatory for a function call to be detected --- spec/syntax/function_spec.rb | 12 ++++++++++++ syntax/elixir.vim | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index a42584af..b148b202 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -17,4 +17,16 @@ __ensure_defimpl__(protocol, for, env) EOF end + + it 'detects function calls with parenthesis' do + expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func') + 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 end diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 934eddb1..014b5939 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -50,6 +50,9 @@ syn keyword elixirBoolean true false nil syn match elixirVariable '@[a-z]\w*' syn match elixirVariable '&\d\+' +syn match elixirFunctionCall '\<[a-z_]\w*[!?]\?\(\s*\.\?\s*(\)\@=' +syn match elixirFunctionCall '\([A-Z]\w*\s*\.\s*\)\@<=[a-z_]\w*[!?]\?' + syn keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__ syn match elixirNumber '\<-\?\d\(_\?\d\)*\(\.[^[:space:][:digit:]]\@!\(_\?\d\)*\)\?\([eE][-+]\?\d\(_\?\d\)*\)\?\>' @@ -197,6 +200,7 @@ hi def link elixirStructDefine Define hi def link elixirExUnitMacro Define hi def link elixirModuleDeclaration Type hi def link elixirPrivateFunctionDeclaration elixirFunctionDeclaration +hi def link elixirFunctionCall Function hi def link elixirFunctionDeclaration Function hi def link elixirPrivateMacroDeclaration elixirMacroDeclaration hi def link elixirMacroDeclaration Macro From 9f5b45b93dc6fd6a53c8f344bd8c9dccbfb6c1a2 Mon Sep 17 00:00:00 2001 From: William Sanches Date: Thu, 29 Aug 2019 20:49:41 -0400 Subject: [PATCH 2/6] Add more tests to the suite --- spec/syntax/function_spec.rb | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index b148b202..1a62269f 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -18,15 +18,57 @@ 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 module without parenthesis' do expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func') Mod.func EOF end + + it 'does not highlight terms without a parentheresis' 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').not_to include_elixir_syntax('elixirFunctionCall', 'func') + Module . func + EOF + end end From 1ec533dda484f31e52a5d61415d0cd039e4748ab Mon Sep 17 00:00:00 2001 From: William Sanches Date: Fri, 30 Aug 2019 15:38:38 -0300 Subject: [PATCH 3/6] Add atom as module syntax support --- spec/syntax/function_spec.rb | 14 +++++++++++++- syntax/elixir.vim | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index 1a62269f..9d5e6ebf 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -48,13 +48,25 @@ 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 'does not highlight terms without a parentheresis' do + it 'detects function calls appended by atom without parenthesis' do + expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func') + :mod.func + EOF + end + + it 'does not highlight function calls without parameters that have no parenthesis' do expect(<<~'EOF').not_to include_elixir_syntax('elixirFunctionCall', 'func') func EOF diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 014b5939..e447f9ef 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -51,7 +51,7 @@ syn match elixirVariable '@[a-z]\w*' syn match elixirVariable '&\d\+' syn match elixirFunctionCall '\<[a-z_]\w*[!?]\?\(\s*\.\?\s*(\)\@=' -syn match elixirFunctionCall '\([A-Z]\w*\s*\.\s*\)\@<=[a-z_]\w*[!?]\?' +syn match elixirFunctionCall '\(:\w\+\s*\.\s*\|[A-Z]\w*\s*\.\s*\)\@<=[a-z_]\w*[!?]\?' syn keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__ From 1dea960565c46bf6aab7f322aabf19bf96341309 Mon Sep 17 00:00:00 2001 From: William Sanches Date: Fri, 30 Aug 2019 16:15:57 -0300 Subject: [PATCH 4/6] Add support to function calls without parenthesis --- spec/syntax/function_spec.rb | 20 +++++++++++++++++++- syntax/elixir.vim | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index 9d5e6ebf..750033e6 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -66,7 +66,25 @@ EOF end - it 'does not highlight function calls without parameters that have no parenthesis' do + 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 diff --git a/syntax/elixir.vim b/syntax/elixir.vim index e447f9ef..3320b181 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -50,7 +50,7 @@ syn keyword elixirBoolean true false nil syn match elixirVariable '@[a-z]\w*' syn match elixirVariable '&\d\+' -syn match elixirFunctionCall '\<[a-z_]\w*[!?]\?\(\s*\.\?\s*(\)\@=' +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 keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__ From 304b4d7dbd51dbfb23af002b1409a6eedcfad82e Mon Sep 17 00:00:00 2001 From: William Sanches Date: Fri, 30 Aug 2019 16:27:43 -0300 Subject: [PATCH 5/6] Fix some broken test tests --- spec/syntax/function_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index 750033e6..5cb095ef 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -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) @@ -97,7 +97,7 @@ end it 'ignores spacing between module and function names' do - expect(<<~'EOF').not_to include_elixir_syntax('elixirFunctionCall', 'func') + expect(<<~'EOF').to include_elixir_syntax('elixirFunctionCall', 'func') Module . func EOF end From 46d028ea725ac4a266afe6c1c3064daf512f7caf Mon Sep 17 00:00:00 2001 From: William Sanches Date: Fri, 30 Aug 2019 16:32:19 -0300 Subject: [PATCH 6/6] Add support to functions after pipes --- spec/syntax/function_spec.rb | 14 ++++++++++++++ syntax/elixir.vim | 1 + 2 files changed, 15 insertions(+) diff --git a/spec/syntax/function_spec.rb b/spec/syntax/function_spec.rb index 5cb095ef..51f2d9a2 100644 --- a/spec/syntax/function_spec.rb +++ b/spec/syntax/function_spec.rb @@ -101,4 +101,18 @@ 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 diff --git a/syntax/elixir.vim b/syntax/elixir.vim index 3320b181..0c8c42b3 100644 --- a/syntax/elixir.vim +++ b/syntax/elixir.vim @@ -52,6 +52,7 @@ syn match elixirVariable '&\d\+' 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 keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__