Skip to content

Commit 792f46f

Browse files
authored
Merge pull request #2866 from carsakiller/addon-path-placeholder
add: placeholder for ${addons} for paths
2 parents 1831e60 + 7a2921b commit 792f46f

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `FIX` Eliminate floating point error in test benchmark output
88
* `FIX` Remove luamake install from make scripts
99
* `NEW` Types with literal fields can be narrowed.
10+
* `NEW` Reference addons installed via the addon manager with `${addons}` [#2866](https://github.com./LuaLS/lua-language-server/pull/2866).
1011

1112
## 3.10.6
1213
`2024-9-10`

script/files.lua

+32-7
Original file line numberDiff line numberDiff line change
@@ -908,18 +908,43 @@ function m.countStates()
908908
return n
909909
end
910910

911+
---Resolve path variables/placeholders like ${3rd} and ${addons}
911912
---@param path string
912-
---@return string
913-
function m.normalize(path)
914-
path = path:gsub('%$%{(.-)%}', function (key)
915-
if key == '3rd' then
916-
return (ROOT / 'meta' / '3rd'):string()
917-
end
918-
if key:sub(1, 4) == 'env:' then
913+
---@return string resolvedPath
914+
function m.resolvePathPlaceholders(path)
915+
path = path:gsub("%$%{(.-)%}", function(key)
916+
if key == "3rd" then
917+
return (ROOT / "meta" / "3rd"):string()
918+
elseif key == "addons" then
919+
-- Common path across OSes
920+
local dataPath = "User/globalStorage/sumneko.lua/addonManager/addons"
921+
922+
if platform.os == "windows" then
923+
return "$APPDATA/Code/" .. dataPath
924+
elseif platform.os == "linux" then
925+
local serverPath = util.expandPath(fs.path("~/.vscode-server/data"):string())
926+
if fs.exists(serverPath) then
927+
-- addons are installed via SSH remote
928+
return serverPath .."/" .. dataPath
929+
else
930+
return "~/.config/Code/" .. dataPath
931+
end
932+
elseif platform.os == "macos" then
933+
return "~/Library/Application/Support/Code/" .. dataPath
934+
end
935+
elseif key:sub(1, 4) == "env:" then
919936
local env = os.getenv(key:sub(5))
920937
return env
921938
end
922939
end)
940+
941+
return path
942+
end
943+
944+
---@param path string
945+
---@return string
946+
function m.normalize(path)
947+
path = m.resolvePathPlaceholders(path)
923948
path = util.expandPath(path)
924949
path = path:gsub('^%.[/\\]+', '')
925950
for _ = 1, 1000 do

0 commit comments

Comments
 (0)