Skip to content

Commit f4493d6

Browse files
committed
fix #1405
1 parent f78d494 commit f4493d6

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.5.2
44
* `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395)
55
* `FIX` [#1403](https://github.com/sumneko/lua-language-server/issues/1403)
6+
* `FIX` [#1405](https://github.com/sumneko/lua-language-server/issues/1405)
67
* `FIX` [#1406](https://github.com/sumneko/lua-language-server/issues/1406)
78

89
## 3.5.1

script/workspace/workspace.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,11 @@ function m.normalize(path)
387387
path = util.expandPath(path)
388388
path = path:gsub('^%.[/\\]+', '')
389389
for _ = 1, 1000 do
390+
if path:sub(1, 2) == '..' then
391+
break
392+
end
390393
local count
391-
path, count = path:gsub('[^/\\]+[/\\]%.%.', '')
394+
path, count = path:gsub('[^/\\]+[/\\]+%.%.', '', 1)
392395
if count == 0 then
393396
break
394397
end

test/tclient/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ require 'tclient.tests.performance-jass-common'
99
require 'tclient.tests.hover-pairs'
1010
require 'tclient.tests.change-workspace-folder'
1111
require 'tclient.tests.jump-source'
12+
require 'tclient.tests.load-relative-library'
1213
require 'tclient.tests.build-meta'
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
local lclient = require 'lclient'
2+
local util = require 'utility'
3+
local ws = require 'workspace'
4+
local files = require 'files'
5+
local furi = require 'file-uri'
6+
local fs = require 'bee.filesystem'
7+
8+
local workspacePath = LOGPATH .. '/not-exist/not-exist/not-exist'
9+
local libraryPath = '../../../load-relative-library'
10+
local libraryFilePath = LOGPATH .. '/load-relative-library/library-file.lua'
11+
12+
---@async
13+
lclient():start(function (client)
14+
client:registerFakers()
15+
16+
client:initialize {
17+
rootUri = furi.encode(workspacePath),
18+
}
19+
20+
client:register('workspace/configuration', function ()
21+
return {
22+
{
23+
['workspace.library'] = { libraryPath }
24+
},
25+
}
26+
end)
27+
28+
fs.create_directories(fs.path(libraryFilePath):parent_path())
29+
if not fs.exists(fs.path(libraryFilePath)) then
30+
util.saveFile(libraryFilePath, 'LIBRARY_FILE = true')
31+
end
32+
33+
client:initialize()
34+
35+
client:notify('textDocument/didOpen', {
36+
textDocument = {
37+
uri = furi.encode(workspacePath .. '/abc/1.lua'),
38+
languageId = 'lua',
39+
version = 0,
40+
text = [[
41+
require 'library-file'
42+
print(LIBRARY_FILE)
43+
]]
44+
}
45+
})
46+
47+
ws.awaitReady()
48+
49+
local locations = client:awaitRequest('textDocument/definition', {
50+
textDocument = { uri = furi.encode(workspacePath .. '/abc/1.lua') },
51+
position = { line = 0, character = 10 },
52+
})
53+
54+
assert(util.equal(locations, {
55+
{
56+
uri = furi.encode(libraryFilePath),
57+
range = {
58+
start = { line = 0, character = 0 },
59+
['end'] = { line = 0, character = 0 },
60+
}
61+
}
62+
}))
63+
end)

0 commit comments

Comments
 (0)