summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-28 16:21:08 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-28 16:21:08 +0800
commit12c658d8f569c52e88b09aadbd221387364276f4 (patch)
treec9d917b6ddebdf9443f88a188fa5839d1a243ca7 /server/src
parent9e875d4ea8ac60939f51771485084c539e66e040 (diff)
downloadlua-language-server-12c658d8f569c52e88b09aadbd221387364276f4.zip
允许不占用return
Diffstat (limited to 'server/src')
-rw-r--r--server/src/emmy/manager.lua10
-rw-r--r--server/src/parser/ast.lua6
-rw-r--r--server/src/parser/grammar.lua3
-rw-r--r--server/src/vm/emmy.lua2
-rw-r--r--server/src/vm/function.lua14
5 files changed, 22 insertions, 13 deletions
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 0407bbc0..658fb56b 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -164,10 +164,12 @@ end
function mt:addReturn(source, bind)
local returnObj = newReturn(self, source)
- if bind.type == 'emmy.generic' then
- returnObj:bindGeneric(bind)
- else
- returnObj:bindType(bind)
+ if bind then
+ if bind.type == 'emmy.generic' then
+ returnObj:bindGeneric(bind)
+ else
+ returnObj:bindType(bind)
+ end
end
return returnObj
end
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index c14328f0..b9cc9b47 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1245,12 +1245,12 @@ local Defs = {
emmy.finish = emmy[#emmy].finish
return emmy
end,
- EmmyReturn = function (type, option)
+ EmmyReturn = function (start, type, finish, option)
local emmy = {
type = 'emmyReturn',
option = option,
- start = type.start,
- finish = type.finish,
+ start = start,
+ finish = finish - 1,
[1] = type,
}
return emmy
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index da850250..e0db8988 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -569,7 +569,8 @@ EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnum*
EmmyOption <- Table?
-> EmmyOption
-EmmyReturn <- EmmyType EmmyOption
+EmmyReturn <- {} %nil {} Table -> EmmyOption
+ / {} EmmyType {} EmmyOption
EmmyField <- (EmmyFieldAccess MustEmmyName %s* EmmyType)
EmmyFieldAccess <- ({'public'} Cut %s*)
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index 3ad0a472..8625442b 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -196,7 +196,7 @@ function mt:doEmmyReturn(action)
---@type emmyMgr
local emmyMgr = self.emmyMgr
self:instantSource(action)
- local type = self:getGenericByType(action[1]) or self:buildEmmyAnyType(action[1])
+ local type = action[1] and (self:getGenericByType(action[1]) or self:buildEmmyAnyType(action[1]))
local rtn = emmyMgr:addReturn(action, type)
action:set('emmy.return', rtn)
self:addEmmyReturn(rtn)
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index beca5769..b6772cd1 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -162,8 +162,11 @@ function mt:rawSetReturn(index, value)
end
function mt:setReturn(index, value)
- if self._emmyReturns then
- return
+ local emmy = self._emmyReturns and self._emmyReturns[index]
+ if emmy then
+ if emmy:bindType() or emmy:bindGeneric() then
+ return
+ end
end
return self:rawSetReturn(index, value)
end
@@ -172,8 +175,11 @@ function mt:mergeReturn(index, value)
if self._removed then
return
end
- if self._emmyReturns then
- return
+ local emmy = self._emmyReturns and self._emmyReturns[index]
+ if emmy then
+ if emmy:bindType() or emmy:bindGeneric() then
+ return
+ end
end
self:set('hasReturn', true)
if not self.returns then