From b7d3394464e0ffb350b9c8481399cc5845c10f07 Mon Sep 17 00:00:00 2001 From: boatbomber Date: Sun, 10 Nov 2024 15:53:58 -0800 Subject: [PATCH] Plugin dev ux improvements (#992) Co-authored-by: kennethloeffler --- .dir-locals.el | 2 ++ .github/workflows/release.yml | 2 +- .gitignore | 4 ++-- .vscode/extensions.json | 8 +++++++ .vscode/settings.json | 4 ++++ CONTRIBUTING.md | 17 +++++++++++++ build.rs | 24 ++++++++++--------- ...efault.project.json => plugin.project.json | 16 ++++++------- plugin/run-tests.server.lua | 2 +- plugin/test | 4 ---- plugin/test-place.project.json | 2 +- plugin/watch-build.sh | 2 -- scripts/unit-test-plugin.sh | 2 ++ scripts/watch-build-plugin.sh | 1 + 14 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 .dir-locals.el create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json rename plugin/default.project.json => plugin.project.json (50%) delete mode 100644 plugin/test delete mode 100644 plugin/watch-build.sh create mode 100644 scripts/unit-test-plugin.sh create mode 100644 scripts/watch-build-plugin.sh diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 000000000..25e8e6c10 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,2 @@ +((nil . ((eglot-luau-rojo-project-path . "plugin.project.json") + (eglot-luau-rojo-sourcemap-enabled . 't)))) \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1718858a..1441c04a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,7 +31,7 @@ jobs: version: 'v0.3.0' - name: Build Plugin - run: rojo build plugin --output Rojo.rbxm + run: rojo build plugin.project.json --output Rojo.rbxm - name: Upload Plugin to Release env: diff --git a/.gitignore b/.gitignore index 88cdf551a..b1a5efe95 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,8 @@ /*.rbxl /*.rbxlx -# Test places for the Roblox Studio Plugin -/plugin/*.rbxlx +# Sourcemap for the Rojo plugin (for better intellisense) +/sourcemap.json # Roblox Studio holds 'lock' files on places *.rbxl.lock diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..6ffebea28 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "JohnnyMorganz.luau-lsp", + "JohnnyMorganz.stylua", + "Kampfkarren.selene-vscode", + "rust-lang.rust-analyzer" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f65783862 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "luau-lsp.sourcemap.rojoProjectFile": "plugin.project.json", + "luau-lsp.sourcemap.autogenerate": true +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8f3efd19f..7eccb0ee6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,23 @@ You'll want these tools to work on Rojo: * Latest stable Rust compiler * Latest stable [Rojo](https://github.com/rojo-rbx/rojo) * [Foreman](https://github.com/Roblox/foreman) +* [Luau Language Server](https://github.com/JohnnyMorganz/luau-lsp) (Only needed if working on the Studio plugin.) + +When working on the Studio plugin, we recommend using this command to automatically rebuild the plugin when you save a change: + +*(Make sure you've enabled the Studio setting to reload plugins on file change!)* + +```bash +bash scripts/watch-build-plugin.sh +``` + +You can also run the plugin's unit tests with the following: + +*(Make sure you have `run-in-roblox` installed first!)* + +```bash +bash scripts/unit-test-plugin.sh +``` ## Documentation Documentation impacts way more people than the individual lines of code we write. diff --git a/build.rs b/build.rs index 9f9a606bb..e423b61be 100644 --- a/build.rs +++ b/build.rs @@ -41,12 +41,12 @@ fn snapshot_from_fs_path(path: &Path) -> io::Result { fn main() -> Result<(), anyhow::Error> { let out_dir = env::var_os("OUT_DIR").unwrap(); - let root_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap(); - let plugin_root = PathBuf::from(root_dir).join("plugin"); + let root_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let plugin_dir = root_dir.join("plugin"); let our_version = Version::parse(env::var_os("CARGO_PKG_VERSION").unwrap().to_str().unwrap())?; let plugin_version = - Version::parse(fs::read_to_string(plugin_root.join("Version.txt"))?.trim())?; + Version::parse(fs::read_to_string(plugin_dir.join("Version.txt"))?.trim())?; assert_eq!( our_version, plugin_version, @@ -54,14 +54,16 @@ fn main() -> Result<(), anyhow::Error> { ); let snapshot = VfsSnapshot::dir(hashmap! { - "default.project.json" => snapshot_from_fs_path(&plugin_root.join("default.project.json"))?, - "fmt" => snapshot_from_fs_path(&plugin_root.join("fmt"))?, - "http" => snapshot_from_fs_path(&plugin_root.join("http"))?, - "log" => snapshot_from_fs_path(&plugin_root.join("log"))?, - "rbx_dom_lua" => snapshot_from_fs_path(&plugin_root.join("rbx_dom_lua"))?, - "src" => snapshot_from_fs_path(&plugin_root.join("src"))?, - "Packages" => snapshot_from_fs_path(&plugin_root.join("Packages"))?, - "Version.txt" => snapshot_from_fs_path(&plugin_root.join("Version.txt"))?, + "default.project.json" => snapshot_from_fs_path(&root_dir.join("plugin.project.json"))?, + "plugin" => VfsSnapshot::dir(hashmap! { + "fmt" => snapshot_from_fs_path(&plugin_dir.join("fmt"))?, + "http" => snapshot_from_fs_path(&plugin_dir.join("http"))?, + "log" => snapshot_from_fs_path(&plugin_dir.join("log"))?, + "rbx_dom_lua" => snapshot_from_fs_path(&plugin_dir.join("rbx_dom_lua"))?, + "src" => snapshot_from_fs_path(&plugin_dir.join("src"))?, + "Packages" => snapshot_from_fs_path(&plugin_dir.join("Packages"))?, + "Version.txt" => snapshot_from_fs_path(&plugin_dir.join("Version.txt"))?, + }), }); let out_path = Path::new(&out_dir).join("plugin.bincode"); diff --git a/plugin/default.project.json b/plugin.project.json similarity index 50% rename from plugin/default.project.json rename to plugin.project.json index 424f107e4..83265250e 100644 --- a/plugin/default.project.json +++ b/plugin.project.json @@ -3,25 +3,25 @@ "tree": { "$className": "Folder", "Plugin": { - "$path": "src" + "$path": "plugin/src" }, "Packages": { - "$path": "Packages", + "$path": "plugin/Packages", "Log": { - "$path": "log" + "$path": "plugin/log" }, "Http": { - "$path": "http" + "$path": "plugin/http" }, "Fmt": { - "$path": "fmt" + "$path": "plugin/fmt" }, "RbxDom": { - "$path": "rbx_dom_lua" + "$path": "plugin/rbx_dom_lua" } }, "Version": { - "$path": "Version.txt" + "$path": "plugin/Version.txt" } } -} \ No newline at end of file +} diff --git a/plugin/run-tests.server.lua b/plugin/run-tests.server.lua index 1e2130f57..0ab3cc05c 100644 --- a/plugin/run-tests.server.lua +++ b/plugin/run-tests.server.lua @@ -1,6 +1,6 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage") -local TestEZ = require(ReplicatedStorage.Packages.TestEZ) +local TestEZ = require(ReplicatedStorage.Packages:WaitForChild("TestEZ", 10)) local Rojo = ReplicatedStorage.Rojo diff --git a/plugin/test b/plugin/test deleted file mode 100644 index caeb88743..000000000 --- a/plugin/test +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -rojo build test-place.project.json -o TestPlace.rbxlx -run-in-roblox --script run-tests.server.lua --place TestPlace.rbxlx \ No newline at end of file diff --git a/plugin/test-place.project.json b/plugin/test-place.project.json index 70875137f..f4da9815a 100644 --- a/plugin/test-place.project.json +++ b/plugin/test-place.project.json @@ -5,7 +5,7 @@ "ReplicatedStorage": { "Rojo": { - "$path": "default.project.json" + "$path": "../plugin.project.json" }, "Packages": { diff --git a/plugin/watch-build.sh b/plugin/watch-build.sh deleted file mode 100644 index 91ce6f894..000000000 --- a/plugin/watch-build.sh +++ /dev/null @@ -1,2 +0,0 @@ -# Continously build the rojo plugin into the local plugin directory on Windows -rojo build plugin/default.project.json -o $LOCALAPPDATA/Roblox/Plugins/Rojo.rbxm --watch diff --git a/scripts/unit-test-plugin.sh b/scripts/unit-test-plugin.sh new file mode 100644 index 000000000..c7ff7c798 --- /dev/null +++ b/scripts/unit-test-plugin.sh @@ -0,0 +1,2 @@ +rojo build plugin/test-place.project.json -o TestPlace.rbxl +run-in-roblox --script plugin/run-tests.server.lua --place TestPlace.rbxl \ No newline at end of file diff --git a/scripts/watch-build-plugin.sh b/scripts/watch-build-plugin.sh new file mode 100644 index 000000000..c21397f25 --- /dev/null +++ b/scripts/watch-build-plugin.sh @@ -0,0 +1 @@ +rojo build plugin.project.json --plugin Rojo.rbxm --watch \ No newline at end of file