summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/tclient/init.lua1
-rw-r--r--test/tclient/lclient.lua8
-rw-r--r--test/tclient/tests/folders-with-single-file.lua66
-rw-r--r--test/tclient/tests/single-mode.lua7
4 files changed, 81 insertions, 1 deletions
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index 872c34a4..b9054a00 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -1,3 +1,4 @@
require 'tclient.tests.single-mode'
require 'tclient.tests.library-ignore-limit'
require 'tclient.tests.multi-workspace'
+require 'tclient.tests.folders-with-single-file'
diff --git a/test/tclient/lclient.lua b/test/tclient/lclient.lua
index 166add42..8da8d138 100644
--- a/test/tclient/lclient.lua
+++ b/test/tclient/lclient.lua
@@ -4,6 +4,7 @@ local proto = require 'proto'
local await = require 'await'
local timer = require 'timer'
local pub = require 'pub'
+local json = require 'json'
require 'provider'
@@ -152,7 +153,12 @@ end
---@async
function mt:awaitRequest(method, params)
return await.wait(function (waker)
- self:request(method, params, waker)
+ self:request(method, params, function (result)
+ if result == json.null then
+ result = nil
+ end
+ waker(result)
+ end)
end)
end
diff --git a/test/tclient/tests/folders-with-single-file.lua b/test/tclient/tests/folders-with-single-file.lua
new file mode 100644
index 00000000..326dd623
--- /dev/null
+++ b/test/tclient/tests/folders-with-single-file.lua
@@ -0,0 +1,66 @@
+local lclient = require 'tclient.lclient'
+local fs = require 'bee.filesystem'
+local util = require 'utility'
+local furi = require 'file-uri'
+local ws = require 'workspace'
+local files = require 'files'
+local scope = require 'workspace.scope'
+
+---@async
+lclient():start(function (client)
+ client:registerFakers()
+
+ client:initialize {
+ rootUri = 'abc',
+ }
+
+ client:notify('textDocument/didOpen', {
+ textDocument = {
+ uri = furi.encode('abc/1.lua'),
+ languageId = 'lua',
+ version = 0,
+ text = [[
+local x
+print(x)
+]]
+ }
+ })
+
+ ws.awaitReady('abc')
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = furi.encode('abc/1.lua') },
+ position = { line = 1, character = 7 },
+ })
+
+ assert(util.equal(locations, {
+ {
+ uri = furi.encode('abc/1.lua'),
+ range = {
+ start = { line = 0, character = 6 },
+ ['end'] = { line = 0, character = 7 },
+ }
+ }
+ }))
+
+ client:notify('textDocument/didOpen', {
+ textDocument = {
+ uri = 'test://single-file.lua',
+ languageId = 'lua',
+ version = 0,
+ text = [[
+local x
+print(x)
+]]
+ }
+ })
+
+ ws.awaitReady(nil)
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = 'test://single-file.lua' },
+ position = { line = 1, character = 0 },
+ })
+
+ assert(#locations > 0)
+end)
diff --git a/test/tclient/tests/single-mode.lua b/test/tclient/tests/single-mode.lua
index 0a7f85ff..10f3e2da 100644
--- a/test/tclient/tests/single-mode.lua
+++ b/test/tclient/tests/single-mode.lua
@@ -35,4 +35,11 @@ print(x)
}
}
}))
+
+ local locations = client:awaitRequest('textDocument/definition', {
+ textDocument = { uri = 'test://single-file.lua' },
+ position = { line = 1, character = 0 },
+ })
+
+ assert(#locations > 0)
end)