filNaj / tree-setter

A treesitter-module which will place equals, semicolons, commas and double points automatically for you!
122 stars 6 forks source link

In Python, after inserting the equals, deletes the next line #4

Closed tlarevo closed 1 year ago

tlarevo commented 1 year ago

Bug preview

Sct4a.gif

Context

I'm using NvChad and my treesitter config as follows;

M.treesitter = {
  ensure_installed = {
    "vim",
    "lua",
    "html",
    "css",
    "javascript",
    "typescript",
    "tsx",
    "c",
    "markdown",
    "markdown_inline",
    "python",
    "svelte",
    "dart",
    "elixir",
    "surface",
    "heex",
  },
  indent = {
    enable = true,
  },
  tree_setter = { enable = true },
}
laureanray commented 1 year ago

This is also happening for C haven't tried other language yet.

filNaj commented 1 year ago

This was happening in all languages. It should now be resolved.

tlarevo commented 1 year ago

@filNaj Thanks a lot for the effort put in to the plugin, if time permits can you explain how, how adding return fixed the issue. I tried fixing the issue myself and couldn't find out the root cause. I'm noob on lua and neovim plugin dev but I would like to learn and contribute whenever possible.

filNaj commented 1 year ago

Adding return prevents the code to continue any further and reach the if statement at the end of the setter.lua file. This if statement is used to insert a ; when the user presses on the enter key (and not the space bar) to go to the next line. This is done by calling vim.api.nvim_buf_set_lines() function. But in the if character == ':' block, we are already calling this same function but with different arguments. So by adding the return, we prevent the vim.api.nvim_buf_set_lines() to be called twice.

Hope that helps.

tlarevo commented 1 year ago

@filNaj thanks a lot for taking time to explain, it makes sense now, I didn't know that with lua you can return without any value. Thanks a lot explaining the scenario 🙏 ❤️