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

Fix live scheme update #1014

Closed numberZero closed 5 years ago

numberZero commented 5 years ago

Scheme picker doesn’t work for me; this PR fixes it. Note that editor:SetupKeywords(nil, editor.spec) is always no-op as it checks for spec == editor.spec.

pkulchenko commented 5 years ago

@numberZero, I'm not sure about this, as it effectively circumvents the caching that is currently present in editor.lua:1789: if spec and ide:IsValidProperty(editor, 'spec') and editor.spec == spec then return end. The same effect can be achieved by removing that line, but it's there to minimize the number of re-applications when the spec identifier doesn't change.

Can you share some details on what you are trying to achieve?

I may consider changing it to if spec and ide:IsValidProperty(editor, 'spec') and editor.spec == spec and not forcespec then return end, which should have the desired effect, but I'd still like to understand the use case.

pkulchenko commented 5 years ago

I missed the part that it's about the scheme picker; let me check.

pkulchenko commented 5 years ago

@numberZero, you are correct; thank you for the report. I'll apply the following patch:

diff --git a/src/editor/editor.lua b/src/editor/editor.lua
index 6b4cac4f..a675203e 100644
--- a/src/editor/editor.lua
+++ b/src/editor/editor.lua
@@ -1786,7 +1786,7 @@ function SetupKeywords(editor, ext, forcespec, styles, font, fontitalic)
   local lexerstyleconvert = nil
   local spec = forcespec or ide:FindSpec(ext, editor:GetLine(0))
   -- found a spec setup lexers and keywords
-  if spec and ide:IsValidProperty(editor, 'spec') and editor.spec == spec then return end
+  if spec and ide:IsValidProperty(editor, 'spec') and editor.spec == spec and not forcespec then return end
   if spec then
     if type(spec.lexer) == "string" then
       local ok, err = setLexLPegLexer(editor, spec)
numberZero commented 5 years ago

That patch works. If you care of minimizing re-applying, though, note that it executes more code: https://github.com/pkulchenko/ZeroBraneStudio/blob/501e480015d2997bfcde29306b8c296d447df449/src/editor/editor.lua#L1812-L1819 https://github.com/pkulchenko/ZeroBraneStudio/blob/501e480015d2997bfcde29306b8c296d447df449/src/editor/editor.lua#L1827-L1843 Not sure is that necessary (not familiar enough with the code).

pkulchenko commented 5 years ago

@numberZero, thank you for checking. I applied the patch, but kept your name on it, since it was your fix.

If you care of minimizing re-applying, though, note that it executes more code:

Right; it should not be a problem, as some of those may need to be re-applied if the configuration has changed.