Skip to content

Commit

Permalink
Accept .luau files (rojo-rbx#552)
Browse files Browse the repository at this point in the history
* accept .luau files

* Accept .luau in snapshot creation

* Update versioning and snapshots.

* fix versioning

* Run rustfmt

* Reduce repetition in extension detection

* Tidy build script change

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
  • Loading branch information
imacodr and LPGhatguy authored Jun 29, 2022
1 parent 700a4cb commit c031d48
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn snapshot_from_fs_path(path: &Path) -> io::Result<VfsSnapshot> {

// We can skip any TestEZ test files since they aren't necessary for
// the plugin to run.
if file_name.ends_with(".spec.lua") {
if file_name.ends_with(".spec.lua") || file_name.ends_with(".spec.luau") {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions src/snapshot_middleware/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ pub fn snapshot_dir_no_meta(
// middleware. Should we figure out a way for that function to add
// relevant paths to this middleware?
path.join("init.lua"),
path.join("init.luau"),
path.join("init.server.lua"),
path.join("init.server.luau"),
path.join("init.client.lua"),
path.join("init.client.luau"),
];

let snapshot = InstanceSnapshot::new()
Expand Down
6 changes: 6 additions & 0 deletions src/snapshot_middleware/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ pub fn snapshot_lua(
("LocalScript", name)
} else if let Some(name) = match_trailing(&file_name, ".lua") {
("ModuleScript", name)
} else if let Some(name) = match_trailing(&file_name, ".server.luau") {
("Script", name)
} else if let Some(name) = match_trailing(&file_name, ".client.luau") {
("LocalScript", name)
} else if let Some(name) = match_trailing(&file_name, ".luau") {
("ModuleScript", name)
} else {
return Ok(None);
};
Expand Down
21 changes: 20 additions & 1 deletion src/snapshot_middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,43 @@ pub fn snapshot_from_vfs(
return snapshot_project(context, vfs, &project_path);
}

let init_path = path.join("init.luau");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

let init_path = path.join("init.lua");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

let init_path = path.join("init.server.luau");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

let init_path = path.join("init.server.lua");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

let init_path = path.join("init.client.luau");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

let init_path = path.join("init.client.lua");
if vfs.metadata(&init_path).with_not_found()?.is_some() {
return snapshot_lua_init(context, vfs, &init_path);
}

snapshot_dir(context, vfs, path)
} else {
if let Ok(name) = path.file_name_trim_end(".lua") {
let script_name = path
.file_name_trim_end(".lua")
.or_else(|_| path.file_name_trim_end(".luau"));

if let Ok(name) = script_name {
match name {
// init scripts are handled elsewhere and should not turn into
// their own children.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ metadata:
- /foo
- /foo/init.meta.json
- /foo/init.lua
- /foo/init.luau
- /foo/init.server.lua
- /foo/init.server.luau
- /foo/init.client.lua
- /foo/init.client.luau
context: {}
name: foo
class_name: Folder
properties: {}
children: []

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ metadata:
- /foo
- /foo/init.meta.json
- /foo/init.lua
- /foo/init.luau
- /foo/init.server.lua
- /foo/init.server.luau
- /foo/init.client.lua
- /foo/init.client.luau
context: {}
name: foo
class_name: Folder
Expand All @@ -27,10 +30,14 @@ children:
- /foo/Child
- /foo/Child/init.meta.json
- /foo/Child/init.lua
- /foo/Child/init.luau
- /foo/Child/init.server.lua
- /foo/Child/init.server.luau
- /foo/Child/init.client.lua
- /foo/Child/init.client.luau
context: {}
name: Child
class_name: Folder
properties: {}
children: []

7 changes: 4 additions & 3 deletions src/web/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,25 @@ impl ApiService {
}
}

/// If this instance is represented by a script, try to find the correct .lua
/// If this instance is represented by a script, try to find the correct .lua or .luau
/// file to open to edit it.
fn pick_script_path(instance: InstanceWithMeta<'_>) -> Option<PathBuf> {
match instance.class_name() {
"Script" | "LocalScript" | "ModuleScript" => {}
_ => return None,
}

// Pick the first listed relevant path that has an extension of .lua that
// Pick the first listed relevant path that has an extension of .lua or .luau that
// exists.
instance
.metadata()
.relevant_paths
.iter()
.find(|path| {
// We should only ever open Lua files to be safe.
// We should only ever open Lua or Luau files to be safe.
match path.extension().and_then(|ext| ext.to_str()) {
Some("lua") => {}
Some("luau") => {}
_ => return false,
}

Expand Down

0 comments on commit c031d48

Please sign in to comment.