fix: more lsp info comment and fix backend opts error

This commit is contained in:
JuanZoran
2023-03-14 22:30:25 +08:00
parent dab105b27f
commit f47abd1691
15 changed files with 102 additions and 50 deletions

View File

@ -4,6 +4,8 @@ local Trans = require('Trans')
---@class TransBackend
---@field query fun(TransData): TransResult
---@field opts TransBackendOpts
---@field no_wait? boolean whether need to wait for the result
---@field name string @backend name
local conf = Trans.conf
@ -22,7 +24,6 @@ end
local default_opts = conf.backend.default
default_opts.__index = default_opts
---@class Trans
---@field backend table<string, TransBackend>
return setmetatable({}, {

View File

@ -92,12 +92,12 @@ end
---Add highlight to buffer
---@param linenr number line number should be set[one index]
---@param col_start number column start [zero index]
---@param col_end number column end
---@param hl_group string highlight group
---@param col_start? number column start [zero index]
---@param col_end? number column end
---@param ns number? highlight namespace
function buffer:add_highlight(linenr, hl_group, col_start, col_end, ns)
linenr = linenr and linenr - 1 or -1
linenr = linenr - 1 or -1
col_start = col_start or 0
api.nvim_buf_add_highlight(self.bufnr, ns or -1, hl_group, linenr, col_start, col_end or -1)
end

View File

@ -48,7 +48,7 @@ return {
interval = 12,
},
},
---@class HoverOptions : TransFrontendOpts
---@class TransHoverOpts : TransFrontendOpts
hover = {
---@type integer Max Width of Hover Window
width = 37,

View File

@ -7,7 +7,7 @@ local Trans = require('Trans')
---@field is_word boolean @Is the str a word
---@field str string @The original string
---@field mode string @The mode of the str
---@field result table<string, TransResult> @The result of the translation
---@field result table<string, TransResult|boolean> @The result of the translation
---@field frontend TransFrontend
---@field backends table<string, TransBackend>
local M = {}

View File

@ -26,7 +26,7 @@ end
---@class TransFrontend
---@field opts TransFrontendOpts
---@field get_active_instance fun():TransFrontend?
---@field process fun(data: TransData, result: TransResult)
---@field process fun(self: TransFrontend, data: TransData, result: TransResult)
---@field wait fun(self: TransFrontend, result: TransResult, name: string, timeout: integer)
---@field execute fun(action: string) @Execute action for frontend instance

View File

@ -27,7 +27,7 @@ local function do_query(data)
backend.query(data)
else
backend.query(data)
frontend:wait(result, name, backend.timeout)
frontend:wait(result, name, backend.opts.timeout)
end

View File

@ -1,5 +1,3 @@
---@class Trans
---@field util TransUtil
local Trans = require('Trans')
local fn, api = vim.fn, vim.api
@ -79,4 +77,6 @@ function M.is_English(str)
return true
end
Trans.util = M
---@class Trans
---@field util TransUtil
return M

View File

@ -169,11 +169,15 @@ end
window.__index = window
---@alias WindowOpts
---|{style: string, border: string, focusable: boolean, noautocmd?: boolean, relative: string, width: integer, height: integer, col: integer, row: integer, zindex?: integer, title?: table | string}
---@class TransWindowOpts
local default_opts = {
enter = false,
winid = -1,
---@type WindowOpts
win_opts = {
style = 'minimal',
border = 'rounded',
@ -182,6 +186,9 @@ local default_opts = {
},
}
---@class TransWindow
---@field buffer TransBuffer attached buffer object
---@field win_opts table window config [**When open**]