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

bug: injected formatter not working #187

Closed
1 task done
petobens opened this issue Nov 8, 2023 · 5 comments
Closed
1 task done

bug: injected formatter not working #187

petobens opened this issue Nov 8, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@petobens
Copy link
Contributor

petobens commented Nov 8, 2023

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

@petobens petobens added the bug Something isn't working label Nov 8, 2023
@mehalter
Copy link
Contributor

mehalter commented Nov 9, 2023

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
Copy link
Contributor

mehalter commented Nov 9, 2023

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

@mehalter
Copy link
Contributor

mehalter commented Nov 9, 2023

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
Copy link
Owner

stevearc commented Nov 9, 2023

Should be fixed, thanks for the report!

@petobens
Copy link
Contributor Author

petobens commented Nov 9, 2023

Thank you!

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