diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-05 11:40:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-05 11:40:52 +0800 |
commit | 750dc445ea6f0d9010b73f9a8b884e6ca55dfb26 (patch) | |
tree | 5432aab152eb5b4014055813b3184feabeca8f04 /server | |
parent | cf035623c1e0f6148cd4cee513ce25810d0d137e (diff) | |
download | lua-language-server-750dc445ea6f0d9010b73f9a8b884e6ca55dfb26.zip |
find_lib
Diffstat (limited to 'server')
-rw-r--r-- | server/libs/bee/filesystem.lni | 2 | ||||
-rw-r--r-- | server/src/core/find_lib.lua | 61 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 3 | ||||
-rw-r--r-- | server/test/find_lib/init.lua | 4 |
4 files changed, 39 insertions, 31 deletions
diff --git a/server/libs/bee/filesystem.lni b/server/libs/bee/filesystem.lni index bb1b1e2d..51358065 100644 --- a/server/libs/bee/filesystem.lni +++ b/server/libs/bee/filesystem.lni @@ -1,9 +1,9 @@ [filesystem] type = 'table' +nick = 'bee::filesystem' [[.source]] type = 'library' name = 'bee.filesystem' -nick = 'bee::filesystem' <default> type = 'function' diff --git a/server/src/core/find_lib.lua b/server/src/core/find_lib.lua index 12eaa2fe..11174b2a 100644 --- a/server/src/core/find_lib.lua +++ b/server/src/core/find_lib.lua @@ -1,45 +1,50 @@ -local function findLib(value) +local function getParentName(lib, isObject) + for _, parent in ipairs(lib.parent) do + if isObject then + if parent.type == 'object' then + return parent.nick or parent.name + end + else + if parent.type ~= 'object' then + return parent.nick or parent.name + end + end + end + return '' +end + +local function findLib(source) + local value = source:bindValue() local lib = value:getLib() if not lib then return nil end if lib.parent then - local res - for _, parent in ipairs(lib.parent) do - if parent.type == value.parentType then - res = parent - end - end - if not res then - res = lib.parent[1] - end - if res.type == 'object' then - local fullKey = ('*%s:%s'):format(res.nick or res.name, lib.name) + if source:getFlag 'object' then + -- *string:sub + local fullKey = ('*%s:%s'):format(getParentName(lib, true), lib.name) return lib, fullKey, true else - local fullKey = ('%s.%s'):format(res.nick or res.name, lib.name) - return lib, fullKey, false - end - else - local res - if not lib.source then - return lib, lib.nick or lib.name, false - end - for _, source in ipairs(lib.source) do - if source.type == value.parentType then - res = source + local parentValue = source:getFlag 'parent' + if parentValue and parentValue:getType() == 'string' then + -- *string.sub + local fullKey = ('*%s.%s'):format(getParentName(lib, false), lib.name) + return lib, fullKey, false + else + -- string.sub + local fullKey = ('%s.%s'):format(getParentName(lib, false), lib.name) + return lib, fullKey, false end end - if not res then - return lib, lib.nick or lib.name, false - end - return lib, res.nick or res.name or lib.nick or lib.name, false + else + local name = lib.nick or lib.name + return lib, name, false end end return function (source) if source:bindValue() then - local lib, fullKey, oo = findLib(source:bindValue()) + local lib, fullKey, oo = findLib(source) return lib, fullKey, oo end return nil diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 2c9e7828..3ab10630 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -456,6 +456,7 @@ function mt:getSimple(simple, max) if object then table.insert(args, 1, object) end + object = nil source:bindCall(func, args) value = self:call(func, args, source) or createValue('any') elseif source.type == 'index' then @@ -464,6 +465,8 @@ function mt:getSimple(simple, max) value = value:getChild(index) or value:setChild(index, createValue('any', source)) source:bindValue(value, 'get') elseif source.type == 'name' then + source:setFlag('parent', value) + source:setFlag('object', object) value = value:getChild(source[1]) or value:setChild(source[1], createValue('any', source)) source:bindValue(value, 'get') elseif source.type == ':' then diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua index a32a9089..ea650970 100644 --- a/server/test/find_lib/init.lua +++ b/server/test/find_lib/init.lua @@ -73,7 +73,7 @@ TEST 'table.insert' [[ require 'table'.<?insert?>() ]] -TEST '*string:sub' [[ +TEST '*string.sub' [[ local str = 'xxx' str.<?sub?>() ]] @@ -83,7 +83,7 @@ local str = 'xxx' str:<?sub?>(1, 1) ]] -TEST '*string:sub' [[ +TEST '*string.sub' [[ ('xxx').<?sub?>() ]] |