diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 2 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 43 | ||||
-rw-r--r-- | server/src/emmy/manager.lua | 1 | ||||
-rw-r--r-- | server/src/emmy/param.lua | 8 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 16 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 3 |
6 files changed, 67 insertions, 6 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index a0a7fb82..18bf12af 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -43,7 +43,7 @@ for _, k in ipairs(KEYS) do KEYMAP[k] = true end -local EMMY_KEYWORD = {'class', 'type', 'alias', 'param', 'return', 'field', 'generic', 'vararg', 'language', 'see'} +local EMMY_KEYWORD = {'class', 'type', 'alias', 'param', 'return', 'field', 'generic', 'vararg', 'language', 'see', 'overload'} local function getDucumentation(name, value) if value:getType() == 'function' then diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index 5358cfaa..2dc15996 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -4,6 +4,7 @@ local function buildValueArgs(func, object, select) end local names = {} local values = {} + local options = {} if func.argValues then for i, value in ipairs(func.argValues) do values[i] = value:getType() @@ -15,6 +16,7 @@ local function buildValueArgs(func, object, select) local param = func:findEmmyParamByName(arg:getName()) if param then values[i] = param:getType() + options[i] = param:getOption() end end end @@ -30,11 +32,20 @@ local function buildValueArgs(func, object, select) max = math.max(#names, #values) end for i = start, max do + local name = names[i] + local value = values[i] or 'any' + local option = options[i] + if option and option.optional then + if i > start then + strs[#strs+1] = ' [' + else + strs[#strs+1] = '[' + end + end if i > start then strs[#strs+1] = ', ' end - local name = names[i] - local value = values[i] or 'any' + if i == select then strs[#strs+1] = '@ARG' end @@ -46,6 +57,10 @@ local function buildValueArgs(func, object, select) if i == select then strs[#strs+1] = '@ARG' end + + if option and option.optional == 'self' then + strs[#strs+1] = ']' + end end if func:hasDots() then if max > 0 then @@ -53,6 +68,15 @@ local function buildValueArgs(func, object, select) end strs[#strs+1] = '...' end + + if options then + for _, option in pairs(options) do + if option.optional == 'after' then + strs[#strs+1] = ']' + end + end + end + local text = table.concat(strs) local argLabel = {} for i = 1, 2 do @@ -91,6 +115,17 @@ local function buildValueReturns(func) return '\n -> ' .. table.concat(strs, ', ') end +---@param func emmyFunction +local function buildEnum(func) + if not func then + return nil + end + local params = func:getEmmyParams() + if not params then + return nil + end +end + local function getComment(func) if not func then return nil @@ -101,6 +136,7 @@ end return function (name, func, object, select) local args, argLabel = buildValueArgs(func, object, select) local returns = buildValueReturns(func) + local enum = buildEnum(func) local comment = getComment(func) local headLen = #('function %s('):format(name) local title = ('function %s(%s)%s'):format(name, args, returns) @@ -110,7 +146,8 @@ return function (name, func, object, select) end return { label = title, - argLabel = argLabel, description = comment, + enum = enum, + argLabel = argLabel, } end diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index 11aa899c..1be0be94 100644 --- a/server/src/emmy/manager.lua +++ b/server/src/emmy/manager.lua @@ -158,6 +158,7 @@ function mt:addParam(source, bind) for i = 3, #source do paramObj:addEnum(source[i][1]) end + paramObj:setOption(source.option) return paramObj end diff --git a/server/src/emmy/param.lua b/server/src/emmy/param.lua index 290ab6e4..6fd41d5a 100644 --- a/server/src/emmy/param.lua +++ b/server/src/emmy/param.lua @@ -47,6 +47,14 @@ function mt:eachEnum(callback) end end +function mt:setOption(option) + self._option = option +end + +function mt:getOption() + return self._option +end + return function (manager, source) local self = setmetatable({ source = source.id, diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 9903dca2..0e408c73 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1233,9 +1233,23 @@ local Defs = { ... } end, - EmmyParam = function (argName, emmyName, ...) + EmmyParam = function (argName, emmyName, options, ...) + local option + if options then + option = {} + for _, pair in ipairs(options) do + if pair.type == 'pair' then + local key = pair[1] + local value = pair[2] + if key.type == 'name' then + option[key[1]] = value[1] + end + end + end + end local emmy = { type = 'emmyParam', + option = option, argName, emmyName, ... diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 50f76d0b..913b0b25 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -560,7 +560,8 @@ EmmyTypeEnums <- %s* '|' %s* String EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnums* -EmmyParam <- MustEmmyName %s* EmmyType EmmyTypeEnums* +EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnums* +EmmyOption <- Table / %nil EmmyReturn <- EmmyType |