diff options
-rw-r--r-- | server/src/core/definition.lua | 8 | ||||
-rw-r--r-- | server/src/core/find_result.lua | 5 | ||||
-rw-r--r-- | server/src/core/vm.lua | 30 |
3 files changed, 28 insertions, 15 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index d7f0019d..52824908 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -1,6 +1,6 @@ local function findFieldBySource(positions, source, vm, result) if source.type == 'name' and source[1] == result.key then - local obj = source.object + local obj = source.bind if obj.type == 'field' then vm:eachInfo(obj, function (info) if info.type == 'set' and info.source == source then @@ -72,13 +72,15 @@ local function parseResultAsVar(vm, result, lsp) local positions = {} local tp = result.type if tp == 'local' then + if result.link then + result = result.link + end if result.value.lib then return positions end if result.value.uri ~= vm.uri then parseResultAcrossUri(positions, vm, result) - elseif result.link then - result = result.link + else vm:eachInfo(result, function (info) if info.type == 'local' then positions[#positions+1] = { diff --git a/server/src/core/find_result.lua b/server/src/core/find_result.lua index dae0e792..a562f192 100644 --- a/server/src/core/find_result.lua +++ b/server/src/core/find_result.lua @@ -14,10 +14,13 @@ local function findAtPos(results, pos, level) for _, source in ipairs(results.sources) do if isValidSource(source) and isContainPos(source, pos) then res[#res+1] = { - object = source.object, + object = source.bind, source = source, range = source.finish - source.start, } + if not source.bind then + error('Miss source object') + end end end if #res == 0 then diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua index e19ac0e7..da016c4e 100644 --- a/server/src/core/vm.lua +++ b/server/src/core/vm.lua @@ -91,8 +91,8 @@ function mt:createDummyVar(source, value) end function mt:createLocal(key, source, value) - if source and source.object then - return source.object + if source and source.bind then + return source.bind end local loc = { type = 'local', @@ -102,7 +102,7 @@ function mt:createLocal(key, source, value) } if source then - source.object = loc + source.bind = loc self.results.sources[#self.results.sources+1] = source source.isLocal = true end @@ -135,12 +135,12 @@ function mt:createLocal(key, source, value) end function mt:createField(value, index, source) - if source and source.object then - return source.object + if source and source.bind then + return source.bind end local field = value:createField(index, source) if source then - source.object = field + source.bind = field self.results.sources[#self.results.sources+1] = source end return field @@ -152,7 +152,7 @@ function mt:getField(value, index, source) return nil end if source then - source.object = field + source.bind = field self.results.sources[#self.results.sources+1] = source end return field @@ -744,9 +744,12 @@ function mt:getLibValue(lib, parentType, v) end function mt:getName(name, source) + if source and source.bind then + return source.bind + end local loc = self.scope.locals[name] if loc then - source.object = loc + source.bind = loc self.results.sources[#self.results.sources+1] = source return loc end @@ -774,7 +777,7 @@ function mt:setName(name, source, value) source.uri = self.uri local loc = self.scope.locals[name] if loc then - source.object = loc + source.bind = loc self.results.sources[#self.results.sources+1] = source self:setValue(loc, value, source) return @@ -1205,8 +1208,11 @@ function mt:doReturn(action) end end -function mt:createLabel(action) - local name = action[1] +function mt:createLabel(source) + if source.bind then + return source.bind + end + local name = source[1] if not self.chunk.labels[name] then local label = { type = 'label', @@ -1215,6 +1221,8 @@ function mt:createLabel(action) self.chunk.labels[name] = label self.results.labels[#self.results.labels+1] = label end + source.bind = self.chunk.labels[name] + self.results.sources[#self.results.sources+1] = source return self.chunk.labels[name] end |