Skip to content

Commit a13a30f

Browse files
committed
fix
1 parent 1c80954 commit a13a30f

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

script/workspace/require-path.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ function m.flush(suri)
164164
end
165165
end
166166

167+
for _, scp in ipairs(scope.folders) do
168+
m.flush(scp.uri)
169+
end
167170
m.flush(nil)
168171

169172
files.watch(function (ev, uri)

script/workspace/scope.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ end
123123
---@return scope
124124
function m.getFolder(uri)
125125
for _, scope in ipairs(m.folders) do
126-
if not uri or scope:isChildUri(uri) then
126+
if scope:isChildUri(uri) then
127127
return scope
128128
end
129129
end

test/tclient/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require 'tclient.tests.single-mode'
22
require 'tclient.tests.library-ignore-limit'
33
require 'tclient.tests.multi-workspace'
4+
require 'tclient.tests.folders-with-single-file'

test/tclient/lclient.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local proto = require 'proto'
44
local await = require 'await'
55
local timer = require 'timer'
66
local pub = require 'pub'
7+
local json = require 'json'
78

89
require 'provider'
910

@@ -152,7 +153,12 @@ end
152153
---@async
153154
function mt:awaitRequest(method, params)
154155
return await.wait(function (waker)
155-
self:request(method, params, waker)
156+
self:request(method, params, function (result)
157+
if result == json.null then
158+
result = nil
159+
end
160+
waker(result)
161+
end)
156162
end)
157163
end
158164

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
local lclient = require 'tclient.lclient'
2+
local fs = require 'bee.filesystem'
3+
local util = require 'utility'
4+
local furi = require 'file-uri'
5+
local ws = require 'workspace'
6+
local files = require 'files'
7+
local scope = require 'workspace.scope'
8+
9+
---@async
10+
lclient():start(function (client)
11+
client:registerFakers()
12+
13+
client:initialize {
14+
rootUri = 'abc',
15+
}
16+
17+
client:notify('textDocument/didOpen', {
18+
textDocument = {
19+
uri = furi.encode('abc/1.lua'),
20+
languageId = 'lua',
21+
version = 0,
22+
text = [[
23+
local x
24+
print(x)
25+
]]
26+
}
27+
})
28+
29+
ws.awaitReady('abc')
30+
31+
local locations = client:awaitRequest('textDocument/definition', {
32+
textDocument = { uri = furi.encode('abc/1.lua') },
33+
position = { line = 1, character = 7 },
34+
})
35+
36+
assert(util.equal(locations, {
37+
{
38+
uri = furi.encode('abc/1.lua'),
39+
range = {
40+
start = { line = 0, character = 6 },
41+
['end'] = { line = 0, character = 7 },
42+
}
43+
}
44+
}))
45+
46+
client:notify('textDocument/didOpen', {
47+
textDocument = {
48+
uri = 'test://single-file.lua',
49+
languageId = 'lua',
50+
version = 0,
51+
text = [[
52+
local x
53+
print(x)
54+
]]
55+
}
56+
})
57+
58+
ws.awaitReady(nil)
59+
60+
local locations = client:awaitRequest('textDocument/definition', {
61+
textDocument = { uri = 'test://single-file.lua' },
62+
position = { line = 1, character = 0 },
63+
})
64+
65+
assert(#locations > 0)
66+
end)

test/tclient/tests/single-mode.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ print(x)
3535
}
3636
}
3737
}))
38+
39+
local locations = client:awaitRequest('textDocument/definition', {
40+
textDocument = { uri = 'test://single-file.lua' },
41+
position = { line = 1, character = 0 },
42+
})
43+
44+
assert(#locations > 0)
3845
end)

0 commit comments

Comments
 (0)