Skip to content

Commit e82c09f

Browse files
committed
fix #1567
1 parent 8ec593e commit e82c09f

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
1717
}
1818
```
1919
* `CHG` [#1177] re-support for symlinks, users need to maintain the correctness of symlinks themselves
20+
* `FIX` [#1567]
2021
* `FIX` [#1593]
2122
* `FIX` [#1606]
2223

2324
[#1177]: https://github.com/sumneko/lua-language-server/issues/1177
2425
[#1458]: https://github.com/sumneko/lua-language-server/issues/1458
2526
[#1557]: https://github.com/sumneko/lua-language-server/issues/1557
2627
[#1558]: https://github.com/sumneko/lua-language-server/issues/1558
28+
[#1567]: https://github.com/sumneko/lua-language-server/issues/1567
2729
[#1593]: https://github.com/sumneko/lua-language-server/issues/1593
2830
[#1606]: https://github.com/sumneko/lua-language-server/issues/1606
2931

script/workspace/scope.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ function mt:isChildUri(uri)
4646
if not self.uri then
4747
return false
4848
end
49-
return uri:sub(1, #self.uri) == self.uri
49+
if self.uri == '' then
50+
return true
51+
end
52+
if self.uri == uri then
53+
return true
54+
end
55+
if uri:sub(1, #self.uri) == self.uri
56+
and uri:sub(#self.uri + 1, #self.uri + 1) == '/' then
57+
return true
58+
end
59+
return false
5060
end
5161

5262
---@param uri uri
@@ -56,7 +66,11 @@ function mt:isLinkedUri(uri)
5666
return false
5767
end
5868
for linkUri in pairs(self._links) do
59-
if uri:sub(1, #linkUri) == linkUri then
69+
if uri == linkUri then
70+
return true
71+
end
72+
if uri:sub(1, #linkUri) == linkUri
73+
and uri:sub(#linkUri + 1, #linkUri + 1) == '/' then
6074
return true
6175
end
6276
end

test/tclient/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ require 'tclient.tests.change-workspace-folder'
1111
require 'tclient.tests.jump-source'
1212
require 'tclient.tests.load-relative-library'
1313
require 'tclient.tests.hover-set-local'
14+
require 'tclient.tests.same-prefix'
15+
1416
require 'tclient.tests.build-meta'

test/tclient/tests/same-prefix.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local lclient = require '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+
local rootPath = LOGPATH .. '/same-prefix'
10+
local rootUri = furi.encode(rootPath)
11+
12+
for _, name in ipairs { 'ws', 'ws1' } do
13+
fs.create_directories(fs.path(rootPath .. '/' .. name))
14+
end
15+
16+
---@async
17+
lclient():start(function (client)
18+
client:registerFakers()
19+
20+
client:initialize {
21+
rootPath = rootPath,
22+
rootUri = rootUri,
23+
workspaceFolders = {
24+
{
25+
name = 'ws',
26+
uri = rootUri .. '/ws',
27+
},
28+
{
29+
name = 'ws1',
30+
uri = rootUri .. '/ws1',
31+
},
32+
}
33+
}
34+
35+
ws.awaitReady(rootUri .. '/ws')
36+
ws.awaitReady(rootUri .. '/ws1')
37+
38+
files.setText(rootUri .. '/ws1/test.lua', [[
39+
]])
40+
41+
files.setText(rootUri .. '/ws/main.lua', [[
42+
require ''
43+
]])
44+
45+
local comps1 = client:awaitRequest('textDocument/completion', {
46+
textDocument = {
47+
uri = rootUri .. '/ws/main.lua',
48+
},
49+
position = {
50+
line = 0,
51+
character = 9,
52+
},
53+
})
54+
for _, item in ipairs(comps1.items) do
55+
assert(item.label ~= 'test')
56+
end
57+
end)

0 commit comments

Comments
 (0)