diff options
author | AlexCai2019 <89138532+AlexCai2019@users.noreply.github.com> | 2022-05-08 01:43:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 01:43:28 +0800 |
commit | 0fd83c4ca9f82a02becab6c304a8a7de75098507 (patch) | |
tree | be9790d9d4823fe728c5b36e94093fe5f42b7725 /script/parser/guide.lua | |
parent | 89203efad8c9b5513e05ca4d5696107924865b10 (diff) | |
parent | 67b4c574849d1667e0ecb39c51aeed8e30b43056 (diff) | |
download | lua-language-server-0fd83c4ca9f82a02becab6c304a8a7de75098507.zip |
Merge branch 'sumneko:master' into master
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r-- | script/parser/guide.lua | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 0ece65fc..06169b09 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -16,6 +16,7 @@ local type = type ---@field uri uri ---@field start integer ---@field finish integer +---@field range integer ---@field effect integer ---@field attrs string[] ---@field specials parser.object[] @@ -56,6 +57,14 @@ local type = type ---@field init parser.object ---@field step parser.object ---@field redundant { max: integer, passed: integer } +---@field filter parser.object +---@field loc parser.object +---@field keyword integer[] +---@field casts parser.object[] +---@field mode? '+' | '-' +---@field hasGoTo? true +---@field hasReturn? true +---@field hasBreak? true ---@field _root parser.object ---@class guide @@ -71,6 +80,7 @@ local blockTypes = { ['repeat'] = true, ['do'] = true, ['function'] = true, + ['if'] = true, ['ifblock'] = true, ['elseblock'] = true, ['elseifblock'] = true, @@ -141,6 +151,9 @@ local childMap = { ['doc.see'] = {'name', 'field'}, ['doc.version'] = {'#versions'}, ['doc.diagnostic'] = {'#names'}, + ['doc.as'] = {'as'}, + ['doc.cast'] = {'loc', '#casts'}, + ['doc.cast.block'] = {'extends'}, } ---@type table<string, fun(obj: parser.object, list: parser.object[])> @@ -393,6 +406,7 @@ function m.getRoot(obj) end local parent = obj.parent if not parent then + log.error('Can not find out root:', obj.type) return nil end obj = parent @@ -413,6 +427,7 @@ function m.getUri(obj) return '' end +---@return parser.object? function m.getENV(source, start) if not start then start = 1 @@ -446,19 +461,17 @@ function m.getFunctionVarArgs(func) end --- 获取指定区块中可见的局部变量 ----@param block table ----@param name string {comment = '变量名'} ----@param pos integer {comment = '可见位置'} -function m.getLocal(block, name, pos) - block = m.getBlock(block) - for _ = 1, 10000 do - if not block then - return nil - end - local locals = block.locals - local res +---@param source parser.object +---@param name string # 变量名 +---@param pos integer # 可见位置 +---@return parser.object? +function m.getLocal(source, name, pos) + local root = m.getRoot(source) + local res + m.eachSourceContain(root, pos, function (src) + local locals = src.locals if not locals then - goto CONTINUE + return end for i = 1, #locals do local loc = locals[i] @@ -471,13 +484,8 @@ function m.getLocal(block, name, pos) end end end - if res then - return res, res - end - ::CONTINUE:: - block = m.getParentBlock(block) - end - error('guide.getLocal overstack') + end) + return res end --- 获取指定区块中所有的可见局部变量名称 @@ -602,6 +610,9 @@ local function addChilds(list, obj) end --- 遍历所有包含position的source +---@param ast parser.object +---@param position integer +---@param callback fun(src: parser.object) function m.eachSourceContain(ast, position, callback) local list = { ast } local mark = {} @@ -922,6 +933,7 @@ function m.getKeyNameOfLiteral(obj) end end +---@return string? function m.getKeyName(obj) if not obj then return nil @@ -1027,8 +1039,6 @@ function m.getKeyType(obj) return type(obj.field[1]) elseif tp == 'doc.type.field' then return type(obj.name[1]) - elseif tp == 'dummy' then - return 'string' end if tp == 'doc.field.name' then return type(obj[1]) |