Skip to content

bug: injected formatter not working #187

Description

@petobens

Neovim version (nvim -v)

NVIM v0.10.0-dev-1496+g4c8fdc018b

Operating system/version

Arch Linux

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

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

```python
x=2
` ``

note there are closing backticks after the code block actually written as ``` (without the space)
3. :w write the file.
4. 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

Activity

  1. mehalter commented on Nov 9, 2023

    @mehalter
    Contributor

    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.

  2. mehalter commented on Nov 9, 2023

    @mehalter
    Contributor

    Bisecting the commits, it looks like it is since the new function formatter resolution commit: 0bbe838

  3. mehalter commented on Nov 9, 2023

    @mehalter
    Contributor

    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

  4. stevearc commented on Nov 9, 2023

    @stevearc
    Owner

    Should be fixed, thanks for the report!

  5. petobens commented on Nov 9, 2023

    @petobens
    ContributorAuthor

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions