diff options
author | CppCXY <812125110@qq.com> | 2022-08-11 19:36:36 +0800 |
---|---|---|
committer | CppCXY <812125110@qq.com> | 2022-08-11 19:36:36 +0800 |
commit | ff9103ae4001d8e520171b99cd192997fc689bc9 (patch) | |
tree | 04c0b685e81aac48210604dc12d24b91862a36d9 /script/vm/local-id.lua | |
parent | 40f191a85ea21bb64c427f9dab4bc597e2a0ea1b (diff) | |
parent | 82bcfef9037c26681993c94b2f92b68d335de3c6 (diff) | |
download | lua-language-server-ff9103ae4001d8e520171b99cd192997fc689bc9.zip |
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'script/vm/local-id.lua')
-rw-r--r-- | script/vm/local-id.lua | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index 80c68769..9168d680 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -4,8 +4,8 @@ local guide = require 'parser.guide' local vm = require 'vm.vm' ---@class parser.object ----@field _localID string ----@field _localIDs table<string, parser.object[]> +---@field _localID string|false +---@field _localIDs table<string, { sets: parser.object[], gets: parser.object[] }> local compileLocalID, getLocal @@ -21,6 +21,7 @@ local compileSwitch = util.switch() compileLocalID(ref) end end) + : case 'setlocal' : case 'getlocal' : call(function (source) source._localID = ('%d'):format(source.node.start) @@ -114,10 +115,19 @@ end function vm.insertLocalID(id, source) local root = guide.getRoot(source) if not root._localIDs then - root._localIDs = util.multiTable(2) + root._localIDs = util.multiTable(2, function () + return { + sets = {}, + gets = {}, + } + end) end local sources = root._localIDs[id] - sources[#sources+1] = source + if guide.isSet(source) then + sources.sets[#sources.sets+1] = source + else + sources.gets[#sources.gets+1] = source + end end function compileLocalID(source) @@ -137,7 +147,7 @@ function compileLocalID(source) end ---@param source parser.object ----@return string? +---@return string|false function vm.getLocalID(source) if source._localID ~= nil then return source._localID @@ -154,7 +164,28 @@ end ---@param source parser.object ---@param key? string ---@return parser.object[]? -function vm.getLocalSources(source, key) +function vm.getLocalSourcesSets(source, key) + local id = vm.getLocalID(source) + if not id then + return nil + end + local root = guide.getRoot(source) + if not root._localIDs then + return nil + end + if key then + if type(key) ~= 'string' then + return nil + end + id = id .. vm.ID_SPLITE .. key + end + return root._localIDs[id].sets +end + +---@param source parser.object +---@param key? string +---@return parser.object[]? +function vm.getLocalSourcesGets(source, key) local id = vm.getLocalID(source) if not id then return nil @@ -169,12 +200,13 @@ function vm.getLocalSources(source, key) end id = id .. vm.ID_SPLITE .. key end - return root._localIDs[id] + return root._localIDs[id].gets end ---@param source parser.object ----@return parser.object[] -function vm.getLocalFields(source) +---@param includeGets boolean +---@return parser.object[]? +function vm.getLocalFields(source, includeGets) local id = vm.getLocalID(source) if not id then return nil @@ -192,9 +224,14 @@ function vm.getLocalFields(source) and lid:sub(#id + 1, #id + 1) == vm.ID_SPLITE -- only one field and not lid:find(vm.ID_SPLITE, #id + 2) then - for _, src in ipairs(sources) do + for _, src in ipairs(sources.sets) do fields[#fields+1] = src end + if includeGets then + for _, src in ipairs(sources.gets) do + fields[#fields+1] = src + end + end end end local cost = os.clock() - clock |