conform.nvim
                                
                                 conform.nvim copied to clipboard
                                
                                    conform.nvim copied to clipboard
                            
                            
                            
                        Inject formatter requires multiple invocations before getting applied on the codeblocks in markdown file
Neovim version (nvim -v)
NVIM v0.10.2
Operating system/version
15.2
Read debugging tips
- [X] I have read through the debugging tips.
Add the debug logs
- [X] I have set log_level = vim.log.levels.DEBUGand pasted the log contents below.
Log file
2025-01-10 15:32:14[DEBUG] Running formatters on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md: { "injected" }
2025-01-10 15:32:14[INFO] Run injected on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md
2025-01-10 15:32:14[INFO] No formatters found for injected treesitter language yaml
2025-01-10 15:32:14[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:14[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:14[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:14[DEBUG] Injected format python:28:35: { "ruff_format" }
2025-01-10 15:32:14[ERROR] Formatter 'injected' error: Vim:E325: ATTENTION
2025-01-10 15:32:16[DEBUG] Running formatters on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md: { "injected" }
2025-01-10 15:32:16[INFO] Run injected on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md
2025-01-10 15:32:16[INFO] No formatters found for injected treesitter language yaml
2025-01-10 15:32:16[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:16[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:16[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:16[DEBUG] Injected format python:28:35: { "ruff_format" }
2025-01-10 15:32:16[INFO] Run ruff_format on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py
2025-01-10 15:32:16[DEBUG] Run command: { "/Users/rbhanot/.local/share/nvim/mason/bin/ruff", "format", "--force-exclude", "--stdin-filename", "/Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py", "-" }
2025-01-10 15:32:16[DEBUG] Run default CWD: /Users/rbhanot/Obsedian
2025-01-10 15:32:16[DEBUG] Injected format json:19:25: { "fixjson" }
2025-01-10 15:32:17[ERROR] Formatter 'injected' error: Vim:E325: ATTENTION
2025-01-10 15:32:17[DEBUG] ruff_format exited with code 0
2025-01-10 15:32:18[DEBUG] Running formatters on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md: { "injected" }
2025-01-10 15:32:18[INFO] Run injected on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md
2025-01-10 15:32:18[INFO] No formatters found for injected treesitter language yaml
2025-01-10 15:32:18[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:18[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:18[INFO] No formatters found for injected treesitter language markdown_inline
2025-01-10 15:32:18[DEBUG] Injected format python:28:35: { "ruff_format" }
2025-01-10 15:32:18[INFO] Run ruff_format on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py
2025-01-10 15:32:18[DEBUG] Run command: { "/Users/rbhanot/.local/share/nvim/mason/bin/ruff", "format", "--force-exclude", "--stdin-filename", "/Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py", "-" }
2025-01-10 15:32:18[DEBUG] Run default CWD: /Users/rbhanot/Obsedian
2025-01-10 15:32:18[DEBUG] Injected format json:19:25: { "fixjson" }
2025-01-10 15:32:18[INFO] Run fixjson on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.2.json
2025-01-10 15:32:18[DEBUG] Run command: { "/Users/rbhanot/.local/share/nvim/mason/bin/fixjson" }
2025-01-10 15:32:18[DEBUG] Run default CWD: /Users/rbhanot/Obsedian
2025-01-10 15:32:18[DEBUG] ruff_format exited with code 0
2025-01-10 15:32:19[DEBUG] fixjson exited with code 0
2025-01-10 15:32:20[DEBUG] Running formatters on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md: { "markdownlint-cli2" }
2025-01-10 15:32:20[INFO] Run markdownlint-cli2 on /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md
2025-01-10 15:32:20[DEBUG] Creating temp file /Users/rbhanot/Obsedian/Main/.conform.2356778.1736491359-ci-cd.md
2025-01-10 15:32:20[DEBUG] Run command: { "/Users/rbhanot/.local/share/nvim/mason/bin/markdownlint-cli2", "--fix", "/Users/rbhanot/Obsedian/Main/.conform.2356778.1736491359-ci-cd.md" }
2025-01-10 15:32:20[DEBUG] Run default CWD: /Users/rbhanot/Obsedian
2025-01-10 15:32:20[DEBUG] markdownlint-cli2 exited with code 1
2025-01-10 15:32:20[DEBUG] Cleaning up temp file /Users/rbhanot/Obsedian/Main/.conform.2356778.1736491359-ci-cd.md
Describe the bug
I have an Obsedian markdown note file that has a few code blocks in it (for now, python and json). When i try to run the injected formatter on the note, the the code blocks do not get formatted on the first time and I have to hit the keymap a few times when it eventually gets formatted correctly.
As can be seen in the above log the first attempts failed wih 2025-01-10 15:32:17[ERROR] Formatter 'injected' error: Vim:E325: ATTENTION.  I also get the following error message each time I run the formatter
   Info  15:32:08 notify.info Restored session: /Users/rbhanot/Obsedian
15:32:14 msg_show Found a swap file by the name "~/.local/state/nvim/swap/%Users%rbhanot%Obsedian%Main%1736491359-ci-cd.md.1.py.swp"
          owned by: rbhanot   dated: Fri Jan 10 13:36:06 2025
         file name: ~rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py
          modified: no
         user name: rbhanot   host name: rbhanot-mn2
        process ID: 15544
While opening file "/Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py"
      CANNOT BE FOUND
(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /Users/rbhanot/Obsedian/Main/1736491359-ci-cd.md.1.py"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/rbhanot/.local/state/nvim/swap//%Users%rbhanot%Obsedian%Main%1736491359-ci-cd.md.1.py.swp"
    to avoid this message.
What is the severity of this bug?
tolerable (can work around it)
Steps To Reproduce
- Create a markdown file with few code blocks for different languages.
- Run the injected formatter.
Expected Behavior
The injected formatter should format the code blocks on the first invokation and not throw errors around swap files.
Minimal example file
---
id: 1736491359-ci-cd
aliases:
tags:
---
# Heading 1
## Heading 2
Some random text
```json
{
  "staging": {
    "key1"                             : "value1",
    "key2":         "value"
  }
}``` 
```python
def hello(name:           str) -> str:
    return          f"Hello {name}"``` 
Minimal init.lua
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        formatters_by_ft = {
        json = { "fixjson" },
        python = { "ruff_format" },
      },
      formatters = {
        injected = {
          options = {
            ignore_errors = true,
            lang_to_ft = {
              python = "python",
              json = "json",
            },
            lang_to_ext = {
              python = "py",
              json = "json",
            },
          },
        },
      },
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
Additional context
No response