diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 13:59:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 13:59:32 +0800 |
commit | 4e4bc7c8908afb100233045a1b15368ba8764c59 (patch) | |
tree | f74a37d86179afb19101d4868782a4a803693eb2 /server | |
parent | 2ece834c7f6923742a5a76108d1a8aad1fc1a611 (diff) | |
download | lua-language-server-4e4bc7c8908afb100233045a1b15368ba8764c59.zip |
支持库的子lib
Diffstat (limited to 'server')
-rw-r--r-- | server/libs/lua53/table.lni | 24 | ||||
-rw-r--r-- | server/src/matcher/compile.lua | 1 | ||||
-rw-r--r-- | server/src/matcher/find_lib.lua | 81 | ||||
-rw-r--r-- | server/test/find_lib/init.lua | 23 |
4 files changed, 106 insertions, 23 deletions
diff --git a/server/libs/lua53/table.lni b/server/libs/lua53/table.lni index 94e60664..756359c3 100644 --- a/server/libs/lua53/table.lni +++ b/server/libs/lua53/table.lni @@ -1,6 +1,3 @@ -[default] -type = 'function' - [table] type = 'table' [[.source]] @@ -8,3 +5,24 @@ type = 'global' [[.source]] type = 'library' name = 'table' + +[default] +type = 'function' +[[.parent]] +type = 'global' +name = 'table' +[[.parent]] +type = 'library' +name = 'table' + +[insert] +[[.args]] +name = 'list' +type = 'table' +[[.args]] +name = 'pos' +type = 'integer' +optional = 'self' +[[.args]] +name = 'value' +type = 'any' diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua index 2c53f618..434a0999 100644 --- a/server/src/matcher/compile.lua +++ b/server/src/matcher/compile.lua @@ -60,6 +60,7 @@ function mt:createLib(name) local lib = { name = name, type = 'lib', + childs = {}, } return lib end diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua index 7001117e..213d6111 100644 --- a/server/src/matcher/find_lib.lua +++ b/server/src/matcher/find_lib.lua @@ -109,19 +109,14 @@ local function isGlobal(var) return var.parent.key == '_ENV' or var.parent.key == '_G' end -local function checkLibAsGlobal(var, name) - local value = var.value or var +local function checkSourceAsGlobal(value, name) if value.key == name and isGlobal(value) then return name end return nil end -local function checkLibAsLibrary(var, name) - local value = var.value - if not value then - return nil - end +local function checkSourceAsLibrary(value, name) if value.type ~= 'lib' then return nil end @@ -131,20 +126,64 @@ local function checkLibAsLibrary(var, name) return nil end -local function checkLib(var, name, lib) +local function checkSource(value, name, lib) if not lib.source then - return checkLibAsGlobal(var, name) + return checkSourceAsGlobal(value, name) end for _, source in ipairs(lib.source) do if source.type == 'global' then - local fullkey = checkLibAsGlobal(var, name) - if fullkey then - return fullkey + local fullKey = checkSourceAsGlobal(value, name) + if fullKey then + return fullKey end elseif source.type == 'library' then - local fullkey = checkLibAsLibrary(var, name) - if fullkey then - return fullkey + local fullKey = checkSourceAsLibrary(value, name) + if fullKey then + return fullKey + end + end + end + return nil +end + +local function checkParentAsGlobal(parentValue, name, parent) + local parentName = checkSourceAsGlobal(parentValue, parent.name) + if not parentName then + return nil + end + return ('%s.%s'):format(parentName, name) +end + +local function checkParentAsLibrary(parentValue, name, parent) + local parentName = checkSourceAsLibrary(parentValue, parent.name) + if not parentName then + return nil + end + return ('%s.%s'):format(parentName, name) +end + +local function checkParent(value, name, lib) + if not lib.parent then + return nil + end + if name ~= value.key then + return nil + end + local parentValue = value.parent + if not parentValue then + return nil + end + parentValue = parentValue.value or parentValue + for _, parent in ipairs(lib.parent) do + if parent.type == 'global' then + local fullKey = checkParentAsGlobal(parentValue, name, parent) + if fullKey then + return fullKey + end + elseif parent.type == 'library' then + local fullKey = checkParentAsLibrary(parentValue, name, parent) + if fullKey then + return fullKey end end end @@ -152,10 +191,12 @@ local function checkLib(var, name, lib) end local function findLib(var, libs) + local value = var.value or var for name, lib in pairs(libs) do - local fullkey = checkLib(var, name, lib) - if fullkey then - return lib, fullkey + local fullKey = checkSource(value, name, lib) + or checkParent(value, name, lib) + if fullKey then + return lib, fullKey end end return nil, nil @@ -163,6 +204,6 @@ end return function (var) local libs = getLibs() - local lib, fullkey = findLib(var, libs) - return lib, fullkey + local lib, fullKey = findLib(var, libs) + return lib, fullKey end diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua index afa9ec2a..1efb2423 100644 --- a/server/test/find_lib/init.lua +++ b/server/test/find_lib/init.lua @@ -55,3 +55,26 @@ local rq = require local lib = 'table' local <?xx?> = rq(lib) ]] + +TEST 'table.insert' [[ +table.<?insert?>() +]] + +TEST 'table.insert' [[ +local t = table +t.<?insert?>() +]] + +TEST 'table.insert' [[ +local insert = table.insert +<?insert?>() +]] + +TEST 'table.insert' [[ +local t = require 'table' +t.<?insert?>() +]] + +TEST 'table.insert' [[ +require 'table'.<?insert?>() +]] |