summaryrefslogtreecommitdiff
path: root/script/plugins/ffi/cdefRerence.lua
diff options
context:
space:
mode:
authorfesily <fesil@foxmail.com>2023-05-12 15:19:09 +0800
committerfesily <fesil@foxmail.com>2023-05-12 15:19:09 +0800
commit86dcb1a7e5eed8cf2e1b7109b4c0debf6967c485 (patch)
tree94b0eda62fe218313028498458f3951e0e6a5b45 /script/plugins/ffi/cdefRerence.lua
parent7fa6ee16cd746b70b070331ae4e48dacc2384ca5 (diff)
downloadlua-language-server-86dcb1a7e5eed8cf2e1b7109b4c0debf6967c485.zip
link server by plugin
Diffstat (limited to 'script/plugins/ffi/cdefRerence.lua')
-rw-r--r--script/plugins/ffi/cdefRerence.lua37
1 files changed, 37 insertions, 0 deletions
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