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

Source specific Configuration

Santo Cariotti edited this page Jan 8, 2022 · 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!

HTML

djhtml

set tabwidth from buffer shiftwidth

Helpful when you have projects with different tabwidth in HTML, often in combination with .editorconfig.

null_ls.builtins.formatting.djhtml.with({
    extra_args = function(params)
        return {
            "--tabwidth",
            vim.api.nvim_buf_get_option(params.bufnr, "shiftwidth"),
        }
    end,
}),

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 Path = require("plenary.path")
        local cargo_toml = Path:new(params.root .. "/" .. "Cargo.toml")

        if cargo_toml:exists() and cargo_toml:is_file() then
            for _, line in ipairs(cargo_toml:readlines()) do
                local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
                if edition then
                    return { "--edition=" .. edition }
                end
            end
        end
        -- default edition when we don't find `Cargo.toml` or the `edition` in it.
        return { "--edition=2021" }
    end,
})
Clone this wiki locally