summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-27 11:32:49 +0800
committersumneko <sumneko@hotmail.com>2019-05-27 11:32:49 +0800
commit23c895e096b8bf9c0873ce3efaca862db246e236 (patch)
treef8d38b8228aa475e6d1bf9d428a37c9ef478dc4d
parentc72ec4e93a463fea2d826f0fbac7aede460a045f (diff)
downloadlua-language-server-23c895e096b8bf9c0873ce3efaca862db246e236.zip
fixed #40 强制使用 @return
-rw-r--r--server/src/vm/function.lua14
-rw-r--r--server/test/hover/init.lua27
2 files changed, 39 insertions, 2 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 1106a0c9..a6f2b0cf 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -145,7 +145,7 @@ function mt:loadLabel(name)
return nil
end
-function mt:setReturn(index, value)
+function mt:rawSetReturn(index, value)
if self._removed then
return
end
@@ -161,10 +161,20 @@ function mt:setReturn(index, value)
end
end
+function mt:setReturn(index, value)
+ if self._emmyReturns then
+ return
+ end
+ return self:rawSetReturn(index, value)
+end
+
function mt:mergeReturn(index, value)
if self._removed then
return
end
+ if self._emmyReturns then
+ return
+ end
self:set('hasReturn', true)
if not self.returns then
self.returns = createMulti()
@@ -324,7 +334,7 @@ function mt:run(vm)
value:mergeType(destValue)
end
end
- self:setReturn(i, value)
+ self:rawSetReturn(i, value)
end
end
end
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index e568335d..cff6af65 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -769,3 +769,30 @@ local names: {
[*integer]: string,
}
]]
+
+TEST [[
+---@return any
+function <?f?>()
+ ---@type integer
+ local a
+ return a
+end
+]]
+[[
+function f()
+ -> any
+]]
+
+TEST [[
+---@return any
+function f()
+ ---@type integer
+ local a
+ return a
+end
+
+local <?x?> = f()
+]]
+[[
+local x: any
+]]