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

Why is luaFuncCall linked to PreProc instead of Function? #19

Open
idbrii opened this issue Jul 19, 2020 · 3 comments
Open

Why is luaFuncCall linked to PreProc instead of Function? #19

idbrii opened this issue Jul 19, 2020 · 3 comments

Comments

@idbrii
Copy link
Contributor

idbrii commented Jul 19, 2020

I've used it without thinking for a while, but recently realized why lua looks weird: function calls don't use the colors for functions.

  HiLink luaFuncCall         PreProc
  HiLink luaFuncId           Function

luaSpecialValue (built-in functions like ipairs) also uses PreProc which makes them look the same. However, for table.insert table is luaSpecialTable and insert is luaFuncCall instead of luaSpecialValue. If not for that inconsistency, it'd be nice for built-ins to stand out.

vim help says Function is:

function name (also: methods for classes)

I can see how that might be interpreted as "names in definitions" and not "names in uses", but using PreProc doesn't make sense to me.

Seems like ideally there's two changes to solve this:

  • Change luaFuncCall to Function
  • highlight functions on luaSpecialTable as luaSpecialValue
@idbrii
Copy link
Contributor Author

idbrii commented Jul 19, 2020

It's also relevant to look at other language's syntax setup since multilingual vim users will benefit from having consistent highlighting behaviour between languages (their syntax files using vim's group names to mean the same thing).

In a survey of vim-polyglot's syntax plugins (where lua is provided by this repo), languages that define some function Call use a wide mix, but only typescript also uses PreProc:

elixir.vim|     hi def link elixirCallbackDefine Define
javascript.vim| hi def link jsFuncCall           Function
rust.vim|       hi def link rustFuncCall         Function
python.vim|     hi def link pythonFunctionCall   Function
erlang.vim|     hi def link erlangGlobalFuncCall Function
erlang.vim|     hi def link erlangLocalFuncCall  Normal
erlang.vim|     hi def link erlangLocalFuncCall  Normal
erlang.vim|     hi def link erlangGlobalFuncCall Normal
lua.vim|        hi def link luaFuncCall          PreProc
common.vim|     hi def link typescriptCall       PreProc
vlang.vim|      hi def link vFunctionCall        Special
omake.vim|      hi def link omakeCallExpr        Statement
go.vim|         hi def link goFunctionCall       Type

@bfrg
Copy link

bfrg commented Nov 9, 2020

I've also found it confusing because it's inconsistent with every other syntax file I've used so far.

FWIW, I have the following in my ~/.vim/after/syntax/lua.vim:

hi link luaFuncKeyword  Statement
hi link luaLocal        Statement
hi link luaBuiltIn      Statement
hi link luaFuncCall     Function
hi link luaSpecialValue Function
hi link luaFuncTable    Identifier

This gives me a much cleaner syntax highlighting.

EDIT
In Vim >= 8.2.1703 the above links will be cleared after running :color {name} since Vim restores the hi-default links after changing the colorscheme. The hi-default links are usually set in $VIMRUNTIME/syntax/<filetype>.vim. We can override them by adding a !:

hi! def link luaFuncKeyword  Statement
hi! def link luaLocal        Statement
hi! def link luaBuiltIn      Statement
hi! def link luaFuncCall     Function
hi! def link luaSpecialValue Function
hi! def link luaFuncTable    Identifier

@Iron-E
Copy link

Iron-E commented Sep 19, 2021

@idbrii half of my colorscheme is finding and fixing those, so that all the colors I choose show up where users expect 😅

Imho going by :h group-name is generally the best thing to do. Function is more specific than Type (Go), Define is for macros (Elixir), PreProc is for pre-processor commands e.g. #[derive(…)] in Rust (Typescript), Special is for tokens not bolonging to other groups (V), and Statement is for statements (which a function call may be or be a part of).


@bfrg if you're interested, here is my list of overrides for this plugin. I go back and forth as to what luaLocal should be, sometimes I think it is more like var from C# and other times I think of it like a Keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants