diff options
author | fesily <fesil@foxmail.com> | 2023-05-12 16:54:03 +0800 |
---|---|---|
committer | fesily <fesil@foxmail.com> | 2023-05-12 16:54:03 +0800 |
commit | 9cc197aa5ca6c5e0314ec38266a2c0e022025307 (patch) | |
tree | 6b38fd2f3cdaf2528ee2b38037e6ceb50bac4e6c /script/plugins/ffi/init.lua | |
parent | 74328ad18382623635f614fd31f559fe90469333 (diff) | |
download | lua-language-server-9cc197aa5ca6c5e0314ec38266a2c0e022025307.zip |
support array
Diffstat (limited to 'script/plugins/ffi/init.lua')
-rw-r--r-- | script/plugins/ffi/init.lua | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/script/plugins/ffi/init.lua b/script/plugins/ffi/init.lua index 66101f90..a551973a 100644 --- a/script/plugins/ffi/init.lua +++ b/script/plugins/ffi/init.lua @@ -2,7 +2,7 @@ local searchCode = require 'plugins.ffi.searchCode' local cdefRerence = require 'plugins.ffi.cdefRerence' local cdriver = require 'plugins.ffi.c-parser.cdriver' local util = require 'plugins.ffi.c-parser.util' -local utility = require 'utility' +local utility = require 'utility' local SDBMHash = require 'SDBMHash' local ws = require 'workspace' local files = require 'files' @@ -134,11 +134,23 @@ function builder:isVoid(ast) return self:isVoid(self:getTypeAst(typename)) end +local function getArrayType(arr) + if type(arr) ~= "table" then + return arr and '[]' or '' + end + local res = '' + for i, v in ipairs(arr) do + res = res .. '[]' + end + return res +end + function builder:buildStructOrUnion(lines, tt, name) lines[#lines+1] = '---@class ' .. self:getType(name) for _, field in ipairs(tt.fields or {}) do if field.name and field.type then - lines[#lines+1] = ('---@field %s %s'):format(field.name, self:getType(field.type)) + lines[#lines+1] = ('---@field %s %s%s'):format(field.name, self:getType(field.type), + getArrayType(field.isarray)) end end end @@ -146,7 +158,7 @@ end function builder:buildFunction(lines, tt, name) local param_names = {} for i, param in ipairs(tt.params or {}) do - lines[#lines+1] = ('---@param %s %s'):format(param.name, self:getType(param.type)) + lines[#lines+1] = ('---@param %s %s%s'):format(param.name, self:getType(param.type), getArrayType(param.idxs)) param_names[#param_names+1] = param.name end if tt.vararg then @@ -213,7 +225,7 @@ do end local function pushEnumValue(enumer, name, v) - v = tonumber(util.expandSingle(v)) + v = tonumber(util.expandSingle(v)) enumer[name] = v enumer[#enumer+1] = v return v |