From 86dcb1a7e5eed8cf2e1b7109b4c0debf6967c485 Mon Sep 17 00:00:00 2001 From: fesily Date: Fri, 12 May 2023 15:19:09 +0800 Subject: link server by plugin --- script/plugins/ffi/cdefRerence.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 script/plugins/ffi/cdefRerence.lua (limited to 'script/plugins/ffi/cdefRerence.lua') diff --git a/script/plugins/ffi/cdefRerence.lua b/script/plugins/ffi/cdefRerence.lua new file mode 100644 index 00000000..819a0dd1 --- /dev/null +++ b/script/plugins/ffi/cdefRerence.lua @@ -0,0 +1,37 @@ +local files = require 'files' +local guide = require 'parser.guide' +local vm = require 'vm' +local reference = require 'core.reference' +local find = string.find +local remove = table.remove + +local function getCdefSourcePosition(ffi_state) + local cdef_position = ffi_state.ast.returns[1][1] + local source = vm.getFields(cdef_position) + for index, value in ipairs(source) do + local name = guide.getKeyName(value) + if name == 'cdef' then + return value.field.start + end + end +end + +---@async +return function () + local ffi_state + for uri in files.eachFile() do + if find(uri, "/ffi.lua", 0, true) then + ffi_state = files.getState(uri) + break + end + end + if ffi_state then + local res = reference(ffi_state.uri, getCdefSourcePosition(ffi_state), true) + if res then + if res[1].uri == ffi_state.uri then + remove(res, 1) + end + return res + end + end +end -- cgit v1.2.3