Page 1 of 1

Lua Formatter ignores tab_size

Posted: 27.09.2023 09:27
by yabobay
I had `tab_size` and `indent_size` set to 2 in my user.json, but lua_fmt which i just installed indents things with 4 spaces by default. So i checked if lua_fmt is configurable, it's not.

So i checked in the source code, and found this:

Code: Select all

    def __str__(self):
        r = ''
        for node in self._nodes:
            r += str(node)
        enter_pos = r.find('\n')
        r = r[:enter_pos].strip(' ') + r[enter_pos:]
        if r.strip(' ') == '\n': return '\n' #20
        return ' ' * _settings.get('tab_size') * self._indent + r
So it's trying to pay attention to `tab_size`, but it's failing. if i change the call to `_settings.get('tab_size')` to another number myself, it uses that number. So it's somehow getting 4 from tab_size? I checked, and it doesn't look like i have any specific tab_size setting for the Lua lexer.

Re: Lua Formatter ignores tab_size

Posted: 28.09.2023 09:11
by main Alexey
I opened the Lua formatter code: py/cuda_fmt_lua/__init__.py .
and i see it is hardcoded to 4 tab-size!

Code: Select all

from .lua_format import lua_format

def do_format(text):

    settings = {
        'tab_size': 4,
        'special_symbol_split': True,
        'bracket_split': False,
        }

    res = lua_format(text.splitlines(), settings)
    return res
change all file content to:

Code: Select all

from .lua_format import lua_format
import cudatext as app

def do_format(text):

    settings = {
        'tab_size': app.ed.get_prop(app.PROP_TAB_SIZE),
        'special_symbol_split': True,
        'bracket_split': False,
        }

    res = lua_format(text.splitlines(), settings)
    return res
seems it works ok now. if so, i will fix it in addons.

Re: Lua Formatter ignores tab_size

Posted: 28.09.2023 17:15
by yabobay
If i edit the file, will it get overwritten when an update comes out for the plugin? (That's what i want to happen)

Re: Lua Formatter ignores tab_size

Posted: 28.09.2023 17:30
by main Alexey
yes, it will (if you did NOT use 'Install from Github' menu item).

Re: Lua Formatter ignores tab_size

Posted: 29.09.2023 11:37
by main Alexey
i applied this fix and updated the addon in AddonsManager.