diff options
-rw-r--r-- | server/locale/enUS/libs/lua53/basic.lni | 13 | ||||
-rw-r--r-- | server/src/matcher/find_lib.lua | 40 | ||||
-rw-r--r-- | server/src/matcher/hover.lua | 25 |
3 files changed, 71 insertions, 7 deletions
diff --git a/server/locale/enUS/libs/lua53/basic.lni b/server/locale/enUS/libs/lua53/basic.lni index 5fd44fdc..e600857f 100644 --- a/server/locale/enUS/libs/lua53/basic.lni +++ b/server/locale/enUS/libs/lua53/basic.lni @@ -1,12 +1,25 @@ [assert] [collectgarbage] +[[.enums]] +enum = 'collect' +description = 'performs a full garbage-collection cycle. This is the default option.' +[[.enums]] +enum = 'isrunning' +description = 'returns a boolean that tells whether the collector is running (i.e., not stopped).' +[[.enums]] +enum = 'count' +description = 'returns the total memory in use by Lua in Kbytes. The value has a fractional part, so that it multiplied by 1024 gives the exact number of bytes in use by Lua (except for overflows).' [dofile] [error] [_G] +description = 'A global variable (not a function) that holds the global environment' +[[.fields]] +field = '_G' +description = 'A global variable (not a function) that holds the global environment' [getmetatable] diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua index ca5577d1..7d0574c0 100644 --- a/server/src/matcher/find_lib.lua +++ b/server/src/matcher/find_lib.lua @@ -1,9 +1,45 @@ local lni = require 'lni' +local function mergeEnum(lib, locale) + if not lib or not locale then + return + end + local pack = {} + for _, enum in ipairs(lib) do + if enum.enum then + pack[enum.enum] = enum + end + end + for _, enum in ipairs(locale) do + if pack[enum.enum] then + pack[enum.enum].description = enum.description + end + end +end + +local function mergeField(lib, locale) + if not lib or not locale then + return + end + local pack = {} + for _, field in ipairs(lib) do + if field.field then + pack[field.field] = field + end + end + for _, field in ipairs(locale) do + if pack[field.field] then + pack[field.field].description = field.description + end + end +end + local function mergeLocale(libs, locale) - for name, obj in pairs(locale) do + for name in pairs(locale) do if libs[name] then - libs[name].description = obj.description + libs[name].description = locale[name].description + mergeEnum(libs[name].enums, locale[name].enums) + mergeField(libs[name].fields, locale[name].fields) end end end diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua index 6a643851..b8058cc1 100644 --- a/server/src/matcher/hover.lua +++ b/server/src/matcher/hover.lua @@ -103,7 +103,7 @@ local function buildEnum(lib) else strs[#strs+1] = '\n | ' end - strs[#strs+1] = ('%q: %s'):format(enum.enum, enum.description or '') + strs[#strs+1] = ('%q -- %s'):format(enum.enum, enum.description or '') end end return table.concat(strs) @@ -113,7 +113,15 @@ local function buildFunctionHover(lib, name) local title = ('function %s(%s)%s'):format(name, buildArgs(lib), buildReturns(lib)) local enum = buildEnum(lib) local tip = lib.description or '' - return ('```lua\n%s%s\n```\n%s'):format(title, enum, tip) + return ([[ +```lua +%s +``` +%s +```lua +%s +``` +]]):format(title, tip, enum) end local function buildField(lib) @@ -122,8 +130,7 @@ local function buildField(lib) end local strs = {} for _, field in ipairs(lib.fields) do - strs[#strs+1] = '\n | ' - strs[#strs+1] = ('%s:%s: %s'):format(field.field, field.type, field.description or '') + strs[#strs+1] = ('\n%s:%s -- %s'):format(field.field, field.type, field.description or '') end return table.concat(strs) end @@ -132,7 +139,15 @@ local function buildTableHover(lib, name) local title = ('table %s'):format(name) local field = buildField(lib) local tip = lib.description or '' - return ('```lua\n%s%s```\n%s'):format(title, field, tip) + return ([[ +```lua +%s +``` +%s +```lua +%s +``` +]]):format(title, tip, field) end return function (results, pos) |