Skip to content

Work with editor code formatters #47

Open
@paul

Description

@paul

Most editors can invoke an external command to format a file, but they don't expect the file to change out from under them.

The simplest would be to support a --stdin flag, that would read the file in stdin, and output the formatted file to stdout.

FWIW, I was able to get it to work with Neovim & conform.vim using the tempfile feature. I'm not sure how many other editors make that possible, though.

formatters = {
  ruboclean = {
    condition = function(ctx)
      return vim.fs.basename(ctx.filename) ~= ".rubocop.yml"
    end,
    command = "ruboclean",
    args = { "$FILENAME", "--preserve-comments", "--preserve-paths", "--silent" },
    stdin = false,
  },
},
formatters_by_ft = {
  yaml = { "ruboclean" }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions