mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Bundle each typedefs file with its respective lune-std crate to fix publishing and cargo-binstall issues
This commit is contained in:
parent
58a65afc2c
commit
b147e83d3c
25 changed files with 148 additions and 108 deletions
|
@ -45,7 +45,7 @@ test-bin *ARGS:
|
||||||
fmt:
|
fmt:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
stylua .lune scripts tests types \
|
stylua .lune crates scripts tests \
|
||||||
--glob "tests/**/*.luau" \
|
--glob "tests/**/*.luau" \
|
||||||
--glob "!tests/roblox/rbx-test-files/**"
|
--glob "!tests/roblox/rbx-test-files/**"
|
||||||
cargo fmt
|
cargo fmt
|
||||||
|
@ -55,7 +55,7 @@ fmt:
|
||||||
fmt-check:
|
fmt-check:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
stylua .lune scripts tests types \
|
stylua .lune crates scripts tests \
|
||||||
--glob "tests/**/*.luau" \
|
--glob "tests/**/*.luau" \
|
||||||
--glob "!tests/roblox/rbx-test-files/**"
|
--glob "!tests/roblox/rbx-test-files/**"
|
||||||
cargo fmt --check
|
cargo fmt --check
|
||||||
|
@ -68,7 +68,7 @@ analyze:
|
||||||
luau-lsp analyze \
|
luau-lsp analyze \
|
||||||
--settings=".vscode/settings.json" \
|
--settings=".vscode/settings.json" \
|
||||||
--ignore="tests/roblox/rbx-test-files/**" \
|
--ignore="tests/roblox/rbx-test-files/**" \
|
||||||
.lune scripts tests types
|
.lune crates scripts tests
|
||||||
|
|
||||||
# Zips up the built binary into a single zip file
|
# Zips up the built binary into a single zip file
|
||||||
[no-exit-message]
|
[no-exit-message]
|
||||||
|
|
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -1133,12 +1133,6 @@ version = "0.27.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
|
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glob"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.26"
|
version = "0.3.26"
|
||||||
|
@ -1413,26 +1407,6 @@ dependencies = [
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "include_dir"
|
|
||||||
version = "0.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
"include_dir_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "include_dir_macros"
|
|
||||||
version = "0.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.6.0"
|
version = "2.6.0"
|
||||||
|
@ -1599,7 +1573,6 @@ dependencies = [
|
||||||
"dialoguer",
|
"dialoguer",
|
||||||
"directories",
|
"directories",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"include_dir",
|
|
||||||
"lune-roblox",
|
"lune-roblox",
|
||||||
"lune-std",
|
"lune-std",
|
||||||
"lune-utils",
|
"lune-utils",
|
||||||
|
|
|
@ -10,6 +10,16 @@ mod values;
|
||||||
|
|
||||||
pub use self::date_time::DateTime;
|
pub use self::date_time::DateTime;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `datetime` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `datetime` standard library module.
|
Creates the `datetime` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,7 @@ end
|
||||||
@param locale -- The locale the time should be formatted in
|
@param locale -- The locale the time should be formatted in
|
||||||
@return string -- The formatting string
|
@return string -- The formatting string
|
||||||
]=]
|
]=]
|
||||||
function DateTime.formatUniversalTime(
|
function DateTime.formatUniversalTime(self: DateTime, formatString: string?, locale: Locale?): string
|
||||||
self: DateTime,
|
|
||||||
formatString: string?,
|
|
||||||
locale: Locale?
|
|
||||||
): string
|
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,16 @@ use self::copy::copy;
|
||||||
use self::metadata::FsMetadata;
|
use self::metadata::FsMetadata;
|
||||||
use self::options::FsWriteOptions;
|
use self::options::FsWriteOptions;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `fs` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `fs` standard library module.
|
Creates the `fs` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
local DateTime = require("./datetime")
|
--!nocheck
|
||||||
|
|
||||||
|
local DateTime = require("@lune/datetime")
|
||||||
type DateTime = DateTime.DateTime
|
type DateTime = DateTime.DateTime
|
||||||
|
|
||||||
export type MetadataKind = "file" | "dir" | "symlink"
|
export type MetadataKind = "file" | "dir" | "symlink"
|
|
@ -8,6 +8,16 @@ mod options;
|
||||||
|
|
||||||
use self::options::{LuauCompileOptions, LuauLoadOptions};
|
use self::options::{LuauCompileOptions, LuauLoadOptions};
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `luau` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `luau` standard library module.
|
Creates the `luau` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,16 @@ use self::{
|
||||||
|
|
||||||
use lune_std_serde::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
use lune_std_serde::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `net` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `net` standard library module.
|
Creates the `net` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,16 @@ mod options;
|
||||||
|
|
||||||
use self::options::ProcessSpawnOptions;
|
use self::options::ProcessSpawnOptions;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `process` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `process` standard library module.
|
Creates the `process` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,16 @@ mod regex;
|
||||||
|
|
||||||
use self::regex::LuaRegex;
|
use self::regex::LuaRegex;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `regex` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `regex` standard library module.
|
Creates the `regex` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,16 @@ static REFLECTION_DATABASE: OnceLock<ReflectionDatabase> = OnceLock::new();
|
||||||
use lune_utils::TableBuilder;
|
use lune_utils::TableBuilder;
|
||||||
use roblox_install::RobloxStudio;
|
use roblox_install::RobloxStudio;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `roblox` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `roblox` standard library module.
|
Creates the `roblox` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -183,10 +183,7 @@ export type DataModelMetatable = {
|
||||||
|
|
||||||
export type DataModel =
|
export type DataModel =
|
||||||
Instance
|
Instance
|
||||||
& typeof(setmetatable(
|
& typeof(setmetatable((nil :: any) :: DataModelProperties, (nil :: any) :: { __index: DataModelMetatable }))
|
||||||
(nil :: any) :: DataModelProperties,
|
|
||||||
(nil :: any) :: { __index: DataModelMetatable }
|
|
||||||
))
|
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
@class Roblox
|
@class Roblox
|
||||||
|
@ -491,11 +488,7 @@ end
|
||||||
@param methodName The name of the method to implement.
|
@param methodName The name of the method to implement.
|
||||||
@param callback The function which will be called when the method is called.
|
@param callback The function which will be called when the method is called.
|
||||||
]=]
|
]=]
|
||||||
function roblox.implementMethod(
|
function roblox.implementMethod(className: string, methodName: string, callback: (instance: Instance, ...any) -> ...any)
|
||||||
className: string,
|
|
||||||
methodName: string,
|
|
||||||
callback: (instance: Instance, ...any) -> ...any
|
|
||||||
)
|
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,16 @@ pub use self::compress_decompress::{compress, decompress, CompressDecompressForm
|
||||||
pub use self::encode_decode::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
pub use self::encode_decode::{decode, encode, EncodeDecodeConfig, EncodeDecodeFormat};
|
||||||
pub use self::hash::HashOptions;
|
pub use self::hash::HashOptions;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `serde` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `serde` standard library module.
|
Creates the `serde` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -139,11 +139,7 @@ end
|
||||||
@param level The compression level to use, clamped to the format's limits. The best compression level is used by default
|
@param level The compression level to use, clamped to the format's limits. The best compression level is used by default
|
||||||
@return The compressed string
|
@return The compressed string
|
||||||
]=]
|
]=]
|
||||||
function serde.compress(
|
function serde.compress(format: CompressDecompressFormat, s: buffer | string, level: number?): string
|
||||||
format: CompressDecompressFormat,
|
|
||||||
s: buffer | string,
|
|
||||||
level: number?
|
|
||||||
): string
|
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -193,11 +189,7 @@ end
|
||||||
@param message The message to hash
|
@param message The message to hash
|
||||||
@return The hash as a base64 string
|
@return The hash as a base64 string
|
||||||
]=]
|
]=]
|
||||||
function serde.hmac(
|
function serde.hmac(algorithm: HashAlgorithm, message: string | buffer, secret: string | buffer): string
|
||||||
algorithm: HashAlgorithm,
|
|
||||||
message: string | buffer,
|
|
||||||
secret: string | buffer
|
|
||||||
): string
|
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,16 @@ static STDIN: LazyLock<Arc<AsyncMutex<BufReader<Unblock<Stdin>>>>> = LazyLock::n
|
||||||
Arc::new(AsyncMutex::new(reader))
|
Arc::new(AsyncMutex::new(reader))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `stdio` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `stdio` standard library module.
|
Creates the `stdio` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
export type Color =
|
export type Color = "reset" | "black" | "red" | "green" | "yellow" | "blue" | "purple" | "cyan" | "white"
|
||||||
"reset"
|
|
||||||
| "black"
|
|
||||||
| "red"
|
|
||||||
| "green"
|
|
||||||
| "yellow"
|
|
||||||
| "blue"
|
|
||||||
| "purple"
|
|
||||||
| "cyan"
|
|
||||||
| "white"
|
|
||||||
export type Style = "reset" | "bold" | "dim"
|
export type Style = "reset" | "bold" | "dim"
|
||||||
|
|
||||||
type PromptFn = (
|
type PromptFn = (
|
|
@ -10,6 +10,16 @@ use mlua_luau_scheduler::Functions;
|
||||||
|
|
||||||
use lune_utils::TableBuilder;
|
use lune_utils::TableBuilder;
|
||||||
|
|
||||||
|
const TYPEDEFS: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/types.d.luau"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string containing type definitions for the `task` standard library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
pub fn typedefs() -> String {
|
||||||
|
TYPEDEFS.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the `task` standard library module.
|
Creates the `task` standard library module.
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,7 @@ end
|
||||||
@param functionOrThread The function or thread to delay
|
@param functionOrThread The function or thread to delay
|
||||||
@return The thread that will be delayed
|
@return The thread that will be delayed
|
||||||
]=]
|
]=]
|
||||||
function task.delay<T...>(
|
function task.delay<T...>(duration: number, functionOrThread: thread | (T...) -> ...any, ...: T...): thread
|
||||||
duration: number,
|
|
||||||
functionOrThread: thread | (T...) -> ...any,
|
|
||||||
...: T...
|
|
||||||
): thread
|
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,6 +61,29 @@ impl LuneStandardLibrary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns type definitions for the library.
|
||||||
|
*/
|
||||||
|
#[must_use]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
|
pub fn typedefs(&self) -> String {
|
||||||
|
match self {
|
||||||
|
#[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::typedefs(),
|
||||||
|
#[cfg(feature = "fs")] Self::Fs => lune_std_fs::typedefs(),
|
||||||
|
#[cfg(feature = "luau")] Self::Luau => lune_std_luau::typedefs(),
|
||||||
|
#[cfg(feature = "net")] Self::Net => lune_std_net::typedefs(),
|
||||||
|
#[cfg(feature = "task")] Self::Task => lune_std_task::typedefs(),
|
||||||
|
#[cfg(feature = "process")] Self::Process => lune_std_process::typedefs(),
|
||||||
|
#[cfg(feature = "regex")] Self::Regex => lune_std_regex::typedefs(),
|
||||||
|
#[cfg(feature = "serde")] Self::Serde => lune_std_serde::typedefs(),
|
||||||
|
#[cfg(feature = "stdio")] Self::Stdio => lune_std_stdio::typedefs(),
|
||||||
|
#[cfg(feature = "roblox")] Self::Roblox => lune_std_roblox::typedefs(),
|
||||||
|
|
||||||
|
_ => unreachable!("no standard library enabled"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates the Lua module for the library.
|
Creates the Lua module for the library.
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ std = [
|
||||||
"std-task",
|
"std-task",
|
||||||
]
|
]
|
||||||
|
|
||||||
cli = ["dep:clap", "dep:include_dir", "dep:rustyline", "dep:zip_next"]
|
cli = ["dep:clap", "dep:rustyline", "dep:zip_next"]
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -76,6 +76,5 @@ lune-utils = { version = "0.1.3", path = "../lune-utils" }
|
||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
clap = { optional = true, version = "4.1", features = ["derive"] }
|
clap = { optional = true, version = "4.1", features = ["derive"] }
|
||||||
include_dir = { optional = true, version = "0.7", features = ["glob"] }
|
|
||||||
rustyline = { optional = true, version = "14.0" }
|
rustyline = { optional = true, version = "14.0" }
|
||||||
zip_next = { optional = true, version = "1.1" }
|
zip_next = { optional = true, version = "1.1" }
|
||||||
|
|
|
@ -1,21 +1,15 @@
|
||||||
use std::{
|
use std::{borrow::BorrowMut, env::current_dir, io::ErrorKind, path::PathBuf, process::ExitCode};
|
||||||
borrow::BorrowMut, collections::HashMap, env::current_dir, io::ErrorKind, path::PathBuf,
|
|
||||||
process::ExitCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use directories::UserDirs;
|
use directories::UserDirs;
|
||||||
use futures_util::future::try_join_all;
|
use futures_util::future::try_join_all;
|
||||||
use include_dir::{include_dir, Dir};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
// TODO: Use a library that supports json with comments since VSCode settings may contain comments
|
// TODO: Use a library that supports json with comments since VSCode settings may contain comments
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
pub(crate) static TYPEDEFS_DIR: Dir<'_> = include_dir!("types");
|
|
||||||
|
|
||||||
pub(crate) static SETTING_NAME_MODE: &str = "luau-lsp.require.mode";
|
pub(crate) static SETTING_NAME_MODE: &str = "luau-lsp.require.mode";
|
||||||
pub(crate) static SETTING_NAME_ALIASES: &str = "luau-lsp.require.directoryAliases";
|
pub(crate) static SETTING_NAME_ALIASES: &str = "luau-lsp.require.directoryAliases";
|
||||||
|
|
||||||
|
@ -25,7 +19,7 @@ pub struct SetupCommand {}
|
||||||
|
|
||||||
impl SetupCommand {
|
impl SetupCommand {
|
||||||
pub async fn run(self) -> Result<ExitCode> {
|
pub async fn run(self) -> Result<ExitCode> {
|
||||||
generate_typedef_files_from_definitions(&TYPEDEFS_DIR)
|
generate_typedef_files_from_definitions()
|
||||||
.await
|
.await
|
||||||
.expect("Failed to generate typedef files");
|
.expect("Failed to generate typedef files");
|
||||||
|
|
||||||
|
@ -142,31 +136,11 @@ fn add_values_to_vscode_settings_json(value: JsonValue) -> JsonValue {
|
||||||
settings_json
|
settings_json
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_typedef_files_from_definitions(dir: &Dir<'_>) -> Result<String> {
|
async fn generate_typedef_files_from_definitions() -> Result<String> {
|
||||||
let contents = read_typedefs_dir_contents(dir);
|
|
||||||
write_typedef_files(contents).await
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_typedefs_dir_contents(dir: &Dir<'_>) -> HashMap<String, Vec<u8>> {
|
|
||||||
let mut definitions = HashMap::new();
|
|
||||||
|
|
||||||
for entry in dir.find("*.luau").unwrap() {
|
|
||||||
let entry_file = entry.as_file().unwrap();
|
|
||||||
let entry_name = entry_file.path().file_name().unwrap().to_string_lossy();
|
|
||||||
|
|
||||||
let typedef_name = entry_name.trim_end_matches(".luau");
|
|
||||||
let typedef_contents = entry_file.contents().to_vec();
|
|
||||||
|
|
||||||
definitions.insert(typedef_name.to_string(), typedef_contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
definitions
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn write_typedef_files(typedef_files: HashMap<String, Vec<u8>>) -> Result<String> {
|
|
||||||
let version_string = env!("CARGO_PKG_VERSION");
|
let version_string = env!("CARGO_PKG_VERSION");
|
||||||
let mut dirs_to_write = Vec::new();
|
let mut dirs_to_write = Vec::new();
|
||||||
let mut files_to_write = Vec::new();
|
let mut files_to_write = Vec::new();
|
||||||
|
|
||||||
// Create the typedefs dir in the users cache dir
|
// Create the typedefs dir in the users cache dir
|
||||||
let cache_dir = UserDirs::new()
|
let cache_dir = UserDirs::new()
|
||||||
.context("Failed to find user home directory")?
|
.context("Failed to find user home directory")?
|
||||||
|
@ -175,13 +149,14 @@ async fn write_typedef_files(typedef_files: HashMap<String, Vec<u8>>) -> Result<
|
||||||
.join(".typedefs")
|
.join(".typedefs")
|
||||||
.join(version_string);
|
.join(version_string);
|
||||||
dirs_to_write.push(cache_dir.clone());
|
dirs_to_write.push(cache_dir.clone());
|
||||||
|
|
||||||
// Make typedef files
|
// Make typedef files
|
||||||
for (builtin_name, builtin_typedef) in typedef_files {
|
for builtin in lune_std::LuneStandardLibrary::ALL {
|
||||||
let path = cache_dir
|
let name = builtin.name().to_lowercase();
|
||||||
.join(builtin_name.to_ascii_lowercase())
|
let path = cache_dir.join(&name).with_extension("luau");
|
||||||
.with_extension("luau");
|
files_to_write.push((name, path, builtin.typedefs()));
|
||||||
files_to_write.push((builtin_name.to_lowercase(), path, builtin_typedef));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write all dirs and files only when we know generation was successful
|
// Write all dirs and files only when we know generation was successful
|
||||||
let futs_dirs = dirs_to_write
|
let futs_dirs = dirs_to_write
|
||||||
.drain(..)
|
.drain(..)
|
||||||
|
|
Loading…
Add table
Reference in a new issue