From edf06af994e3287bca5e6228a7b75c0734606700 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 2 Dec 2022 22:31:37 -0500 Subject: [PATCH] pretty, null-ls w/ lua sql nix prettier --- bash/default.nix | 2 +- home.nix | 20 +++--- htop/default.nix | 1 - iterm2/default.nix | 1 - nvim/config/lua/aerial-config.lua | 8 +-- nvim/config/lua/base.lua | 8 +-- nvim/config/lua/cmp-config.lua | 100 ++++++++++++--------------- nvim/config/lua/init.lua | 2 +- nvim/config/lua/lsp-config.lua | 62 ++++++++--------- nvim/config/lua/lsp-lines-config.lua | 4 +- nvim/config/lua/lualine-config.lua | 8 +-- nvim/config/lua/neoformat-config.lua | 10 --- nvim/config/lua/noice-config.lua | 40 +++++------ nvim/config/lua/null-ls-config.lua | 28 ++++++++ nvim/config/lua/telescope-config.lua | 14 ++-- nvim/config/lua/ts-config.lua | 5 +- nvim/default.nix | 54 ++++++++------- 17 files changed, 180 insertions(+), 187 deletions(-) delete mode 100644 nvim/config/lua/neoformat-config.lua create mode 100644 nvim/config/lua/null-ls-config.lua diff --git a/bash/default.nix b/bash/default.nix index 5121cfd..81e59f1 100644 --- a/bash/default.nix +++ b/bash/default.nix @@ -6,7 +6,7 @@ shellAliases = { grep = "grep --color"; }; - profileExtra ='' + profileExtra = '' set -o vi [ ! -z $TMUX ] || tmux a || tmux neofetch diff --git a/home.nix b/home.nix index d81db02..fd9d605 100644 --- a/home.nix +++ b/home.nix @@ -36,7 +36,7 @@ in tldr ] ++ optionals isDarwin [ iterm2 - ] ++ optionals isLinux []; + ] ++ optionals isLinux [ ]; # Misc Programs programs.jq.enable = true; @@ -50,13 +50,15 @@ in # Darwin Spotlight Indexing Hack home.activation = mkIf isDarwin { - copyApplications = let - apps = pkgs.buildEnv { - name = "home-manager-applications"; - paths = config.home.packages; - pathsToLink = "/Applications"; - }; - in lib.hm.dag.entryAfter [ "writeBoundary" ] '' + copyApplications = + let + apps = pkgs.buildEnv { + name = "home-manager-applications"; + paths = config.home.packages; + pathsToLink = "/Applications"; + }; + in + lib.hm.dag.entryAfter [ "writeBoundary" ] '' baseDir="$HOME/Applications/Home Manager Apps" if [ -d "$baseDir" ]; then rm -rf "$baseDir" @@ -67,7 +69,7 @@ in $DRY_RUN_CMD cp ''${VERBOSE_ARG:+-v} -fHRL "$appFile" "$baseDir" $DRY_RUN_CMD chmod ''${VERBOSE_ARG:+-v} -R +w "$target" done - ''; + ''; }; # Darwin Spotlight Indexing Hack diff --git a/htop/default.nix b/htop/default.nix index 1aa61c2..1191125 100644 --- a/htop/default.nix +++ b/htop/default.nix @@ -5,4 +5,3 @@ source = ./config/htoprc; }; } - diff --git a/iterm2/default.nix b/iterm2/default.nix index 50512f3..0e0dd3c 100644 --- a/iterm2/default.nix +++ b/iterm2/default.nix @@ -10,4 +10,3 @@ in }; }; } - diff --git a/nvim/config/lua/aerial-config.lua b/nvim/config/lua/aerial-config.lua index 21851a2..2e75b4c 100644 --- a/nvim/config/lua/aerial-config.lua +++ b/nvim/config/lua/aerial-config.lua @@ -1,8 +1,8 @@ require('aerial').setup({ - on_attach = function(bufnr) - vim.keymap.set('n', '{', 'AerialPrev', {buffer = bufnr}) - vim.keymap.set('n', '}', 'AerialNext', {buffer = bufnr}) - end + on_attach = function(bufnr) + vim.keymap.set('n', '{', 'AerialPrev', {buffer = bufnr}) + vim.keymap.set('n', '}', 'AerialNext', {buffer = bufnr}) + end }) vim.keymap.set('n', 'a', 'AerialToggle!') diff --git a/nvim/config/lua/base.lua b/nvim/config/lua/base.lua index 51ffb61..380d813 100644 --- a/nvim/config/lua/base.lua +++ b/nvim/config/lua/base.lua @@ -2,11 +2,11 @@ vim.g.nord_borders = true vim.g.nord_contrast = true vim.cmd('colorscheme nord') ---vim.cmd('colorscheme embark') ---vim.cmd('colorscheme gruvbox-material') +-- vim.cmd('colorscheme embark') +-- vim.cmd('colorscheme gruvbox-material') -- Set Leader -vim.keymap.set("n", "", "", { silent = true }) +vim.keymap.set("n", "", "", {silent = true}) vim.g.mapleader = " " -- Disable NetRW @@ -41,7 +41,7 @@ vim.opt.foldlevel = 2 -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap=true, silent=true } +local opts = {noremap = true, silent = true} vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) diff --git a/nvim/config/lua/cmp-config.lua b/nvim/config/lua/cmp-config.lua index 7498dff..d57ff3c 100644 --- a/nvim/config/lua/cmp-config.lua +++ b/nvim/config/lua/cmp-config.lua @@ -1,81 +1,71 @@ local cmp = require('cmp') require("luasnip.loaders.from_vscode").lazy_load() - -- Check Tab Completion local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, + col) + :match("%s") == nil end cmp.setup({ - snippet = { - expand = function(args) - require'luasnip'.lsp_expand(args.body) - end - }, + snippet = { + expand = function(args) require'luasnip'.lsp_expand(args.body) end + }, - mapping = cmp.mapping.preset.insert({ + mapping = cmp.mapping.preset.insert({ - -- Tab Completion - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), + -- Tab Completion + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, {"i", "s"}), - -- Reverse Tab Completion - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { "i", "s" }), + -- Reverse Tab Completion + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, {"i", "s"}), - -- Misc Mappings - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), + -- Misc Mappings + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({select = true}) - }), + }), - -- Default Sources - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - { name = 'buffer' }, - }) + -- Default Sources + sources = cmp.config.sources({ + {name = 'nvim_lsp'}, {name = 'luasnip'}, {name = 'path'}, + {name = 'buffer'} + }) }) -- Completion - `/` and `?` -cmp.setup.cmdline({ '/', '?' }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' }, - } +cmp.setup.cmdline({'/', '?'}, { + mapping = cmp.mapping.preset.cmdline(), + sources = {{name = 'buffer'}} }) -- Completion = `:` cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' }, - { name = 'cmdline' }, - }) + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({{name = 'path'}, {name = 'cmdline'}}) }) -- Autopairs local cmp_autopairs = require('nvim-autopairs.completion.cmp') -cmp.event:on( - 'confirm_done', - cmp_autopairs.on_confirm_done() -) +cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) diff --git a/nvim/config/lua/init.lua b/nvim/config/lua/init.lua index c5c9704..656738b 100644 --- a/nvim/config/lua/init.lua +++ b/nvim/config/lua/init.lua @@ -7,7 +7,7 @@ require('leap-config') require('lsp-config') require('lsp-lines-config') require('lualine-config') -require('neoformat-config') +require('null-ls-config') require('noice-config') require('numb-config') require('telescope-config') diff --git a/nvim/config/lua/lsp-config.lua b/nvim/config/lua/lsp-config.lua index 1e34cc4..b2dd5a7 100644 --- a/nvim/config/lua/lsp-config.lua +++ b/nvim/config/lua/lsp-config.lua @@ -2,59 +2,51 @@ local nix_vars = require("nix-vars") local nvim_lsp = require('lspconfig') local on_attach = function(client, bufnr) - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap=true, silent=true, buffer=bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) - vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = {noremap = true, silent = true, buffer = bufnr} + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, + bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', + function() vim.lsp.buf.format {async = true} end, bufopts) end -- Define LSP Flags & Capabilities -local lsp_flags = { - debounce_text_changes = 150, -} +local lsp_flags = {debounce_text_changes = 150} local capabilities = require('cmp_nvim_lsp').default_capabilities() -- Python LSP Configuration -nvim_lsp.pyright.setup{ +nvim_lsp.pyright.setup { on_attach = on_attach, flags = lsp_flags, - capabilities = capabilities, + capabilities = capabilities } -- HTML LSP Configuration -nvim_lsp.html.setup{ +nvim_lsp.html.setup { on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, - cmd = { - nix_vars.htmlserver, - "--stdio", - } + cmd = {nix_vars.htmlserver, "--stdio"} } -- Typescript / Javascript LSP Configuration -nvim_lsp.tsserver.setup{ +nvim_lsp.tsserver.setup { on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, - cmd = { - nix_vars.tsserver, - "--stdio", - "--tsserver-path", - nix_vars.tslib, - } + cmd = {nix_vars.tsserver, "--stdio", "--tsserver-path", nix_vars.tslib} } diff --git a/nvim/config/lua/lsp-lines-config.lua b/nvim/config/lua/lsp-lines-config.lua index ffc3e2f..a5336e8 100644 --- a/nvim/config/lua/lsp-lines-config.lua +++ b/nvim/config/lua/lsp-lines-config.lua @@ -1,4 +1,2 @@ require("lsp_lines").setup() -vim.diagnostic.config({ - virtual_text = false, -}) +vim.diagnostic.config({virtual_text = false}) diff --git a/nvim/config/lua/lualine-config.lua b/nvim/config/lua/lualine-config.lua index 88a0428..6674905 100644 --- a/nvim/config/lua/lualine-config.lua +++ b/nvim/config/lua/lualine-config.lua @@ -1,6 +1,6 @@ require('lualine').setup({ - options = { - theme = "nord", - -- theme = "OceanicNext", - } + options = { + theme = "nord" + -- theme = "OceanicNext", + } }) diff --git a/nvim/config/lua/neoformat-config.lua b/nvim/config/lua/neoformat-config.lua deleted file mode 100644 index 6344f32..0000000 --- a/nvim/config/lua/neoformat-config.lua +++ /dev/null @@ -1,10 +0,0 @@ -vim.g.neoformat_sql_sqlformat = { - exe = "sqlformat", - args = { "--reindent", "-k", "upper", "-" }, - stdin = 1 -} - -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = { "*.sql" }, - command = "Neoformat", -}) diff --git a/nvim/config/lua/noice-config.lua b/nvim/config/lua/noice-config.lua index 10cd989..02e8e38 100644 --- a/nvim/config/lua/noice-config.lua +++ b/nvim/config/lua/noice-config.lua @@ -1,32 +1,26 @@ -- Noice Doc Scrolling vim.keymap.set("n", "", function() - if not require("noice.lsp").scroll(4) then - return "" - end -end, { silent = true, expr = true }) + if not require("noice.lsp").scroll(4) then return "" end +end, {silent = true, expr = true}) vim.keymap.set("n", "", function() - if not require("noice.lsp").scroll(-4) then - return "" - end -end, { silent = true, expr = true }) + if not require("noice.lsp").scroll(-4) then return "" end +end, {silent = true, expr = true}) -- Noice Setup require("noice").setup({ - lsp = { - override = { - ["vim.lsp.util.convert_input_to_markdown_lines"] = true, - ["vim.lsp.util.stylize_markdown"] = true, - ["cmp.entry.get_documentation"] = false, + lsp = { + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = false + }, + signature = {enabled = false} }, - signature = { - enabled = false, - }, - }, - presets = { - command_palette = true, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = false, -- add a border to hover docs and signature help - }, + presets = { + command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false -- add a border to hover docs and signature help + } }) diff --git a/nvim/config/lua/null-ls-config.lua b/nvim/config/lua/null-ls-config.lua new file mode 100644 index 0000000..4ba41f4 --- /dev/null +++ b/nvim/config/lua/null-ls-config.lua @@ -0,0 +1,28 @@ +local null_ls = require("null-ls") + +null_ls.setup({ + sources = { + null_ls.builtins.completion.spell, + null_ls.builtins.formatting.nixpkgs_fmt, + null_ls.builtins.formatting.lua_format, + null_ls.builtins.formatting.prettier.with({ + filetypes = {"json", "yaml", "markdown"} + }), null_ls.builtins.diagnostics.sqlfluff + .with({extra_args = {"--dialect", "ansi"}}), + null_ls.builtins.formatting.sqlfluff + .with({extra_args = {"--dialect", "ansi"}}) + }, + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({group = augroup, buffer = bufnr}) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + -- vim.lsp.buf.format({ async = true }) + end + }) + end + end +}) diff --git a/nvim/config/lua/telescope-config.lua b/nvim/config/lua/telescope-config.lua index 8492bea..1d45077 100644 --- a/nvim/config/lua/telescope-config.lua +++ b/nvim/config/lua/telescope-config.lua @@ -1,12 +1,12 @@ require('telescope').setup { - extensions = { - fzf = { - fuzzy = true, - override_generic_sorter = true, - override_file_sorter = true, - case_mode = "smart_case", + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case" + } } - } } require('telescope').load_extension('fzf') diff --git a/nvim/config/lua/ts-config.lua b/nvim/config/lua/ts-config.lua index 526df4e..e2e648c 100644 --- a/nvim/config/lua/ts-config.lua +++ b/nvim/config/lua/ts-config.lua @@ -1,6 +1,3 @@ require'nvim-treesitter.configs'.setup { - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, + highlight = {enable = true, additional_vim_regex_highlighting = false} } diff --git a/nvim/default.nix b/nvim/default.nix index 2af6557..25e54da 100644 --- a/nvim/default.nix +++ b/nvim/default.nix @@ -15,38 +15,38 @@ in # ------------------ # --- Completion --- # ------------------ - cmp-buffer # Buffer Word Completion - cmp-cmdline # Command Line Completion - cmp-nvim-lsp # Main LSP - cmp-path # Path Completion - cmp_luasnip # Snippets Completion + cmp-buffer # Buffer Word Completion + cmp-cmdline # Command Line Completion + cmp-nvim-lsp # Main LSP + cmp-path # Path Completion + cmp_luasnip # Snippets Completion friendly-snippets # Snippets - lsp_lines-nvim # Inline Diagnostics - luasnip # Snippets - nvim-cmp # Completions - nvim-lspconfig # LSP Config + lsp_lines-nvim # Inline Diagnostics + luasnip # Snippets + nvim-cmp # Completions + nvim-lspconfig # LSP Config # ------------------ # ----- Helpers ---- # ------------------ - aerial-nvim # Code Outline - comment-nvim # Code Comments - diffview-nvim # Diff View - leap-nvim # Quick Movement - neo-tree-nvim # File Explorer - neoformat # Format - numb-nvim # Peek / Jump to Lines - nvim-autopairs # Automatically Close Pairs (),[],{} + aerial-nvim # Code Outline + comment-nvim # Code Comments + diffview-nvim # Diff View + leap-nvim # Quick Movement + neo-tree-nvim # File Explorer + null-ls-nvim # Formatters + numb-nvim # Peek / Jump to Lines + nvim-autopairs # Automatically Close Pairs (),[],{} telescope-fzf-native-nvim # Faster Telescope - telescope-nvim # Fuzzy Finder - vim-nix # Nix Helpers + telescope-nvim # Fuzzy Finder + vim-nix # Nix Helpers # ------------------ # --- Theme / UI --- # ------------------ - nord-nvim # Theme - lualine-nvim # Bottom Line - noice-nvim # UI Tweaks + nord-nvim # Theme + lualine-nvim # Bottom Line + noice-nvim # UI Tweaks nvim-web-devicons # Dev Icons # ------------------ @@ -58,7 +58,8 @@ in plugins: with pkgs; subtractLists [ tree-sitter-grammars.tree-sitter-bash tree-sitter-grammars.tree-sitter-kotlin - ] tree-sitter.allGrammars + ] + tree-sitter.allGrammars ) ) @@ -76,8 +77,11 @@ in nodePackages.typescript-language-server nodePackages.vscode-html-languageserver-bin - # Parser - python310Packages.sqlparse + # Formatters + luaformatter + nixpkgs-fmt + nodePackages.prettier + sqlfluff ];