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

Disabled formating with enabled autosave plugin #1262

Closed
4 tasks done
wert2all opened this issue Nov 7, 2024 · 10 comments · Fixed by #1265
Closed
4 tasks done

Disabled formating with enabled autosave plugin #1262

wert2all opened this issue Nov 7, 2024 · 10 comments · Fixed by #1265
Labels
bug Something isn't working

Comments

@wert2all
Copy link

wert2all commented Nov 7, 2024

Checklist

  • I have searched through the AstroNvim documentation
  • I have searched through the existing issues of this project
  • I have searched the existing issues of plugins related to this issue
  • I can replicate the bug with the minimal repro.lua provided below

Neovim version (nvim -v)

0.10.2

Operating system/version

arch

Terminal/GUI

kitty

Describe the bug

caused by #511

Formating buffer does not work (disabled ) if "astrocommunity.pack.angular" and "astrocommunity.editing-support.auto-save-nvim" is enabled (maybe on go pack too)

Steps to Reproduce

  1. install pure astro nvim
  2. enable astrocommunity.pack.angular end astrocommunity.editing-support.auto-save-nvim on community.lua file
  3. open some template file of angular project and try to insert something like new empty lines
  4. go to normal move
  5. format bugger does not executed automatically

Expected behavior

buffer should be forma

Screenshots

No response

Additional Context

No response

@wert2all wert2all added the bug Something isn't working label Nov 7, 2024
@ALameLlama
Copy link
Member

ALameLlama commented Nov 7, 2024

I won't be at a computer for the next few days to test this, but the way I understood these auto save hooks is It'll disable formatting during any auto save and then restore the settings. So if you want to format it, you'll need to manually save or use :Format

@wert2all
Copy link
Author

wert2all commented Nov 8, 2024

So if you want to format it, you'll need to manually save or use :format

weird behavior as for me - or autosave or autoformat :)
Nvim should autoformat and autosave at same time for my opinion.

I check it again:

  1. open html document
  2. :w

✅ format and save

  1. open html document
  2. switch to i-mode
  3. add some spaces
  4. back to normal

❌ no format

  1. open html document
  2. :w
  3. ✅ format and save
  4. switch to i-mode
  5. add some spaces
  6. back to normal
  7. ❌ no format

@ALameLlama
Copy link
Member

I believe we added this to prevent it from formatting the code unexpectedly, e.g, you leave insert mode to copy and paste or try to select something in visual mode and than it formats in the middle you trying to do something else moving the code around

If you really want to avoid using these hooks it might be easier to either install the plugin directly

return {
  "okuuva/auto-save.nvim",
  event = { "User AstroFile", "InsertEnter" },
  opts = {},
}

or disable the auto commands doing something like

  { import = "astrocommunity.editing-support.auto-save-nvim" },
  {
    "AstroNvim/astrocore",
    opts = {
      autocmds = {
        autoformat_toggle = {},
      },
    },
  },

@ALameLlama
Copy link
Member

when testing this, I also noticed that the buffer setting wasn't getting restored correctly. so if you went into insert mode, did something, went to normal mode and then :w it wouldn't format even if you had it enabled before. but I think this is a different issue then what you are describing

#1265

@wert2all
Copy link
Author

I believe we added this to prevent it from formatting the code unexpectedly, e.g, you leave insert mode to copy and paste or try to select something in visual mode and than it formats in the middle you trying to do something else moving the code around

make sense...

ps. #1265 will fix this issue as for me, closing

@wert2all wert2all closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2024
@xino1010
Copy link

Hi there!

I have this configuration on my AstroNvim.

File ~/.config/nvim/lua/plugins/auto-save.lua.

return {
  {
    "okuuva/auto-save.nvim",
    -- version = '^1.0.0', -- see https://devhints.io/semver, alternatively use '*' to use the latest tagged release
    cmd = "ASToggle", -- optional for lazy loading on command
    event = { "InsertLeave", "TextChanged" }, -- optional for lazy loading on trigger events
    opts = {
      -- your config goes here
      -- or just leave it empty :)
      trigger_events = {
        defer_save = { "InsertLeave", "TextChanged", "TextChangedI" },
      },
      debounce_delay = 2500,
    },
  },
}

File ~/.config/nvim/lua/community.lua

return {
  "AstroNvim/astrocommunity",
  { import = "astrocommunity.pack.lua" },
  -- import/override with your plugins folder
  ...
  { import = "astrocommunity.editing-support.auto-save-nvim" },
}

It works perfectly (save without leaving the editor after 2500ms) but I noticed the file is not formatted automatically, I need to execute :w or leader lf myself.

is it feasible to get what i want?

Thank you

@ALameLlama
Copy link
Member

https://github.com/AstroNvim/astrocommunity/blob/main/lua/astrocommunity/editing-support/auto-save-nvim/init.lua#L8-L45

We have this logic here to disable formatting with autosave to prevent it from shifting while you're using it, I believe you can disable the auto command like I showed in the second example #1262 (comment)

@xino1010
Copy link

xino1010 commented Dec 1, 2024

Does not work, file is saved after 2500ms but not formatted

return {
  {
    "okuuva/auto-save.nvim",
    -- version = '^1.0.0', -- see https://devhints.io/semver, alternatively use '*' to use the latest tagged release
    cmd = "ASToggle", -- optional for lazy loading on command
    event = { "InsertLeave", "TextChanged" }, -- optional for lazy loading on trigger events
    opts = {
      -- your config goes here
      -- or just leave it empty :)
      trigger_events = {
        defer_save = { "InsertLeave", "TextChanged", "TextChangedI" },
      },
      debounce_delay = 2500,
      autocmds = {
        autoformat_toggle = {},
      },
    },
  },
}

@ALameLlama
Copy link
Member

the autocmd is on Astrocore and not on the plugin directly.

 {
    "AstroNvim/astrocore",
    opts = {
      autocmds = {
        autoformat_toggle = {},
      },
    },
  },

@xino1010
Copy link

xino1010 commented Dec 2, 2024

This is exactly I was looking for, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants