Skip to content

Commit 4c5b524

Browse files
committed
#1385 normalize uri
1 parent 3d21c63 commit 4c5b524

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

script/file-uri.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,11 @@ function m.split(uri)
9292
return uri:match('([^:]*):/?/?([^/]*)(.*)')
9393
end
9494

95+
function m.normalize(uri)
96+
if uri == '' then
97+
return uri
98+
end
99+
return m.encode(m.decode(uri))
100+
end
101+
95102
return m

script/files.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ local uriMap = {}
5555
---@return uri
5656
function m.getRealUri(uri)
5757
local filename = furi.decode(uri)
58+
-- normalize uri
59+
uri = furi.encode(filename)
5860
local path = fs.path(filename)
5961
local suc, exists = pcall(fs.exists, path)
6062
if not suc or not exists then

script/workspace/workspace.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ end
4545

4646
--- 初始化工作区
4747
function m.create(uri)
48+
uri = furi.normalize(uri)
4849
log.info('Workspace create: ', uri)
4950
if uri == furi.encode '/'
5051
or uri == furi.encode(os.getenv 'HOME' or '') then

test/tclient/tests/single-mode.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lclient():start(function (client)
99

1010
client:notify('textDocument/didOpen', {
1111
textDocument = {
12-
uri = 'file://single-file.lua',
12+
uri = 'file:///single-file.lua',
1313
languageId = 'lua',
1414
version = 0,
1515
text = [[
@@ -25,13 +25,13 @@ print(TEST)
2525
ws.awaitReady()
2626

2727
local locations = client:awaitRequest('textDocument/definition', {
28-
textDocument = { uri = 'file://single-file.lua' },
28+
textDocument = { uri = 'file:///single-file.lua' },
2929
position = { line = 1, character = 7 },
3030
})
3131

3232
assert(util.equal(locations, {
3333
{
34-
uri = 'file://single-file.lua',
34+
uri = 'file:///single-file.lua',
3535
range = {
3636
start = { line = 0, character = 6 },
3737
['end'] = { line = 0, character = 7 },
@@ -40,20 +40,20 @@ print(TEST)
4040
}))
4141

4242
local locations = client:awaitRequest('textDocument/definition', {
43-
textDocument = { uri = 'file://single-file.lua' },
43+
textDocument = { uri = 'file:///single-file.lua' },
4444
position = { line = 1, character = 0 },
4545
})
4646

4747
assert(#locations > 0)
4848

4949
local locations = client:awaitRequest('textDocument/definition', {
50-
textDocument = { uri = 'file://single-file.lua' },
50+
textDocument = { uri = 'file:///single-file.lua' },
5151
position = { line = 3, character = 0 },
5252
})
5353

5454
assert(util.equal(locations, {
5555
{
56-
uri = 'file://single-file.lua',
56+
uri = 'file:///single-file.lua',
5757
range = {
5858
start = { line = 3, character = 0 },
5959
['end'] = { line = 3, character = 4 },

0 commit comments

Comments
 (0)