summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-22 19:12:31 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-22 19:12:31 +0800
commit235a3049c63836b686d1b81fe6bb4775b4021449 (patch)
treea1a798c163dd7e33977389a3da9dca365bca8a6a /script/vm/compiler.lua
parent3278c8c0b54934ac61a8a98688ab94f45ba15a9b (diff)
downloadlua-language-server-235a3049c63836b686d1b81fe6bb4775b4021449.zip
cleanup
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua94
1 files changed, 62 insertions, 32 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index c8323a49..2cb2d93c 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -66,7 +66,7 @@ end
local function searchFieldByLocalID(source, key, pushResult)
local fields
if key then
- fields = vm.getLocalSourcesSets(source, key)
+ fields = vm.getLocalSets(source, key)
else
fields = vm.getLocalFields(source, false)
end
@@ -1234,42 +1234,72 @@ local compilerSwitch = util.switch()
if key == nil then
return
end
- if type(key) == 'table' then
- ---@cast key vm.node
- local uri = guide.getUri(source)
- local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
- if value then
- vm.setNode(source, value)
- end
- for k in key:eachObject() do
- if k.type == 'global' and k.cate == 'type' then
- ---@cast k vm.global
- vm.compileByParentNode(source.node, k, function (src)
- vm.setNode(source, vm.compileNode(src))
- if src.value then
- vm.setNode(source, vm.compileNode(src.value))
- end
- end)
+
+ ---@type vm.node, boolean
+ local cacheNode, needCompile
+
+ do
+ local localInfo = vm.getLocalInfo(source)
+ if localInfo then
+ cacheNode = localInfo.node
+ if not cacheNode then
+ needCompile = true
+ cacheNode = vm.createNode()
+ localInfo.node = cacheNode
+ end
+ else
+ local parentNode = vm.compileNode(source.node)
+ if not parentNode.fields then
+ parentNode.fields = {}
+ end
+ cacheNode = parentNode.fields[key]
+ if not cacheNode then
+ needCompile = true
+ cacheNode = vm.createNode()
+ parentNode.fields[key] = cacheNode
end
end
- else
- ---@cast key string
- vm.compileByParentNode(source.node, key, function (src)
- if src.value then
- if bindDocs(src) then
- vm.setNode(source, vm.compileNode(src))
- elseif src.value.type ~= 'nil' then
- vm.setNode(source, vm.compileNode(src.value))
- local node = vm.getNode(src)
- if node then
- vm.setNode(source, node)
- end
+ end
+
+ if needCompile then
+ if type(key) == 'table' then
+ ---@cast key vm.node
+ local uri = guide.getUri(source)
+ local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
+ if value then
+ cacheNode:merge(value)
+ end
+ for k in key:eachObject() do
+ if k.type == 'global' and k.cate == 'type' then
+ ---@cast k vm.global
+ vm.compileByParentNode(source.node, k, function (src)
+ cacheNode:merge(vm.compileNode(src))
+ if src.value then
+ cacheNode:merge(vm.compileNode(src.value))
+ end
+ end)
end
- else
- vm.setNode(source, vm.compileNode(src))
end
- end)
+ else
+ ---@cast key string
+ vm.compileByParentNode(source.node, key, function (src)
+ if src.value then
+ if bindDocs(src) then
+ cacheNode:merge(vm.compileNode(src))
+ elseif src.value.type ~= 'nil' then
+ cacheNode:merge(vm.compileNode(src.value))
+ local node = vm.getNode(src)
+ if node then
+ cacheNode:merge(node)
+ end
+ end
+ else
+ cacheNode:merge(vm.compileNode(src))
+ end
+ end)
+ end
end
+ vm.setNode(source, cacheNode)
end)
: case 'setglobal'
: call(function (source)