Configure LuaLS for single-file script workspaces
Native and manual checks / native (ubuntu-24.04) (push) Waiting to run
Native and manual checks / native (windows-2025) (push) Waiting to run
Native and manual checks / manual (push) Waiting to run
Windows editor and software Vulkan / windows-graphics (push) Waiting to run
Native and manual checks / native (ubuntu-24.04) (push) Waiting to run
Native and manual checks / native (windows-2025) (push) Waiting to run
Native and manual checks / manual (push) Waiting to run
Windows editor and software Vulkan / windows-graphics (push) Waiting to run
This commit is contained in:
@@ -218,6 +218,8 @@ not encrypted code. A C++-only project continues to export without the Lua VM.
|
||||
|
||||
Run `faset_lua_setup`. It copies annotation-only declarations to
|
||||
`.faset/lua/faset.lua` and creates `.luarc.json` **only if it does not already exist**.
|
||||
It also creates `Scripts/.luarc.json` for editors that open an individual Lua file
|
||||
with `Scripts` as the workspace root. Existing configuration files are preserved.
|
||||
For an existing LuaLS configuration, merge these settings yourself:
|
||||
|
||||
```json
|
||||
|
||||
+11
-1
@@ -493,16 +493,26 @@ void Session::register_commands() {
|
||||
const auto source = config_.engine_root / "tools/lua";
|
||||
const auto annotations = project_path(config_.project_root, ".faset/lua/faset.lua");
|
||||
const auto configuration = project_path(config_.project_root, ".luarc.json");
|
||||
const auto scripts_configuration =
|
||||
project_path(config_.project_root, "Scripts/.luarc.json");
|
||||
atomic_write(annotations, read_text(source / "faset.lua"));
|
||||
const bool create_configuration = !std::filesystem::exists(configuration);
|
||||
if (create_configuration)
|
||||
atomic_write_json(configuration, read_json(source / "luarc.json"));
|
||||
// Zed can open a script as a single-file workspace rooted at Scripts.
|
||||
// Give that workspace its own relative path to the API declarations.
|
||||
const bool create_scripts_configuration =
|
||||
!std::filesystem::exists(scripts_configuration);
|
||||
if (create_scripts_configuration)
|
||||
atomic_write_json(scripts_configuration,
|
||||
read_json(source / "luarc-scripts.json"));
|
||||
log(create_configuration
|
||||
? "LuaLS configured: .luarc.json and .faset/lua/faset.lua"
|
||||
: "LuaLS annotations updated; existing .luarc.json preserved. Add .faset/lua "
|
||||
"to workspace.library if needed");
|
||||
return Json{{"annotations", ".faset/lua/faset.lua"},
|
||||
{"configuration_created", create_configuration}};
|
||||
{"configuration_created", create_configuration},
|
||||
{"scripts_configuration_created", create_scripts_configuration}};
|
||||
});
|
||||
commands_.add(
|
||||
"faset_script_open",
|
||||
|
||||
@@ -71,16 +71,24 @@ int main() {
|
||||
"test", "Project settings erased Lua configuration or external editor command");
|
||||
const auto setup = commands.call("faset_lua_setup", Json::object());
|
||||
require(setup.at("configuration_created") == true &&
|
||||
setup.at("scripts_configuration_created") == true &&
|
||||
std::filesystem::is_regular_file(root / ".faset/lua/faset.lua") &&
|
||||
read_json(root / ".luarc.json").at("runtime.version") == "Lua 5.4",
|
||||
"test", "LuaLS setup did not install annotations and configuration");
|
||||
require(read_json(root / "Scripts/.luarc.json").at("workspace.library") ==
|
||||
Json::array({"../.faset/lua"}),
|
||||
"test", "Single-file Lua workspace cannot find Faset annotations");
|
||||
const Json custom_luarc = {{"runtime.version", "Lua 5.4"},
|
||||
{"workspace.library", {"Custom/Lua"}},
|
||||
{"custom_setting", true}};
|
||||
const Json custom_scripts_luarc = {{"workspace.library", {"../Custom/Lua"}}};
|
||||
atomic_write_json(root / ".luarc.json", custom_luarc);
|
||||
require(commands.call("faset_lua_setup", Json::object()).at("configuration_created") ==
|
||||
false &&
|
||||
read_json(root / ".luarc.json") == custom_luarc,
|
||||
atomic_write_json(root / "Scripts/.luarc.json", custom_scripts_luarc);
|
||||
const auto repeated_setup = commands.call("faset_lua_setup", Json::object());
|
||||
require(repeated_setup.at("configuration_created") == false &&
|
||||
repeated_setup.at("scripts_configuration_created") == false &&
|
||||
read_json(root / ".luarc.json") == custom_luarc &&
|
||||
read_json(root / "Scripts/.luarc.json") == custom_scripts_luarc,
|
||||
"test", "LuaLS setup overwrote the user's configuration");
|
||||
auto reject_command = [&](const std::string& name, const Json& args,
|
||||
const std::string& code) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"runtime.version": "Lua 5.4",
|
||||
"runtime.path": ["?.lua", "?/init.lua"],
|
||||
"workspace.library": ["../.faset/lua"],
|
||||
"workspace.checkThirdParty": false,
|
||||
"diagnostics.globals": ["faset"]
|
||||
}
|
||||
Reference in New Issue
Block a user