Repository navigation
Open
Description
I have confirmed that this is a bug related to nvf
- This is a bug, and not an user error or a support request. I understand that my issue will be closed if it is not a bug in nvf.
- I have checked the issues tab and confirmed that my issue has not yet been reported. I understand that my issue will be closed if it is a duplicate.
Description
When vim.lsp.formatOnSave is enabled, no matter what the value of vim.languages.clang.format is, on save it will always format. It seems that formatOnSave either overrides or does not honor the value of vim.languages.clang.format. I have confirmed that setting vim.languages.rust.format to false works as expected.
Installation Method
Home Manager Module (homeManagerModules.default)
Installation Method (Other)
No response
nvf Version
master
Reproduction steps
Use below settings
settings.vim = {
lsp = {
enable = true;
formatOnSave = true;
};
languages.clang = {
enable = true;
format.enable = false;
};
};Open a C file and save.
Expected behavior
The file does not get formatted.
Actual Behavior
The file does get formatted.
System Information
- system: `"x86_64-linux"`
- host os: `Linux 7.0.10-zen1, NixOS, 26.11 (Zokor), 26.11.20260606.a799d3e`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.34.7`
- nixpkgs: `/nix/store/wz6pw7bm0qmj0j6n8i2craddlhj662l5-source`Relevant log output
-- nvf-print-config
-- SECTION: globalsScript
vim.g.editorconfig = true
vim.g.mapleader = " "
vim.g.maplocalleader = ","
-- SECTION: basic
vim.o.smartcase = false
vim.o.ignorecase = false
-- SECTION: optionsScript
vim.opt.autoindent = true
vim.opt.backup = false
vim.opt.cmdheight = 1
vim.opt.cursorlineopt = "line"
vim.opt.encoding = "utf-8"
vim.opt.errorbells = false
vim.opt.expandtab = false
vim.opt.hidden = true
vim.opt.mouse = ""
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.shiftwidth = 8
vim.opt.signcolumn = "yes"
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.swapfile = false
vim.opt.tabstop = 8
vim.opt.termguicolors = true
vim.opt.tm = 500
vim.opt.updatetime = 300
vim.opt.visualbell = false
vim.opt.wrap = false
vim.opt.writebackup = false
-- SECTION: lazyConfigs
require('lz.n').load({{"blink-cmp",
["after"] = function()
require("blink.cmp").setup({["cmdline"] = {["keymap"] = {["<C-Space>"] = {"show",
"fallback"},
["<C-d>"] = {"scroll_documentation_up",
"fallback"},
["<C-e>"] = {"hide",
"fallback"},
["<C-f>"] = {"scroll_documentation_down",
"fallback"},
["<S-Tab>"] = {"select_prev",
"fallback"},
["<Tab>"] = {"select_next",
"show",
"fallback"},
["preset"] = "none"}},
["completion"] = {["documentation"] = {["auto_show"] = true,
["auto_show_delay_ms"] = 200},
["list"] = {["selection"] = {["auto_insert"] = true,
["preselect"] = false}},
["menu"] = {["auto_show"] = true}},
["fuzzy"] = {["implementation"] = "prefer_rust",
["prebuilt_binaries"] = {["download"] = false}},
["keymap"] = {["<C-Space>"] = {"show",
"fallback"},
["<C-d>"] = {"scroll_documentation_up",
"fallback"},
["<C-e>"] = {"hide",
"fallback"},
["<C-f>"] = {"scroll_documentation_down",
"fallback"},
["<CR>"] = {"accept",
"fallback"},
["<S-Tab>"] = {"select_prev",
"snippet_backward",
"fallback"},
["<Tab>"] = {"select_next",
"snippet_forward",
function(cmp)
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
if has_words_before then
return cmp.show()
end
end
,
"fallback"},
["preset"] = "none"},
["sources"] = {["default"] = {"lsp",
"path",
"snippets",
"buffer"},
["providers"] = {}}})
end
},
{"crates-nvim",
["after"] = function()
require("crates").setup({["completion"] = {["crates"] = {["enabled"] = true,
["max_results"] = 8,
["min_chars"] = 3}},
["lsp"] = {["actions"] = true,
["completion"] = true,
["enabled"] = true,
["hover"] = true}})
end
,
["event"] = {{["event"] = "BufRead",
["pattern"] = "Cargo.toml"}}}})
require('lzn-auto-require').enable()
-- SECTION: pluginConfigs
-- SECTION: conform-nvim
require("conform").setup({["default_format_opts"] = {["lsp_format"] = "fallback"},
["format_after_save"] = function()
if not vim.g.formatsave or vim.b.disableFormatSave then
return
else
return {["lsp_format"] = "fallback"}
end
end
,
["format_on_save"] = function()
if not vim.g.formatsave or vim.b.disableFormatSave then
return
else
return {lsp_format = "fallback", timeout_ms = 500}
end
end
,
["formatters"] = {["cabal-fmt"] = {["command"] = "/nix/store/88f0kylayws4yznm4kg0bw5jd4y7s5v3-cabal-fmt-0.1.12-bin/bin/cabal-fmt"},
["nixfmt"] = {["command"] = "/nix/store/sgijssgx5ylh2vhajwp98f9sbhsdwhjy-nixfmt-1.3.1/bin/nixfmt"},
["ormolu"] = {["command"] = "/nix/store/7g70hdmw7hpan2rgvklrsfpy1lwd8jks-ormolu-0.8.0.2-bin/bin/ormolu"},
["rustfmt"] = {["command"] = "/nix/store/1x0ba5x31jqzhhk02qz4lxkznmp6q3nl-rustfmt-1.95.0/bin/rustfmt"}},
["formatters_by_ft"] = {["cabal"] = {"cabal-fmt"},
["haskell"] = {"ormolu"},
["lhaskell"] = {"ormolu"},
["nix"] = {"nixfmt"},
["rust"] = {"rustfmt"}}})
-- SECTION: lsp-setup
vim.g.formatsave = true;
local attach_keymaps = function(client, bufnr)
vim.keymap.set('n', "<leader>lgD", vim.lsp.buf.declaration, {buffer=bufnr, noremap=true, silent=true, desc="Go to declaration"})
vim.keymap.set('n', "<leader>lgd", vim.lsp.buf.definition, {buffer=bufnr, noremap=true, silent=true, desc="Go to definition"})
vim.keymap.set('n', "<leader>lgt", vim.lsp.buf.type_definition, {buffer=bufnr, noremap=true, silent=true, desc="Go to type"})
vim.keymap.set('n', "<leader>lgi", vim.lsp.buf.implementation, {buffer=bufnr, noremap=true, silent=true, desc="List implementations"})
vim.keymap.set('n', "<leader>lgr", vim.lsp.buf.references, {buffer=bufnr, noremap=true, silent=true, desc="List references"})
vim.keymap.set('n', "<leader>lgn", vim.diagnostic.goto_next, {buffer=bufnr, noremap=true, silent=true, desc="Go to next diagnostic"})
vim.keymap.set('n', "<leader>lgp", vim.diagnostic.goto_prev, {buffer=bufnr, noremap=true, silent=true, desc="Go to previous diagnostic"})
vim.keymap.set('n', "<leader>le", vim.diagnostic.open_float, {buffer=bufnr, noremap=true, silent=true, desc="Open diagnostic float"})
vim.keymap.set('n', "<leader>lH", vim.lsp.buf.document_highlight, {buffer=bufnr, noremap=true, silent=true, desc="Document highlight"})
vim.keymap.set('n', "<leader>lS", vim.lsp.buf.document_symbol, {buffer=bufnr, noremap=true, silent=true, desc="List document symbols"})
vim.keymap.set('n', "<leader>lwa", vim.lsp.buf.add_workspace_folder, {buffer=bufnr, noremap=true, silent=true, desc="Add workspace folder"})
vim.keymap.set('n', "<leader>lwr", vim.lsp.buf.remove_workspace_folder, {buffer=bufnr, noremap=true, silent=true, desc="Remove workspace folder"})
vim.keymap.set('n', "<leader>lwl", function() vim.notify(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, {buffer=bufnr, noremap=true, silent=true, desc="List workspace folders"})
vim.keymap.set('n', "<leader>lws", vim.lsp.buf.workspace_symbol, {buffer=bufnr, noremap=true, silent=true, desc="List workspace symbols"})
vim.keymap.set('n', "<leader>lh", vim.lsp.buf.hover, {buffer=bufnr, noremap=true, silent=true, desc="Trigger hover"})
vim.keymap.set('n', "<leader>ls", vim.lsp.buf.signature_help, {buffer=bufnr, noremap=true, silent=true, desc="Signature help"})
vim.keymap.set('n', "<leader>ln", vim.lsp.buf.rename, {buffer=bufnr, noremap=true, silent=true, desc="Rename symbol"})
vim.keymap.set('n', "<leader>la", vim.lsp.buf.code_action, {buffer=bufnr, noremap=true, silent=true, desc="Code action"})
vim.keymap.set('n', "<leader>lf", vim.lsp.buf.format, {buffer=bufnr, noremap=true, silent=true, desc="Format"})
vim.keymap.set('n', "<leader>ltf", function() vim.b.disableFormatSave = not vim.b.disableFormatSave end, {buffer=bufnr, noremap=true, silent=true, desc="Toggle format on save"})
end
default_on_attach = function(client, bufnr)
attach_keymaps(client, bufnr)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('blink.cmp').get_lsp_capabilities()
-- SECTION: nvim-lint
require("lint").linters_by_ft = {["nix"] = {"statix",
"deadnix"}}
local linters = require("lint").linters
local nvf_linters = {["deadnix"] = {["cmd"] = "/nix/store/ddy7ba32ww1hz9x4pvir84s5x3np5i5c-deadnix-1.3.1/bin/deadnix"},
["statix"] = {["cmd"] = "/nix/store/v5wmprihi3ywkh9ksdvwgiixrxj29r66-statix-0-unstable-2026-05-14/bin/statix"}}
for linter, config in pairs(nvf_linters) do
if linters[linter] == nil then
linters[linter] = config
else
for key, val in pairs(config) do
linters[linter][key] = val
end
end
end
nvf_lint = function(buf)
local ft = vim.api.nvim_get_option_value("filetype", { buf = buf })
local linters = require("lint").linters
local linters_from_ft = require("lint").linters_by_ft[ft]
-- if no linter is configured for this filetype, stops linting
if linters_from_ft == nil then return end
for _, name in ipairs(linters_from_ft) do
local linter = linters[name]
assert(linter, 'Linter with name `' .. name .. '` not available')
if type(linter) == "function" then
linter = linter()
end
-- for require("lint").lint() to work, linter.name must be set
linter.name = linter.name or name
local cwd = linter.required_files
-- if no configuration files are configured, lint
if cwd == nil then
require("lint").lint(linter)
else
-- if configuration files are configured and present in the project, lint
for _, fn in ipairs(cwd) do
local path = vim.fs.joinpath(linter.cwd or vim.fn.getcwd(), fn);
if vim.uv.fs_stat(path) then
require("lint").lint(linter)
break
end
end
end
end
end
-- SECTION: rustaceanvim
vim.g.rustaceanvim = {
-- LSP
tools = {
hover_actions = {
replace_builtin_hover = false
},
},
server = {
cmd = {"/nix/store/qjnh4ffw6qkydcsh0i8jl3wf6yvf9n8r-rust-analyzer-2026-06-01/bin/rust-analyzer"},
default_settings = {
},
on_attach = function(client, bufnr)
default_on_attach(client, bufnr)
local opts = { noremap=true, silent=true, buffer = bufnr }
vim.keymap.set("n", "<localleader>rr", ":RustLsp runnables<CR>", opts)
vim.keymap.set("n", "<localleader>rp", ":RustLsp parentModule<CR>", opts)
vim.keymap.set("n", "<localleader>rm", ":RustLsp expandMacro<CR>", opts)
vim.keymap.set("n", "<localleader>rc", ":RustLsp openCargo", opts)
vim.keymap.set("n", "<localleader>rg", ":RustLsp crateGraph x11", opts)
end
},
}
-- SECTION: augroups
local nvf_autogroups = {}
for _, group in ipairs({{["clear"] = true,
["enable"] = true,
["name"] = "nvf_nvim_lint"},
{["clear"] = true,
["enable"] = true,
["name"] = "nvf_lazy_file_hooks"},
{["clear"] = true,
["enable"] = true,
["name"] = "nvf_lsp"}}) do
if group.name then
nvf_autogroups[group.name] = { clear = group.clear }
end
end
for group_name, options in pairs(nvf_autogroups) do
vim.api.nvim_create_augroup(group_name, options)
end
-- SECTION: autocmds
local nvf_autocommands = {{["callback"] = function(args)
nvf_lint(args.buf)
end
,
["enable"] = true,
["event"] = {"BufWritePost"},
["nested"] = false,
["once"] = false},
{["command"] = "doautocmd User LazyFile",
["enable"] = true,
["event"] = {"BufReadPost",
"BufNewFile",
"BufWritePre"},
["group"] = "nvf_lazy_file_hooks",
["nested"] = false,
["once"] = true},
{["callback"] = function(event)
local bufnr = event.buf
local client = vim.lsp.get_client_by_id(event.data.client_id)
default_on_attach(client, bufnr)
end
,
["desc"] = "LSP on-attach add keybinds, enable inlay hints, and other plugin integrations",
["enable"] = true,
["event"] = {"LspAttach"},
["group"] = "nvf_lsp",
["nested"] = false,
["once"] = false},
{["command"] = "if line(\"'\\\"\") <= line(\"$\") | execute \"normal! g`\\\"\" | else | execute \"normal! G\" | endif",
["enable"] = true,
["event"] = {"BufReadPost"},
["nested"] = false,
["once"] = false},
{["command"] = "set expandtab shiftwidth=2 tabstop=2",
["enable"] = true,
["event"] = {"BufEnter"},
["nested"] = false,
["once"] = false,
["pattern"] = {"*.nix"}},
{["command"] = "set expandtab shiftwidth=2 tabstop=2",
["enable"] = true,
["event"] = {"BufEnter"},
["nested"] = false,
["once"] = false,
["pattern"] = {"*.hs"}}}
for _, autocmd in ipairs(nvf_autocommands) do
vim.api.nvim_create_autocmd(
autocmd.event,
{
group = autocmd.group,
pattern = autocmd.pattern,
buffer = autocmd.buffer,
desc = autocmd.desc,
callback = autocmd.callback,
command = autocmd.command,
once = autocmd.once,
nested = autocmd.nested
}
)
end
-- SECTION: lsp-util
-- Port of nvim-lspconfig util
local util = { path = {} }
util.default_config = {
log_level = vim.lsp.protocol.MessageType.Warning,
message_level = vim.lsp.protocol.MessageType.Warning,
settings = vim.empty_dict(),
init_options = vim.empty_dict(),
handlers = {},
autostart = true,
capabilities = vim.lsp.protocol.make_client_capabilities(),
}
-- global on_setup hook
util.on_setup = nil
do
local validate = vim.validate
local api = vim.api
local lsp = vim.lsp
local nvim_eleven = vim.fn.has 'nvim-0.11' == 1
local iswin = vim.uv.os_uname().version:match 'Windows'
local function escape_wildcards(path)
return path:gsub('([%[%]%?%*])', '\\%1')
end
local function is_fs_root(path)
if iswin then
return path:match '^%a:$'
else
return path == '/'
end
end
local function traverse_parents(path, cb)
path = vim.uv.fs_realpath(path)
local dir = path
-- Just in case our algo is buggy, don't infinite loop.
for _ = 1, 100 do
dir = vim.fs.dirname(dir)
if not dir then
return
end
-- If we can't ascend further, then stop looking.
if cb(dir, path) then
return dir, path
end
if is_fs_root(dir) then
break
end
end
end
util.root_pattern = function(...)
local patterns = util.tbl_flatten { ... }
return function(startpath)
startpath = util.strip_archive_subpath(startpath)
for _, pattern in ipairs(patterns) do
local match = util.search_ancestors(startpath, function(path)
for _, p in ipairs(vim.fn.glob(table.concat({ escape_wildcards(path), pattern }, '/'), true, true)) do
if vim.uv.fs_stat(p) then
return path
end
end
end)
if match ~= nil then
return match
end
end
end
end
util.root_markers_with_field = function(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
local found = vim.fs.find(new_names, { path = path, upward = true })
for _, f in ipairs(found or {}) do
-- Match the given `field`.
for line in io.lines(f) do
if line:find(field) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
end
end
return root_files
end
util.insert_package_json = function(root_files, field, fname)
return util.root_markers_with_field(root_files, { 'package.json', 'package.json5' }, field, fname)
end
util.strip_archive_subpath = function(path)
-- Matches regex from zip.vim / tar.vim
path = vim.fn.substitute(path, 'zipfile://\\(.\\{-}\\)::[^\\\\].*$', '\\1', '')
path = vim.fn.substitute(path, 'tarfile:\\(.\\{-}\\)::.*$', '\\1', '')
return path
end
util.get_typescript_server_path = function(root_dir)
local project_roots = vim.fs.find('node_modules', { path = root_dir, upward = true, limit = math.huge })
for _, project_root in ipairs(project_roots) do
local typescript_path = project_root .. '/typescript'
local stat = vim.loop.fs_stat(typescript_path)
if stat and stat.type == 'directory' then
return typescript_path .. '/lib'
end
end
return ''
end
util.search_ancestors = function(startpath, func)
if nvim_eleven then
validate('func', func, 'function')
end
if func(startpath) then
return startpath
end
local guard = 100
for path in vim.fs.parents(startpath) do
-- Prevent infinite recursion if our algorithm breaks
guard = guard - 1
if guard == 0 then
return
end
if func(path) then
return path
end
end
end
util.path.is_descendant = function(root, path)
if not path then
return false
end
local function cb(dir, _)
return dir == root
end
local dir, _ = traverse_parents(path, cb)
return dir == root
end
util.tbl_flatten = function(t)
--- @diagnostic disable-next-line:deprecated
return nvim_eleven and vim.iter(t):flatten(math.huge):totable() or vim.tbl_flatten(t)
end
end
-- SECTION: lsp-servers
-- Individual LSP configurations managed by nvf.
vim.lsp.config["*"] = {["capabilities"] = capabilities,
["enable"] = true}
vim.lsp.config["clangd"] = {["capabilities"] = {["offsetEncoding"] = {"utf-8",
"utf-16"},
["textDocument"] = {["completion"] = {["editsNearCursor"] = true}}},
["cmd"] = {"/nix/store/kvpilgp8anmfppznpvczb34y3wfdbhaj-clang-tools-21.1.8/bin/clangd"},
["enable"] = true,
["filetypes"] = {"c",
"cpp",
"objc",
"objcpp",
"cuda",
"proto"},
["on_attach"] = function(client, bufnr)
local function switch_source_header(bufnr)
local method_name = "textDocument/switchSourceHeader"
local client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd", })[1]
if not client then
return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name))
end
local params = vim.lsp.util.make_text_document_params(bufnr)
client.request(method_name, params, function(err, result)
if err then
error(tostring(err))
end
if not result then
vim.notify('corresponding file cannot be determined')
return
end
vim.cmd.edit(vim.uri_to_fname(result))
end, bufnr)
end
local function symbol_info()
local bufnr = vim.api.nvim_get_current_buf()
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
if not clangd_client or not clangd_client:supports_method 'textDocument/symbolInfo' then
return vim.notify('Clangd client not found', vim.log.levels.ERROR)
end
local win = vim.api.nvim_get_current_win()
local params = vim.lsp.util.make_position_params(win, clangd_client.offset_encoding)
clangd_client:request('textDocument/symbolInfo', params, function(err, res)
if err or #res == 0 then
-- Clangd always returns an error, there is not reason to parse it
return
end
local container = string.format('container: %s', res[1].containerName) ---@type string
local name = string.format('name: %s', res[1].name) ---@type string
vim.lsp.util.open_floating_preview({ name, container }, "", {
height = 2,
width = math.max(string.len(name), string.len(container)),
focusable = false,
focus = false,
border = 'single',
title = 'Symbol Info',
})
end, bufnr)
end
vim.api.nvim_buf_create_user_command(
bufnr,
"ClangdSwitchSourceHeader",
function(arg)
switch_source_header(0)
end,
{desc = "Switch between source/header"}
)
vim.api.nvim_buf_create_user_command(
bufnr,
"ClangdShowSymbolInfo",
function(arg)
symbol_info()
end,
{desc = "Show symbol info"}
)
end
,
["root_markers"] = {".git",
".clangd",
".clang-tidy",
".clang-format",
"compile_commands.json",
"compile_flags.txt",
"configure.ac"}}
vim.lsp.config["haskell-language-server"] = {["cmd"] = {"/nix/store/9a0ri4dlsmhwd0fv2rqj6vl55ninjji5-haskell-language-server-wrapper/bin/haskell-language-server-wrapper",
"--lsp"},
["enable"] = true,
["filetypes"] = {"haskell",
"lhaskell"},
["root_markers"] = {"hie.yaml",
"stack.yaml",
"cabal.project",
"*.cabal",
"package.yaml"}}
vim.lsp.config["nil"] = {["cmd"] = {"/nix/store/1nm1a17mzb751hs9m2il1k5iv6x499df-nil-2025-06-13/bin/nil"},
["enable"] = true,
["filetypes"] = {"nix"},
["root_markers"] = {"flake.nix",
".git"}}
-- Enable configured LSPs explicitly
vim.lsp.enable({"clangd",
"haskell-language-server",
"nil"})
-- SECTION: mappings
vim.keymap.set({"n",
"v"}, ";", ":", {["expr"] = false,
["noremap"] = true,
["nowait"] = false,
["remap"] = false,
["script"] = false,
["silent"] = true,
["unique"] = false})
vim.keymap.set({"n"}, "<C-h>", "20zh", {["expr"] = false,
["noremap"] = true,
["nowait"] = false,
["remap"] = false,
["script"] = false,
["silent"] = true,
["unique"] = false})
vim.keymap.set({"n"}, "<C-l>", "20zl", {["expr"] = false,
["noremap"] = true,
["nowait"] = false,
["remap"] = false,
["script"] = false,
["silent"] = true,
["unique"] = false})
Activity
snoweuph commentedon Jul 21, 2026
what does
:ConformInfoshow?JustinCWeiler commentedon Jul 23, 2026
:ConformInfooutput:horriblename commentedon Jul 23, 2026
conform will use the LSP for formatting (if it supports it) if there is no formatters configured.
to disable format-on-save completely, you can use
<leader>ltfto disable per-buffer (seevim.lsp.mappings.toggleFormatOnSave), or setvim.g.formatsave = falseto disable on all files. The latter is an internal thing but I'll figure out a way to expose them properly in the docs soon