Skip to content

add: placeholder for ${addons} for paths #2866

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

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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 @@ -7,6 +7,7 @@
* `FIX` Eliminate floating point error in test benchmark output
* `FIX` Remove luamake install from make scripts
* `NEW` Types with literal fields can be narrowed.
* `NEW` Reference addons installed via the addon manager with `${addons}` [#2866](https://github.com/LuaLS/lua-language-server/pull/2866).

## 3.10.6
`2024-9-10`
Expand Down
39 changes: 32 additions & 7 deletions script/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,18 +908,43 @@ function m.countStates()
return n
end

---Resolve path variables/placeholders like ${3rd} and ${addons}
---@param path string
---@return string
function m.normalize(path)
path = path:gsub('%$%{(.-)%}', function (key)
if key == '3rd' then
return (ROOT / 'meta' / '3rd'):string()
end
if key:sub(1, 4) == 'env:' then
---@return string resolvedPath
function m.resolvePathPlaceholders(path)
path = path:gsub("%$%{(.-)%}", function(key)
if key == "3rd" then
return (ROOT / "meta" / "3rd"):string()
elseif key == "addons" then
-- Common path across OSes
local dataPath = "User/globalStorage/sumneko.lua/addonManager/addons"

if platform.os == "windows" then
return "$APPDATA/Code/" .. dataPath
elseif platform.os == "linux" then
local serverPath = util.expandPath(fs.path("~/.vscode-server/data"):string())
if fs.exists(serverPath) then
-- addons are installed via SSH remote
return serverPath .."/" .. dataPath
else
return "~/.config/Code/" .. dataPath
end
elseif platform.os == "macos" then
return "~/Library/Application/Support/Code/" .. dataPath
end
elseif key:sub(1, 4) == "env:" then
local env = os.getenv(key:sub(5))
return env
end
end)

return path
end

---@param path string
---@return string
function m.normalize(path)
path = m.resolvePathPlaceholders(path)
path = util.expandPath(path)
path = path:gsub('^%.[/\\]+', '')
for _ = 1, 1000 do
Expand Down
Loading