From fd074ff39a69238bb72b37373babd6043e30a5d8 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 30 Dec 2021 12:11:01 +0100 Subject: [PATCH] Fix problem when opening project's module document It wasn't fine to call core.open_doc without filename argument and later call Doc:save without providing both the filename and the absolute filename. It was giving a Doc in an inconsistent status where self.filename was set but not self.abs_filename. Added an asset to detect early the problem if ever happens again. In turn the problem prevented the project's module hook to work if the file was newly created. --- data/core/commands/core.lua | 11 +++-------- data/core/doc/init.lua | 2 ++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 16b371f3..3242e2ef 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -141,14 +141,9 @@ command.add(nil, { end, ["core:open-project-module"] = function() - local filename = ".lite_project.lua" - if system.get_file_info(filename) then - core.root_view:open_doc(core.open_doc(filename)) - else - local doc = core.open_doc() - core.root_view:open_doc(doc) - doc:save(filename) - end + local doc = core.open_doc(".lite_project.lua") + core.root_view:open_doc(doc) + doc:save() end, ["core:change-project-folder"] = function() diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 06cde9f9..7b97db35 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -85,6 +85,8 @@ function Doc:save(filename, abs_filename) assert(self.filename, "no filename set to default to") filename = self.filename abs_filename = self.abs_filename + else + assert(self.filename or abs_filename, "calling save on unnamed doc without absolute path") end local fp = assert( io.open(filename, "wb") ) for _, line in ipairs(self.lines) do