lua: Add Windows support (#13871)

The current version of the extension tries to download the Windows
binary files for lua-language-server like this:
`lua-language-server-3.9.3-win32-x64.tar.gz`

The [Windows binary
files](https://github.com/LuaLS/lua-language-server/releases) are only
released as zip archives, so it will fail to get the required files.


This pr changes the following:
- Add check for Windows specific zip archive
- Add check for Windows specific .exe executable

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Idris Saklou 2024-07-05 20:11:11 +02:00 committed by GitHub
parent 61e4b6413a
commit 19490d8806
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,7 +37,7 @@ impl LuaExtension {
let (platform, arch) = zed::current_platform();
let asset_name = format!(
"lua-language-server-{version}-{os}-{arch}.tar.gz",
"lua-language-server-{version}-{os}-{arch}.{extension}",
version = release.version,
os = match platform {
zed::Os::Mac => "darwin",
@ -49,6 +49,10 @@ impl LuaExtension {
zed::Architecture::X8664 => "x64",
zed::Architecture::X86 => return Err("unsupported platform x86".into()),
},
extension = match platform {
zed::Os::Mac | zed::Os::Linux => "tar.gz",
zed::Os::Windows => "zip",
},
);
let asset = release
@ -58,7 +62,13 @@ impl LuaExtension {
.ok_or_else(|| format!("no asset found matching {:?}", asset_name))?;
let version_dir = format!("lua-language-server-{}", release.version);
let binary_path = format!("{version_dir}/bin/lua-language-server");
let binary_path = format!(
"{version_dir}/bin/lua-language-server{extension}",
extension = match platform {
zed::Os::Mac | zed::Os::Linux => "",
zed::Os::Windows => ".exe",
},
);
if !fs::metadata(&binary_path).map_or(false, |stat| stat.is_file()) {
zed::set_language_server_installation_status(
@ -69,7 +79,10 @@ impl LuaExtension {
zed::download_file(
&asset.download_url,
&version_dir,
zed::DownloadedFileType::GzipTar,
match platform {
zed::Os::Mac | zed::Os::Linux => zed::DownloadedFileType::GzipTar,
zed::Os::Windows => zed::DownloadedFileType::Zip,
},
)
.map_err(|e| format!("failed to download file: {e}"))?;