diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/value.lua | 38 | ||||
-rw-r--r-- | server/src/core/vm.lua | 4 | ||||
-rw-r--r-- | server/test/hover/init.lua | 23 |
3 files changed, 44 insertions, 21 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 diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua index 05e4458d..89dd2330 100644 --- a/server/test/hover/init.lua +++ b/server/test/hover/init.lua @@ -307,19 +307,16 @@ local y: number = 1 ]] TEST[[ -local function get_warnings(warnings) - local error = nil - local level = 'on' - for _, warn in ipairs(warnings) do - if warn == 'error' then - <?error?> = true - else - level = warn - end - end - return {error = error, level = level} -end +local mt = {} +mt.a = 1 +mt.b = 2 +mt.c = 3 +local <?obj?> = setmetatable({}, {__index = mt}) ]] [[ -local error: boolean = true +local obj: { + a: number = 1, + b: number = 2, + c: number = 3, +} ]] |