diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-30 10:44:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-30 10:44:20 +0800 |
commit | 0f900c018198d20d5c795c099ac28013677ba7c4 (patch) | |
tree | 1cbf33d597d0deca90127a40d844eaebb8ef7063 /server/src/core | |
parent | 0579771df784cbfbe1dcc824c62e06782a803cef (diff) | |
download | lua-language-server-0f900c018198d20d5c795c099ac28013677ba7c4.zip |
也会遍历出__index里的内容
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/value.lua | 38 | ||||
-rw-r--r-- | server/src/core/vm.lua | 4 |
2 files changed, 34 insertions, 8 deletions
diff --git a/server/src/core/value.lua b/server/src/core/value.lua index e7ba547b..7b79d2ab 100644 --- a/server/src/core/value.lua +++ b/server/src/core/value.lua @@ -1,4 +1,6 @@ -local DefaultSource = { start = 0, finish = 0 } +local function getDefaultSource() + return { start = 0, finish = 0 } +end local mt = {} mt.__index = mt @@ -62,7 +64,7 @@ function mt:createField(name, source) local field = { type = 'field', key = name, - source = source or DefaultSource, + source = source or getDefaultSource(), } if not self._child then @@ -149,11 +151,13 @@ function mt:getField(name, source, stack) return field end -function mt:rawEachField(callback) +function mt:rawEachField(callback, mark) if not self._child then return nil end - local mark = {} + if not mark then + mark = {} + end for _, childs in pairs(self._child) do for name, field in pairs(childs) do if not mark[name] then @@ -168,8 +172,26 @@ function mt:rawEachField(callback) return nil end -function mt:eachField(callback) - return self:rawEachField(callback) +function mt:eachField(callback, mark, stack) + if not mark then + mark = {} + end + local res = self:rawEachField(callback, mark) + if res ~= nil then + return res + end + local indexMeta = self:getMeta('__index') + if not indexMeta then + return nil + end + if not stack then + stack = 0 + end + stack = stack + 1 + if stack > 10 then + return nil + end + return indexMeta.value:eachField(callback, mark, stack) end function mt:removeUri(uri) @@ -224,7 +246,7 @@ function mt:addInfo(tp, source, var) end self._info[uri][#self._info[uri]+1] = { type = tp, - source = source or DefaultSource, + source = source or getDefaultSource(), var = var, } return self @@ -251,7 +273,7 @@ return function (tp, source, value) end -- TODO lib里的多类型 local self = setmetatable({ - source = source or DefaultSource, + source = source or getDefaultSource(), uri = source and source.uri, }, mt) if value ~= nil then diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua index 156b73d4..518277e2 100644 --- a/server/src/core/vm.lua +++ b/server/src/core/vm.lua @@ -20,6 +20,7 @@ function mt:createDummyVar(source, value) type = 'local', key = '', source = source or getDefaultSource(), + close = self.scope.block.finish, } if source then @@ -43,6 +44,9 @@ function mt:createLocal(key, source, value) source = source or getDefaultSource(), close = self.scope.block.finish, } + if not loc.close then + error('Miss close') + end if source then source.bind = loc |