summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-19 02:05:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-19 02:05:45 +0800
commit9b91ebedd8ede80fcd0c001fffe96d2a10e41b39 (patch)
treeb30e6ec4c1d55bd2c2d676979d107cfdaa30f6cb /script
parentbd3cd4a5d1cf8effcf8d8403372d59553245e026 (diff)
downloadlua-language-server-9b91ebedd8ede80fcd0c001fffe96d2a10e41b39.zip
run local in function
Diffstat (limited to 'script')
-rw-r--r--script/vm/compiler.lua53
1 files changed, 37 insertions, 16 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index ad2ce276..4b81f2c7 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -863,7 +863,8 @@ local compilerSwitch = util.switch()
---@param source parser.object
: call(function (source)
compileLocal(source)
- if not source.ref then
+ local refs = source.ref
+ if not refs then
return
end
@@ -871,32 +872,52 @@ local compilerSwitch = util.switch()
if not source._hasSorted then
source._hasSorted = true
- table.sort(source.ref, function (a, b)
+ table.sort(refs, 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
- if ref.value and not hasMark then
- vm.setNode(ref, vm.getNode(lastLoc):copy())
- if ref.value.type == 'table' then
- vm.setNode(ref, ref.value)
- else
- vm.setNode(ref, vm.compileNode(ref.value))
+
+ local parentFunc = guide.getParentFunction(source)
+
+ local index = 1
+ local function runFunction(loc, currentFunc)
+ while true do
+ local ref = refs[index]
+ if not ref then
+ break
+ end
+ if ref.start > currentFunc.finish then
+ break
+ end
+ local func = guide.getParentFunction(ref)
+ if func == currentFunc then
+ index = index + 1
+ if ref.type == 'setlocal' then
+ if ref.value and not hasMark then
+ if ref.value.type == 'table' then
+ vm.setNode(ref, ref.value)
+ else
+ vm.setNode(ref, vm.compileNode(ref.value))
+ end
+ else
+ vm.setNode(ref, vm.getNode(loc))
+ end
+ loc = ref
+ elseif ref.type == 'getlocal' then
+ vm.setNode(ref, vm.getNode(loc), true)
end
else
- vm.setNode(ref, vm.getNode(lastLoc))
+ runFunction(loc, func)
end
- lastLoc = ref
- elseif ref.type == 'getlocal' then
- vm.setNode(ref, vm.getNode(lastLoc), true)
end
end
+ runFunction(source, parentFunc)
+
if not hasMark then
for _, ref in ipairs(source.ref) do
- if ref.type == 'setlocal' then
+ if ref.type == 'setlocal'
+ and guide.getParentFunction(ref) == parentFunc then
vm.setNode(source, vm.getNode(ref))
end
end