diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-15 20:47:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-15 20:47:58 +0800 |
commit | 9dc051dc1f6bf44a171816db5e3e5b454fc45a57 (patch) | |
tree | b912d15aeb66b9c463dc3f0180d122d3f3a48527 | |
parent | fcc64b070a4c3cf0af7470ae8587080d336fed73 (diff) | |
download | lua-language-server-9dc051dc1f6bf44a171816db5e3e5b454fc45a57.zip |
improve
-rw-r--r-- | script/core/noder.lua | 19 | ||||
-rw-r--r-- | script/core/searcher.lua | 11 | ||||
-rw-r--r-- | script/vm/globals.lua | 3 | ||||
-rw-r--r-- | test/definition/bug.lua | 5 |
4 files changed, 30 insertions, 8 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index 9bb2b9b5..b1eff89a 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -7,9 +7,11 @@ local SPLIT_CHAR = '\x1F' local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$' local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*' local ANY_FIELD_CHAR = '*' +local INDEX_CHAR = '[' local RETURN_INDEX = SPLIT_CHAR .. '#' local PARAM_INDEX = SPLIT_CHAR .. '&' local TABLE_KEY = SPLIT_CHAR .. '<' +local INDEX_FIELD = SPLIT_CHAR .. INDEX_CHAR local ANY_FIELD = SPLIT_CHAR .. ANY_FIELD_CHAR local URI_CHAR = '@' local URI_REGEX = URI_CHAR .. '([^' .. URI_CHAR .. ']*)' .. URI_CHAR .. '(.*)' @@ -71,15 +73,14 @@ local function getKey(source) or source.type == 'getindex' then local index = source.index if not index then - return ANY_FIELD_CHAR, source.node + return INDEX_CHAR, source.node end if index.type == 'string' or index.type == 'boolean' or index.type == 'number' then return ('%q'):format(index[1] or ''), source.node - elseif index.type ~= 'function' - and index.type ~= 'table' then - return ANY_FIELD_CHAR, source.node + else + return INDEX_CHAR, source.node end elseif source.type == 'tableindex' then local index = source.index @@ -377,6 +378,7 @@ m.PARAM_INDEX = PARAM_INDEX m.TABLE_KEY = TABLE_KEY m.ANY_FIELD = ANY_FIELD m.URI_CHAR = URI_CHAR +m.INDEX_FIELD = INDEX_FIELD --- 寻找doc的主体 ---@param obj parser.guide.object @@ -433,6 +435,15 @@ function m.compileNode(noders, source) end end end + if source.special == 'setmetatable' + or source.special == 'require' + or source.special == 'dofile' + or source.special == 'loadfile' + or source.special == 'rawset' + or source.special == 'rawget' then + local node = getNode(noders, id) + node.skip = true + end -- self -> mt:xx if source.type == 'local' and source[1] == 'self' then local func = guide.getParentFunction(source) diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 2b4b4caa..5b187c3a 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -457,6 +457,9 @@ function m.searchRefsByID(status, uri, expect, mode) status.crossed[id] = true local isCall = field and field:sub(2, 2) == noder.RETURN_INDEX local tid = id .. (field or '') + if FOOTPRINT then + status.footprint[#status.footprint+1] = ('checkGlobal:%s + %s, isCall: %s'):format(id, field, isCall, tid) + end for guri, def in pairs(uris) do if def then crossSearch(status, guri, tid, mode) @@ -509,7 +512,7 @@ function m.searchRefsByID(status, uri, expect, mode) if node.require then checkRequire(node.require, field) - return true + return end local isSepcial = checkSpecial(id, node, field) @@ -532,6 +535,8 @@ function m.searchRefsByID(status, uri, expect, mode) if node.call then callStack[#callStack] = nil end + + return false end local function checkAnyField(id, field) @@ -574,8 +579,8 @@ function m.searchRefsByID(status, uri, expect, mode) end local node = noder.getNodeByID(root, id) if node then - local skip = searchNode(id, node, field) - if skip then + searchNode(id, node, field) + if node.skip and field then return end end diff --git a/script/vm/globals.lua b/script/vm/globals.lua index 6a481bd1..cb759551 100644 --- a/script/vm/globals.lua +++ b/script/vm/globals.lua @@ -25,7 +25,8 @@ local function pushGlobals(uri) end local nodes = noder.compileNodes(state.ast) for id in pairs(nodes) do - if id:sub(1, 2) == 'g:' then + if id:sub(1, 2) == 'g:' + and noder.getFirstID(id) == id then if not globalsMap[id] then globalsMap[id] = {} end diff --git a/test/definition/bug.lua b/test/definition/bug.lua index d9ed7afc..de67a8f4 100644 --- a/test/definition/bug.lua +++ b/test/definition/bug.lua @@ -229,3 +229,8 @@ end local <!b!> = B:get() print(<?b?>) ]] + +TEST [[ +g[a.b.c] = 1 +print(g.<?x?>) +]] |