Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid crashing when nvim_win_set_option received invalid status line text #1190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kiddos
Copy link

@kiddos kiddos commented Feb 8, 2024

For some programming language there are some string formatting functions like String.format("%d", a) or printf("%d", a"). If lualine is combined with nvim_treesitter#statusline like the following:

lualine_x = {
  {
    'nvim_treesitter#statusline',
    type = 'vim_fun'
  },
  'encoding',
  'fileformat',
  'filetype'
},

It will sometimes crash when the code has % in it.

For example,

package samples.quickstart.service.pojo;

import java.util.HashMap;

public class StockQuoteService {
    private HashMap map = new HashMap();

    public double getPrice(String symbol) {
        Double price = (Double) map.get(symbol);
        if(price != null){
            return price.doubleValue();
        }
        return 42.00;
    }

    private void writeLog(String symbol, double price) {
        map.put(symbol, new Double(price));
        try {
            Path p = Paths.get("/home", "user", "Document", "templogs", "folde" String.format("%d.log", System.currentTimeMillis()));
        }
    }
}

the %d should be %%d in status line text, but when the line gets too long nvim_treesitter#statusline will try to trim the output text and replace with ..., and something the extra % get trimmed off, which may look something like the following

...%d.log", System.currentTimeMillis())) -> "folde" String.format("%%d.log", System.currentTimeMillis())

and this would throw. (this trigger may differ for different screen widths)

one cheap solution is to wrap vim.api.nvim_win_set_option with pcall. another solution would be to make sure vim.api.nvim_win_set_option is never called with a single %.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant