From dc3e319f27cfc0b3924d489b8d510ef318ae76c9 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Tue, 23 May 2023 02:56:59 -0500 Subject: [PATCH] Working on LSP and shit like that, Astro config is confusing, need to learn it myself from scratch --- cspell.json | 1 + init.lua | 6 ++- keymaps.lua | 32 +++++++++------ lazy-lock.json | 21 ++++++++++ lua/user/alpha.lua | 2 +- lua/user/auto-save.lua | 2 +- lua/user/autoswap.lua | 5 +++ lua/user/glow-markdown.lua | 6 ++- lua/user/lsp.lua | 28 ++++++++++++++ lua/user/mason.lua | 65 +++++++++++++++++++++++++++++++ lua/user/neo-tree.lua | 46 ++++++++++++++++++++++ lua/user/null-ls.lua | 47 +++++++++++++++++++++++ lua/user/open-github.lua | 10 +++++ lua/user/plenary.lua | 5 +++ lua/user/rest-http.lua | 11 ++++++ lua/user/rust-tools.lua | 6 +++ lua/user/telescope.lua | 42 ++++++++++++++++++++ lua/user/treesitter.lua | 79 ++++++++++++++++++++++++++++++++++++++ options.lua | 4 +- 19 files changed, 400 insertions(+), 18 deletions(-) create mode 100644 cspell.json create mode 100644 lua/user/autoswap.lua create mode 100644 lua/user/lsp.lua create mode 100644 lua/user/mason.lua create mode 100644 lua/user/neo-tree.lua create mode 100644 lua/user/null-ls.lua create mode 100644 lua/user/open-github.lua create mode 100644 lua/user/plenary.lua create mode 100644 lua/user/rest-http.lua create mode 100644 lua/user/rust-tools.lua create mode 100644 lua/user/telescope.lua create mode 100644 lua/user/treesitter.lua diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..918aec3 --- /dev/null +++ b/cspell.json @@ -0,0 +1 @@ +{"language":"en","version":"0.2","words":["nvim","builtins","stylua","rustfmt","pendo","tanstack","ripgrep","Typeahead","overscan","autorun","mediatype","BIOINF","Transitioner","pkce","ilike","arrayify","arrayified","komodo","wezterm","gcloud","pbpaste"],"flagWords":[]} diff --git a/init.lua b/init.lua index fb5dca0..9def82b 100644 --- a/init.lua +++ b/init.lua @@ -18,7 +18,11 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) -require("lazy").setup("user", {}) +require("lazy").setup("user", { + change_detection = { + enabled = false, + } +}) vim.cmd 'colorscheme material' diff --git a/keymaps.lua b/keymaps.lua index 59b1fcc..50ddb2a 100644 --- a/keymaps.lua +++ b/keymaps.lua @@ -34,8 +34,6 @@ local mappings = { ["p"] = { '"*p', desc = "Paste from system clipboard" }, -- TODO L-c to close buffer - ["gf"] = { ":OpenInGHFile ", desc = "Open in github" }, - ["fs"] = { function() require("telescope.builtin").live_grep { @@ -51,15 +49,8 @@ local mappings = { ["st"] = { function() scratch ".ts" end, desc = "New ts scratch file" }, ["sb"] = { function() scratch ".sh" end, desc = "New shell scratch file" }, ["sj"] = { function() scratch ".js" end, desc = "New js scratch file" }, - ["∆"] = { - ":m .+1==g", - desc = "Move the line up", - }, - ["˚"] = { - ":m .-2==g", - desc = "Move the line down", - }, - ["r"] = { function() require("rest-nvim").run() end, desc = "Send http request" }, + + ["Q"] = { ":qa", desc = "Quit all" }, [","] = { name = " Misc Tools" }, [",c"] = { name = " Casing" }, @@ -163,7 +154,24 @@ function set_mappings(map_table, base) if package.loaded["which-key"] then which_key_register() end -- if which-key is loaded already, register end --- TODO load mappings from user plugins +for _, file in ipairs(vim.fn.readdir(vim.fn.stdpath('config')..'/lua/user', [[v:val =~ '\.lua$']])) do + local uplugin = require('user.'..file:gsub('%.lua$', '')) + if (uplugin[1] ~= nil) then + if (uplugin.mappings ~= nil) then + for mode, keymaps in pairs(uplugin.mappings) do + -- Add new mode if not already existing + if (mappings[mode] == nil) then + mappings[mode] = {} + end + + for key, value in pairs(keymaps) do + mappings[mode][key] = value; + end + end + end + + end +end set_mappings(mappings); diff --git a/lazy-lock.json b/lazy-lock.json index ef34eb5..28510a2 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,9 +1,30 @@ { + "SchemaStore.nvim": { "branch": "main", "commit": "15f37630d3abfb98607dd8e4625b731a8558b96d" }, "alpha-nvim": { "branch": "main", "commit": "1838ae926e8d49fe5330d1498ee8289ae2c340bc" }, "auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" }, "gitsigns.nvim": { "branch": "main", "commit": "c18b7ca0b5b50596722f3a1572eb9b8eb520c0f1" }, "glow.nvim": { "branch": "advanced_window", "commit": "f1157d4cb7e46e830c72004e7e1adb81a1f9b04c" }, "lazy.nvim": { "branch": "main", "commit": "6610b15dfd76f7992423916e2b87f031881d7b25" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "c55d18f3947562e699d34d89681edbf9f0e250d3" }, + "mason-null-ls.nvim": { "branch": "main", "commit": "54d702020bf94e4eefd357f0b738317af30217eb" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "c836e511e796d2b6a25ad9f164f5b25d8b9ff705" }, + "mason.nvim": { "branch": "main", "commit": "08b2fd308e0107eab9f0b59d570b69089fd0b522" }, "material.nvim": { "branch": "main", "commit": "0c725897bc3d22c45fbf25a602002ee02f06f619" }, + "neo-tree.nvim": { "branch": "v2.x", "commit": "20c2f2f5ba083bbb1e37b8bc3d590621434f31e9" }, + "neodev.nvim": { "branch": "main", "commit": "2daabebac1b0b2ab7abba298c1a8f07a542866a6" }, + "nui.nvim": { "branch": "main", "commit": "698e75814cd7c56b0dd8af4936bcef2d13807f3c" }, + "null-ls.nvim": { "branch": "main", "commit": "77e53bc3bac34cc273be8ed9eb9ab78bcf67fa48" }, + "nvim-dap": { "branch": "master", "commit": "56118cee6af15cb9ddba9d080880949d8eeb0c9f" }, + "nvim-lspconfig": { "branch": "master", "commit": "1c13e529bd5683b54a39b633a560d2f00fcb25af" }, + "nvim-treesitter": { "branch": "master", "commit": "f2778bd1a28b74adf5b1aa51aa57da85adfa3d16" }, + "nvim-ts-autotag": { "branch": "main", "commit": "40615e96075c743ef47aaf9de966dc348bec6459" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "0bf8fbc2ca8f8cdb6efbd0a9e32740d7a991e4c3" }, + "openingh.nvim": { "branch": "main", "commit": "374c081409dc238018cd986410f16190d8f9f680" }, + "plenary.nvim": { "branch": "master", "commit": "9ac3e9541bbabd9d73663d757e4fe48a675bb054" }, + "rest.nvim": { "branch": "main", "commit": "d8dc204e9f6fd930d9d1d709f0d19138f804431a" }, + "rust-tools.nvim": { "branch": "master", "commit": "71d2cf67b5ed120a0e31b2c8adb210dd2834242f" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "580b6c48651cabb63455e97d7e131ed557b8c7e2" }, + "telescope.nvim": { "branch": "master", "commit": "40c31fdde93bcd85aeb3447bb3e2a3208395a868" }, + "vim-autoswap": { "branch": "master", "commit": "e587e4b14a605d8921942ba65a37583813289272" }, "which-key.nvim": { "branch": "main", "commit": "e271c28118998c93a14d189af3395812a1aa646c" } } \ No newline at end of file diff --git a/lua/user/alpha.lua b/lua/user/alpha.lua index 99b51c5..7fc725a 100644 --- a/lua/user/alpha.lua +++ b/lua/user/alpha.lua @@ -47,7 +47,7 @@ dashboard.config.layout[1].val = vim.fn.max { 2, vim.fn.floor(vim.fn.winheight(0 dashboard.config.opts.noautocmd = true return dashboard - end, + end, config = function(_, opts) require("alpha").setup(opts.config) diff --git a/lua/user/auto-save.lua b/lua/user/auto-save.lua index 13c6820..4c5bab6 100644 --- a/lua/user/auto-save.lua +++ b/lua/user/auto-save.lua @@ -1,5 +1,5 @@ return { "Pocco81/auto-save.nvim", commit = "979b6c82f60cfa80f4cf437d77446d0ded0addf0", -- May 22, 2023 - event = "User AstroFile", + event = "BufEnter", } diff --git a/lua/user/autoswap.lua b/lua/user/autoswap.lua new file mode 100644 index 0000000..22ed228 --- /dev/null +++ b/lua/user/autoswap.lua @@ -0,0 +1,5 @@ +return { + "gioele/vim-autoswap", + commit = "e587e4b14a605d8921942ba65a37583813289272", + event = "BufEnter", +} diff --git a/lua/user/glow-markdown.lua b/lua/user/glow-markdown.lua index 56dd931..aaa3ff5 100644 --- a/lua/user/glow-markdown.lua +++ b/lua/user/glow-markdown.lua @@ -7,7 +7,9 @@ return { }, cmd = "Glow", mappings = { - ["m"] = { name = " Markdown" }, - ["mp"] = { ":Glow ", desc = "Markdown preview" }, + n = { + ["m"] = { "", name = " Markdown" }, + ["mp"] = { ":Glow ", desc = "Markdown preview" }, + } } } diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua new file mode 100644 index 0000000..bcfd393 --- /dev/null +++ b/lua/user/lsp.lua @@ -0,0 +1,28 @@ +return { + { + "b0o/SchemaStore.nvim", + commit = "15f37630d3abfb98607dd8e4625b731a8558b96d", + }, + { + "folke/neodev.nvim", + commit = "2daabebac1b0b2ab7abba298c1a8f07a542866a6", + opts = { + override = function(root_dir, library) + for _, astronvim_config in ipairs(astronvim.supported_configs) do + if root_dir:match(astronvim_config) then + library.plugins = true + break + end + end + vim.b.neodev_enabled = library.enabled + end, + }, + }, + { + "neovim/nvim-lspconfig", + commit = "1c13e529bd5683b54a39b633a560d2f00fcb25af", + dependencies = { + "williamboman/mason-lspconfig.nvim", + } + } +} diff --git a/lua/user/mason.lua b/lua/user/mason.lua new file mode 100644 index 0000000..ec65824 --- /dev/null +++ b/lua/user/mason.lua @@ -0,0 +1,65 @@ +return { + { + "williamboman/mason.nvim", + build = ":MasonUpdate", -- :MasonUpdate updates registry contents + commit = "08b2fd308e0107eab9f0b59d570b69089fd0b522", + cmd = { + "Mason", + "MasonInstall", + "MasonUninstall", + "MasonUninstallAll", + "MasonLog", + "MasonUpdate", -- AstroNvim extension here as well + "MasonUpdateAll", -- AstroNvim specific + }, + opts = { + ui = { + icons = { + package_installed = "✓", + package_uninstalled = "✗", + package_pending = "⟳", + }, + }, + }, + --config = function(_, opts) + --require('mason').setup(opts) + --for _, plugin in ipairs { "mason-lspconfig", "mason-null-ls", "mason-nvim-dap" } do + -- pcall(require, plugin) + --end + --end + }, + { + "williamboman/mason-lspconfig.nvim", + dependencies = { + "williamboman/mason.nvim", + }, + commit = "c55d18f3947562e699d34d89681edbf9f0e250d3", + cmd = { "LspInstall", "LspUninstall" }, + opts = { + ensure_installed = { "lua_ls", "rust_analyzer", "tsserver", "pyright", "cssls", "cssmodules_ls" }, + }, + }, + { + "jay-babu/mason-null-ls.nvim", + commit = "54d702020bf94e4eefd357f0b738317af30217eb", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "williamboman/mason.nvim", + "jose-elias-alvarez/null-ls.nvim", + }, + opts = { + ensure_installed = { "prettier", "stylua", "black", "rust_fmt" }, + }, + }, + { + "jay-babu/mason-nvim-dap.nvim", + commit = "c836e511e796d2b6a25ad9f164f5b25d8b9ff705", + dependencies = { + "williamboman/mason.nvim", + "mfussenegger/nvim-dap", + }, + opts = { + ensure_installed = { "codelldb" }, + }, + }, +} diff --git a/lua/user/neo-tree.lua b/lua/user/neo-tree.lua new file mode 100644 index 0000000..59a79b1 --- /dev/null +++ b/lua/user/neo-tree.lua @@ -0,0 +1,46 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + commit = "e5594d53986b34e584e8afe2ea6ad99d6f6d2105", + dependencies = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim" }, + cmd = "Neotree", + init = function() vim.g.neo_tree_remove_legacy_commands = true end, + pin = true, + tag = '2.56', + opts = { + auto_clean_after_session_restore = true, + close_if_last_window = true, + sources = { "filesystem" }, + filesystem = { + follow_current_file = true, + group_empty_dirs = true, + filtered_items = { + visible = true, + hide_dotfiles = false, + hide_gitignored = false, + hide_by_name = { + ".DS_Store", + }, + }, + }, + nesting_rules = { + ["ts"] = { ".cjs", ".cjs.map", ".d.ts", ".d.ts.map", ".js", ".js.map", ".mjs", ".mjs.map", ".test.ts" }, + ["tsx"] = { ".d.ts", ".d.ts.map", ".js;", ".js.map;", ".jsx;", ".jsx.map;", ".module.scss;", ".svg" }, + ["scss"] = { ".css", ".css.map" }, + }, + }, + mappings = { + n = { + ["e"] = { "Neotree toggle", desc = "Toggle Explorer" }, + ["o"] = { + function() + if vim.bo.filetype == "neo-tree" then + vim.cmd.wincmd "p" + else + vim.cmd.Neotree "focus" + end + end, + desc = "Toggle Explorer Focus", + }, + } + } +} diff --git a/lua/user/null-ls.lua b/lua/user/null-ls.lua new file mode 100644 index 0000000..41c6635 --- /dev/null +++ b/lua/user/null-ls.lua @@ -0,0 +1,47 @@ +-- npm install -g cspell@latest + +local output = vim.fn.system { + "which", + "cspell", +} +if output == nil or output == "" then + -- if v:shell_error != 0 then + vim.fn.system { + "npm", + "install", + "-g", + "cspell@latest", + } +end + +return { + "jose-elias-alvarez/null-ls.nvim", + commit = "77e53bc3bac34cc273be8ed9eb9ab78bcf67fa48", + opts = function(_, config) + -- config variable is the default definitions table for the setup function call + local null_ls = require "null-ls" + + -- Check supported formatters and linters + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics + config.sources = { + -- Set a formatter + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.prettier, + null_ls.builtins.formatting.rustfmt, + -- null_ls.builtins.code_actions.proselint, -- TODO looks interesting + null_ls.builtins.code_actions.cspell.with { + config = { + find_json = function() return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/lua/user/;") end, + }, + }, + null_ls.builtins.diagnostics.cspell.with { + extra_args = { "--config", "~/.config/nvim/lua/user/cspell.json" }, + }, + } + + config.update_in_insert = true + + return config -- return final config table + end, +} diff --git a/lua/user/open-github.lua b/lua/user/open-github.lua new file mode 100644 index 0000000..b42c6af --- /dev/null +++ b/lua/user/open-github.lua @@ -0,0 +1,10 @@ +return { + "Almo7aya/openingh.nvim", + commit = "374c081409dc238018cd986410f16190d8f9f680", + event = "User AstroFile", + mappings = { + n = { + ["gf"] = { ":OpenInGHFile ", desc = "Open in github" }, + }, + }, +} diff --git a/lua/user/plenary.lua b/lua/user/plenary.lua new file mode 100644 index 0000000..427a216 --- /dev/null +++ b/lua/user/plenary.lua @@ -0,0 +1,5 @@ +return { + "nvim-lua/plenary.nvim", + commit = "9ac3e9541bbabd9d73663d757e4fe48a675bb054", +} + diff --git a/lua/user/rest-http.lua b/lua/user/rest-http.lua new file mode 100644 index 0000000..4b11dfc --- /dev/null +++ b/lua/user/rest-http.lua @@ -0,0 +1,11 @@ +return { + "rest-nvim/rest.nvim", + commit = "d8dc204e9f6fd930d9d1d709f0d19138f804431a", + event = "BufEnter *.http", + requires = { "nvim-lua/plenary.nvim" }, + mappings = { + n = { + ["r"] = { function() require("rest-nvim").run() end, desc = "Send http request" }, + } + }, +} diff --git a/lua/user/rust-tools.lua b/lua/user/rust-tools.lua new file mode 100644 index 0000000..853cdb7 --- /dev/null +++ b/lua/user/rust-tools.lua @@ -0,0 +1,6 @@ +return { + "simrat39/rust-tools.nvim", + commit = "71d2cf67b5ed120a0e31b2c8adb210dd2834242f", + event = "BufEnter *.rs", + after = { "mason-lspconfig.nvim", "inlay-hints." }, +} diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua new file mode 100644 index 0000000..a25a917 --- /dev/null +++ b/lua/user/telescope.lua @@ -0,0 +1,42 @@ +return { + "nvim-telescope/telescope.nvim", + commit = "40c31fdde93bcd85aeb3447bb3e2a3208395a868", + dependencies = { + { "nvim-telescope/telescope-fzf-native.nvim", enabled = vim.fn.executable "make" == 1, build = "make" }, + }, + cmd = "Telescope", + opts = function() + local actions = require "telescope.actions" + local get_icon = require("astronvim.utils").get_icon + return { + defaults = { + prompt_prefix = string.format("%s ", get_icon "Search"), + selection_caret = string.format("%s ", get_icon "Selected"), + path_display = { "truncate" }, + sorting_strategy = "ascending", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + }, + vertical = { + mirror = false, + }, + width = 0.87, + height = 0.80, + preview_cutoff = 120, + }, + + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + }, + n = { ["q"] = actions.close }, + }, + }, + } + end, +} diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua new file mode 100644 index 0000000..5f5b2fc --- /dev/null +++ b/lua/user/treesitter.lua @@ -0,0 +1,79 @@ +return { + "nvim-treesitter/nvim-treesitter", + dependencies = { "windwp/nvim-ts-autotag", "JoosepAlviste/nvim-ts-context-commentstring" }, + commit = "f2778bd1a28b74adf5b1aa51aa57da85adfa3d16", + build = ":TSUpdate", + event = "BufEnter", + cmd = { + "TSBufDisable", + "TSBufEnable", + "TSBufToggle", + "TSDisable", + "TSEnable", + "TSToggle", + "TSInstall", + "TSInstallInfo", + "TSInstallSync", + "TSModuleInfo", + "TSUninstall", + "TSUpdate", + "TSUpdateSync", + }, + opts = { + -- "all", + ensure_installed = { + "http", + "json", + "bash", + "css", + "diff", + "dockerfile", + "dot", + "git_rebase", + "gitattributes", + "html", + "java", + "javascript", + "jq", + "jsdoc", + "json5", + "kotlin", + "latex", + "make", + "markdown", + "markdown_inline", + "nix", + "passwd", + "prisma", + "proto", + "python", + "regex", + "rst", + "rust", + "scss", + "sql", + "svelte", + "terraform", + "toml", + "tsx", + "typescript", + "vue", + "yaml", + }, + -- auto_install = true, + highlight = { + enable = true, + disable = function(_, bufnr) return vim.api.nvim_buf_line_count(bufnr) > 10000 end, + additional_vim_regex_highlighting = false, + }, + incremental_selection = { enable = true }, + ident = { enable = true }, + autotag = { enable = true }, + context_commentstring = { enable = true, enable_autocmd = false }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = nil, + }, + }, +} diff --git a/options.lua b/options.lua index e3089ff..469f385 100644 --- a/options.lua +++ b/options.lua @@ -15,4 +15,6 @@ vim.opt.breakindent = true -- set tab length vim.opt.tabstop = 2; vim.opt.shiftwidth = 2; - +-- split to the right or below always +vim.opt.splitbelow = true +vim.opt.splitright = true