pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.61k stars 519 forks source link

Hangs on saving a cloned view. #1060

Closed xopxe closed 4 years ago

xopxe commented 4 years ago
  1. Open a file
  2. Clone view it
  3. Edit the first view (both get marked with an asterisk)
  4. Hit save The program gets grayed out and unresponsive with 100% CPU usage. When I close the application sometimes results in a broken session file and zb fails to start again until I delete it.

ZeroBrane from git, Ubuntu 18.04.

pkulchenko commented 4 years ago

@xopxe, thank you for the report. Can't reproduce this on Windows, but will try on Linux. Do you have any other plugins running at the same time?

xopxe commented 4 years ago

Yes, I'm using these:

xopxe@timur:~/.zbstudio/packages$ ls -l
total 24
-rw-r--r-- 1 xopxe xopxe 3067 Aug 29  2019 cloneview.lua
-rw-r--r-- 1 xopxe xopxe  500 Aug 29  2019 edgemark.lua
-rw-r--r-- 1 xopxe xopxe 3048 Aug 29  2019 highlightselected.lua
-rw-r--r-- 1 xopxe xopxe 1694 Aug 29  2019 moveline.lua
-rw-r--r-- 1 xopxe xopxe 2750 Aug 29  2019 referencepanel.lua
-rw-r--r-- 1 xopxe xopxe 1521 Feb  4  2015 uniquetabname.lua

Also, my user.lua is as follows:

editor.fontname = "Ubuntu Mono"
editor.fontsize = 12
styles.indicator.fncall.st = wxstc.wxSTC_INDIC_PLAIN
styles.indicator.varglobal = {fg = {255,0,0}, u=true}
--xop https://github.com/pkulchenko/ZeroBraneStudio/issues/323#issuecomment-47281548
local G = ... -- this now points to the global environment in the script
local luaspec = G.ide.specs.lua
luaspec.exts[#luaspec.exts+1] = "conf"
editor.autoactivate = true
singleinstance=false
pkulchenko commented 4 years ago

It's not a problem with cloneview; it's a problem with uniquetabname plugin. It used to be the case that cloned windows didn't have full paths (which was relied on in uniquetabname), but later this logic was changed to allow saving cloned tabs from either original or cloned tab. This affected the check in uniquetabname, which now tries to come up with a unique name for each cloned tab and fails. Working on a fix.

pkulchenko commented 4 years ago

@xopxe, this patch against uniquetabname.lua fixes the issue for me:

diff --git a/uniquetabname.lua b/uniquetabname.lua
index 9722a58..6530035 100644
--- a/uniquetabname.lua
+++ b/uniquetabname.lua
@@ -4,25 +4,38 @@ local function makeUnique(exeditor)
   for id, doc in pairs(ide:GetDocuments()) do
     if doc:GetEditor() ~= exeditor and doc:GetFileName() and doc:GetFilePath() then
       local fn = doc:GetFileName()
-      docs[fn] = docs[fn] or {}
-      table.insert(docs[fn], {doc = doc, parts = wx.wxFileName(doc:GetFilePath()):GetDirs()})
+      local fpath = doc:GetFilePath()
+      local uniquepath = true
+      if docs[fn] then
+        for _, tab in pairs(docs[fn]) do
+          if tab.path == fpath then uniquepath = false end
+        end
+      end
+      if uniquepath then
+        docs[fn] = docs[fn] or {}
+        table.insert(docs[fn], {doc = doc, path = fpath, parts = wx.wxFileName(doc:GetFilePath()):GetDirs()})
+      end
     end
   end

   while true do
     local updated = false
+    local newdocs = {}
     for fn, tabs in pairs(docs) do
       if #tabs > 1 then -- conflicting name
         updated = true
-        docs[fn] = nil
+        newdocs[fn] = nil
         for _, tab in ipairs(tabs) do
-          local fn = (table.remove(tab.parts) or '?').. sep .. fn
-          docs[fn] = docs[fn] or {}
-          table.insert(docs[fn], tab)
+          local fn = (table.remove(tab.parts) or '?') .. sep .. fn
+          if not docs[fn] then
+            newdocs[fn] = newdocs[fn] or {}
+            table.insert(newdocs[fn], tab)
+          end
         end
       end
     end
     if not updated then break end
+    docs = newdocs
   end

   -- update all labels as some might have lost their conflicts
@@ -34,7 +47,7 @@ return {
   name = "Unique tabname",
   description = "Updates editor tab names to always stay unique.",
   author = "Paul Kulchenko",
-  version = 0.1,
+  version = 0.2,

   onEditorLoad = function(self) makeUnique() end,
   onEditorSave = function(self) makeUnique() end,

Let me know if this works for you as well.

xopxe commented 4 years ago

With the patch it works correctly, thanks.