Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'mfussenegger/nvim-lint'
- Plug 'mhartington/formatter.nvim'
+
+ if has('nvim-0.10')
+ Plug 'stevearc/conform.nvim'
+ Plug 'shuber2/mason-conform', {'branch': 'fix-autoinstall-registrywarning'}
+ else
+ Plug 'mhartington/formatter.nvim'
+ endif
endif
-- end
}
- local formatter = require("formatter")
-
- -- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
- require("formatter").setup {
- -- Enable or disable logging
- logging = true,
- -- Set the log level
- log_level = vim.log.levels.WARN,
- -- All formatter configurations are opt-in
- filetype = {
- bib = {
- function()
- return {
- exe = "bibtex-tidy"
- }
- end
+ -- Conform requires nvim-0.10
+ if vim.fn.has('nvim-0.10') == 1 then
+ require("mason-conform").setup({})
+ require("conform").setup({
+ formatters_by_ft = {
+ bib = { "bibtex-tidy"},
},
- c = { require("formatter.filetypes.c").clangformat },
- cpp = { require("formatter.filetypes.cpp").clangformat },
- css = require('formatter.filetypes.css').prettier,
- html = require('formatter.filetypes.html').prettier,
- java = { require("formatter.filetypes.java").clangformat },
- javascript = require('formatter.filetypes.javascript').prettier,
- json = require('formatter.filetypes.json').jq,
- python = { require("formatter.filetypes.python").autopep8 },
- xml = { require("formatter.filetypes.xml").xmllint },
- lua = { require("formatter.filetypes.lua").stylua },
-
- -- Use the special "*" filetype for defining formatter configurations on
- -- any filetype
- ["*"] = {
- -- "formatter.filetypes.any" defines default configurations for any
- -- filetype
- require("formatter.filetypes.any").remove_trailing_whitespace
+ })
+
+ -- https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md#format-command
+ vim.api.nvim_create_user_command("Format",
+ function(args)
+ local range = nil
+ if args.count ~= -1 then
+ local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
+ range = {
+ start = { args.line1, 0 },
+ ["end"] = { args.line2, end_line:len() },
+ }
+ end
+ require("conform").format({ async = true, lsp_format = "fallback", range = range })
+ end,
+ { range = true }
+ )
+ else
+ local formatter = require("formatter")
+
+ -- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
+ require("formatter").setup {
+ -- Enable or disable logging
+ logging = true,
+ -- Set the log level
+ log_level = vim.log.levels.WARN,
+ -- All formatter configurations are opt-in
+ filetype = {
+ bib = {
+ function()
+ return {
+ exe = "bibtex-tidy"
+ }
+ end
+ },
+ c = { require("formatter.filetypes.c").clangformat },
+ cpp = { require("formatter.filetypes.cpp").clangformat },
+ css = require('formatter.filetypes.css').prettier,
+ html = require('formatter.filetypes.html').prettier,
+ java = { require("formatter.filetypes.java").clangformat },
+ javascript = require('formatter.filetypes.javascript').prettier,
+ json = require('formatter.filetypes.json').jq,
+ python = { require("formatter.filetypes.python").autopep8 },
+ xml = { require("formatter.filetypes.xml").xmllint },
+ lua = { require("formatter.filetypes.lua").stylua },
+
+ -- Use the special "*" filetype for defining formatter configurations on
+ -- any filetype
+ ["*"] = {
+ -- "formatter.filetypes.any" defines default configurations for any
+ -- filetype
+ require("formatter.filetypes.any").remove_trailing_whitespace
+ }
+ }
}
- }
- }
+ end
require('lint').linters_by_ft = {
gitcommit = {'gitlint',},