Skip to content

bug: conform.formatexpr is still returning 0 even when no formatters are present for the filetype #269

@ndavd

Description

@ndavd

Neovim version (nvim -v)

v0.10.0-dev-2048+g367e52cc7

Operating system/version

Linux

Add the debug logs

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

Log file

[DEBUG] Running formatters on /.../Foo.sol: {}
[DEBUG] No formatters found for /.../Foo.sol

Describe the bug

Being it so that no conform formatters are present its formatexpr should be returning 1 so that it may fallback to the next available formatter.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

Open file without formatters. E.g. a Solidity file (*.sol).

Additional context

It used to work, so not sure when it exactly broke. This is the custom formatexpr that I've been using so far:

Formatexpr = function()
  local timeout_ms = 10000

  local n = require('conform').formatexpr({ timeout_ms = timeout_ms })

  if n == 0 then
    return 0
  end

  local whole_buffer_selected = vim.v.count == vim.fn.line('$')
  if whole_buffer_selected and supports_buffer_formatting() then
    -- Execute LSP buffer format (useful for those LSPs which don't support range formatting)
    vim.lsp.buf.format({ timeout_ms = timeout_ms })
    return 0
  end

  -- Fallback
  return 1
end

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