diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-18 23:08:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-18 23:08:37 +0800 |
commit | f03bfa6794b0970dcfcc9043c02e541686085d3d (patch) | |
tree | 1c05c3e9592c2fc8f8fa3a942b3202d75cee8155 /script | |
parent | ec09f57b1adbb9a258bc4a68741cce678c7c77e7 (diff) | |
download | lua-language-server-f03bfa6794b0970dcfcc9043c02e541686085d3d.zip |
run locals
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/compiler.lua | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 80180bce..ad2ce276 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -15,6 +15,7 @@ local vm = require 'vm.vm' ---@field _node vm.node ---@field _localBase table ---@field _globalBase table +---@field _hasSorted boolean local searchFieldSwitch = util.switch() : case 'table' @@ -859,6 +860,7 @@ local compilerSwitch = util.switch() end) : case 'local' : case 'self' + ---@param source parser.object : call(function (source) compileLocal(source) if not source.ref then @@ -867,6 +869,12 @@ local compilerSwitch = util.switch() local hasMark = vm.getNode(source):getData 'hasDefined' + if not source._hasSorted then + source._hasSorted = true + table.sort(source.ref, function (a, b) + return (a.range or a.start) < (b.range or b.start) + end) + end local lastLoc = source for _, ref in ipairs(source.ref) do if ref.type == 'setlocal' then @@ -881,6 +889,8 @@ local compilerSwitch = util.switch() vm.setNode(ref, vm.getNode(lastLoc)) end lastLoc = ref + elseif ref.type == 'getlocal' then + vm.setNode(ref, vm.getNode(lastLoc), true) end end @@ -899,16 +909,6 @@ local compilerSwitch = util.switch() : case 'getlocal' : call(function (source) vm.compileNode(source.node) - - local lastLoc = source.node - for _, ref in ipairs(source.node.ref) do - if ref.type == 'setlocal' - and (ref.range or ref.start) < source.start then - lastLoc = ref - end - end - - vm.setNode(source, vm.getNode(lastLoc)) end) : case 'setfield' : case 'setmethod' |