summaryrefslogtreecommitdiff
path: root/test/crossfile
diff options
context:
space:
mode:
authorSewbacca <sebastian.kalus@kolabnow.com>2022-12-01 23:12:30 +0100
committerSewbacca <sebastian.kalus@kolabnow.com>2022-12-01 23:12:30 +0100
commit2492c1fb71d213de22756949a65e9811af50a92d (patch)
tree6d19bfedaad7e304247d123a871ac9e120181780 /test/crossfile
parentd848fdaf49fa8be5c12aed73cea3cac34ca8836d (diff)
parent6999dbb25bf2b7ae306599eceaa0f438ee4f8b8f (diff)
downloadlua-language-server-2492c1fb71d213de22756949a65e9811af50a92d.zip
Merge branch 'master' into feature/auto-require-without-init
Diffstat (limited to 'test/crossfile')
-rw-r--r--test/crossfile/completion.lua37
-rw-r--r--test/crossfile/definition.lua3
-rw-r--r--test/crossfile/diagnostic.lua71
-rw-r--r--test/crossfile/hover.lua555
-rw-r--r--test/crossfile/references.lua10
5 files changed, 635 insertions, 41 deletions
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 12b33323..8504758e 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -5,36 +5,11 @@ local platform = require 'bee.platform'
local util = require 'utility'
local config = require 'config'
local catch = require 'catch'
+local define = require 'proto.define'
rawset(_G, 'TEST', true)
-local CompletionItemKind = {
- Text = 1,
- Method = 2,
- Function = 3,
- Constructor = 4,
- Field = 5,
- Variable = 6,
- Class = 7,
- Interface = 8,
- Module = 9,
- Property = 10,
- Unit = 11,
- Value = 12,
- Enum = 13,
- Keyword = 14,
- Snippet = 15,
- Color = 16,
- File = 17,
- Reference = 18,
- Folder = 19,
- EnumMember = 20,
- Constant = 21,
- Struct = 22,
- Event = 23,
- Operator = 24,
- TypeParameter = 25,
-}
+local CompletionItemKind = define.CompletionItemKind
local EXISTS = {}
@@ -413,7 +388,7 @@ config.set(nil, 'Lua.runtime.path', {
TEST {
{
- path = 'D:/xxxx/1.lua',
+ path = 'tt/xxxx/1.lua',
content = '',
},
{
@@ -423,7 +398,7 @@ TEST {
},
completion = {
{
- label = 'D:.xxxx',
+ label = 'tt.xxxx',
kind = CompletionItemKind.File,
textEdit = EXISTS,
},
@@ -439,12 +414,12 @@ config.set(nil, 'Lua.runtime.path', originRuntimePath)
local originRuntimePath = config.get(nil, 'Lua.runtime.path')
config.set(nil, 'Lua.runtime.path', {
- 'D:/?/1.lua',
+ 'tt/?/1.lua',
})
TEST {
{
- path = 'D:/xxxx/1.lua',
+ path = 'tt/xxxx/1.lua',
content = '',
},
{
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 45f21697..e924c43f 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -26,6 +26,7 @@ local function founded(targets, results)
return true
end
+---@async
function TEST(datas)
local targetList = {}
local sourceList
@@ -434,7 +435,7 @@ TEST {
{
path = 'a.lua',
content = [[
- local <!x!>
+ local x
return {
<!x!> = x,
}
diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua
index dd06351f..126a2ab8 100644
--- a/test/crossfile/diagnostic.lua
+++ b/test/crossfile/diagnostic.lua
@@ -8,6 +8,7 @@ local catch = require 'catch'
config.get(nil, 'Lua.diagnostics.neededFileStatus')['deprecated'] = 'Any'
config.get(nil, 'Lua.diagnostics.neededFileStatus')['type-check'] = 'Any'
+config.get(nil, 'Lua.diagnostics.neededFileStatus')['duplicate-set-field'] = 'Any'
config.get(nil, 'Lua.diagnostics.neededFileStatus')['codestyle-check'] = 'None'
rawset(_G, 'TEST', true)
@@ -140,3 +141,73 @@ TEST {
content = 'require "f.a"',
},
}
+
+TEST {
+ { path = 'a.lua', content = [[
+ ---@class A
+ ---@field package x string
+
+ ---@type A
+ local obj
+
+ print(obj.x)
+ ]]},
+}
+
+TEST {
+ { path = 'a.lua', content = [[
+ ---@class A
+ ---@field package x string
+ ]]},
+ { path = 'b.lua', content = [[
+ ---@type A
+ local obj
+
+ print(obj.<!x!>)
+ ]]}
+}
+
+TEST {
+ { path = 'a.lua', content = [[
+ ---@class A
+ ---@field <!x!> number
+ ]]},
+ { path = 'b.lua', content = [[
+ ---@class A
+ ---@field <!x!> number
+ ]]}
+}
+
+TEST {
+ { path = 'a.lua', content = [[
+ ---@class A
+ local mt
+
+ function <!mt:init!>()
+ end
+ ]]},
+ { path = 'b.lua', content = [[
+ ---@class A
+ local mt
+
+ function <!mt:init!>()
+ end
+ ]]}
+}
+
+TEST {
+ { path = 'a.lua', content = [[
+ ---@class A
+ local mt
+
+ function mt:init()
+ end
+ ]]},
+ { path = 'b.lua', content = [[
+ ---@class B: A
+ local mt
+
+ function mt:init()
+ end
+ ]]}
+}
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index 0bf8165b..c0b1691f 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -58,8 +58,8 @@ function TEST(expect)
local hover = core.byUri(sourceUri, sourcePos)
assert(hover)
- hover = tostring(hover):gsub('\r\n', '\n')
- assert(eq(hover, expect.hover))
+ local content = tostring(hover):gsub('\r\n', '\n')
+ assert(eq(content, expect.hover))
end
TEST {
@@ -77,6 +77,7 @@ TEST {
```
---
+
* [a.lua](file:///a.lua) (搜索路径: `?.lua`)]],
}
@@ -109,6 +110,7 @@ TEST {
```
---
+
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `Folder\?.lua`)]],
}
@@ -127,6 +129,7 @@ TEST {
```
---
+
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]],
}
@@ -145,6 +148,7 @@ TEST {
```
---
+
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]],
}
else
@@ -163,6 +167,7 @@ TEST {
```
---
+
* [Folder/a.lua](file:///Folder/a.lua) (搜索路径: `Folder/?.lua`)]],
}
end
@@ -329,6 +334,7 @@ function f(x: number)
```
---
+
abc]]
}
@@ -350,6 +356,7 @@ TEST {
```
---
+
abc]]
}
@@ -488,6 +495,7 @@ function f(<?x?>) end
```
---
+
this is comment]]
}
@@ -557,6 +565,7 @@ function f(arg1: integer, arg2: integer)
```
---
+
comment1
@*param* `arg2` — comment2
@@ -666,6 +675,7 @@ function f()
```
---
+
comment1
comment2]]}
@@ -681,7 +691,7 @@ TEST {{ path = 'a.lua', content = '', }, {
},
hover = [[
```lua
-function f(a: boolean|true|false)
+function f(a: boolean)
```
---
@@ -710,6 +720,7 @@ local x: A
```
---
+
AAA]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -730,6 +741,7 @@ local x: A {
```
---
+
AAA]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -749,9 +761,11 @@ local x: A
```
---
+
BBB
---
+
AAA]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -770,9 +784,11 @@ hover = [[
```
---
+
AAA
---
+
BBB]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -791,9 +807,11 @@ hover = [[
```
---
+
BBB
---
+
AAA]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -811,7 +829,7 @@ food.secondField = 2
},
hover = [[
```lua
-(field) Food.firstField: number = 0
+(field) Food.firstField: number
```]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -829,6 +847,7 @@ local food: unknown
```
---
+
I'm a multiline comment
]]}
@@ -937,6 +956,7 @@ function bthci.rawhci(hcibytes: any, callback: any)
```
---
+
Sends a raw HCI command to the BlueTooth controller.]]}
TEST {{ path = 'a.lua', content = '', }, {
@@ -1021,6 +1041,7 @@ function fn()
```
---
+
line1
line2]]}
@@ -1156,5 +1177,531 @@ TEST {
```
---
+
The color of your awesome apple!]]
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@type fun(x: number, y: number, ...: number):(x: number, y: number, ...: number)
+ local <?f?>
+ ]]
+ },
+ hover = [[
+```lua
+local f: fun(x: number, y: number, ...number):(x: number, y: number, ...number)
+```
+
+---
+
+```lua
+function f(x: number, y: number, ...: number)
+ -> x: number
+ 2. y: number
+ 3. ...number
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@param p 'a1' | 'a2'
+ ---@param ... 'a3' | 'a4'
+ ---@return 'r1' | 'r2' ret1
+ ---@return 'r3' | 'r4' ...
+ local function <?f?>(p, ...) end
+ ]]
+ },
+ hover = [[
+```lua
+function f(p: 'a1'|'a2', ...'a3'|'a4')
+ -> ret1: 'r1'|'r2'
+ 2. ...'r3'|'r4'
+```
+
+---
+
+```lua
+p:
+ | 'a1'
+ | 'a2'
+
+...(param):
+ | 'a3'
+ | 'a4'
+
+ret1:
+ | 'r1'
+ | 'r2'
+
+...(return):
+ | 'r3'
+ | 'r4'
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@type integer @ comments
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: integer
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ --- comments
+ ---@type integer
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: integer
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@type integer
+ --- comments
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: integer
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@TODO XXXX
+ ---@type integer @ comments
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: integer
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@type integer @ comments
+ ---@TODO XXXX
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: integer
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ --[here](x.lua)
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: unknown
+```
+
+---
+
+[here](file:///x.lua)]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ --[here](D:/x.lua)
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: unknown
+```
+
+---
+
+[here](file:///d%3A/x.lua)]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ --[here](command:xxxxx)
+ local <?n?>
+ ]]
+ },
+ hover = [[
+```lua
+local n: unknown
+```
+
+---
+
+[here](command:xxxxx)]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@class A
+ ---@field x number # comments
+
+ ---@type A
+ local t
+
+ print(t.<?x?>)
+ ]]
+ },
+ hover = [[
+```lua
+(field) A.x: number
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ -- comments
+ <?A?> = function () end
+ ]]
+ },
+ hover = [[
+```lua
+function A()
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ local t = {
+ -- comments
+ <?A?> = function () end
+ }
+ ]]
+ },
+ hover = [[
+```lua
+function A()
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ -- comments
+ ---@return number
+ <?A?> = function () end
+ ]]
+ },
+ hover = [[
+```lua
+function A()
+ -> number
+```
+
+---
+
+ comments]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@alias A
+ ---| 1 # comment1
+ ---| 2 # comment2
+
+ ---@type A
+ local <?x?>
+ ]]
+ },
+ hover = [[
+```lua
+local x: 1|2
+```
+
+---
+
+```lua
+A:
+ | 1 -- comment1
+ | 2 -- comment2
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@enum <?A?>
+ local t = {
+ x = 1,
+ y = 2,
+ z = 3,
+ }
+ ]]
+ },
+ hover = [[
+```lua
+(enum) A
+```
+
+---
+
+```lua
+{
+ x: integer = 1,
+ y: integer = 2,
+ z: integer = 3,
+}
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@enum <?A?>
+ local t =
+ {
+ x = 1,
+ y = 2,
+ z = 3,
+ }
+ ]]
+ },
+ hover = [[
+```lua
+(enum) A
+```
+
+---
+
+```lua
+{
+ x: integer = 1,
+ y: integer = 2,
+ z: integer = 3,
+}
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@enum <?A?>
+ local t = {
+ x = 1 << 0,
+ y = 1 << 1,
+ z = 1 << 2,
+ }
+ ]]
+ },
+ hover = [[
+```lua
+(enum) A
+```
+
+---
+
+```lua
+{
+ x: integer = 1,
+ y: integer = 2,
+ z: integer = 4,
+}
+```]]
+}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@alias someType
+ ---| "#" # description
+
+ ---@type someType
+ local <?someValue?>
+ ]]
+ },
+ hover = [[
+```lua
+local someValue: "#"
+```
+
+---
+
+```lua
+someType:
+ | "#" -- description
+```]]
+}
+
+TEST { { path = 'a.lua', content = [[
+---@overload fun(x: number)
+---@overload fun(x: number, y: number)
+local function <?f?>(...)
+end
+]] },
+hover = [[
+```lua
+function f(x: number)
+```
+
+---
+
+```lua
+function f(x: number, y: number)
+```]]
+}
+
+TEST { { path = 'a.lua', content = [[
+---@overload fun(x: number)
+---@overload fun(x: number, y: number)
+local function f(...)
+end
+
+<?f?>
+]] },
+hover = [[
+```lua
+function f(x: number)
+```
+
+---
+
+```lua
+function f(x: number, y: number)
+```]]
+}
+
+TEST { {path = 'a.lua', content = [[
+---@class A
+
+---@see A # comment1
+local <?x?>
+]]},
+hover = [[
+```lua
+local x: unknown
+```
+
+---
+
+See: [A](file:///a.lua#1#10) comment1]]
+}
+
+TEST { {path = 'a.lua', content = [[
+---@class A
+
+TTT = 1
+
+---@see A # comment1
+---@see TTT # comment2
+local <?x?>
+]]},
+hover = [[
+```lua
+local x: unknown
+```
+
+---
+
+See:
+ * [A](file:///a.lua#1#10) comment1
+ * [TTT](file:///a.lua#3#0) comment2]]
+}
+
+TEST { {path = 'a.lua', content = [[
+---comment1
+---comment2
+---@overload fun()
+---@param x number
+local function <?f?>(x) end
+]]},
+hover = [[
+```lua
+function f(x: number)
+```
+
+---
+
+comment1
+comment2
+
+---
+
+```lua
+function f()
+```]]
+}
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index 1a9f2508..0b7beb82 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -83,7 +83,7 @@ function TEST(datas)
end
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local positions = core(sourceUri, sourcePos)
+ local positions = core(sourceUri, sourcePos, true)
if positions then
local result = {}
for i, position in ipairs(positions) do
@@ -361,15 +361,15 @@ TEST {
{
path = 'a.lua',
content = [[
- local <~t~> = require 'b'
- return <!t!>
+ local <~x~> = require 'b'
+ return <!x!>
]]
},
{
path = 'b.lua',
content = [[
- local t = require 'a'
- return t
+ local y = require 'a'
+ return y
]]
},
}