summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-12 10:27:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-12 10:27:09 +0800
commit70f06353bf44da468331508f8306f6d8bd80f82f (patch)
treec2f195af0b985b0ee5e0a39d37f3863c143ca9f5 /server
parent396cc15abad6f2d331412714a04965b0ee1ca2a7 (diff)
downloadlua-language-server-70f06353bf44da468331508f8306f6d8bd80f82f.zip
修正一些bug
Diffstat (limited to 'server')
-rw-r--r--server/src/core/diagnostics.lua3
-rw-r--r--server/src/core/hover/function.lua3
-rw-r--r--server/src/vm/function.lua47
-rw-r--r--server/src/vm/value.lua1
-rw-r--r--server/src/vm/vm.lua4
5 files changed, 29 insertions, 29 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index f052d7d2..571e083b 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -214,9 +214,6 @@ function mt:searchRedundantParameters(callback)
return
end
local max = #func.args
- if func:getObject() then
- max = max + 1
- end
local passed = #args
for i = max + 1, passed do
local extra = args[i]
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index f8f7655e..9bb532ae 100644
--- a/server/src/core/hover/function.lua
+++ b/server/src/core/hover/function.lua
@@ -4,9 +4,6 @@ local function buildValueArgs(func, object, select)
end
local names = {}
local values = {}
- if func:getObject() then
- names[#names+1] = 'self'
- end
if func.args then
for _, arg in ipairs(func.args) do
names[#names+1] = arg:getName()
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 700f1a19..8d45ef8e 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -131,7 +131,7 @@ function mt:setObject(value, source)
end
function mt:getObject()
- return self._objectValue, self._objectSource
+ return self._objectSource, self._objectValue
end
function mt:hasRuned()
@@ -149,18 +149,29 @@ function mt:run(vm)
end
-- 第一次运行函数时,创建函数的参数
- if self._runed ~= 1 then
- return
- end
+ if self._runed == 1 then
+ -- 如果是面向对象形式的函数,创建隐藏的参数self
+ if self._objectSource then
+ local loc = createLocal('self', self._objectSource, self._objectValue)
+ loc:set('hide', true)
+ self:saveLocal('self', loc)
+ self.args[#self.args+1] = loc
+ end
- -- 如果是面向对象形式的函数,创建隐藏的参数self
- if self._objectSource then
- local loc = createLocal('self', self._objectSource, self._objectValue)
- self:saveLocal('self', loc)
+ -- 显性声明的参数
+ self:createArgs(vm)
end
- -- 显性声明的参数
- self:createArgs(vm)
+ -- 向局部变量中填充参数
+ for i, loc in ipairs(self.args) do
+ loc:setValue(self.argValues[i] or createValue('nil', arg))
+ end
+ if self._dots then
+ self._dots = createMulti()
+ for i = #self.args + 1, #self.argValues do
+ self._dots:push(self.argValues[i])
+ end
+ end
end
function mt:setArgs(values)
@@ -172,19 +183,15 @@ function mt:setArgs(values)
end
end
-function mt:createArg(vm, arg, values)
+function mt:createArg(vm, arg)
vm:instantSource(arg)
arg:set('arg', true)
if arg.type == 'name' then
- local value = table.remove(values, 1) or createValue('nil', arg)
- local loc = createLocal(arg[1], arg, value)
+ local loc = createLocal(arg[1], arg, createValue('nil', arg))
self:saveLocal(arg[1], loc)
self.args[#self.args+1] = loc
elseif arg.type == '...' then
self._dots = createMulti()
- for i = 1, #values do
- self._dots:set(i, values[i])
- end
end
end
@@ -211,16 +218,12 @@ function mt:createArgs(vm)
if not args then
return
end
- local values = {}
- for i, value in ipairs(self.argValues) do
- values[i] = value
- end
if args.type == 'list' then
for _, arg in ipairs(args) do
- self:createArg(vm, arg, values)
+ self:createArg(vm, arg)
end
else
- self:createArg(vm, args, values)
+ self:createArg(vm, args)
end
end
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index a3aad7a6..e6cbf876 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -207,6 +207,7 @@ function mt:mergeValue(value)
self:setType(tp, rate)
end
end
+ value._type = self._type
if value._child then
if not self._child then
self._child = {}
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index f965b429..a8834806 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -100,7 +100,9 @@ function mt:runFunction(func)
-- 暂时使用这种方式激活参数的source
for _, arg in ipairs(func.args) do
- self:bindLocal(arg.source, arg, 'local')
+ if arg.source ~= func:getObject() then
+ self:bindLocal(arg.source, arg, 'local')
+ end
end
local originFunction = self:getCurrentFunction()