From 9ddbb2c8aace4145eaf52d4ba61be11b4ca949a7 Mon Sep 17 00:00:00 2001 From: Noah Pederson Date: Fri, 12 Jul 2024 08:29:42 -0500 Subject: [PATCH] Sync nvim from NixOS/odin --- dotfiles/config/nvim/init.lua | 144 +++-------- dotfiles/config/nvim/lua/completion.lua | 3 +- dotfiles/config/nvim/lua/lsp.lua | 63 ++--- dotfiles/config/nvim/lua/plugins.lua | 331 ++++++++++++++++++------ 4 files changed, 315 insertions(+), 226 deletions(-) diff --git a/dotfiles/config/nvim/init.lua b/dotfiles/config/nvim/init.lua index 3178fb3..b0bfb7a 100644 --- a/dotfiles/config/nvim/init.lua +++ b/dotfiles/config/nvim/init.lua @@ -5,12 +5,13 @@ vim.g.maplocalleader = "," -- Load Plugins require("plugins") -- Color Scheme -vim.cmd.colorscheme "catppuccin-mocha" -vim.g.everforest_background = "hard" -vim.opt.background = "dark" +vim.cmd.colorscheme "catppuccin" +-- vim.cmd([[colorscheme kanagawa]]) -- Config for Nord, which I usually use ---vim.g.nord_italic = false ---vim.g.nord_bold = false +-- vim.g.nord_italic = false +-- vim.g.nord_bold = false +-- vim.opt.background = "light" +vim.opt.background = "dark" -- Formatting and vim config vim.opt.expandtab = true @@ -39,17 +40,11 @@ vim.opt.textwidth = 88 vim.g.sexp_enable_insert_mode_mappings = 1 -- LuaLine Config -require("lualine").setup( - { - options = { - icons_enabled = true, - theme = "auto" - } - } -) +require("lualine").setup({options = {icons_enabled = true, theme = "auto"}}) -- CTags -vim.opt.tags = vim.opt.tags + vim.fn.expand("~/.local/tmp/ctags") + vim.fn.expand("~/repos/gerbil/src/TAGS") +vim.opt.tags = vim.opt.tags + vim.fn.expand("~/.local/tmp/ctags") + + vim.fn.expand("~/repos/gerbil/src/TAGS") -- Conjure @@ -62,8 +57,6 @@ end set_gerbil() vim.api.nvim_create_user_command("ConjureGerbil", set_gerbil, {}) - - -- Chibi-scheme local set_chibi = function() vim.g["conjure#client#scheme#stdio#command"] = "chibi-scheme -R" @@ -79,18 +72,8 @@ local set_chicken = function() end vim.api.nvim_create_user_command("ConjureChicken", set_chicken, {}) --- Neoformat -vim.g.neoformat_run_all_formatters = 1 -vim.g.neoformat_enabled_python = {"black", "docformatter", "isort"} -vim.g.neoformat_python_black = { - exe = "ruff", - stdin = 1, - args = {'format', '-q', '-'} -} - -- KEYMAPS - -local keymap = vim.api.nvim_set_keymap +local keymap = vim.keymap.set local noremap = {noremap = true} local silentnoremap = {noremap = true, silent = true} -- Easier breaking from edit modes @@ -146,92 +129,43 @@ keymap("n", "", "zl", silentnoremap) -- LSP Documentation viewer keymap("n", "K", "lua vim.lsp.buf.hover()", silentnoremap) --- Autoformat -keymap("n", "", "Neoformat", silentnoremap) +-- Autoformat! +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 }) +keymap("n", "", "Format", silentnoremap) -- Python Specific vim.g.python3_host_prog = vim.fn.expand("~/.envs/nvim/bin/python3") -- Set up Treesitter -require("nvim-treesitter.configs").setup( - { - highlight = { - enable = true, - disable = {} - }, - indent = { - enable = true, - disable = {} - }, - ensure_installed = { - "c", - "cpp", - "capnp", - "cmake", - "bash", - "dockerfile", - "diff", - "devicetree", - "dot", - "ebnf", - "elixir", - "erlang", - "clojure", - "fortran", - "go", - "gomod", - "gosum", - "graphql", - "git_config", - "git_rebase", - "gitcommit", - "gitignore", - "gleam", - "julia", - "fish", - "toml", - "haskell", - "hare", - "http", - "html", - "ini", - "json", - "jq", - "latex", - "llvm", - "mermaid", - "make", - "meson", - "ninja", - "yaml", - "python", - "proto", - "racket", - "rst", - "scala", - "html", - "tsx", - "rust", - "scheme", - "fennel", - "lua", - "markdown", - "markdown_inline", - "sql", - "thrift", - "typescript", - "verilog", - "vim", - "zig", - "uxntal" - } +-- TODO: move this to plugins.lua +require("nvim-treesitter.configs").setup({ + highlight = {enable = true, disable = {}}, + indent = {enable = true, disable = {}}, + ensure_installed = { + "c", "cpp", "capnp", "cmake", "bash", "dockerfile", "diff", + "devicetree", "dot", "ebnf", "elixir", "erlang", "clojure", "fortran", + "go", "gomod", "gosum", "graphql", "git_config", "git_rebase", + "gitcommit", "gitignore", "gleam", "julia", "fish", "toml", "haskell", + "hare", "http", "html", "ini", "json", "jq", "latex", "llvm", "mermaid", + "make", "meson", "ninja", "yaml", "python", "proto", "racket", "rst", + "scala", "html", "tsx", "rust", "scheme", "fennel", "lua", "markdown", + "markdown_inline", "sql", "thrift", "typescript", "verilog", "vim", + "zig", "uxntal", "kdl", "vimdoc", "janet_simple" } -) +}) --- Set up Which Key? -require("which-key").setup({}) -- ######################## ---# Require other configs # +-- # Require other configs # -- ######################## -- LSP require("lsp") diff --git a/dotfiles/config/nvim/lua/completion.lua b/dotfiles/config/nvim/lua/completion.lua index 8142902..5a4467e 100644 --- a/dotfiles/config/nvim/lua/completion.lua +++ b/dotfiles/config/nvim/lua/completion.lua @@ -19,7 +19,8 @@ cmp.setup({ [''] = cmp.mapping.confirm({select = true}) -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ - {name = 'nvim_lsp'}, {name = 'vsnip'} -- For vsnip users. + {name = 'nvim_lsp'}, {name = 'vsnip'}, -- For vsnip users. + {name = 'supermaven'}, {name = 'conjure'} }, {{name = 'buffer'}}) }) require("cmp_git").setup() diff --git a/dotfiles/config/nvim/lua/lsp.lua b/dotfiles/config/nvim/lua/lsp.lua index 0e33c50..88d10db 100644 --- a/dotfiles/config/nvim/lua/lsp.lua +++ b/dotfiles/config/nvim/lua/lsp.lua @@ -3,27 +3,13 @@ local capabilities = require('cmp_nvim_lsp').default_capabilities() -- ######################## -- #### Set up LSPs #### -- ######################## --- --- TypeScript -nvim_lsp.tsserver.setup { - capabilities = capabilities, - flags = {debounce_text_changes = 150} -} - --- Clojure -nvim_lsp.clojure_lsp.setup {capabilities = capabilities} local util = require("lspconfig.util") -- Rust -nvim_lsp.rust_analyzer.setup({ - capabilities = capabilities, - diagnostics = {enable = true} -}) -- Python LSP nvim_lsp.pylsp.setup({ - capabilities = capabilities, - cmd = {"/home/noah/.envs/nvim/bin/pylsp"}, + -- cmd = {"/home/noah/.envs/nvim/bin/pylsp"}, root_dir = function(fname) local root_files = { "pants.toml", "pyproject.toml", "setup.py", "setup.cfg", "Pipfile" @@ -32,34 +18,7 @@ nvim_lsp.pylsp.setup({ util.root_pattern(unpack(root_files))(fname) end }) - --- More Python, I like it strict -nvim_lsp.pyright.setup {capabilities = capabilities} -nvim_lsp.ruff_lsp.setup {capabilities = capabilities} - --- nvim_lsp.scheme_langserver.setup{} - --- Golang -nvim_lsp.gopls.setup {capabilities = capabilities} --- Lots of things --- nvim_lsp.diagnosticls.setup( --- { --- flags = { --- debounce_text_changes = 150 --- } --- } --- ) --- JSON -nvim_lsp.jsonls.setup {capabilities = capabilities} -nvim_lsp.jsonls.setup {capabilities = capabilities} --- Vim -nvim_lsp.vimls.setup {capabilities = capabilities} - -nvim_lsp.bashls.setup {capabilities = capabilities} -nvim_lsp.ccls.setup {capabilities = capabilities} -nvim_lsp.asm_lsp.setup {capabilities = capabilities} nvim_lsp.lua_ls.setup { - capabilities = capabilities, settings = { Lua = { runtime = { @@ -79,7 +38,25 @@ nvim_lsp.lua_ls.setup { } } } -nvim_lsp.fennel_ls.setup {capabilities = capabilities} + +-- LSPs that just use default config +local simple_lsps = { + "fennel_ls", "nil_ls", "htmx", "bzl", "bufls", "crystalline", "dockerls", + "erlangls", "elixirls", "fortls", "gleam", "gopls", "hls", "jsonls", + "vimls", "asm_lsp", "ccls", "pyright", -- ruff", idk if this is wrong? + "ruff_lsp", "clojure_lsp", "guile_ls", + -- Of course the Java-based ones are verbose af + "kotlin_language_server", "java_language_server", "jsonls", "pest_ls", + "ocamllsp", "reason_ls", "racket_langserver", "rust_analyzer", + "scheme_langserver", "sqls", "thriftls", "typst_lsp", "vhdl_ls", "yamlls", + "zls", "tsserver", "eslint", "metals", "futhark_lsp", "roc_ls", + -- disabled because it's broken + -- "scheme_langserver", +} +-- #simple_lsps is the length of the table when treated as a list... funky! +for _, v in pairs(simple_lsps) do nvim_lsp[v].setup { + capabilities = capabilities +} end -- Whenever an LSP is attached to a buffer local on_attach = function(ev) diff --git a/dotfiles/config/nvim/lua/plugins.lua b/dotfiles/config/nvim/lua/plugins.lua index 141ae73..5ff5d13 100644 --- a/dotfiles/config/nvim/lua/plugins.lua +++ b/dotfiles/config/nvim/lua/plugins.lua @@ -18,40 +18,99 @@ require("lazy").setup({ -- Color themes "shaunsingh/nord.nvim", "shaunsingh/moonlight.nvim", "folke/tokyonight.nvim", "cranberry-clockworks/coal.nvim", - "hardselius/warlock", "sainnhe/everforest", - {"catppuccin/nvim", name = "catppuccin", priority = 1000}, - {"rebelot/kanagawa.nvim", opts = {compile = true}}, + "hardselius/warlock", + { "catppuccin/nvim", name = "catppuccin", priority = 1000 }, + { + "neanias/everforest-nvim", + version = false, + lazy = false, + priority = 500, -- make sure to load this before all the other start plugins + main = "everforest", + opts = { background = "hard" } + }, + { "rebelot/kanagawa.nvim", opts = { compile = true } }, -- show indents and whitespace characters "lukas-reineke/indent-blankline.nvim", -- Completion - "hrsh7th/nvim-cmp", "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", "hrsh7th/cmp-vsnip", "hrsh7th/vim-vsnip", - "petertriho/cmp-git", -- nvim lsp plugins - "neovim/nvim-lspconfig", { + -- Completion + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + --"hrsh7th/cmp-vsnip", + --"hrsh7th/vim-vsnip", + "petertriho/cmp-git", + "hrsh7th/cmp-cmdline" + } + }, -- nvim lsp plugins + "neovim/nvim-lspconfig", + { "nvimdev/lspsaga.nvim", dependencies = { "nvim-tree/nvim-web-devicons", "nvim-treesitter/nvim-treesitter" }, - opts = {lightbulb = {enable = false}}, + opts = { lightbulb = { enable = false } }, event = "LspAttach" - }, -- Syntax Highlighting from the future + }, { + -- Syntax Highlighting from the future "nvim-treesitter/nvim-treesitter", - init = function() vim.cmd([[":TSUpdate"]]) end - }, -- GitGutter, shows inline difs - -- "airblade/vim-gitgutter", -- Git wrapper plugin - -- "tpope/vim-fugitive", - { - "NeogitOrg/neogit", "nvim-lua/plenary.nvim", -- required - "sindrets/diffview.nvim", -- optional - Diff integration - "nvim-telescope/telescope.nvim" - }, "akinsho/git-conflict.nvim", -- surround with pairs )))))) - -- "tpope/vim-surround", + --init = function() vim.cmd([[":TSUpdate"]]) end, + main = "nvim-treesitter.configs", + opts = { + ensure_installed = 'all', + ignore_install = { 'norg' }, + sync_intall = true, + highlight = { + enable = true, + }, + }, + build = ":TSUpdate", + version = false, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + }, + }, -- Git stuff + -- GitGutter, shows inline difs + "airblade/vim-gitgutter", -- "tpope/vim-fugitive", -- old git command + { + "NeogitOrg/neogit", + dependencies = { + "nvim-lua/plenary.nvim", -- required + "sindrets/diffview.nvim", -- optional - Diff integration + "nvim-telescope/telescope.nvim" + }, + config = true + }, -- Auto format tool - {"sbdchd/neoformat", lazy = true, cmd = "Neoformat"}, - -- Distraction free writing: GoYo + Limelight - {"junegunn/limelight.vim", lazy = true, ft = "markdown"}, - {"junegunn/goyo.vim", lazy = true, ft = "markdown"}, -- Golang plugins - -- use {"fatih/vim-go", run = ":GoUpdateBinaries", lazy = true, ft = "go"} + { + "stevearc/conform.nvim", + lazy = true, + opt = { + python = { "isort", "black" }, + lua = { "lua-format" }, + clojure = { "cljfmt" }, + rust = { "rustfmt" }, + haskell = { "ormolu", "stylish-haskell" }, + go = { "goimports", "gofmt" }, + java = { "google-java-format" }, + javascript = { "prettier" }, + html = { "prettier" }, + yaml = { "prettier" }, + sh = { "shfmt" }, + c = { "clang-format" }, + } + }, + { + "hedyhli/outline.nvim", + lazy = true, + cmd = { "Outline", "OutlineOpen" }, + config = true, + keys = { + { "o", "Outline", desc = "Toggle outline" }, + }, + }, { "ray-x/go.nvim", ft = "go", @@ -63,43 +122,167 @@ require("lazy").setup({ }, { "nvim-lualine/lualine.nvim", - dependencies = {"nvim-tree/nvim-web-devicons"} - }, "junegunn/fzf.vim", { + dependencies = { "nvim-tree/nvim-web-devicons" } + }, + "junegunn/fzf.vim", + { dir = "~/.fzf", build = function() vim.fn["fzf#install"](0) end, - dependencies = {"junegunn/fzf.vim"} - }, -- "romgrk/barbar.nvim", -- Polyglot - "sheerun/vim-polyglot", -- Telescope, find anything fast + dependencies = { "junegunn/fzf.vim" } + }, + -- Telescope, find anything fast "nvim-lua/plenary.nvim", - {"nvim-telescope/telescope.nvim", dependencies = {"nvim-lua/plenary.nvim"}}, - "nvim-telescope/telescope-symbols.nvim", - {"folke/trouble.nvim", dependencies = "nvim-tree/nvim-web-devicons"}, + { + "nvim-telescope/telescope.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-symbols.nvim", + } + }, + { + "folke/trouble.nvim", + dependencies = "nvim-tree/nvim-web-devicons" + }, -- Which key is bound? - "folke/which-key.nvim", -- literally the best plugin ever - -- Lithsps - {"guns/vim-sexp", ft = {"hy", "scheme", "clojure"}}, -- )))))) - {"hiphish/rainbow-delimiters.nvim"}, - -- {"gpanders/nvim-parinfer", ft = {"scheme", "lisp", "fennel", "clojure", "lua"}}, - -- { - -- "eraserhd/parinfer-rust", - -- build = "RUSTFLAGS='-C target-feature=+crt-static' cargo build --release", - -- ft = {"scheme", "lisp", "fennel", "clojure", "lua"}, - -- }, + { + "folke/which-key.nvim", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + config = true + }, -- literally the best plugin ever + -- Developing my neovim + { "folke/neodev.nvim", config = true }, -- Lithsps + --{ "m4xshen/autoclose.nvim" }, + { + "windwp/nvim-autopairs", + event = "InsertEnter", + config = function() + local pairs = require("nvim-autopairs") + + pairs.setup({ + check_ts = true, + enable_check_bracket_line = false, + }) + + pairs.get_rules("`")[1].not_filetypes = { "clojure", "scheme", "scm", "janet" } + pairs.get_rules("'")[1].not_filetypes = { "clojure", "scheme", "scm", "janet", "rust" } + end, + }, + { + "gpanders/nvim-parinfer", + ft = { "hy", "scheme", "scm", "clojure", "fennel", "janet", "lisp", "python", "lua" } + }, + --'janet-lang/janet.vim', + -- )))))) + { + "julienvincent/nvim-paredit", + config = function() + local paredit = require('nvim-paredit') + paredit.setup({ + indent = { + enabled = true, + }, + --filetypes = {"clojure", "fennel", "janet"}, + keys = { + ["w"] = { + function() + -- place cursor and set mode to `insert` + paredit.cursor.place_cursor( + -- wrap element under cursor with `( ` and `)` + paredit.wrap.wrap_element_under_cursor("( ", ")"), + -- cursor placement opts + { placement = "inner_start", mode = "insert" } + ) + end, + "Wrap element insert head", + }, + + ["W"] = { + function() + paredit.cursor.place_cursor( + paredit.wrap.wrap_element_under_cursor("(", ")"), + { placement = "inner_end", mode = "insert" } + ) + end, + "Wrap element insert tail", + }, + -- same as above but for enclosing form + ["i"] = { + function() + paredit.cursor.place_cursor( + paredit.wrap.wrap_enclosing_form_under_cursor("( ", ")"), + { placement = "inner_start", mode = "insert" } + ) + end, + "Wrap form insert head", + }, + ["I"] = { + function() + paredit.cursor.place_cursor( + paredit.wrap.wrap_enclosing_form_under_cursor("(", ")"), + { placement = "inner_end", mode = "insert" } + ) + end, + "Wrap form insert tail", + }, + ["["] = { + function() + paredit.cursor.place_cursor( + paredit.wrap.wrap_enclosing_form_under_cursor("[", "]"), + { placement = "inner_start", mode = "insert" } + ) + end, + }, + ["{"] = { + function() + paredit.cursor.place_cursor( + paredit.wrap.wrap_enclosing_form_under_cursor("{", "}"), + { placement = "inner_end", mode = "insert" } + ) + end, + }, + }, + }) + end, + ft = { "hy", "scheme", "scm", "clojure", "fennel", "janet", "lisp", "python", "lua" } + }, + { + "chiefnoah/nvim-paredit-janet", + dependencies = { "julienvincent/nvim-paredit" }, + lazy = true, + ft = { "janet" }, + config = function() + require("nvim-paredit-janet").setup() + end, + }, + { + "julienvincent/nvim-paredit-fennel", + dependencies = { "julienvincent/nvim-paredit" }, + ft = { "fennel" }, + config = true, + }, + { "hiphish/rainbow-delimiters.nvim" }, + --{ "gpanders/nvim-parinfer", ft = { "scheme", "scm", "lisp", "fennel", "clojure", "lua", "janet" } }, -- Conjure, lisp is magical { "Olical/conjure", - ft = {"scheme", "lisp", "fennel", "clojure", "lua"}, + ft = { "scheme", "scm", "lisp", "fennel", "clojure", "lua", "janet" }, config = function() vim.g["conjure#client#scheme#stdio#command"] = "gxi" vim.g["conjure#client#scheme#stdio#prompt_pattern"] = "%d*> $?" - end - }, {"p1xelHer0/gerbil.nvim", ft = "scheme"}, -- Fennel, Luasthp - {"jaawerth/fennel.vim", lazy = true, ft = "fennel"}, - {"rktjmp/hotpot.nvim", lazy = true, ft = "fennel"}, - {"Olical/nfnl", ft = "fennel"}, -- Rust stuff - "pest-parser/pest.vim", { + end, + dependencies = { "PaterJason/cmp-conjure" } + }, + { "PaterJason/cmp-conjure", lazy = true }, + { "p1xelHer0/gerbil.nvim", ft = "scheme" }, -- Fennel, Luasthp + { "jaawerth/fennel.vim", lazy = true, ft = "fennel" }, + { "rktjmp/hotpot.nvim", lazy = true, ft = "fennel" }, + { "Olical/nfnl", ft = "fennel" }, -- Rust stuff + { "simrat39/rust-tools.nvim", - ft = {"rust"}, + ft = { "rust" }, config = function() local rt = require("rust-tools") rt.setup({ @@ -107,41 +290,35 @@ require("lazy").setup({ on_attach = function(_, bufnr) -- Hover actions vim.keymap.set("n", "", - rt.hover_actions.hover_actions, - {buffer = bufnr}) + rt.hover_actions.hover_actions, + { buffer = bufnr }) -- Code action groups vim.keymap.set("n", "a", - rt.code_action_group.code_action_group, - {buffer = bufnr}) + rt.code_action_group.code_action_group, + { buffer = bufnr }) end } }) end, - dependencies = {"nvim-lua/plenary.nvim"} - }, {"mfussenegger/nvim-dap", lazy = true, ft = {"c", "rust"}}, { + dependencies = { "nvim-lua/plenary.nvim" } + }, + { "mfussenegger/nvim-dap", lazy = true, ft = { "c", "rust" } }, + { "saecki/crates.nvim", tag = "v0.4.0", - dependencies = {"nvim-lua/plenary.nvim"}, + dependencies = { "nvim-lua/plenary.nvim" }, config = function() require("crates").setup() end, - ft = {"rust"} - }, -- RISC-V Assembly syntax highlighting - {"kylelaker/riscv.vim", ft = "riscv"}, -- Hare Stuff + ft = { "rust" } + }, -- RISC-V Assembly syntax highlighting + { "kylelaker/riscv.vim", ft = "riscv" }, -- Hare Stuff -- Haredoc - {url = "https://git.sr.ht/~torresjrjr/vim-haredoc", ft = {"hare"}}, - -- Hare.vim - {url = "https://git.sr.ht/~sircmpwn/hare.vim"}, -- TCL - {"lewis6991/tree-sitter-tcl", build = "make"}, -- LF - {"ptzz/lf.vim", cmd = {"Lf"}, dependencies = {"voldikss/vim-floaterm"}}, - -- Copilot - -- use {"github/copilot.vim", lazy = true, cmd = {"Copilot"}} - -- Mason - { - "williamboman/mason.nvim", - init = function() vim.cmd([[":MasonUpdate"]]) end, - dependencies = { - "williamboman/mason-lspconfig.nvim", "mfussenegger/nvim-dap", - "jose-elias-alvarez/null-ls.nvim" - }, - config = function() require("mason").setup() end - } + { + url = "https://git.sr.ht/~torresjrjr/vim-haredoc", + ft = { "hare" }, + branch = "dev" + }, -- Hare.vim + { url = "https://git.sr.ht/~sircmpwn/hare.vim", ft = { "hare" } }, -- TCL + { "lewis6991/tree-sitter-tcl", build = "make" }, -- LF + { "ptzz/lf.vim", cmd = { "Lf" }, dependencies = { "voldikss/vim-floaterm" } }, + "imsnif/kdl.vim" }, nil) -- 2.45.2