stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
3.12k stars 163 forks source link

bug: injected formatter not working #187

Closed petobens closed 11 months ago

petobens commented 11 months ago

Neovim version (nvim -v)

NVIM v0.10.0-dev-1496+g4c8fdc018b

Operating system/version

Arch Linux

Add the debug logs

Log file

Log file: /tmp/nvim-minimal/state/nvim/conform.log                                                                                                                                                             │
``│          17:29:56[INFO] Run prettierd on /home/pedro/Desktop/foo.md                                                                                                                                           │
~ │          17:29:56[DEBUG] Run command: { "prettierd", "/home/pedro/Desktop/foo.md" }                                                                                                                           │
~ │          17:29:56[DEBUG] Run CWD: /home/pedro                                                                                                                                                                 │
~ │          17:29:57[DEBUG] prettierd exited with code 0                                                                                                                                                         │
~ │          17:29:57[INFO] Run injected on /home/pedro/Desktop/foo.md                                                                                                                                            │
~ │          17:29:57[DEBUG] Injected format python:4:4: { {                                                                                                                                                      │
~ │              available = true,                                                                                                                                                                                │
~ │              command = "black",                                                                                                                                                                               │
~ │              name = "black"                                                                                                                                                                                   │
~ │            } }         

Formatters for this buffer:                                                                                                                                                                                    │
~ │prettierd ready (markdown)                                                                                                                                                                                     │
~ │injected ready (markdown)                                                                                                                                                                                      │

Describe the bug

The injected formatter doesn't appear to update the injected code in a markdown file

Steps To Reproduce

  1. Using the minimal init.lua file open nvim
  2. edit a foo.md file with
    
    # H1
x=2
` ``

note there are closing backticks after the code block actually written as ``` (without the space)

  1. :w write the file.
  2. The python code is not formatted

Expected Behavior

Get the code block formatted as

x = 2

Minimal example file

No response

Minimal init.lua

local root = '/tmp/nvim-minimal'

-- Set stdpaths to use root dir
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 = {
    {
        'nvim-treesitter/nvim-treesitter',
        build = ':TSUpdate',
        config = function()
            require('nvim-treesitter.configs').setup({
                ensure_installed = {
                    'markdown',
                    'markdown_inline',
                    'python',
                },
            })
        end,
    },
    {
        'stevearc/conform.nvim',
        config = function()
            require('conform').setup({
                formatters_by_ft = {
                    markdown = { 'prettierd', 'injected' },
                    python = { 'black' },
                },
                format_on_save = function()
                    return { timeout_ms = 700, quiet = true, lsp_fallback = false }
                end,
                notify_on_error = true,
                log_level = vim.log.levels.DEBUG,
            })
        end,
    },
}
require('lazy').setup(plugins, {
    root = root .. '/plugins',
})

Additional context

conforminjected

mehalter commented 11 months ago

I can also confirm that the injected formatter doesn't seem to be working on my end. I tested this with the latest Neovim nightly as well as stable and the injected formatters are not working on either.

mehalter commented 11 months ago

Bisecting the commits, it looks like it is since the new function formatter resolution commit: https://github.com/stevearc/conform.nvim/commit/0bbe83830be5a07a1161bb1a23d7280310656177

mehalter commented 11 months ago

I am trying to format a markdown file with injected Lua code. Here are the debug logs:

09:34:28[DEBUG] Running formatters on /home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs/src/content/docs/configuration/core_plugins.md: { "prettierd", "injected" }
09:34:28[INFO] Run prettierd on /home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs/src/content/docs/configuration/core_plugins.md
09:34:28[DEBUG] Run command: { "prettierd", "/home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs/src/content/docs/configuration/core_plugins.md" }
09:34:28[DEBUG] Run CWD: /home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs
09:34:28[DEBUG] prettierd exited with code 0
09:34:28[INFO] Run injected on /home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs/src/content/docs/configuration/core_plugins.md
09:34:28[DEBUG] Injected format lua:13:116: { {
    available = true,
    command = "stylua",
    cwd = "/home/mhalter3@icl.gtri.org/Documents/git/github.com/AstroNvim/docs",
    name = "stylua"
  } }

looks like it is getting a list of formatter tables rather than formatter names

stevearc commented 11 months ago

Should be fixed, thanks for the report!

petobens commented 11 months ago

Thank you!