diff --git a/CHANGELOG.md b/CHANGELOG.md index c90e1af509..8f4f0361ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ BUG FIXES: [[GH-1513]](https://github.com/fatih/vim-go/pull/1513) * `:GoImpl` tab-completion would sometimes stop working [[GH-1581]](https://github.com/fatih/vim-go/pull/1581). +* Add `g:go_highlight_function_arguments` to highlight function arguments. + [[GH-1587]](https://github.com/fatih/vim-go/pull/1587). IMPROVEMENTS: diff --git a/doc/vim-go.txt b/doc/vim-go.txt index cf9e711c4d..60218be02e 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1094,9 +1094,9 @@ SETTINGS *go-settings* *'g:go_test_prepend_name'* Prepend the name of the failed test to each test message generated by a failed -test. By default it is disabled. +test. By default it is disabled. > - let g:go_test_prepend_name = 0 + let g:go_test_prepend_name = 0 < *'g:go_test_timeout'* @@ -1703,6 +1703,14 @@ Highlight operators such as `:=` , `==`, `-=`, etc. Highlight function names. > let g:go_highlight_functions = 0 +< + *'g:go_highlight_function_arguments'* + +Highlight the variable names in arguments and return values in function +declarations. Setting this implies the functionality from +|'g:go_highlight_functions'|. +> + let g:go_highlight_function_arguments = 0 < *'g:go_highlight_methods'* diff --git a/syntax/go.vim b/syntax/go.vim index 783912d51f..8e7df12243 100644 --- a/syntax/go.vim +++ b/syntax/go.vim @@ -38,6 +38,10 @@ if !exists("g:go_highlight_functions") let g:go_highlight_functions = 0 endif +if !exists("g:go_highlight_function_arguments") + let g:go_highlight_function_arguments = 0 +endif + if !exists("g:go_highlight_methods") let g:go_highlight_methods = 0 endif @@ -94,7 +98,7 @@ if exists("g:go_fold_enable") if index(g:go_fold_enable, 'package_comment') == -1 let s:fold_package_comment = 0 endif - + " Disabled by default. if index(g:go_fold_enable, 'comment') > -1 let s:fold_comment = 1 @@ -229,14 +233,14 @@ endif " var, const if s:fold_varconst syn region goVar start='var (' end='^\s*)$' transparent fold - \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments syn region goConst start='const (' end='^\s*)$' transparent fold - \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments else - syn region goVar start='var (' end='^\s*)$' transparent - \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + syn region goVar start='var (' end='^\s*)$' transparent + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments syn region goConst start='const (' end='^\s*)$' transparent - \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar + \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments endif " Single-line var, const, and import. @@ -343,14 +347,22 @@ endif hi def link goOperator Operator " Functions; -if g:go_highlight_functions != 0 - syn match goDeclaration /\/ nextgroup=goReceiver,goFunction skipwhite skipnl - syn match goReceiver /(\(\w\|[ *]\)\+)/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl - syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained +if g:go_highlight_functions isnot 0 || g:go_highlight_function_arguments isnot 0 + syn match goFunctionCall /\w\+\ze(/ contains=goBuiltins,goDeclaration + syn match goDeclaration /\/ nextgroup=goReceiver,goFunction,goSimpleArguments skipwhite skipnl + syn match goReceiverVar /\w\+\ze\s\+\(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl + syn match goFunction /\w\+/ nextgroup=goSimpleArguments contained skipwhite skipnl syn match goReceiverType /\w\+/ contained - syn match goFunction /\w\+/ contained - syn match goFunctionCall /\w\+\ze(/ contains=GoBuiltins,goDeclaration +if g:go_highlight_function_arguments isnot 0 + syn match goSimpleArguments /(\(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goArgumentName nextgroup=goSimpleArguments skipwhite skipnl + syn match goArgumentName /\w\+\(\s*,\s*\w\+\)*\ze\s\+\(\w\|\.\|\*\|\[\)/ contained nextgroup=goArgumentType skipwhite skipnl + syn match goArgumentType /\([^,)]\|\_s\)\+,\?/ contained nextgroup=goArgumentName skipwhite skipnl + \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock + hi def link goReceiverVar goArgumentName + hi def link goArgumentName Identifier +endif + syn match goReceiver /(\s*\w\+\(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl else syn keyword goDeclaration func endif