From d283727cffff43312e5129801e265c2957d507d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Apr 2019 17:09:56 +0800 Subject: =?UTF-8?q?=E5=87=BD=E6=95=B0=E9=87=8D=E6=96=B0=E4=BB=8E=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/completion.lua | 11 ++++++--- server/src/core/diagnostics.lua | 11 ++++++--- server/src/core/hover/hover.lua | 5 ++-- server/src/core/signature.lua | 16 ++++++++---- server/src/vm/source.lua | 54 ++++++++++++++++++++++++++++++++++++++--- server/src/vm/vm.lua | 2 +- 6 files changed, 80 insertions(+), 19 deletions(-) (limited to 'server/src') diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 027f7faa..112e6408 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -400,12 +400,17 @@ local function searchCallArg(vm, source, word, callback, pos) return a.start > b.start end) local call = results[1] - local func, args = call:bindCall() - if not func then + local args = call:bindCall() + if not args then return end - local lib = func:getLib() + local value = call:findCallFunction() + if not value then + return + end + + local lib = value:getLib() if not lib then return end diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 71995167..7337dd7b 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -203,14 +203,17 @@ end function mt:searchRedundantParameters(callback) self.vm:eachSource(function (source) - local call, args = source:bindCall() - if not call then + local args = source:bindCall() + if not args then return end - local func = call:getFunction() - if not func then + + local value = source:findCallFunction() + if not value then return end + + local func = value:getFunction() -- 参数中有 ... ,不用再检查了 if func:hasDots() then return diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua index f09bfce4..dfaeed35 100644 --- a/server/src/core/hover/hover.lua +++ b/server/src/core/hover/hover.lua @@ -177,7 +177,7 @@ end local function hoverAsValue(source, lsp, select) local lib, fullkey = findLib(source) - local value = source:bindValue() + local value = source:findValue() local name = fullkey or buildValueName(source) local hover @@ -186,7 +186,8 @@ local function hoverAsValue(source, lsp, select) if lib then hover = getFunctionHoverAsLib(name, lib, object, select) else - hover = getFunctionHover(name, value:getFunction(), object, select) + local func = value:getFunction() + hover = getFunctionHover(name, func, object, select) end else hover = getValueHover(source, name, value, lib) diff --git a/server/src/core/signature.lua b/server/src/core/signature.lua index 23dba97a..5dcce85f 100644 --- a/server/src/core/signature.lua +++ b/server/src/core/signature.lua @@ -47,10 +47,16 @@ local function getFunctionSource(call) end local function getHover(call, pos) - local func, args = call:bindCall() - if not func then + local args = call:bindCall() + if not args then + return + end + + local value = call:findCallFunction() + if not value then return end + local select = getSelect(args, pos) local source = getFunctionSource(call) local object = source:get 'object' @@ -60,7 +66,7 @@ local function getHover(call, pos) if lib then hover = getFunctionHoverAsLib(name, lib, object, select) else - hover = getFunctionHover(name, func:getFunction(), object, select) + hover = getFunctionHover(name, value:getFunction(), object, select) end if hover and hover.argLabel then return hover @@ -68,8 +74,8 @@ local function getHover(call, pos) end local function isInFunctionOrTable(call, pos) - local func, args = call:bindCall() - if not func then + local args = call:bindCall() + if not args then return false end local select = getSelect(args, pos) diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index c364d9cf..ce1d325b 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -48,12 +48,11 @@ function mt:bindValue(value, action) end end -function mt:bindCall(func, args) - if func then - self._bindCall = func +function mt:bindCall(args) + if args then self._bindCallArgs = args else - return self._bindCall, self._bindCallArgs + return self._bindCallArgs end end @@ -96,6 +95,53 @@ function mt:isDead() return self._dead end +function mt:findValue() + local value = self:bindValue() + if not value then + return nil + end + if not value:isGlobal() then + return value + end + if self.type ~= 'name' then + return value + end + local parent = self:get 'parent' + if not parent then + return value + end + local name = self[1] + if type(name) ~= 'string' then + return value + end + return parent:getChild(name) or value +end + +function mt:findCallFunction() + local simple = self:get 'simple' + if not simple then + return nil + end + local source + for i = 1, #simple do + if simple[i] == self then + source = simple[i-1] + end + end + if not source then + return nil + end + local value = source:bindValue() + if value and value:getFunction() then + return value + end + value = source:findValue() + if value and value:getFunction() then + return value + end + return nil +end + local function instant(source) if source.id then return false diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 5d6b024f..a26fe808 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -462,7 +462,7 @@ function mt:getSimple(simple, max) table.insert(args, 1, simple[i-3]) end object = nil - source:bindCall(func, args) + source:bindCall(args) value = self:call(func, values, source) or valueMgr.create('any', self:getDefaultSource()) elseif source.type == 'index' then local child = source[1] -- cgit v1.2.3