summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2021-12-21 22:49:59 +0800
committersumneko <sumneko@hotmail.com>2021-12-21 22:49:59 +0800
commitb7344640a0ab9a07551ee5ebc435657b45659553 (patch)
tree0fef08a7dbb0a115e0e1249b6123fd529cf1fc58 /test
parentc47baf932309a05673b7931fdf6a1be207fb7bc4 (diff)
parentec4f497aa2624d9dce29e1de0cfd28ecd85e7df3 (diff)
downloadlua-language-server-b7344640a0ab9a07551ee5ebc435657b45659553.zip
Merge remote-tracking branch 'origin/master' into multi-workspace
Diffstat (limited to 'test')
-rw-r--r--test/completion/common.lua27
-rw-r--r--test/crossfile/definition.lua90
-rw-r--r--test/crossfile/hover.lua84
-rw-r--r--test/diagnostics/init.lua11
4 files changed, 197 insertions, 15 deletions
diff --git a/test/completion/common.lua b/test/completion/common.lua
index 94b55514..b03d55ca 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -2593,7 +2593,7 @@ c:<??>
TEST [[
---@class Class
----@field on fun(x: "'aaa'"|"'bbb'")
+---@field on fun(self, x: "'aaa'"|"'bbb'")
local c
c:on(<??>)
@@ -2605,7 +2605,7 @@ TEST [[
---@field on fun(x: "'aaa'"|"'bbb'")
local c
-c:on('<??>')
+c.on('<??>')
]]
(EXISTS)
@@ -3037,3 +3037,26 @@ end)
}
},
}
+
+TEST [[
+---@meta
+
+---@alias testAlias
+---| "'test1'"
+---| "'test2'"
+---| "'test3'"
+
+---@class TestClass
+local TestClass = {}
+
+---@overload fun(self: TestClass, arg2: testAlias)
+---@param arg1 integer
+---@param arg2 testAlias
+function TestClass:testFunc2(arg1, arg2) end
+
+---@type TestClass
+local t
+
+t:testFunc2(<??>)
+]]
+(EXISTS)
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 8f4dd7e8..c9a95658 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -867,3 +867,93 @@ print(t.<?x?>)
]]
}
}
+
+local originRuntimePath = config.get 'Lua.runtime.path'
+
+config.set('Lua.runtime.path', {
+ './?.lua'
+})
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+return {
+ <!x!> = 1,
+}
+]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+local t = require 'a'
+print(t.<?x?>)
+ ]]
+ }
+}
+
+config.set('Lua.runtime.path', {
+ '/home/?.lua'
+})
+TEST {
+ {
+ path = '/home/a.lua',
+ content = [[
+return {
+ <!x!> = 1,
+}
+]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+local t = require 'a'
+print(t.<?x?>)
+ ]]
+ }
+}
+
+config.set('Lua.runtime.pathStrict', true)
+config.set('Lua.runtime.path', {
+ './?.lua'
+})
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+return {
+ <!x!> = 1,
+}
+]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+local t = require 'a'
+print(t.<?x?>)
+ ]]
+ }
+}
+
+config.set('Lua.runtime.path', {
+ '/home/?.lua'
+})
+TEST {
+ {
+ path = '/home/a.lua',
+ content = [[
+return {
+ <!x!> = 1,
+}
+]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+local t = require 'a'
+print(t.<?x?>)
+ ]]
+ }
+}
+
+config.set('Lua.runtime.pathStrict', false)
+config.set('Lua.runtime.path', originRuntimePath)
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index 86471936..492efe43 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -41,20 +41,17 @@ end
function TEST(expect)
files.removeAll()
- local targetScript, targetList = catch(expect[1].content, '?')
- local targetUri = furi.encode(expect[1].path)
-
- local sourceScript, sourceList = catch(expect[2].content, '?')
- local sourceUri = furi.encode(expect[2].path)
-
- files.setText(targetUri, targetScript)
- files.setText(sourceUri, sourceScript)
-
- if targetList['?'] then
- local targetPos = (targetList['?'][1][1] + targetList['?'][1][2]) // 2
- core.byUri(targetUri, targetPos)
+ local sourcePos, sourceUri
+ for _, file in ipairs(expect) do
+ local script, list = catch(file.content, '?')
+ local uri = furi.encode(file.path)
+ files.setText(uri, script)
+ if list['?'] then
+ sourceUri = uri
+ sourcePos = (list['?'][1][1] + list['?'][1][2]) // 2
+ end
end
- local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2
+
local hover = core.byUri(sourceUri, sourcePos)
assert(hover)
hover = tostring(hover):gsub('\r\n', '\n')
@@ -1075,3 +1072,64 @@ global G: A {
}
```]]
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@overload fun(self, a)
+ function C:<?f?>(a, b) end
+ ]]
+ },
+ hover = [[
+```lua
+method C:f(a: any, b: any)
+```
+
+---
+
+```lua
+method C:f(a: any)
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@overload fun(self, a)
+ function C.<?f?>(a, b) end
+ ]]
+ },
+ hover = [[
+```lua
+function C.f(a: any, b: any)
+```
+
+---
+
+```lua
+function C.f(self: any, a: any)
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@async
+ ---@overload async fun(self, a)
+ function C:<?f?>(a, b) end
+ ]]
+ },
+ hover = [[
+```lua
+async method C:f(a: any, b: any)
+```
+
+---
+
+```lua
+async method C:f(a: any)
+```]]
+}
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index f95c0bad..16c85a63 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -975,6 +975,14 @@ end
TEST [[
---@param a number
+return function (<!a!>)
+end
+]]
+
+TEST [[
+---@meta
+
+---@param a number
return function (a)
end
]]
@@ -1154,6 +1162,7 @@ TEST [[
local emit = {}
]]
+config.get 'Lua.diagnostics.neededFileStatus' ['unused-local'] = 'None'
TEST [[
---@param table table
---@param metatable table
@@ -1292,6 +1301,8 @@ trim('str', 'left')
trim('str', nil)
]]
+config.get 'Lua.diagnostics.neededFileStatus' ['unused-local'] = 'Any'
+
---不完整的函数参数定义,会跳过检查
TEST [[
---@param mode string