Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可否同时提供注解文件? #322

Open
fxliang opened this issue Mar 15, 2024 · 2 comments
Open

可否同时提供注解文件? #322

fxliang opened this issue Mar 15, 2024 · 2 comments

Comments

@fxliang
Copy link
Contributor

fxliang commented Mar 15, 2024

如下这样的一个sample,这样在一些带lsp的编辑器中就可以实现编辑的时候的代码提示和自动补全功能
image
image

----------------------------------------------------------------
---@class KeyEventReg
---@field modifier number modifier of KeyEventReg
---@field keycode number keycode of KeyEventReg
KeyEventReg = { }
_KeyEventReg = { }
_KeyEventReg.kShiftMask = (1<<0)
_KeyEventReg.kLockMask = (1<<1)
_KeyEventReg.kCtrlMask = (1<<2)
_KeyEventReg.kMod1Mask = (1<<3)
_KeyEventReg.kAltMask = (1<<3)
_KeyEventReg.kMod2Mask = (1<<4)
_KeyEventReg.kMod3Mask = (1<<5)
_KeyEventReg.kMod4Mask = (1<<6)
_KeyEventReg.kMod5Mask = (1<<7)
_KeyEventReg.kReleaseMask = (1<<30)
_KeyEventReg.kSuperMask = (1<<26)
_KeyEventReg.kHyperMask = (1<<27)
_KeyEventReg.kMetaMask = (1<<28)
_KeyEventReg.kModifierMask = 0x5f001fff
---@func fun(): string
---key info for human being
---binding of rime::KeyEvent::repr()
---@return string
function KeyEventReg:repr()
    -- not actually fullfield here
    return ""
end
---@func fun(): boolean
---check if it's shifted
---binding of rime::KeyEvent::shift()
---@return boolean
function KeyEventReg:shift() return (self.modifier & _KeyEventReg.kShiftMask) end
---check if it's released
---binding of rime::KeyEvent::release()
---@func fun(): boolean
---@return boolean
function KeyEventReg:release() return (self.modifier & _KeyEventReg.kReleaseMask) end
---@func fun(): boolean
---check if it's ctrled
---binding of rime::KeyEvent::ctrl()
---@return boolean
function KeyEventReg:ctrl() return (self.modifier & _KeyEventReg.kCtrlMask) end
---@func fun(): boolean
---check if it's capslocked
---binding of rime::KeyEvent::caps()
---@return boolean
function KeyEventReg:caps() return (self.modifier & _KeyEventReg.kLockMask) end
---@func fun(): boolean
---check if it's supered
---binding of rime::KeyEvent::super()
---@return boolean
function KeyEventReg:super() return (self.modifier & _KeyEventReg.kSuperMask) end
---@func fun(): boolean
---check if it's alted
---binding of rime::KeyEvent::alt()
---@return boolean
function KeyEventReg:alt() return (self.modifier & _KeyEventReg.kAltMask) end
---@func fun(): boolean
---@param key KeyEventReg
---check if is == key
---binding of rime::KeyEvent::operator==
---@return boolean
function KeyEventReg:eq(key)
    return self.keycode == key.keycode and self.modifier == key.modifier
end
---@func fun(): boolean
---@param key KeyEventReg
---check if is < key
---binding of rime::KeyEvent::operator<
---@return boolean
function KeyEventReg:lt(key)
    if not self:eq(key) then
        return self.keycode < key.keycode
    else
        return self.modifier < key.modifier
    end
end

---@param arg1 string | number
---@param ... nil | number
---@return KeyEventReg | nil
---Create a KeyEventReg by KeyEvent(repr) or KeyEvent(keycode, modifier)
function KeyEvent(arg1, ...)
end
@hchunhui
Copy link
Owner

可能可以新建一个 contrib 目录,用于收集类似的辅助开发配置和纯 lua 层面的开发框架?

@tansongchen
Copy link

@hchunhui 作者大大好,我在 @lost-melody 的工作的基础上做了一份完整的定义文件,可以被 vscode 等编辑器中的 lua language server 识别,目前发布在 GitHub Gists 上:

https://gist.github.com/tansongchen/d4ed4fc4886d2ddee60dc5403c5005f4

如有需要,也可以合并进本仓库

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants