diff options
author | unknown <sumnekosun@intranet.123u.com> | 2019-04-02 17:09:56 +0800 |
---|---|---|
committer | unknown <sumnekosun@intranet.123u.com> | 2019-04-02 17:09:56 +0800 |
commit | d283727cffff43312e5129801e265c2957d507d6 (patch) | |
tree | 93333303de1715e6c2754213d6721bdcfcf73a22 /server/src | |
parent | 43e0d5819011e069893ee9f05eba2fc90d1b4bf5 (diff) | |
download | lua-language-server-d283727cffff43312e5129801e265c2957d507d6.zip |
函数重新从全局查找
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 11 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 11 | ||||
-rw-r--r-- | server/src/core/hover/hover.lua | 5 | ||||
-rw-r--r-- | server/src/core/signature.lua | 16 | ||||
-rw-r--r-- | server/src/vm/source.lua | 54 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 2 |
6 files changed, 80 insertions, 19 deletions
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] |