diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-28 20:32:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-28 20:32:24 +0800 |
commit | 86c17f83e5b94ed478231b68bffc648a479e89f5 (patch) | |
tree | da5c120855608d7473545473dad202ca3698d14b | |
parent | 845d1be1c9f3f74ac0674d4bb7d0a37ca83a3a65 (diff) | |
download | lua-language-server-86c17f83e5b94ed478231b68bffc648a479e89f5.zip |
cleanup
-rw-r--r-- | script/core/noder.lua | 23 | ||||
-rw-r--r-- | script/core/searcher.lua | 71 | ||||
-rw-r--r-- | test/full/projects.lua | 2 |
3 files changed, 59 insertions, 37 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index 3dabf66c..b4480e66 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -6,6 +6,7 @@ local files = require 'files' local SPLIT_CHAR = '\x1F' local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$' local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*' +local HEAD_REGEX = '^' .. SPLIT_CHAR .. '?[^' .. SPLIT_CHAR .. ']*' local ANY_FIELD_CHAR = '*' local INDEX_CHAR = '[' local RETURN_INDEX = SPLIT_CHAR .. '#' @@ -1067,9 +1068,26 @@ function m.getFirstID(id) if count == 0 then return nil end + if firstID == '' then + return nil + end return firstID end +---根据ID来获取第一个节点的ID或field +---@param id string +---@return string +function m.getHeadID(id) + local headID, count = id:match(HEAD_REGEX) + if count == 0 then + return nil + end + if headID == '' then + return nil + end + return headID +end + ---根据ID来获取上个节点的ID ---@param id string ---@return string @@ -1078,6 +1096,9 @@ function m.getLastID(id) if count == 0 then return nil end + if lastID == '' then + return nil + end return lastID end @@ -1097,7 +1118,7 @@ end ---@return boolean function m.hasField(id) local firstID = m.getFirstID(id) - if firstID == id then + if firstID == id or not firstID then return false end local nextChar = id:sub(#firstID + 1, #firstID + 1) diff --git a/script/core/searcher.lua b/script/core/searcher.lua index c5e22619..f068ed59 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -4,12 +4,8 @@ local files = require 'files' local generic = require 'core.generic' local ws = require 'workspace' local vm = require 'vm.vm' -local await = require 'await' local collector = require 'core.collector' -local NONE = {'NONE'} -local LAST = {'LAST'} - local ignoredSources = { ['int:'] = true, ['num:'] = true, @@ -195,11 +191,11 @@ local function checkLock(status, k1, k2) lock1 = {} locks[k1] = lock1 end - if lock1[NONE] then + if lock1[''] then return true end if k2 == nil then - k2 = NONE + k2 = '' end if lock1[k2] then return true @@ -245,6 +241,22 @@ local function checkCache(status, uri, expect, mode) return false end +local function checkMark(mark, id, field) + if noder.getIDLength(id) > 10 then + return false + end + local cmark = mark[id] + if not cmark then + cmark = {} + mark[id] = {} + end + if cmark[field or ''] then + return false + end + cmark[field or ''] = true + return true +end + function m.searchRefsByID(status, uri, expect, mode) local ast = files.getState(uri) if not ast then @@ -266,15 +278,7 @@ function m.searchRefsByID(status, uri, expect, mode) if ignoredIDs[firstID] and (field or firstID ~= id) then return end - local cmark = mark[id] - if not cmark then - cmark = {} - mark[id] = cmark - end - if cmark[NONE] then - return - end - if cmark[field or NONE] then + if not checkMark(mark, id, field) then return end if TRACE then @@ -287,7 +291,6 @@ function m.searchRefsByID(status, uri, expect, mode) status.footprint[#status.footprint+1] = 'search\t' .. id end end - cmark[field or NONE] = true searchStep(id, field) if TRACE then log.debug('pop:', id, field) @@ -302,26 +305,24 @@ function m.searchRefsByID(status, uri, expect, mode) end local function checkLastID(id, field) - local cmark = mark[id] - if not cmark then - cmark = {} - mark[id] = cmark - end - local fieldLength = noder.getIDLength(field) - if cmark[LAST] and fieldLength >= cmark[LAST] then - return - end - local lastID = noder.getLastID(id) - if not lastID then + if field then return end - local newField = id:sub(#lastID + 1) - if field then - newField = newField .. field + local leftID = '' + local rightID + + while true do + local firstID = noder.getHeadID(rightID or id) + if not firstID or firstID == id then + return + end + leftID = leftID .. firstID + if leftID == id then + return + end + rightID = id:sub(#leftID + 1) + search(leftID, rightID) end - cmark[LAST] = fieldLength - search(lastID, newField) - return lastID end local function searchID(id, field) @@ -663,10 +664,10 @@ function m.searchRefsByID(status, uri, expect, mode) local stepCount = 0 local stepMaxCount = 1e3 - local statusMaxCount = 1e5 + local statusMaxCount = 1e4 if mode == 'allref' or mode == 'alldef' then stepMaxCount = 1e4 - statusMaxCount = 1e6 + statusMaxCount = 1e5 end function searchStep(id, field) stepCount = stepCount + 1 diff --git a/test/full/projects.lua b/test/full/projects.lua index 5504c48e..b2e6d3cc 100644 --- a/test/full/projects.lua +++ b/test/full/projects.lua @@ -46,4 +46,4 @@ local function doProjects(pathname) end --doProjects [[C:\SSSEditor\client\Output\Lua]] ---doProjects [[C:\W3-Server\script]] +doProjects [[C:\W3-Server\script]] |