diff options
author | fesily <fesil@foxmail.com> | 2023-05-12 15:19:09 +0800 |
---|---|---|
committer | fesily <fesil@foxmail.com> | 2023-05-12 15:19:09 +0800 |
commit | 86dcb1a7e5eed8cf2e1b7109b4c0debf6967c485 (patch) | |
tree | 94b0eda62fe218313028498458f3951e0e6a5b45 /script/plugins/ffi/searchCode.lua | |
parent | 7fa6ee16cd746b70b070331ae4e48dacc2384ca5 (diff) | |
download | lua-language-server-86dcb1a7e5eed8cf2e1b7109b4c0debf6967c485.zip |
link server by plugin
Diffstat (limited to 'script/plugins/ffi/searchCode.lua')
-rw-r--r-- | script/plugins/ffi/searchCode.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/script/plugins/ffi/searchCode.lua b/script/plugins/ffi/searchCode.lua new file mode 100644 index 00000000..9e74e7c0 --- /dev/null +++ b/script/plugins/ffi/searchCode.lua @@ -0,0 +1,66 @@ +local vm = require 'vm' + +local function getLiterals(arg) + local literals = vm.getLiterals(arg) + local res = {} + for k, v in pairs(literals) do + if type(k) == 'string' then + res[#res+1] = k + end + end + return res +end + +---@return string[]? +local function getCode(CdefReference) + local target = CdefReference.target + if not (target.type == 'field' and target.parent.type == 'getfield') then + return + end + target = target.parent.parent + if target.type == 'call' then + return getLiterals(target.args and target.args[1]) + elseif target.type == 'local' then + local res = {} + for _, o in ipairs(target.ref) do + if o.parent.type ~= 'call' then + goto CONTINUE + end + local target = o.parent + local literals = vm.getLiterals(target.args and target.args[1]) + if not literals then + goto CONTINUE + end + for k, v in pairs(literals) do + if type(k) == 'string' then + res[#res+1] = k + end + end + ::CONTINUE:: + end + return res + end +end + +---@async +return function (CdefReference, target_uri) + if not CdefReference then + return nil + end + local codeResults + for i, v in ipairs(CdefReference) do + if v.uri ~= target_uri then + goto continue + end + local codes = getCode(v) + if not codes then + goto continue + end + for i, v in ipairs(codes) do + codeResults = codeResults or {} + codeResults[#codeResults+1] = v + end + ::continue:: + end + return codeResults +end |