summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/core/hover/function.lua28
-rw-r--r--server/src/emmy/manager.lua1
-rw-r--r--server/src/emmy/param.lua8
-rw-r--r--server/src/parser/ast.lua16
-rw-r--r--server/src/parser/grammar.lua3
-rw-r--r--server/test/hover/init.lua10
6 files changed, 62 insertions, 4 deletions
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index 5358cfaa..b0971308 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
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
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index f1a18c06..108bc978 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -812,3 +812,13 @@ local <toclose> <const> <?x?> = 1
[[
local <toclose> <const> x: number = 1
]]
+
+TEST [[
+---@param x number {optional = 'after'}
+---@param y boolean {optional = 'self'}
+---@param z string
+function <?f?>(x, y, z) end
+]]
+[=[
+function f([x: number [, y: boolean], z: string])
+]=]