From 6c610fea29c0677f79c1eb984f1e649f96d4ca64 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Sat, 4 Nov 2023 21:42:53 +0000
Subject: [PATCH] feat(nvim): use rstfmt for rst file formatting

Add `vimPlugins.conform-nvim` to add formatting rst files with `rstfmt`.

This isn't supported as a formatter in `none-ls`, and I wanted to try
and potentially switch to `conform-nvim` and `nvim-lint` in the future,
so this is a potential first step towards that.

`rstfmt` itself is already installed and available within my additional
Vim packages.

This currently needs to be run manually, as I don't want to change my
default keybind for formatting until I've supported all the filetypes and formatters
I have in `none-ls`.

To run the foramt manually, run `:lua require"conform".format()`.

See:

- https://github.com/stevearc/conform.nvim
- https://github.com/mfussenegger/nvim-lint
- https://pypi.org/project/rstfmt
- https://www.youtube.com/watch?v=ybUE4D80XSk
---
 config/neovim/after/plugin/conform.lua | 11 +++++++++++
 system/shared/home-manager.nix         |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 config/neovim/after/plugin/conform.lua

diff --git a/config/neovim/after/plugin/conform.lua b/config/neovim/after/plugin/conform.lua
new file mode 100644
index 00000000..6c472346
--- /dev/null
+++ b/config/neovim/after/plugin/conform.lua
@@ -0,0 +1,11 @@
+local conform = require "conform"
+
+conform.setup {
+  formatters_by_ft = {
+    rst = { "rstfmt" },
+  },
+}
+
+conform.formatters.rstfmt = {
+  command = "rstfmt";
+}
diff --git a/system/shared/home-manager.nix b/system/shared/home-manager.nix
index f77b2be7..e40a511e 100644
--- a/system/shared/home-manager.nix
+++ b/system/shared/home-manager.nix
@@ -595,7 +595,8 @@ in
       vimPlugins.nvim-treesitter-context
       vimPlugins.nvim-treesitter-textobjects
 
-      # LSP
+      # LSP, linting and formatting
+      pkgsUnstable.vimPlugins.conform-nvim
       pkgsUnstable.vimPlugins.none-ls-nvim
       vimPlugins.lsp-status-nvim
       vimPlugins.nvim-lspconfig