diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-08-05 21:03:22 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-08-05 21:03:22 +0800 |
commit | d5ed4fb29ef4d1275349bab60f5f5e9500dba4d2 (patch) | |
tree | d6d2465bed9c904f9820fe3f36f4986a5885d1c0 /script/core | |
parent | 0c9ec9b4bd3a53657e8d6d2e63f5bd6927165c03 (diff) | |
download | lua-language-server-d5ed4fb29ef4d1275349bab60f5f5e9500dba4d2.zip |
stash
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/noder.lua | 123 | ||||
-rw-r--r-- | script/core/searcher.lua | 34 |
2 files changed, 131 insertions, 26 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index 5efdf8a2..92eea166 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -611,6 +611,7 @@ local function bindValue(noders, source, id) if not valueID then return end + m.compilePartNodes(noders, value) if source.type == 'getlocal' or source.type == 'setlocal' then source = source.node @@ -826,17 +827,21 @@ compileNodeMap = util.switch() for _, src in ipairs(source.bindSources) do pushForward(noders, getID(src), id) pushForward(noders, id, getID(src)) + m.compilePartNodes(noders, src) end end for _, enumUnit in ipairs(source.enums) do pushForward(noders, id, getID(enumUnit)) + m.compilePartNodes(noders, enumUnit) end for _, resumeUnit in ipairs(source.resumes) do pushForward(noders, id, getID(resumeUnit)) + m.compilePartNodes(noders, resumeUnit) end for _, typeUnit in ipairs(source.types) do local unitID = getID(typeUnit) pushForward(noders, id, unitID) + m.compilePartNodes(noders, typeUnit) if source.bindSources then for _, src in ipairs(source.bindSources) do pushBackward(noders, unitID, getID(src)) @@ -1414,18 +1419,121 @@ function m.compileAllNodes(source) return noders end ----编译全局变量的node +local partNodersMap = util.switch() + : case 'local' + : call(function (noders, source) + local refs = source.ref + if refs then + for i = 1, #refs do + local ref = refs[i] + m.compilePartNodes(noders, ref) + end + end + + local nxt = source.next + if nxt then + m.compilePartNodes(noders, nxt) + end + + local node = getMethodNode(source) + if node then + m.compilePartNodes(noders, node) + end + end) + : case 'setlocal' + : case 'getlocal' + : call(function (noders, source) + m.compilePartNodes(noders, source.node) + + local nxt = source.next + if nxt then + m.compilePartNodes(noders, nxt) + end + end) + : case 'setfield' + : case 'getfield' + : case 'setmethod' + : case 'getmethod' + : call(function (noders, source) + local node = source.node + m.compilePartNodes(noders, node) + + local nxt = source.next + if nxt then + m.compilePartNodes(noders, nxt) + end + end) + : case 'setglobal' + : case 'getglobal' + : call(function (noders, source) + local nxt = source.next + if nxt then + m.compilePartNodes(noders, nxt) + end + end) + : case 'label' + : call(function (noders, source) + local refs = source.ref + if not refs then + return + end + for i = 1, #refs do + local ref = refs[i] + m.compilePartNodes(noders, ref) + end + end) + : case 'goto' + : call(function (noders, source) + m.compilePartNodes(noders, source.node) + end) + : case 'table' + : call(function (noders, source) + for i = 1, #source do + local field = source[i] + m.compilePartNodes(noders, field) + end + end) + : case 'tablefield' + : case 'tableindex' + : call(function (noders, source) + m.compilePartNodes(noders, source.parent) + end) + : getMap() + +---编译Class的node +---@param noders noders ---@param source parser.guide.object ---@return table -function m.compileGlobalNodes(source) - +function m.compilePartNodes(noders, source) + do return end + if source._noded then + return + end + m.compileNode(noders, source) + local f = partNodersMap[source.type] + if f then + f(noders, source) + end + + local parent = source.parent + if parent.value == source then + m.compilePartNodes(noders, parent) + end end ----编译Class的node ----@param source parser.guide.object +---编译全局变量的node +---@param root parser.guide.object ---@return table -function m.compileClassNodes(source) - +function m.compileGlobalNodes(root) + local noders = m.getNoders(root) + local env = guide.getENV(root) + m.compilePartNodes(noders, env) + + local docs = root.docs + for i = 1, #docs do + local doc = docs[i] + m.compileNode(noders, doc) + end end files.watch(function (ev, uri) @@ -1435,7 +1543,6 @@ files.watch(function (ev, uri) if state then m.compileAllNodes(state.ast) --m.compileGlobalNodes(state.ast) - --m.compileClassNodes(state.ast) end end if ev == 'remove' then diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 6397e6b9..10571c03 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -27,19 +27,20 @@ local getRoot = guide.getRoot local ceach = collector.each -local getNoders = noder.getNoders -local getID = noder.getID -local getLastID = noder.getLastID -local removeID = noder.removeID -local getNodersByUri = noder.getNodersByUri -local getFirstID = noder.getFirstID -local getHeadID = noder.getHeadID -local eachForward = noder.eachForward -local getUriAndID = noder.getUriAndID -local eachBackward = noder.eachBackward -local eachSource = noder.eachSource -local compileAllNodes = noder.compileAllNodes -local isGlobalID = noder.isGlobalID +local getNoders = noder.getNoders +local getID = noder.getID +local getLastID = noder.getLastID +local removeID = noder.removeID +local getNodersByUri = noder.getNodersByUri +local getFirstID = noder.getFirstID +local getHeadID = noder.getHeadID +local eachForward = noder.eachForward +local getUriAndID = noder.getUriAndID +local eachBackward = noder.eachBackward +local eachSource = noder.eachSource +local compileAllNodes = noder.compileAllNodes +local compilePartNoders = noder.compilePartNodes +local isGlobalID = noder.isGlobalID local SPLIT_CHAR = noder.SPLIT_CHAR local RETURN_INDEX = noder.RETURN_INDEX @@ -910,11 +911,8 @@ local function prepareSearch(source) if not source then return end - local root = getRoot(source) - if not root then - return - end - --compileAllNodes(root) + local noders = getNoders(source) + compilePartNoders(noders, source) local uri = getUri(source) local id = getID(source) return uri, id |