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.6k stars 519 forks source link

Outline incorrect when there's elseif after repeat..until loop #1086

Closed steveRoll-git closed 3 years ago

steveRoll-git commented 3 years ago

The outline doesn't close a function when there's an elseif keyword right after a repeat until block. For example, this code:

function a()
  if true then
    repeat until x
  elseif 123 then

  end
end

function b()

end

will cause the outline to look like this: image

(By the way, this is similar to #946 which I also reported a while back. There could be more keywords that cause this)

pkulchenko commented 3 years ago

@steveRoll-git, good catch; thank you for the report!

The following patch fixes the issue for me:

diff --git a/lualibs/lua_parser_loose.lua b/lualibs/lua_parser_loose.lua
index abf6ce32..432f2149 100644
--- a/lualibs/lua_parser_loose.lua
+++ b/lualibs/lua_parser_loose.lua
@@ -82,7 +82,7 @@ function PARSE.parse_scope(lx, f, level)
     -- Detect end of previous statement
     if c.tag == 'Eof' -- trigger 'Statement' at the end of file
     or c.tag == 'Keyword' and (
-       c[1] == 'break' or c[1] == 'goto' or c[1] == 'do' or c[1] == 'while' or c[1] == 'else' or
+       c[1] == 'break' or c[1] == 'goto' or c[1] == 'do' or c[1] == 'while' or c[1] == 'else' or c[1] == 'elseif' or
        c[1] == 'repeat' or c[1] == 'if' or c[1] == 'for' or c[1] == 'function' and lx:peek().tag == 'Id' or
        c[1] == 'local' or c[1] == ';' or c[1] == 'until' or c[1] == 'return' or c[1] == 'end')
     or c.tag == 'Id' and
steveRoll-git commented 3 years ago

Yes, it fixed it for me too.