Skip to content

Commit

Permalink
fix #1567
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Oct 11, 2022
1 parent 8ec593e commit e82c09f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
}
```
* `CHG` [#1177] re-support for symlinks, users need to maintain the correctness of symlinks themselves
* `FIX` [#1567]
* `FIX` [#1593]
* `FIX` [#1606]

[#1177]: https://github.com/sumneko/lua-language-server/issues/1177
[#1458]: https://github.com/sumneko/lua-language-server/issues/1458
[#1557]: https://github.com/sumneko/lua-language-server/issues/1557
[#1558]: https://github.com/sumneko/lua-language-server/issues/1558
[#1567]: https://github.com/sumneko/lua-language-server/issues/1567
[#1593]: https://github.com/sumneko/lua-language-server/issues/1593
[#1606]: https://github.com/sumneko/lua-language-server/issues/1606

Expand Down
18 changes: 16 additions & 2 deletions script/workspace/scope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ function mt:isChildUri(uri)
if not self.uri then
return false
end
return uri:sub(1, #self.uri) == self.uri
if self.uri == '' then
return true
end
if self.uri == uri then
return true
end
if uri:sub(1, #self.uri) == self.uri
and uri:sub(#self.uri + 1, #self.uri + 1) == '/' then
return true
end
return false
end

---@param uri uri
Expand All @@ -56,7 +66,11 @@ function mt:isLinkedUri(uri)
return false
end
for linkUri in pairs(self._links) do
if uri:sub(1, #linkUri) == linkUri then
if uri == linkUri then
return true
end
if uri:sub(1, #linkUri) == linkUri
and uri:sub(#linkUri + 1, #linkUri + 1) == '/' then
return true
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/tclient/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ require 'tclient.tests.change-workspace-folder'
require 'tclient.tests.jump-source'
require 'tclient.tests.load-relative-library'
require 'tclient.tests.hover-set-local'
require 'tclient.tests.same-prefix'

require 'tclient.tests.build-meta'
57 changes: 57 additions & 0 deletions test/tclient/tests/same-prefix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local lclient = require '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'

local rootPath = LOGPATH .. '/same-prefix'
local rootUri = furi.encode(rootPath)

for _, name in ipairs { 'ws', 'ws1' } do
fs.create_directories(fs.path(rootPath .. '/' .. name))
end

---@async
lclient():start(function (client)
client:registerFakers()

client:initialize {
rootPath = rootPath,
rootUri = rootUri,
workspaceFolders = {
{
name = 'ws',
uri = rootUri .. '/ws',
},
{
name = 'ws1',
uri = rootUri .. '/ws1',
},
}
}

ws.awaitReady(rootUri .. '/ws')
ws.awaitReady(rootUri .. '/ws1')

files.setText(rootUri .. '/ws1/test.lua', [[
]])

files.setText(rootUri .. '/ws/main.lua', [[
require ''
]])

local comps1 = client:awaitRequest('textDocument/completion', {
textDocument = {
uri = rootUri .. '/ws/main.lua',
},
position = {
line = 0,
character = 9,
},
})
for _, item in ipairs(comps1.items) do
assert(item.label ~= 'test')
end
end)

0 comments on commit e82c09f

Please sign in to comment.