Skip to content

Commit

Permalink
feat: support table.field = function style functions
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
numToStr committed Apr 23, 2022
1 parent da4aab1 commit b6d4693
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion emmylua.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ end
---@see U.mul
---@see U.sum
---@see U.sub
function U.magical(this, that)
U.magical = function(this, that)
return (U.mul(this, that) / U.sum(that, this)), (U.sum(this, that) * U.sub(that, this))
end

Expand Down
32 changes: 16 additions & 16 deletions src/fixtures/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ local U = {}
---@param this number First number
---@param that number Second number
local function mul(this, that)
print(this * that)
print(this * that)
end

---Add two integar and print it
---@param this number First number
---@param that number Second number
function U.sum(this, that)
print(this + that)
print(this + that)
end

---Subtract second from the first integar
Expand All @@ -54,7 +54,7 @@ end
---@return number
---@usage `require("module.U").sub(10, 5)`
function U.sub(this, that)
return this - that
return this - that
end

---This is a magical function
Expand All @@ -65,8 +65,8 @@ end
---@see U.mul
---@see U.sum
---@see U.sub
function U.magical(this, that)
return (U.mul(this, that) / U.sum(that, this)), (U.sum(this, that) * U.sub(that, this))
U.magical = function(this, that)
return (U.mul(this, that) / U.sum(that, this)), (U.sum(this, that) * U.sub(that, this))
end

---@class Human The Homosapien
Expand All @@ -78,11 +78,11 @@ end
---@return Human
---@usage `require('Human'):create()`
function U:create()
return setmetatable({
legs = 2,
hands = 2,
brain = false,
}, { __index = self })
return setmetatable({
legs = 2,
hands = 2,
brain = false,
}, { __index = self })
end

---@class Chai Ingredients for making chai
Expand All @@ -95,19 +95,19 @@ end
---A object containing the recipe for making chai
---@type Chai
U.chai = {
milk = "1.5 Cup",
water = "0.5 Cup",
sugar = "3 tablespoon",
tea_leaves = "2 tablespoon",
cardamom = "2 pieces",
milk = '1.5 Cup',
water = '0.5 Cup',
sugar = '3 tablespoon',
tea_leaves = '2 tablespoon',
cardamom = '2 pieces',
}

---@alias Lines string[] All the lines in the buffer

---Returns all the content of the buffer
---@return Lines
function U.get_all()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end

return U
9 changes: 7 additions & 2 deletions src/frontend/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ impl Lua {
.then_ignore(just('='))
.map(|x| format!("---@expr {x} private")),
))),
func.ignore_then(dotted)
func.clone()
.ignore_then(dotted)
.map(|x| format!("---@func {x} public")),
expr.map(|x| format!("---@expr {x} public")),
choice((
expr.then_ignore(func)
.map(|x| format!("---@func {x} public")),
expr.map(|x| format!("---@expr {x} public")),
)),
keyword("return")
.ignore_then(ident().padded())
.then_ignore(end())
Expand Down
4 changes: 4 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
quote_style = "AutoPreferSingle"

0 comments on commit b6d4693

Please sign in to comment.