Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add variable substitution support for vscode's ${workspaceFolder:x} #3053

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
cfgs[2] = {} -- only warns missing `b`
```
This enables the previous missing field check behavior before [#2970](https://github.com/LuaLS/lua-language-server/issues/2970)
* `NEW` Added variable substitution support for vscode's `${workspaceFolder:x}` when resolving path placeholders [#2987](https://github.com/LuaLS/lua-language-server/issues/2987)

## 3.13.5
`2024-12-20`
Expand Down
11 changes: 11 additions & 0 deletions script/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,17 @@ function m.resolvePathPlaceholders(path)
elseif key:sub(1, 4) == "env:" then
local env = os.getenv(key:sub(5))
return env
elseif key == "workspaceFolder" then
local ws = require 'workspace'
return ws.rootUri and furi.decode(ws.rootUri)
elseif key:match("^workspaceFolder:.+$") then
local folderName = key:match("^workspaceFolder:(.+)$")
for _, scp in ipairs(scope.folders) do
if scp:getFolderName() == folderName then
return scp.uri and furi.decode(scp.uri)
end
end
log.warn(('variable ${%s} cannot be resolved when processing path: %s'):format(key, path))
end
end)

Expand Down
2 changes: 1 addition & 1 deletion script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ m.register 'initialize' {

if params.workspaceFolders then
for _, folder in ipairs(params.workspaceFolders) do
workspace.create(files.getRealUri(folder.uri))
workspace.create(files.getRealUri(folder.uri), folder.name)
end
elseif params.rootUri then
workspace.create(files.getRealUri(params.rootUri))
Expand Down
10 changes: 9 additions & 1 deletion script/workspace/scope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local m = {}
---@class scope
---@field type scope.type
---@field uri? uri
---@field folderName? string
---@field _links table<uri, boolean>
---@field _data table<string, any>
---@field _gc gc
Expand Down Expand Up @@ -134,6 +135,11 @@ function mt:getName()
return self.uri or ('<' .. self.type .. '>')
end

---@return string?
function mt:getFolderName()
return self.folderName
end

function mt:gc(obj)
self._gc:add(obj)
end
Expand Down Expand Up @@ -187,10 +193,12 @@ end
m.reset()

---@param uri uri
---@param folderName? string
---@return scope
function m.createFolder(uri)
function m.createFolder(uri, folderName)
local scope = createScope 'folder'
scope.uri = uri
scope.folderName = folderName

local inserted = false
for i, otherScope in ipairs(m.folders) do
Expand Down
4 changes: 2 additions & 2 deletions script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function m.initRoot(uri)
end

--- 初始化工作区
function m.create(uri)
function m.create(uri, folderName)
log.info('Workspace create: ', uri)
local scp = scope.createFolder(uri)
local scp = scope.createFolder(uri, folderName)
m.folders[#m.folders+1] = scp
if uri == furi.encode '/'
or uri == furi.encode(os.getenv 'HOME' or '') then
Expand Down
Loading