chore: remove useless code

This commit is contained in:
JuanZoran 2023-04-24 20:58:46 +08:00
parent 156e03306a
commit 854bce7b5a
2 changed files with 52 additions and 52 deletions

View File

@ -2,7 +2,7 @@ local api, fn = vim.api, vim.fn
---@class TransBuffer ---@class TransBuffer
---@field bufnr integer buffer handle ---@field bufnr integer buffer handle
---@field [number] string|TransNode|TransNode[] buffer[line] content ---@field [integer] string|TransNode|TransNode[] buffer[line] content
local buffer = {} local buffer = {}
-- INFO : corountine can't invoke C function -- INFO : corountine can't invoke C function

View File

@ -4,62 +4,63 @@ local util = require 'Trans'.util
---@field [1] string text to be rendered ---@field [1] string text to be rendered
---@field render fun(self: TransNode, buffer: TransBuffer, line: number, col: number) render the node ---@field render fun(self: TransNode, buffer: TransBuffer, line: number, col: number) render the node
local item = (function()
---@class TransItem : TransNode
local mt = {
---@param self TransItem
---@param buffer TransBuffer
---@param line integer
---@param col integer
render = function(self, buffer, line, col)
if self[2] then
buffer:add_highlight(line, self[2], col, col + #self[1])
end
end,
}
mt.__index = mt
---@class TransItem : TransNode ---Basic item node
local item_meta = { ---@param tuple {[1]: string, [2]: string?}
---@param self TransItem ---@return TransItem
---@param buffer TransBuffer return function(tuple)
---@param line integer return setmetatable(tuple, mt)
---@param col integer end
render = function(self, buffer, line, col) end)()
if self[2] then
buffer:add_highlight(line, self[2], col, col + #self[1])
end
end,
}
---@class TransText : TransNode local text = (function()
---@field step string ---@class TransText : TransNode
---@field nodes TransNode[] ---@field step string
local text_meta = { ---@field nodes TransNode[]
---@param self TransText
---@param buffer TransBuffer
---@param line integer
---@param col integer
render = function(self, buffer, line, col)
local nodes = self.nodes
local step = self.step
local len = step and #step or 0
for _, node in ipairs(nodes) do local mt = {
node:render(buffer, line, col) ---@param self TransText
col = col + #node[1] + len ---@param buffer TransBuffer
end ---@param line integer
end, ---@param col integer
} render = function(self, buffer, line, col)
local nodes = self.nodes
local step = self.step
local len = step and #step or 0
item_meta.__index = item_meta for _, node in ipairs(nodes) do
text_meta.__index = text_meta node:render(buffer, line, col)
col = col + #node[1] + len
end
end,
}
mt.__index = mt
---Basic item node ---@param nodes {[number]: TransNode, step: string?}
---@param tuple {[1]: string, [2]: string?} ---@return TransText
---@return TransItem return function(nodes)
local function item(tuple) return setmetatable({
return setmetatable(tuple, item_meta) [1] = table.concat(util.list_fields(nodes, 1), nodes.step),
end step = nodes.step,
nodes = nodes,
}, mt)
end
---@param nodes {[number]: TransNode, step: string?} end)()
---@return TransText
local function text(nodes)
return setmetatable({
[1] = table.concat(util.list_fields(nodes, 1), nodes.step),
step = nodes.step,
nodes = nodes,
}, text_meta)
end
---@param args {[number]: TransNode, width: integer, spin: string?} ---@param args {[number]: TransNode, width: integer, spin: string?}
@ -85,7 +86,6 @@ end
---@class TransUtil ---@class TransUtil
---@field node TransNodes ---@field node TransNodes
---@class TransNodes ---@class TransNodes
return { return {
item = item, item = item,