Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Source specific Configuration

zmtq05 edited this page Dec 24, 2021 · 8 revisions

This page documents extended / advanced configurations for specific sources.

The configurations here are user-maintained and not guaranteed to work. If something is broken, fix it! If something is missing, add it!

Rust

rustfmt

specifying edition

Note: If you are using rust-analyzer, format with rust-analyzer. It reads edition from Cargo.toml.

Choose one of the following:

  1. specify in rustfmt.toml.
edition = "2021"
  1. hardcode it.
null_ls.builtins.formatting.rustfmt.with({
  extra_args = { "--edition=2021" }
}
  1. read from Cargo.toml.
null_ls.builtins.formatting.rustfmt.with({
  extra_args = function(params)
    local cargo_toml = params.root .. "/" .. "Cargo.toml"
    local fd = vim.loop.fs_open(cargo_toml, "r", 438)
    if not fd then
      return
    end
    local stat = vim.loop.fs_fstat(fd)
    local data = vim.loop.fs_read(fd, stat.size, 0)
    vim.loop.fs_close(fd)
    for _, line in ipairs(vim.split(data, "\n")) do
      local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
      -- regex maybe wrong.
      if edition then
        return { "--edition=" .. edition }
      end
    end
  end
}
Clone this wiki locally