diff --git a/.lune/fmt.luau b/.lune/fmt.luau new file mode 100644 index 0000000..2f78179 --- /dev/null +++ b/.lune/fmt.luau @@ -0,0 +1,13 @@ +--> Run stylua to check for formatting errors + +local process = require("@lune/process") + +local CommandBuilder = require("./util/exec") + +process.exit( + CommandBuilder.new("stylua") + :withArg(".") + :withArgs(process.args) + :withStdioStrategy("forward") + :exec().code +) \ No newline at end of file diff --git a/.lune/tests/reporter.luau b/.lune/tests/reporter.luau index b1e56af..472060f 100644 --- a/.lune/tests/reporter.luau +++ b/.lune/tests/reporter.luau @@ -1,3 +1,5 @@ +--> lib: Extension to base frktest reporter for live status reporting + local stdio = require("@lune/stdio") local frktest = require("../../lune_packages/frktest") diff --git a/.lune/typecheck.luau b/.lune/typecheck.luau new file mode 100644 index 0000000..db52153 --- /dev/null +++ b/.lune/typecheck.luau @@ -0,0 +1,15 @@ +--> Run luau-lsp analysis to check for type errors + +local process = require("@lune/process") + +local CommandBuilder = require("./util/exec") + +process.exit( + CommandBuilder.new("luau-lsp") + :withArg("analyze") + :withArgs({ "--settings", ".vscode/settings.json" }) + :withArgs({ "--ignore", "'**/*_packages/**/*'" }) + :withArg(".") + :withStdioStrategy("forward") + :exec().code +) \ No newline at end of file diff --git a/.lune/util/channel.luau b/.lune/util/channel.luau index c3fcf4d..e311988 100644 --- a/.lune/util/channel.luau +++ b/.lune/util/channel.luau @@ -1,5 +1,5 @@ ---- An MPSC synchronization primitive powered by Lua upvalues which retains only ---- one value at a time. +--> util: An MPSC synchronization primitive powered by Lua upvalues which retains only +--> one value at a time. --- ## Usage --- ```luau diff --git a/.lune/util/exec.luau b/.lune/util/exec.luau new file mode 100644 index 0000000..aaf1931 --- /dev/null +++ b/.lune/util/exec.luau @@ -0,0 +1,123 @@ +--> lib: Builder pattern class to spawn child processes + +local process = require("@lune/process") +local stdio = require("@lune/stdio") + +local CommandBuilder = {} + +export type CommandBuilder = typeof(setmetatable( + {} :: CommandBuilderFields, + { __index = CommandBuilder } +)) +type CommandBuilderFields = { + program: string, + args: { string }, + stdioStrategy: IoStrategyMapping?, +} +export type StdioStrategy = "pipe" | "forward" | "none" +export type IoStrategyMapping = { + stdout: StdioStrategy?, + stderr: StdioStrategy?, +} + +local DEFAULT_STDIO_STRATEGY: IoStrategyMapping = { + stdout = "pipe", + stderr = "pipe", +} +function CommandBuilder.new(program: string) + return setmetatable( + { + program = program, + args = {}, + stdioStrategy = nil, + } :: CommandBuilderFields, + { + __index = CommandBuilder, + } + ) +end + +function CommandBuilder.withArg( + self: CommandBuilder, + arg: string +): CommandBuilder + table.insert(self.args, arg) + return self +end + +function CommandBuilder.withArgs( + self: CommandBuilder, + args: { string } +): CommandBuilder + for _, arg in args do + self:withArg(arg) + end + + return self +end + +function CommandBuilder.withStdioStrategy( + self: CommandBuilder, + strategy: StdioStrategy | IoStrategyMapping +): CommandBuilder + self.stdioStrategy = if typeof(strategy) == "string" + then { + stdout = strategy, + stderr = strategy, + } + else strategy + return self +end + +local function intoSpawnOptionsStdioKind( + strategy: StdioStrategy +): process.SpawnOptionsStdioKind + if strategy == "pipe" then + return "default" + end + + if strategy == "forward" then + return "forward" + end + + if strategy == "none" then + return "none" + end + + error(`Non-strategy provided: {strategy}`) +end + +function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult + print( + "$", + stdio.style("dim") .. self.program, + table.concat(self.args, " ") .. stdio.style("reset") + ) + + local function translateIoStrategyMappings(mappings: IoStrategyMapping) + local translatedMappings: process.SpawnOptionsStdio = {} + for field: string, value in pairs(mappings) do + translatedMappings[field] = intoSpawnOptionsStdioKind(value) + end + + return translatedMappings + end + + local child = process.spawn(self.program, self.args, { + shell = true, + stdio = translateIoStrategyMappings( + self.stdioStrategy or DEFAULT_STDIO_STRATEGY + ), + }) + + if not child.ok then + print( + `\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`, + child.code + ) + end + + return child +end + +return CommandBuilder \ No newline at end of file diff --git a/pesde.lock b/pesde.lock index 531ab76..4a0f5b8 100644 --- a/pesde.lock +++ b/pesde.lock @@ -112,6 +112,34 @@ index_url = "https://github.com/daimond113/pesde-index" environment = "lune" lib = "lib/init.luau" +[graph."pesde/luau_lsp"."1.38.0 lune"] +direct = ["luau-lsp", { name = "pesde/luau_lsp", version = "^1.38.0", target = "lune" }, "dev"] +resolved_ty = "dev" + +[graph."pesde/luau_lsp"."1.38.0 lune".target] +environment = "lune" +bin = "init.luau" + +[graph."pesde/luau_lsp"."1.38.0 lune".dependencies] +"lukadev_0/option" = ["1.2.0 lune", "option"] +"lukadev_0/result" = ["1.2.0 lune", "result"] +"pesde/toolchainlib" = ["0.1.7 lune", "core"] + +[graph."pesde/luau_lsp"."1.38.0 lune".pkg_ref] +ref_ty = "pesde" +name = "pesde/luau_lsp" +version = "1.38.0" +index_url = "https://github.com/pesde-pkg/index" + +[graph."pesde/luau_lsp"."1.38.0 lune".pkg_ref.dependencies] +core = [{ name = "pesde/toolchainlib", version = "^0.1.7", index = "https://github.com/daimond113/pesde-index", target = "lune" }, "standard"] +option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "standard"] +result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "standard"] + +[graph."pesde/luau_lsp"."1.38.0 lune".pkg_ref.target] +environment = "lune" +bin = "init.luau" + [graph."pesde/stylua"."2.0.2 lune"] direct = ["stylua", { name = "pesde/stylua", version = "^2.0.2", target = "lune" }, "dev"] resolved_ty = "dev" diff --git a/pesde.toml b/pesde.toml index b0b7db3..15f12d8 100644 --- a/pesde.toml +++ b/pesde.toml @@ -23,3 +23,4 @@ default = "https://github.com/pesde-pkg/index" stylua = { name = "pesde/stylua", version = "^2.0.2", target = "lune" } frktest = { name = "itsfrank/frktest", version = "^0.0.2", target = "lune" } asciitable = { name = "kimpure/asciitable", version = "^0.1.4" } +luau-lsp = { name = "pesde/luau_lsp", version = "^1.38.0", target = "lune" }