summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-07 18:40:34 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-07 18:40:34 +0800
commit11acb1981bf74b012cd02e4c140577f29692fc98 (patch)
treeaf2ff463280d7a09a8ed94d2ba23c80f9cffe866 /server
parentf37431779e9975d0c71c196ac563ccecdb3f79ea (diff)
downloadlua-language-server-11acb1981bf74b012cd02e4c140577f29692fc98.zip
支持昵称
Diffstat (limited to 'server')
-rw-r--r--server/libs/bee/filesystem.lni21
-rw-r--r--server/src/matcher/find_lib.lua30
-rw-r--r--server/test/find_lib/init.lua10
3 files changed, 44 insertions, 17 deletions
diff --git a/server/libs/bee/filesystem.lni b/server/libs/bee/filesystem.lni
new file mode 100644
index 00000000..99f2c4de
--- /dev/null
+++ b/server/libs/bee/filesystem.lni
@@ -0,0 +1,21 @@
+[filesystem]
+type = 'table'
+[[.source]]
+type = 'library'
+name = 'bee.filesystem'
+
+[default]
+type = 'function'
+[[.parent]]
+type = 'library'
+name = 'bee.filesystem'
+nick = 'fs'
+
+[current_path]
+[[.args]]
+name = 'new_path'
+type = '*filesystem'
+optional = 'self'
+[[.returns]]
+type = '*filesystem'
+optional = 'self'
diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua
index 5da379c6..3d98aef7 100644
--- a/server/src/matcher/find_lib.lua
+++ b/server/src/matcher/find_lib.lua
@@ -118,35 +118,35 @@ local function isGlobal(var)
return var.parent.key == '_ENV' or var.parent.key == '_G'
end
-local function checkSourceAsGlobal(value, name)
+local function checkSourceAsGlobal(value, name, showname)
if value.key == name and isGlobal(value) then
- return name
+ return showname or name
end
return nil
end
-local function checkSourceAsLibrary(value, name)
+local function checkSourceAsLibrary(value, name, showname)
if value.type ~= 'lib' then
return nil
end
if value.name == name then
- return name
+ return showname or name
end
return nil
end
-local function checkSource(value, name, lib)
+local function checkSource(value, libname, lib)
if not lib.source then
- return checkSourceAsGlobal(value, name)
+ return checkSourceAsGlobal(value, libname)
end
for _, source in ipairs(lib.source) do
if source.type == 'global' then
- local fullKey = checkSourceAsGlobal(value, name)
+ local fullKey = checkSourceAsGlobal(value, source.name or libname, source.nick or libname)
if fullKey then
return fullKey
end
elseif source.type == 'library' then
- local fullKey = checkSourceAsLibrary(value, name)
+ local fullKey = checkSourceAsLibrary(value, source.name or libname, source.nick or libname)
if fullKey then
return fullKey
end
@@ -156,19 +156,19 @@ local function checkSource(value, name, lib)
end
local function checkParentAsGlobal(parentValue, name, parent)
- local parentName = checkSourceAsGlobal(parentValue, parent.name)
+ local parentName = checkSourceAsGlobal(parentValue, parent.name, parent.nick)
if not parentName then
return nil
end
- return ('%s.%s'):format(parent.name, name)
+ return ('%s.%s'):format(parentName, name)
end
local function checkParentAsLibrary(parentValue, name, parent)
- local parentName = checkSourceAsLibrary(parentValue, parent.name)
+ local parentName = checkSourceAsLibrary(parentValue, parent.name, parent.nick)
if not parentName then
return nil
end
- return ('%s.%s'):format(parent.name, name)
+ return ('%s.%s'):format(parentName, name)
end
local function checkParentAsObject(parentValue, name, parent)
@@ -213,12 +213,12 @@ end
local function findLib(var, libs)
local value = var.value or var
- for name, lib in pairs(libs) do
- local fullKey = checkSource(value, name, lib)
+ for libname, lib in pairs(libs) do
+ local fullKey = checkSource(value, libname, lib)
if fullKey then
return lib, fullKey, false
end
- local fullKey, oo = checkParent(value, name, lib)
+ local fullKey, oo = checkParent(value, libname, lib)
if fullKey then
return lib, fullKey, oo
end
diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua
index 06e04912..09f0997d 100644
--- a/server/test/find_lib/init.lua
+++ b/server/test/find_lib/init.lua
@@ -93,6 +93,12 @@ TEST '*string:sub' [[
('xxx').<?sub?> = 1
]]
-TEST '*string:sub' [[
-('xxx'):<?sub?>()
+TEST 'filesystem' [[
+local <?fs?> = require 'bee.filesystem'
+]]
+
+TEST 'fs.current_path' [[
+local filesystem = require 'bee.filesystem'
+
+ROOT = filesystem.<?current_path?>()
]]