Skip to content

Commit

Permalink
normalize uri from RPC
Browse files Browse the repository at this point in the history
fix #1810
  • Loading branch information
sumneko committed Jan 17, 2023
1 parent efffa22 commit bddeb50
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# changelog

## 3.6.7
* `FIX` [#1810]
* `FIX` [#1829]

[#1810]: https://github.com/sumneko/lua-language-server/issues/1810
[#1829]: https://github.com/sumneko/lua-language-server/issues/1829

## 3.6.6
Expand Down
2 changes: 1 addition & 1 deletion script/file-uri.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function m.isValid(uri)
end

function m.normalize(uri)
if uri == '' then
if not m.isValid(uri) then
return uri
end
return m.encode(m.decode(uri))
Expand Down
2 changes: 1 addition & 1 deletion script/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end
---@return uri
function m.getRealUri(uri)
if platform.OS ~= 'Windows' then
return uri
return furi.normalize(uri)
end
local filename = furi.decode(uri)
-- normalize uri
Expand Down
18 changes: 10 additions & 8 deletions script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ m.register 'initialize' {

if params.workspaceFolders then
for _, folder in ipairs(params.workspaceFolders) do
workspace.create(folder.uri)
workspace.create(files.getRealUri(folder.uri))
end
elseif params.rootUri then
workspace.create(params.rootUri)
workspace.create(files.getRealUri(params.rootUri))
end

local response = {
Expand Down Expand Up @@ -249,12 +249,14 @@ m.register 'workspace/didChangeWorkspaceFolders' {
function (params)
log.debug('workspace/didChangeWorkspaceFolders', inspect(params))
for _, folder in ipairs(params.event.added) do
workspace.create(folder.uri)
local uri = files.getRealUri(folder.uri)
workspace.create(uri)
m.updateConfig()
workspace.reload(scope.getScope(folder.uri))
workspace.reload(scope.getScope(uri))
end
for _, folder in ipairs(params.event.removed) do
workspace.remove(folder.uri)
local uri = files.getRealUri(folder.uri)
workspace.remove(uri)
end
end
}
Expand All @@ -263,12 +265,12 @@ m.register 'textDocument/didOpen' {
---@async
function (params)
local doc = params.textDocument
local scheme = furi.split(doc.uri)
local supports = config.get(doc.uri, 'Lua.workspace.supportScheme')
local uri = files.getRealUri(doc.uri)
local scheme = furi.split(uri)
local supports = config.get(uri, 'Lua.workspace.supportScheme')
if not util.arrayHas(supports, scheme) then
return
end
local uri = files.getRealUri(doc.uri)
log.debug('didOpen', uri)
local text = doc.text
files.setText(uri, text, true, function (file)
Expand Down
3 changes: 0 additions & 3 deletions script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ end

--- 初始化工作区
function m.create(uri)
if furi.isValid(uri) then
uri = furi.normalize(uri)
end
log.info('Workspace create: ', uri)
local scp = scope.createFolder(uri)
m.folders[#m.folders+1] = scp
Expand Down
18 changes: 18 additions & 0 deletions test/tclient/tests/change-workspace-folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ lclient():start(function (client)
assert(files.getState(rootUri .. '/ws1/test.lua') == nil)
assert(files.getState(rootUri .. '/ws2/test.lua') == nil)
assert(files.getState(rootUri .. '/ws3/test.lua') ~= nil)

-- normalize uri
client:notify('workspace/didChangeWorkspaceFolders', {
event = {
added = {
{
name = 'ws2',
uri = rootUri .. '%2F%77%73%32'--[[/ws2]],
},
},
removed = {},
},
})

ws.awaitReady(rootUri .. '/ws2')
assert(files.getState(rootUri .. '/ws1/test.lua') == nil)
assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil)
assert(files.getState(rootUri .. '/ws3/test.lua') ~= nil)
end)

0 comments on commit bddeb50

Please sign in to comment.