Accept .luau files (#552)

* 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>
This commit is contained in:
Samuel P
2022-06-29 16:53:10 -06:00
committed by GitHub
parent 8ea41480b7
commit acf7456371
7 changed files with 45 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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()

View File

@@ -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);
};

View File

@@ -57,16 +57,31 @@ 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);
@@ -74,7 +89,11 @@ pub fn snapshot_from_vfs(
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.

View File

@@ -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: []

View File

@@ -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
@@ -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: []

View File

@@ -244,7 +244,7 @@ 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() {
@@ -252,16 +252,17 @@ fn pick_script_path(instance: InstanceWithMeta<'_>) -> Option<PathBuf> {
_ => 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,
}