1
0
Fork 0

nvim: null-ls -> nvim-lint

Also use Neoformat as a fallback if no LSP formatter is attached
This commit is contained in:
Daniel Kempkens 2022-04-19 14:56:22 +02:00
parent 857592bb7c
commit 796fd8d12c
16 changed files with 120 additions and 105 deletions

View file

@ -0,0 +1,2 @@
(let [lo vim.opt_local]
(set lo.formatprg "fnlfmt -"))

View file

@ -0,0 +1,6 @@
(let [lo vim.opt_local]
(set lo.tabstop 4)
(set lo.shiftwidth 4)
(set lo.softtabstop 4)
(set lo.formatprg :fish_indent))

View file

@ -0,0 +1,3 @@
(let [lo vim.opt_local]
(set lo.formatprg "shfmt -i 2"))

View file

@ -89,8 +89,10 @@
(set g.loaded_getscriptPlugin 1) (set g.loaded_getscriptPlugin 1)
(set g.loaded_logipat 1) (set g.loaded_logipat 1)
(set g.loaded_tutor_mode_plugin 1) (set g.loaded_tutor_mode_plugin 1)
(let [diagnostic (require :nifoc.diagnostic)] (let [diagnostic (require :nifoc.diagnostic)
(diagnostic.setup)) formatting (require :nifoc.formatting)]
(diagnostic.setup)
(formatting.setup))
(require :configuration.plugins) (require :configuration.plugins)
;; Keymap ;; Keymap
(let [keymap (require :nifoc.keymap)] (let [keymap (require :nifoc.keymap)]

View file

@ -1,8 +1,7 @@
(let [mod {} (let [mod {}
cmd vim.cmd cmd vim.cmd
api vim.api api vim.api
keymap (require :nifoc.keymap) keymap (require :nifoc.keymap)]
lsp-format (require :lsp-format)]
(fn mod.setup [] (fn mod.setup []
(vim.diagnostic.config {:underline true (vim.diagnostic.config {:underline true
:virtual_text false :virtual_text false
@ -24,11 +23,4 @@
{:focus false}) {:focus false})
:buffer bufnr}))) :buffer bufnr})))
(fn mod.maybe-enable-fixer [client bufnr]
(when client.server_capabilities.documentRangeFormattingProvider
(api.nvim_buf_set_option bufnr :formatexpr "v:lua.vim.lsp.formatexpr()"))
(when client.server_capabilities.documentFormattingProvider
(api.nvim_buf_set_var bufnr :nifoc_fixer_enabled 1)
(lsp-format.on_attach client bufnr)))
mod) mod)

View file

@ -0,0 +1,25 @@
(let [mod {}
b vim.b
cmd vim.cmd
api vim.api]
(fn mod.setup []
(let [augroup (vim.api.nvim_create_augroup :NifocFormatting {:clear true})
aucmd vim.api.nvim_create_autocmd]
(aucmd :BufWritePre {:callback #(mod.maybe-format-buffer) :group augroup})))
(fn mod.maybe-enable-lsp [client bufnr]
(when client.server_capabilities.documentRangeFormattingProvider
(api.nvim_buf_set_option bufnr :formatexpr "v:lua.vim.lsp.formatexpr()"))
(when client.server_capabilities.documentFormattingProvider
(api.nvim_buf_set_var bufnr :nifoc_lsp_formatter_enabled 1)))
(fn mod.maybe-format-buffer []
(let [formatprg (vim.opt_local.formatprg:get)
formatprg-exe (-> formatprg (vim.split " " {:trimempty true}) (. 1))]
(if (= b.nifoc_lsp_formatter_enabled 1)
(vim.lsp.buf.formatting_sync nil 1000)
(not= formatprg-exe nil)
(cmd (.. "undojoin | Neoformat " formatprg-exe)))))
mod)

View file

@ -73,8 +73,6 @@
;; Debug ;; Debug
(map-entry :<leader>dli :<cmd>LspInfo<CR> (map-entry :<leader>dli :<cmd>LspInfo<CR>
{:description "LSP Info"}) {:description "LSP Info"})
(map-entry :<leader>dln :<cmd>NullLsInfo<CR>
{:description "null-ls Info"})
(map-entry :<leader>dlr :<cmd>LspRestart<CR> (map-entry :<leader>dlr :<cmd>LspRestart<CR>
{:description "LSP Restart"}) {:description "LSP Restart"})
(map-entry :<leader>dt (map-entry :<leader>dt
@ -141,3 +139,4 @@
:opts {:buffer bufnr}})])) :opts {:buffer bufnr}})]))
mod) mod)

View file

@ -49,7 +49,8 @@
(if (and (buffer-not-empty?) vim.wo.spell) "ﮒ" "")) (if (and (buffer-not-empty?) vim.wo.spell) "ﮒ" ""))
(fn mod.fixer-enabled? [] (fn mod.fixer-enabled? []
(if (buffer-variable-exists? :nifoc_fixer_enabled) "" "")) (if (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled)
(not= (vim.opt_local.formatprg:get) "")) "" ""))
(fn mod.treesitter-enabled? [] (fn mod.treesitter-enabled? []
(if (buffer-variable-exists? :nifoc_treesitter_enabled) "" "")) (if (buffer-variable-exists? :nifoc_treesitter_enabled) "" ""))
@ -58,3 +59,4 @@
(if (buffer-variable-exists? :nifoc_lsp_enabled) "" "")) (if (buffer-variable-exists? :nifoc_lsp_enabled) "" ""))
mod) mod)

View file

@ -3,7 +3,8 @@
illuminate (require :illuminate) illuminate (require :illuminate)
virtual-types (require :virtualtypes) virtual-types (require :virtualtypes)
cmp (require :cmp_nvim_lsp) cmp (require :cmp_nvim_lsp)
diagnostic (require :nifoc.diagnostic)] diagnostic (require :nifoc.diagnostic)
formatting (require :nifoc.formatting)]
(fn custom-attach [client bufnr] (fn custom-attach [client bufnr]
(when client.server_capabilities.documentSymbolProvider (when client.server_capabilities.documentSymbolProvider
(lsp-status.on_attach client bufnr)) (lsp-status.on_attach client bufnr))
@ -12,7 +13,7 @@
(when client.server_capabilities.codeLensProvider (when client.server_capabilities.codeLensProvider
(virtual-types.on_attach client bufnr)) (virtual-types.on_attach client bufnr))
(diagnostic.maybe-enable-lsp client bufnr) (diagnostic.maybe-enable-lsp client bufnr)
(diagnostic.maybe-enable-fixer client bufnr)) (formatting.maybe-enable-lsp client bufnr))
(fn custom-attach-no-format [client bufnr] (fn custom-attach-no-format [client bufnr]
(set client.server_capabilities.documentFormattingProvider false) (set client.server_capabilities.documentFormattingProvider false)
@ -25,8 +26,10 @@
:diagnostics false}) :diagnostics false})
(lsp-status.register_progress) (lsp-status.register_progress)
;; Custom handler ;; Custom handler
(tset vim.lsp.handlers "textDocument/hover" (vim.lsp.with vim.lsp.handlers.hover {:border "rounded"})) (tset vim.lsp.handlers :textDocument/hover
(tset vim.lsp.handlers "textDocument/signatureHelp" (vim.lsp.with vim.lsp.handlers.signature_help {:border "rounded"})) (vim.lsp.with vim.lsp.handlers.hover {:border :rounded}))
(tset vim.lsp.handlers :textDocument/signatureHelp
(vim.lsp.with vim.lsp.handlers.signature_help {:border :rounded}))
;; Servers ;; Servers
(let [default-capabilities (vim.lsp.protocol.make_client_capabilities) (let [default-capabilities (vim.lsp.protocol.make_client_capabilities)
capabilities (vim.tbl_extend :keep capabilities (vim.tbl_extend :keep
@ -34,7 +37,9 @@
lsp-status.capabilities) lsp-status.capabilities)
flags {:allow_incremental_sync true :debounce_text_changes 700} flags {:allow_incremental_sync true :debounce_text_changes 700}
default-config {:on_attach custom-attach : capabilities : flags} default-config {:on_attach custom-attach : capabilities : flags}
default-config-no-format {:on_attach custom-attach-no-format : capabilities : flags} default-config-no-format {:on_attach custom-attach-no-format
: capabilities
: flags}
default-servers [:bashls default-servers [:bashls
:cssls :cssls
:dockerls :dockerls
@ -50,13 +55,12 @@
((. lsp name :setup) default-config)) ((. lsp name :setup) default-config))
;; Custom ;; Custom
(lsp.elixirls.setup (->> {:cmd [:elixir-ls]} (lsp.elixirls.setup (->> {:cmd [:elixir-ls]}
(vim.tbl_extend :force default-config-no-format))) (vim.tbl_extend :force default-config)))
(lsp.tsserver.setup (->> {:cmd [:typescript-language-server (lsp.tsserver.setup (->> {:cmd [:typescript-language-server
:--stdio :--stdio
:--tsserver-path :--tsserver-path
:tsserver] :tsserver]}
:on_attach custom-attach-no-format} (vim.tbl_extend :force default-config-no-format)))
(vim.tbl_extend :force default-config)))
(lsp.jsonls.setup (->> {:cmd [:vscode-json-language-server :--stdio]} (lsp.jsonls.setup (->> {:cmd [:vscode-json-language-server :--stdio]}
(vim.tbl_extend :force default-config))) (vim.tbl_extend :force default-config)))
(lsp.solargraph.setup (->> {:settings {:solargraph {:diagnostics true}}} (lsp.solargraph.setup (->> {:settings {:solargraph {:diagnostics true}}}
@ -70,7 +74,5 @@
:path (vim.split package.path :path (vim.split package.path
";")} ";")}
:diagnostics {:globals [:vim]} :diagnostics {:globals [:vim]}
:workspace {:library {(vim.fn.expand "\$VIMRUNTIME/lua") true
(vim.fn.expand "\$VIMRUNTIME/lua/vim/lsp") true}}
:telemetry {:enable false}}}} :telemetry {:enable false}}}}
(vim.tbl_extend :force default-config))))) (vim.tbl_extend :force default-config)))))

View file

@ -0,0 +1,3 @@
(let [g vim.g]
(set g.neoformat_try_formatprg 1)
(set g.neoformat_basic_format_trim 1))

View file

@ -1,25 +0,0 @@
(let [null-ls (require :null-ls)
builtins null-ls.builtins
diagnostic (require :nifoc.diagnostic)]
(null-ls.setup {:debounce 700
:sources [; Formatting
builtins.formatting.fish_indent
builtins.formatting.fnlfmt
builtins.formatting.mix
(builtins.formatting.shfmt.with {:extra_args [:-i
:2]})
; Diagnostics
builtins.diagnostics.credo
builtins.diagnostics.deadnix
builtins.diagnostics.fish
builtins.diagnostics.hadolint
(builtins.diagnostics.shellcheck.with {:extra_args [:-f
:gcc
:-x]})
builtins.diagnostics.statix
; Code Actions
builtins.code_actions.shellcheck
builtins.code_actions.statix]
:on_attach (lambda [client bufnr]
(diagnostic.maybe-enable-lsp client bufnr)
(diagnostic.maybe-enable-fixer client bufnr))}))

View file

@ -0,0 +1,16 @@
(let [lint (require :lint)
augroup (vim.api.nvim_create_augroup :NifocLint {:clear true})
aucmd vim.api.nvim_create_autocmd]
(set lint.linters_by_ft {:dockerfile [:hadolint]
:elixir [:credo]
:fennel [:fennel]
:nix [:nix :statix]
:sh [:shellcheck]})
(fn setup-linting [opts]
(aucmd [:BufWritePost :BufWinEnter :InsertLeave]
{:callback #(lint.try_lint) :buffer opts.buf :group augroup}))
(each [ft _ (pairs lint.linters_by_ft)]
(aucmd :InsertEnter {:pattern ft :callback setup-linting :group augroup})))

View file

@ -96,11 +96,11 @@
}, },
"locked": { "locked": {
"dir": "contrib", "dir": "contrib",
"lastModified": 1650231013, "lastModified": 1650333806,
"narHash": "sha256-8Eb0+pUhFZpXZsO8wxmdcwJ4K82PBThEarAg7QmN1ic=", "narHash": "sha256-ZrnN9ssclGTChvomcqL4Uact8L9+yToywNwrjyUULgI=",
"owner": "neovim", "owner": "neovim",
"repo": "neovim", "repo": "neovim",
"rev": "1facad23473eb2d045fe77199b3b0b9fd2586895", "rev": "147cc60d24f093b5154824889f2151489774ef33",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -119,11 +119,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1650269777, "lastModified": 1650356316,
"narHash": "sha256-xTHOaVcKotrhhZIXBlI+i+7T/9i9g2IBaJ876ZgKWNQ=", "narHash": "sha256-RojfPzSC+veD2SCugaMNJ9c+TzD9hPIToWkC2venhrU=",
"owner": "nix-community", "owner": "nix-community",
"repo": "neovim-nightly-overlay", "repo": "neovim-nightly-overlay",
"rev": "bc6898a27fae45321c8ced1c422e07700e2ae451", "rev": "1c8ffbfa48d212eb806e3ea3eeae4c6c444130d5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -186,11 +186,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1650242648, "lastModified": 1650328756,
"narHash": "sha256-obFzwzRRlQGKhvmGYlZEwqI3bAMxvdNoTmxBmZ+Axao=", "narHash": "sha256-rA/Pdrl/vBpl/URdkF03bb7N8fp111OIP7+Aqb+YOKE=",
"owner": "arqv", "owner": "arqv",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "913098cca4e4d8ba68578de9203fe532d0886069", "rev": "77597e467567b462efce312d1c99b5a6dc24ea92",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -127,20 +127,12 @@ in
type = "fennel"; type = "fennel";
} }
{
plugin = null-ls-nvim;
config = builtins.readFile ../../config/nvim/plugins/null-ls.fnl;
type = "fennel";
}
virtual-types-nvim virtual-types-nvim
# Linter
{ {
plugin = lsp-format-nvim; plugin = nvim-lint;
config = '' config = builtins.readFile ../../config/nvim/plugins/nvim-lint.fnl;
(let [lsp-format (require :lsp-format)]
(lsp-format.setup))
'';
type = "fennel"; type = "fennel";
} }
@ -283,6 +275,13 @@ in
type = "fennel"; type = "fennel";
} }
# Formatting
{
plugin = neoformat;
config = builtins.readFile ../../config/nvim/plugins/neoformat.fnl;
type = "fennel";
}
# Comments # Comments
{ {
plugin = comment-nvim; plugin = comment-nvim;

View file

@ -111,12 +111,12 @@
}; };
nvim-treesitter = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-treesitter = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-treesitter"; pname = "nvim-treesitter";
version = "1650300646"; version = "1650354015";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "nvim-treesitter"; owner = "nvim-treesitter";
repo = "nvim-treesitter"; repo = "nvim-treesitter";
rev = "a8bce851bf3bde7c9c25b1d504dc25c877d66713"; rev = "6f6cb20692049eb610d3210816869da8aba0a6e8";
sha256 = "dYjGt8x209i/SKtDQLLrJsuEM4L/9tXyTcPsvpILtQw="; sha256 = "aH52YKr57eevBRT6t4pGe9UFIMn9/R2XhEnzKuXDZ3k=";
fetchSubmodules = true; fetchSubmodules = true;
}; };
meta.homepage = "https://github.com/nvim-treesitter/nvim-treesitter"; meta.homepage = "https://github.com/nvim-treesitter/nvim-treesitter";
@ -200,18 +200,6 @@
}; };
meta.homepage = "https://github.com/neovim/nvim-lspconfig"; meta.homepage = "https://github.com/neovim/nvim-lspconfig";
}; };
null-ls-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "null-ls.nvim";
version = "1650144148";
src = pkgs.fetchFromGitHub {
owner = "jose-elias-alvarez";
repo = "null-ls.nvim";
rev = "a887bd6c1bb992ccf48e673b40e061c3e816204f";
sha256 = "gbo5sMd+mT/U1nQYAci2pdYNEOg/qFrpVfv6gVawLtY=";
fetchSubmodules = true;
};
meta.homepage = "https://github.com/jose-elias-alvarez/null-ls.nvim";
};
virtual-types-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { virtual-types-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "virtual-types.nvim"; pname = "virtual-types.nvim";
version = "1647533682"; version = "1647533682";
@ -224,17 +212,17 @@
}; };
meta.homepage = "https://github.com/jubnzv/virtual-types.nvim"; meta.homepage = "https://github.com/jubnzv/virtual-types.nvim";
}; };
lsp-format-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-lint = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "lsp-format.nvim"; pname = "nvim-lint";
version = "1650261785"; version = "1650293110";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "lukas-reineke"; owner = "mfussenegger";
repo = "lsp-format.nvim"; repo = "nvim-lint";
rev = "454ec5f0ef6c2712da3f3982155f7a992faa8a00"; rev = "e5416bdb27a0e61cd213850646534a18bb2ba61d";
sha256 = "gYXv2g4vmx4/bAsU/BUZK04TwHXua6tZ97LBUwGQ/kM="; sha256 = "v4bItOqhrutK7Wr/pM1Pkx+lGFTGrLoZ88esm1K/MuM=";
fetchSubmodules = true; fetchSubmodules = true;
}; };
meta.homepage = "https://github.com/lukas-reineke/lsp-format.nvim"; meta.homepage = "https://github.com/mfussenegger/nvim-lint";
}; };
LuaSnip = pkgs.vimUtils.buildVimPluginFrom2Nix { LuaSnip = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "LuaSnip"; pname = "LuaSnip";
@ -250,12 +238,12 @@
}; };
nvim-cmp = pkgs.vimUtils.buildVimPluginFrom2Nix { nvim-cmp = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-cmp"; pname = "nvim-cmp";
version = "1650293446"; version = "1650365016";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "hrsh7th"; owner = "hrsh7th";
repo = "nvim-cmp"; repo = "nvim-cmp";
rev = "2aa7eee28b4d49e999c694ca733a393da5808dd6"; rev = "07132dc597e94a8b6df75efce9784a581f55742c";
sha256 = "Ws6hjdtOP14hG0BYm88RooZMbIVWAqlyYUOBDoonw3A="; sha256 = "9wPv8mXax2fr1L6TeiFOSK7ZdXNg1v/1eRj00OFDw1Y=";
fetchSubmodules = true; fetchSubmodules = true;
}; };
meta.homepage = "https://github.com/hrsh7th/nvim-cmp"; meta.homepage = "https://github.com/hrsh7th/nvim-cmp";
@ -406,12 +394,12 @@
}; };
vim-matchup = pkgs.vimUtils.buildVimPluginFrom2Nix { vim-matchup = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "vim-matchup"; pname = "vim-matchup";
version = "1645154316"; version = "1650317917";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "andymass"; owner = "andymass";
repo = "vim-matchup"; repo = "vim-matchup";
rev = "7fd8806138f404498db7a3e848d8fa55ad61e7cf"; rev = "8727de1b4311c0ad62682f724fa19fce6ec4dad3";
sha256 = "94MxL1tajiKfgA8gpu2cO3jQmRj64Kg80efzlgHfMhg="; sha256 = "3oKc9M853+KOw3Bc5jOG2SO96B7XKoFENCSPR22yEGs=";
fetchSubmodules = true; fetchSubmodules = true;
}; };
meta.homepage = "https://github.com/andymass/vim-matchup"; meta.homepage = "https://github.com/andymass/vim-matchup";
@ -478,12 +466,12 @@
}; };
gitsigns-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { gitsigns-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "gitsigns.nvim"; pname = "gitsigns.nvim";
version = "1650291976"; version = "1650366768";
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "lewis6991"; owner = "lewis6991";
repo = "gitsigns.nvim"; repo = "gitsigns.nvim";
rev = "565b94d79c760b0aa877a6cc28dc04f08c411c8e"; rev = "6527d8c847d1cf11bbf646ac00b1cc2c4ac41c74";
sha256 = "mwZfQEovDXVS7TlS8UcJVSk4Odmiv1PcQaQumNihcoI="; sha256 = "wDTkFVif4cel0zqAYx78pceQYMJMBpBmlT2pGDUvI8o=";
fetchSubmodules = true; fetchSubmodules = true;
}; };
meta.homepage = "https://github.com/lewis6991/gitsigns.nvim"; meta.homepage = "https://github.com/lewis6991/gitsigns.nvim";

View file

@ -33,11 +33,12 @@
rm -rf ./xdg_cache rm -rf ./xdg_cache
- src: nvim-telescope/telescope-ui-select.nvim - src: nvim-telescope/telescope-ui-select.nvim
# # LSP # LSP
- src: neovim/nvim-lspconfig - src: neovim/nvim-lspconfig
- src: jose-elias-alvarez/null-ls.nvim
- src: jubnzv/virtual-types.nvim - src: jubnzv/virtual-types.nvim
- src: lukas-reineke/lsp-format.nvim
# Linter
- src: mfussenegger/nvim-lint
# Snippets # Snippets
- src: L3MON4D3/LuaSnip - src: L3MON4D3/LuaSnip