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.59k stars 518 forks source link

analyzer is not updated, when project is changed #1151

Closed jjvbsag closed 1 year ago

jjvbsag commented 2 years ago

I use https://github.com/pkulchenko/ZeroBranePackage/blob/master/projectsettings.lua to have different settings for different project. Now I wanted to use staticanalyzer.luacheck = {options = {...}} do define project specific globals and conditions.

But the checker is cached in ZeroBraneStudio/src/editor/inspect.lua line 279 fff

 local checkers = {}
local function warnings_from_string(...)
  local checktype = (ide.config.staticanalyzer.luacheck
    -- luacheck globals depend on the interpreter, so create different checkers if needed
    and "luacheck" .. (ide:GetInterpreter():GetFileName() or "")
    or "luainspect")
  if not checkers[checktype] then checkers[checktype] = create_checker() end
  return checkers[checktype](...)
end

and then never updated again, if the project is changed. I always have to restart zbs

pkulchenko commented 2 years ago

@jjvbsag, the checker is cached, but the cache is interpreter-specific:

and "luacheck" .. (ide:GetInterpreter():GetFileName() or "")

When the interpreter is changed, is should run create_checker() again; does this not happen for you (it does happen for me)?

jjvbsag commented 2 years ago

:-) But: The interpreter in the projects is all the same, just the target runtime and available lua libs (on embedded arm-hosts) differ from project to project. And I want luacheck to verify, only existing functions are called.

pkulchenko commented 1 year ago

Are you saying that the cache should also check for Project path? That may work. Can you try this patch:

diff --git a/src/editor/inspect.lua b/src/editor/inspect.lua
index 76e95e29..f0a6a9ec 100644
--- a/src/editor/inspect.lua
+++ b/src/editor/inspect.lua
@@ -280,7 +280,7 @@ local checkers = {}
 local function warnings_from_string(...)
   local checktype = (ide.config.staticanalyzer.luacheck
     -- luacheck globals depend on the interpreter, so create different checkers if needed
-    and "luacheck" .. (ide:GetInterpreter():GetFileName() or "")
+    and "luacheck" .. (ide:GetInterpreter():GetFileName() or "") .. (ide:GetProject() or "")
     or "luainspect")
   if not checkers[checktype] then checkers[checktype] = create_checker() end
   return checkers[checktype](...)
jjvbsag commented 1 year ago

@pkulchenko : Did not help in my special case (well at least it doesnt crash ZBS :smiley: ). But this may also be my fault, because I load the luacheck options inside (project specific) Package:onProjectLoad() using

    local path=self.fpath:match("(.*[\\/])").."luacheck-options.lua"
    local luacheck_options=dofile(path)
    ide.config.staticanalyzer.luacheck={options=luacheck_options}

do you see any conflicts with this code?

pkulchenko commented 1 year ago

The patch is not going to help in your case, but that's a quite special case, so I'm not sure if it needs to be handled. I guess, you'll have to reload your settings from OnProjectLoad and OnInterpreterLoad events. It will then detect the change with this patch in place (as long as you update ide.config.staticanalyzer.luacheck values). BTW, it should work with staticanalyzer.luacheck={options=luacheck_options}, as you shouldn't need to specify ide.config prefix (as far as I remember).

jjvbsag commented 1 year ago

@pkulchenko Ok, I wasn't aware of the OnInterpreterLoad event. I will try. As it is really a special case and I assume not relevant for anybody else, I will close this issue. Thank you for your support.

pkulchenko commented 1 year ago

@jjvbsag, your case may be quite specific, but I still think that adding .. (ide:GetProject() or "") may be worth it.

Can you tell me what exactly you do? I'm curious why switching the project is not detected even when you add the patch shown above. It should reset the value if either the interpreter or the project changed, which is what happens in your case, right?

jjvbsag commented 1 year ago

@pkulchenko Yes, I also believe ide:GetProject() does not harm.

To be honest, I'm still fighting with luacheck to be verbose with relevant errors and shut up with nonerelevant. In our embedded project there are a lot of preloaded modules, which define either global objects with lot of methods and also a bunch of globally available functions. Now I try to prepare luacheck options to know all of them, which is a hassle. But in the meantime I managed to use luacheck with my luacheck-options.lua module from shell, so turnaround-time by Close-ZBS, Reopen-ZBS is not an issue any more.

Once more, thanks for your support.

pkulchenko commented 1 year ago

@jjvbsag, BTW, there is ID.RESTART item that can be associated with a shortcut or a toolbar/menu item to add a one-click IDE reload. It should save the configuration and unsaved editor tabs as well.