Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Implement command CSFixUsings #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

StefanFanaru
Copy link

@StefanFanaru StefanFanaru commented May 23, 2024

I've added a nvim user command that allows you to remove all unecesarry using directives from the current buffer.
:CSFixUsings

You can set it up with conform.nvim to be executed every time you format the buffer:

{
	"stevearc/conform.nvim",
	keys = {
		{
			"<leader>f",
			function()
				require("conform").format({ async = true, lsp_fallback = true })
				if vim.bo[0].filetype == "cs" then
					vim.cmd("CSFixUsings")
				end
			end,
			mode = "",
			desc = "[F]ormat buffer",
		},
	},
	(...)
}

And/or you can set it up to run automatically when you write your buffer

vim.api.nvim_create_autocmd("BufWritePre", {
	pattern = "*",
	callback = function(args)
		if vim.bo[0].filetype == "cs" then
			vim.cmd("CSFixUsings")
		end
		-- optional, if you use conform and want this
		require("conform").format({ bufnr = args.buf })
	end,
})

Waiting for your feedback.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant