summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-10-11 16:19:08 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-10-11 16:19:08 +0800
commite82c09fd0b06e8d4ca872759fb6bb4d50506dd6a (patch)
treea126cdd41e72a1a45db6cdf875c2c0d021a2ce1c
parent8ec593e83fff0ba00466361cdee5dece07c5d98e (diff)
downloadlua-language-server-e82c09fd0b06e8d4ca872759fb6bb4d50506dd6a.zip
fix #1567
-rw-r--r--changelog.md2
-rw-r--r--script/workspace/scope.lua18
-rw-r--r--test/tclient/init.lua2
-rw-r--r--test/tclient/tests/same-prefix.lua57
4 files changed, 77 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md
index f14d1c57..403d7e00 100644
--- a/changelog.md
+++ b/changelog.md
@@ -17,6 +17,7 @@ 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]
@@ -24,6 +25,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
[#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
diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua
index 4649d354..e6fcfeb7 100644
--- a/script/workspace/scope.lua
+++ b/script/workspace/scope.lua
@@ -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
@@ -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
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index 6f861142..eff77d8a 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -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'
diff --git a/test/tclient/tests/same-prefix.lua b/test/tclient/tests/same-prefix.lua
new file mode 100644
index 00000000..bc2a1f9b
--- /dev/null
+++ b/test/tclient/tests/same-prefix.lua
@@ -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)