diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 17:13:04 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 17:13:04 +0800 |
commit | 894db9dc2125acdfe9ef69759bf7709d25552eef (patch) | |
tree | f0234ff09a6667ea4e41f85a9d8a90caea820a8a /server | |
parent | 26acef86a9acef06f63605a2dfff0647f36655de (diff) | |
download | lua-language-server-894db9dc2125acdfe9ef69759bf7709d25552eef.zip |
修正一些bug
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/document_symbol.lua | 4 | ||||
-rw-r--r-- | server/src/core/find_source.lua | 2 | ||||
-rw-r--r-- | server/src/core/references.lua | 9 | ||||
-rw-r--r-- | server/src/service.lua | 3 | ||||
-rw-r--r-- | server/src/vm/source.lua | 18 | ||||
-rw-r--r-- | server/src/vm/value.lua | 5 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 26 |
7 files changed, 44 insertions, 23 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index af77cc93..2b1ecfbf 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -72,7 +72,7 @@ local function buildLocal(vm, source, callback) valueSource = source end local name = hvr.name - if vm.uri ~= value.uri and name == '' then + if name == '' then name = tostring(source[1] or '') end -- 由于范围不允许交叉,为了支持 local x, y, z = 1, 2, 3 的形式 @@ -126,7 +126,7 @@ local function buildSet(vm, source, callback) valueSource = source end local name = hvr.name - if vm.uri ~= value.uri and name == '' then + if name == '' then name = tostring(source[1] or '') end -- 由于范围不允许交叉,为了支持 x, y, z = 1, 2, 3 的形式 diff --git a/server/src/core/find_source.lua b/server/src/core/find_source.lua index 52b42501..65df6b95 100644 --- a/server/src/core/find_source.lua +++ b/server/src/core/find_source.lua @@ -6,7 +6,7 @@ local function isContainPos(obj, pos) end local function isValidSource(source) - return source.start ~= nil + return source.start ~= nil and source.start ~= 0 end local function findAtPos(sources, pos, level) diff --git a/server/src/core/references.lua b/server/src/core/references.lua index 8a94c69c..2cc14abb 100644 --- a/server/src/core/references.lua +++ b/server/src/core/references.lua @@ -53,10 +53,17 @@ return function (vm, pos, declarat) return end mark[src] = true + if src.start == 0 then + return + end + local uri = src.uri + if uri == '' then + uri = nil + end positions[#positions+1] = { src.start, src.finish, - src.uri, + uri, } end) return positions diff --git a/server/src/service.lua b/server/src/service.lua index 0c533b35..a66864a8 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -332,6 +332,9 @@ function mt:compileVM(uri) else return nil end + if obj.vm then + obj.vm:remove() + end obj.vm = vm obj.vmCost = os.clock() - clock obj.vmVersion = version diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index 8c80262a..22132166 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -62,6 +62,21 @@ function mt:getUri() return self.uri end +function mt:setVM() + self.vm = vm +end + +function mt:isRemoved() + if not self.vm then + return true + end + if self.vm._removed then + self.vm = nil + return true + end + return false +end + function mt:set(name, v) if not self._flag then self._flag = {} @@ -80,10 +95,11 @@ function mt:getName() return self[1] end -return function (source) +return function (vm, source) if source._hasInstant then return false end + source.vm = vm setmetatable(source, mt) return true end diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index fe727caf..f41d30e0 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -246,9 +246,12 @@ function mt:addInfo(tp, source, ...) if self._info[source] then return end + if not source then + return + end local info = { type = tp, - source = source or getDefaultSource(), + source = source, ... } self._info[#self._info+1] = info diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index ad25235c..d6524958 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -12,7 +12,7 @@ local mt = {} mt.__index = mt function mt:getDefaultSource() - return { + return self:instantSource { start = 0, finish = 0, uri = self:getUri(), @@ -27,19 +27,6 @@ function mt:scopePop() self.currentFunction:pop() end -function mt:eachInfo(var, callback) - if not self.results.infos[var] then - return nil - end - for _, info in ipairs(self.results.infos[var]) do - local res = callback(info) - if res ~= nil then - return res - end - end - return nil -end - function mt:buildTable(source) local tbl = self:createValue('table', source) if not source then @@ -723,7 +710,7 @@ function mt:doReturn(action) values:eachValue(function (n, value) value.uri = self:getUri() func:setReturn(n, value) - value:addInfo('return', action[n]) + value:addInfo('return', action[n] or value.source) end) end @@ -1077,10 +1064,11 @@ function mt:getUri() end function mt:instantSource(source) - if instantSource(source) then + if instantSource(self, source) then source:setUri(self:getUri()) self.sources[#self.sources+1] = source end + return source end function mt:bindLocal(source, loc, action) @@ -1118,7 +1106,7 @@ function mt:createLocal(key, source, value) loc = createLocal(key, source, value) self:saveLocal(key, loc) self:bindLocal(source, loc, 'local') - value:addInfo('local', source) + value:addInfo('local', source or self:getDefaultSource()) return loc end @@ -1141,6 +1129,10 @@ function mt:eachSource(callback) end end +function mt:remove() + self._removed = true +end + local function compile(ast, lsp, uri) local vm = setmetatable({ funcs = {}, |