Skip to content

Commit

Permalink
feat: Add support for the Lua language
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 24, 2019
1 parent 37da783 commit f1f1b12
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ on the function declaration. You can simply put your cursor on a function, press
- [x] Typescript ([JSDoc](https://jsdoc.app))
- [x] Coffeescript ([JSDoc](https://jsdoc.app))
- [x] FlowJS
- [x] Lua ([LDoc](https://github.com/stevedonovan/LDoc))
- [ ] Java ([JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html))
- [ ] Lua ([LuaDoc](http://lua-users.org/wiki/DocumentingLuaCode))
- [ ] Ruby ([RDoc](https://ruby.github.io/rdoc))
- [ ] Scala ([ScalaDoc](https://docs.scala-lang.org/style/scaladoc.html))
- [ ] Kotlin ([KDoc](https://kotlinlang.org/docs/reference/kotlin-doc.html))
Expand Down
154 changes: 154 additions & 0 deletions ftplugin/lua.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
" ==============================================================================
" The Lua documentation should follow the 'LDoc' conventions.
" see https://github.com/stevedonovan/LDoc
" ==============================================================================

let s:save_cpo = &cpoptions
set cpoptions&vim

let b:doge_patterns = []

""
" ==============================================================================
" Matches regular function expressions and class methods.
" ==============================================================================
"
" {match}: Regex explanation
" \m
" Interpret the pattern as a magic pattern.
"
" ^
" Matches the position before the first character in the string.
"
" \%(local\s*\)\?
" This should match the 'local' keyword.
" ------------------------------------------------------------------------
" Matches an optional and non-capturing group, denoted as '\%( ... \)\?',
" that may contain the keyword 'local' followed by 0 or more spaces, denoted
" as '\s*'.
"
" function\s*\%([[:alnum:]_:.]\+[:.]\)\?\([[:alnum:]_]\+\)\s*
" This should match the function name.
" An example scenario it should match would be 'function a.b:c (arg1, arg2)'
" where 'c' is the method name.
" ------------------------------------------------------------------------
" Matches the 'function' keyword followed by 0 or more spaces, denoted as
" '\s*', followed by an optional and non-capturing group, denoted as
" '\%( ... \)\?', that may contain 1 or more of the following characters
" '[[:alnum:]_:.]', followed by one of the following characters '[:.]',
" followed a captured group, denoted as '\( ... \)', which may contain the
" characters '[[:alnum:]_]', which can finally be followed by 0 or more
" spaces, denoted as '\s*'.
"
"
" (\(.\{-}\))
" This should match the function parameters.
" ------------------------------------------------------------------------
" Matches parenthesis, denoted as '( ... )' which contains a captured group,
" denoted as '\( ... \)', which may contain as few as possible characters,
" denoted as '.\{-}'.
"
" {parameters.match}: Regex explanation
" \m
" Interpret the pattern as a magic pattern.
"
" \([^,]\+\)
" This should match the parameter name.
" ------------------------------------------------------------------------
" Matches a captured group that may contain 1 or more of the following
" characters: '[^,]'.
call add(b:doge_patterns, {
\ 'match': '\m^\%(local\s*\)\?function\s*\%([[:alnum:]_:.]\+[:.]\)\?\([[:alnum:]_]\+\)\s*(\(.\{-}\))',
\ 'match_group_names': ['funcName', 'parameters'],
\ 'parameters': {
\ 'match': '\([^,]\+\)',
\ 'match_group_names': ['name'],
\ 'format': ['@param', '{name}', 'TODO'],
\ },
\ 'comment': {
\ 'insert': 'above',
\ 'opener': '--[[',
\ 'closer': '--]]',
\ 'trim_comparision_check': 0,
\ 'template': [
\ '---[[',
\ '-- TODO',
\ '-- {parameters}',
\ '--]]',
\ ],
\ },
\ })

""
" ==============================================================================
" Matches regular function expressions as a variable value.
" ==============================================================================
"
" {match}: Regex explanation
" \m
" Interpret the pattern as a magic pattern.
"
" ^
" Matches the position before the first character in the string.
"
" \%(local\s*\)\?
" This should match the 'local' keyword.
" ------------------------------------------------------------------------
" Matches an optional and non-capturing group, denoted as '\%( ... \)\?',
" that may contain the keyword 'local' followed by 0 or more spaces, denoted
" as '\s*'.
"
" \%([[:alnum:]_:.]\+[:.]\)\?\([[:alnum:]_]\+\)\s*=\s*
" This should match the function name.
" An example scenario it should match would be 'function a.b:c (arg1, arg2)'
" where 'c' is the method name.
" ------------------------------------------------------------------------
" Matches an optional and non-capturing group, denoted as '\%( ... \)\?',
" that may contain 1 or more of the following characters '[[:alnum:]_:.]',
" followed by one of the following characters '[:.]', followed a captured
" group, denoted as '\( ... \)', which may contain the characters
" '[[:alnum:]_]', which can finally be followed by 0 or more spaces, an
" equal sign, again followed by 0 or more spaces.
"
" \%(\s*function\s*\)\?(\(.\{-}\))
" This should match the function declaration with its parameters.
" ------------------------------------------------------------------------
" Matches an optional and non-capturing group, denoted as '\%( ... \)\?',
" that may contain the 'function' keyword, followed by 0 or more spaces,
" denoted as '\s*', followed by parenthesis, denoted as '( ... )' which
" contains a captured group, denoted as '\( ... \)', which should contain as
" few characters as possible, denoted as '.\{-}'.
"
" {parameters.match}: Regex explanation
" \m
" Interpret the pattern as a magic pattern.
"
" \([^,]\+\)
" This should match the parameter name.
" ------------------------------------------------------------------------
" Matches a captured group that may contain 1 or more of the following
" characters: '[^,]'.
call add(b:doge_patterns, {
\ 'match': '\m^\%(local\s*\)\?\%([[:alnum:]_:.]\+[:.]\)\?\([[:alnum:]_]\+\)\s*=\s*\%(\s*function\s*\)\?(\(.\{-}\))',
\ 'match_group_names': ['funcName', 'parameters'],
\ 'parameters': {
\ 'match': '\([^,]\+\)',
\ 'match_group_names': ['name'],
\ 'format': ['@param', '{name}', 'TODO'],
\ },
\ 'comment': {
\ 'insert': 'above',
\ 'opener': '--[[',
\ 'closer': '--]]',
\ 'trim_comparision_check': 0,
\ 'template': [
\ '---[[',
\ '-- TODO',
\ '-- {parameters}',
\ '--]]',
\ ],
\ },
\ })

let &cpoptions = s:save_cpo
unlet s:save_cpo
70 changes: 70 additions & 0 deletions playground/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- #! /usr/bin/env lua

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
-- @param arg3 TODO
-- @param arg4 TODO
--]]
function new_function(arg1, arg2, arg3, arg4)
-- ...
end

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
-- @param arg3 TODO
--]]
local function new_function(arg1, arg2, arg3)
-- ...
end

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
-- @param arg3 TODO
--]]
function BotDetectionHandler:access(arg1, arg2, arg3)
end

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
--]]
myprint = function(arg1, arg2)
print("This is my print function - ##",param,"##")
end

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
-- @param arg3 TODO
-- @param arg4 TODO
-- @param arg5 TODO
--]]
local myprint = function(arg1, arg2, arg3, arg4, arg5)
print("This is my print function - ##",param,"##")
end

---[[
-- TODO
-- @param arg1 TODO
-- @param arg2 TODO
--]]
function a.b:c (arg1, arg2) body end

---[[
-- TODO
-- @param self TODO
-- @param arg1 TODO
-- @param arg2 TODO
--]]
a.b.c = function (self, arg1, arg2) body end

myobj:foo(n)
myobj.foo(myobj, n)

0 comments on commit f1f1b12

Please sign in to comment.