BetterLua.vim icon indicating copy to clipboard operation
BetterLua.vim copied to clipboard

Other annotations supported by luals

Open vurentjie opened this issue 1 year ago • 0 comments

luals supports a few other annotations found here: https://luals.github.io/wiki/annotations/

I managed to hack something together in my after/syntax to highlight these rules. Not sure if you plan on supporting any of these. But thought I'd mention it in case someone else experiences this.

I also picked up that @class annotations are not allowing periods (.) unless I add them to my 'iskeyword' option, but I did not want to do that.

e.g see before/after examples below:

---@class com.Class: com.OtherClass

Before without fixes: After with fixes:
Screenshot from 2024-09-01 18-27-43 Screenshot from 2024-09-01 18-27-24

What I added in my after/syntax/lua.vim, it's a bit rough in parts, and have not tested it thoroughly :

[updated: after spending few days made a few more tweaks, so far this is what I settled on]

syn match luaEmmyFluff /[^@-]\S*/ contained containedin=luaEmmyComment contains=luaEmmyType

syn match luaEmmyAliasName /\K[^ ]\+/ contained containedin=luaEmmyComment
\ nextgroup=luaEmmyBar,luaEmmyType

syn match luaEmmyClassName /[^: ]\+/ contained
  \ nextgroup=luaEmmyClassColon

syn match luaEmmyType /\K[0-9\.\k]*/ contained containedin=luaEmmyComment
  \ nextgroup=luaEmmyBar

syn match luaEmmyType /\(disable\|enable\|disable\-line\|disable\-next\-line\)/ contained containedin=luaEmmyComment
  \ nextgroup=luaEmmyClassColon
  \ skipnl skipempty skipwhite

syn match luaEmmyKeyword /@\(diagnostic\|enum\|cast\|meta\|module\|source\|version\)/ contained containedin=luaEmmyComment
  \ nextgroup=luaEmmyType
  \ skipnl skipempty skipwhite

syn match luaEmmyKeyword /@\(async\|nodiscard\|protected\|private\)/ contained containedin=luaEmmyComment
  \ skipnl skipempty skipwhite

syn match luaEmmyKeyword /@operator\(\s\+\K\k*\(([^)]*)\)*\)*/ contained keepend containedin=luaEmmyComment contains=luaEmmyOperator
  \ nextgroup=luaEmmyClassColon
  \ skipnl skipempty skipwhite

syn match luaEmmyOperatorArgs /\(([^)]*)\)*/ contained
\ skipnl skipempty skipwhite

syn match luaEmmyOperator /@operator\s\+\zs\K\k*\(([^)]*)\)*/ contained keepend containedin=luaEmmyComment contains=luaEmmyOperatorArgs
  \ nextgroup=luaEmmyClassColon
  \ skipnl skipempty skipwhite

hi def link luaEmmyComment           Comment
hi def link luaEmmyClassName         Special
hi def link luaEmmyType              Type
hi def link luaEmmyAliasName         Special
hi def link luaEmmyParamName         Special
hi def link luaEmmyFieldName         Special
hi def link luaEmmyFieldExposure     StorageClass
hi def link luaEmmyGenericName       Special
hi def link luaEmmyGenericParentName Type
hi def link luaEmmySeeReference      SpecialComment
hi def link luaEmmyKeyword           PreProc
hi def link luaEmmyOperator Function

vurentjie avatar Sep 01 '24 16:09 vurentjie