From 6b2b0c377a0c3e4fa9d998b7bac1a597bad1562c Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Wed, 6 Dec 2023 16:09:17 -0600 Subject: [PATCH] improvements, installed ollama gen --- cspell.json | 2 +- lazy-lock.json | 1 + lua/plugins/lsp.lua | 9 +- lua/plugins/null-ls.lua | 61 ++++++------ lua/plugins/telescope.lua | 37 ++++--- lua/plugins/treesitter.lua | 10 -- lua/plugins/which-key.lua | 1 + lua/plugins_disabled/autoclose.lua | 4 - lua/plugins_disabled/rust-tools.lua | 9 -- lua/tools/scratch-files.lua | 143 +++++++++++++++------------- lua/util.lua | 35 ++++--- 11 files changed, 151 insertions(+), 161 deletions(-) delete mode 100644 lua/plugins_disabled/autoclose.lua delete mode 100644 lua/plugins_disabled/rust-tools.lua diff --git a/cspell.json b/cspell.json index 4b26b46..69bd610 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"language":"en","version":"0.2","flagWords":[],"words":["nvim","builtins","stylua","rustfmt","pendo","tanstack","ripgrep","Typeahead","overscan","autorun","mediatype","BIOINF","Transitioner","pkce","ilike","arrayify","arrayified","komodo","wezterm","gcloud","pbpaste","Hasher","semvers","upserted","dtos","Yeatts","Mahon","Beaubier","Taussing","chakra","langchain","openai","getattr","llms","docstore","kwargs","svgr","healthcheck","venv","virtualenv","ringofstorms","nestjs","oneshot","templating","tiktoken","pydantic","NCCN","clsx","reactflow","Convo","DSAB","pgvector","postprocess","stylelua","sqlx","genemichaels","williamboman","substr","findfile","Hammerspoon","eventtap","OSTYPE","sccache","binstall","elif","autofocus","colours","Resizer","esac","pannable","zoomable","elkjs","Arrayible","Falsey","xyflow","leftnav","topnav","nodrag","nowheel","janky","draghandle","Sandboxed","Dismissable","dashdraw","chrono","serde","rustls","schemars","webserver","concats","deepmerge","Customizer","reqwest","brotli","peekable","PDEPO","dotenv","taskserver","walkdir","uuidgen","tolower","nzzzv","tabprevious","tabnext","vsplit","tabclose","tabnew","Neotree","noequalalways","equalalways","bufdo","winnr","keymap","mapleader","maplocalleader","keymaps","setloclist","itertools"]} +{"words":["nvim","builtins","stylua","rustfmt","pendo","tanstack","ripgrep","Typeahead","overscan","autorun","mediatype","BIOINF","Transitioner","pkce","ilike","arrayify","arrayified","komodo","wezterm","gcloud","pbpaste","Hasher","semvers","upserted","dtos","Yeatts","Mahon","Beaubier","Taussing","chakra","langchain","openai","getattr","llms","docstore","kwargs","svgr","healthcheck","venv","virtualenv","ringofstorms","nestjs","oneshot","templating","tiktoken","pydantic","NCCN","clsx","reactflow","Convo","DSAB","pgvector","postprocess","stylelua","sqlx","genemichaels","williamboman","substr","findfile","Hammerspoon","eventtap","OSTYPE","sccache","binstall","elif","autofocus","colours","Resizer","esac","pannable","zoomable","elkjs","Arrayible","Falsey","xyflow","leftnav","topnav","nodrag","nowheel","janky","draghandle","Sandboxed","Dismissable","dashdraw","chrono","serde","rustls","schemars","webserver","concats","deepmerge","Customizer","reqwest","brotli","peekable","PDEPO","dotenv","taskserver","walkdir","uuidgen","tolower","nzzzv","tabprevious","tabnext","vsplit","tabclose","tabnew","Neotree","noequalalways","equalalways","bufdo","winnr","keymap","mapleader","maplocalleader","keymaps","setloclist","itertools","ollama"],"version":"0.2","language":"en","flagWords":[]} diff --git a/lazy-lock.json b/lazy-lock.json index b6a2c53..3a4c3e6 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -11,6 +11,7 @@ "copilot.lua": { "branch": "master", "commit": "3665ed0f3ef3ad68673df7195789d134d0d1fdb0" }, "crates.nvim": { "branch": "main", "commit": "1dffccc0a95f656ebe00cacb4de282473430c5a1" }, "diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" }, + "gen.nvim": { "branch": "main", "commit": "aa951166745dd3cb5a7bf8297ce2bd20d3bb4e00" }, "gitsigns.nvim": { "branch": "main", "commit": "6ef8c54fb526bf3a0bc4efb0b2fe8e6d9a7daed2" }, "glow.nvim": { "branch": "advanced_window", "commit": "f1157d4cb7e46e830c72004e7e1adb81a1f9b04c" }, "indent-blankline.nvim": { "branch": "master", "commit": "29be0919b91fb59eca9e90690d76014233392bef" }, diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 7dd7678..00bac25 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -184,7 +184,7 @@ return { build = ":MasonUpdate", opts = {}, }, - { "folke/neodev.nvim", opts = {} }, -- lua stuff + { "folke/neodev.nvim", opts = {} }, -- lua stuff { "williamboman/mason-lspconfig.nvim", }, @@ -264,6 +264,7 @@ return { [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.abort() + fallback() else fallback() end @@ -286,11 +287,11 @@ return { -- TODO I am getting lag sometimes I think this may be the cause, limiting to 100 for a while to see what happens { name = "nvim_lsp", priority = 8, max_item_count = 100 }, -- This source integrates with LuaSnip, a snippet engine for Neovim. It suggests snippets that you can insert into your code - { name = "luasnip", priority = 7 }, + { name = "luasnip", priority = 7 }, -- This source provides file path completions, helping you to complete file paths in your code - { name = "path", priority = 7 }, + { name = "path", priority = 7 }, -- This source provides completion items from the current buffer, meaning it suggests words that have already been typed in the same file. - { name = "buffer", priority = 6 }, + { name = "buffer", priority = 6 }, -- Rust crates.io integration { name = "crates" }, }, diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua index ec6e005..64d7c2e 100644 --- a/lua/plugins/null-ls.lua +++ b/lua/plugins/null-ls.lua @@ -1,24 +1,10 @@ -local function prereqs() - local output_cspell = vim.fn.system({ - "which", - "cspell", - }) - if output_cspell == nil or output_cspell == "" or output_cspell == "cspell not found" then - print("Installing cspell globally with npm") - vim.fn.system({ - "npm", - "install", - "-g", - "cspell", - }) - end -end +local U = require("util") +local cspell = U.cmd_executable("cspell") return { { "jose-elias-alvarez/null-ls.nvim", dependencies = { "williamboman/mason.nvim" }, - build = prereqs, opts = function(_, config) -- config variable is the default definitions table for the setup function call local null_ls = require("null-ls") @@ -74,30 +60,41 @@ return { null_ls.builtins.formatting.prettier, -- typescript/javascript null_ls.builtins.formatting.stylua.with({ extra_args = { "--indent-type", "spaces", "--indent-width", "2" }, - }), -- lua + }), -- lua --null_ls.builtins.formatting.rustfmt, -- rust rust_formatter_genemichaels, -- order matters, run genemichaels first then rustfmt rust_formatter_rustfmt, -- rust_formatter_sqlx, -- see tools/sqlx-format.lua null_ls.builtins.formatting.black, -- python -- 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/;") - end, - }, - }), - null_ls.builtins.diagnostics.cspell.with({ - extra_args = { "--config", "~/.config/nvim/cspell.json" }, - diagnostics_postprocess = function(diagnostic) - -- vim.notify(vim.inspect(diagnostic)) - diagnostic.message = diagnostic.user_data.misspelled - diagnostic.severity = vim.diagnostic.severity.HINT - end, - }), } + if cspell then + table.insert( + config.sources, + null_ls.builtins.code_actions.cspell.with({ + config = { + find_json = function() + return vim.fn.findfile("cspell.json", vim.fn.environ().HOME .. "/.config/nvim/;") + end, + }, + }) + ) + table.insert( + config.sources, + null_ls.builtins.diagnostics.cspell.with({ + extra_args = { "--config", "~/.config/nvim/cspell.json" }, + diagnostics_postprocess = function(diagnostic) + -- vim.notify(vim.inspect(diagnostic)) + diagnostic.message = diagnostic.user_data.misspelled + diagnostic.severity = vim.diagnostic.severity.HINT + end, + }) + ) + else + vim.notify("cspell is missing, spelling suggestions will not work", 2) + end + config.update_in_insert = true config.debug = true diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 6cd9cec..c3319e0 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,17 +1,4 @@ -local function prereqs() - local output = vim.fn.system({ - "which", - "rg", - }) - if output == nil or output == "" or string.find(output, "not installed for the toolchain") then - print("Installing ripgrep globally with rtx") - vim.fn.system({ - "rtx", - "global", - "ripgrep@latest", - }) - end -end +local U = require("util") return { "nvim-telescope/telescope.nvim", @@ -21,7 +8,13 @@ return { { "nvim-telescope/telescope-fzf-native.nvim", enabled = vim.fn.executable("make") == 1, build = "make" }, { "nvim-telescope/telescope-ui-select.nvim" }, }, - build = prereqs, + init = function() + U.cmd_executable("rg", { + [false] = function() + vim.notify("rg not installed, live grep will not function.", 2) + end, + }) + end, cmd = "Telescope", keys = { { "f", "", desc = "Find ..." }, @@ -53,11 +46,15 @@ return { { "fw", function() - if vim.fn.executable("rg") == 0 then - vim.notify("rg not installed, live grep will not function.", 3) - end - require("telescope.builtin").live_grep({ - hidden = true, + U.cmd_executable("rg", { + function() + require("telescope.builtin").live_grep({ + hidden = true, + }) + end, + function() + vim.notify("rg not installed, live grep will not function.", 3) + end, }) end, desc = "Find Words", diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index b4aaad5..389d2a5 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,12 +1,3 @@ -local auto = true -local output = vim.fn.system({ - "which", - "tree-sitter", -}) -if output == nil or output == "" then - auto = false -end - return { { "nvim-treesitter/nvim-treesitter", @@ -67,7 +58,6 @@ return { "vue", "yaml", }, - -- auto_install = auto, highlight = { enable = true, use_languagetree = true, diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 6089c5a..56aafc2 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -26,6 +26,7 @@ return { ["Q"] = { name = "+Q Quit and remove session" }, ["s"] = { name = "Scratch Files" }, ["t"] = { name = "Tabs" }, + ["x"] = { name = "Generative AI, Ollama" }, }) end, } diff --git a/lua/plugins_disabled/autoclose.lua b/lua/plugins_disabled/autoclose.lua deleted file mode 100644 index c2979f1..0000000 --- a/lua/plugins_disabled/autoclose.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - "m4xshen/autoclose.nvim", - opts = {}, -} diff --git a/lua/plugins_disabled/rust-tools.lua b/lua/plugins_disabled/rust-tools.lua deleted file mode 100644 index bdd55f4..0000000 --- a/lua/plugins_disabled/rust-tools.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - { - "simrat39/rust-tools.nvim", - event = "BufEnter *.rs", - dependencies = { "mason-lspconfig.nvim", "lvimuser/lsp-inlayhints.nvim" }, - opts = {}, - }, - { "Saecki/crates.nvim", tag = "v0.3.0", dependencies = { "nvim-lua/plenary.nvim" }, opts = {} }, -} diff --git a/lua/tools/scratch-files.lua b/lua/tools/scratch-files.lua index 1347cd6..56d8a4a 100644 --- a/lua/tools/scratch-files.lua +++ b/lua/tools/scratch-files.lua @@ -6,72 +6,81 @@ local scratch = function(extension) vim.cmd("execute 'edit " .. filepath .. "'") end -require("util").keymaps_old({ - n = { - ["fsw"] = { - function() - require("telescope.builtin").live_grep({ - search_dirs = { "~/dev/scratches/" }, - }) - end, - desc = "Find Words in Scratches", - }, - ["fsf"] = { - function() - require("telescope.builtin").find_files({ - search_dirs = { "~/dev/scratches/" }, - }) - end, - desc = "Find Scratches", - }, - ["s"] = { "", desc = "Scratch File" }, - ["ss"] = { - function() - scratch(".txt") - end, - desc = "New [t]e[xt] scratch file", - }, - ["sn"] = { - function() - scratch(".json") - end, - desc = "New json scratch file", - }, - ["sm"] = { - function() - scratch(".md") - end, - desc = "New [m]ark[d]own scratch file", - }, - ["sq"] = { - function() - scratch(".sql") - end, - desc = "New sql scratch file", - }, - ["st"] = { - function() - scratch(".ts") - end, - desc = "New [t]ype[s]cript scratch file", - }, - ["sb"] = { - function() - scratch(".sh") - end, - desc = "New [sh]ell scratch file", - }, - ["sj"] = { - function() - scratch(".js") - end, - desc = "New [j]ava[s]cript scratch file", - }, - ["sr"] = { - function() - scratch(".rs") - end, - desc = "New [r]u[s]t scratch file", - }, +local U = require("util") + +U.keymaps({ + { + "fsw", + function() + require("telescope.builtin").live_grep({ + search_dirs = { "~/dev/scratches/" }, + }) + end, + desc = "Find Words in Scratches", + }, + { + "fsf", + function() + require("telescope.builtin").find_files({ + search_dirs = { "~/dev/scratches/" }, + }) + end, + desc = "Find Scratches", + }, + { "s", "", desc = "Scratch File" }, + ["ss"] = { + function() + scratch(".txt") + end, + desc = "New text scratch file", + }, + { + "sn", + function() + scratch(".json") + end, + desc = "New json scratch file", + }, + { + "sm", + function() + scratch(".md") + end, + desc = "New markdown scratch file", + }, + { + "sq", + function() + scratch(".sql") + end, + desc = "New sql scratch file", + }, + { + "st", + function() + scratch(".ts") + end, + desc = "New typescript scratch file", + }, + { + "sb", + function() + scratch(".sh") + end, + desc = "New shell scratch file", + }, + { + "sj", + function() + scratch(".js") + end, + desc = "New javascript scratch file", + }, + { + "sr", + function() + scratch(".rs") + end, + desc = "New rust scratch file", }, }) diff --git a/lua/util.lua b/lua/util.lua index b3c6075..fd627b3 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -1,23 +1,30 @@ local M = {} -function M.keymaps_old(mappings) - for mode, maps in pairs(mappings) do - for keymap, options in pairs(maps) do - if options then - local cmd = options - local keymap_opts = {} - if type(options) == "table" then - cmd = options[1] - keymap_opts = vim.tbl_deep_extend("force", keymap_opts, options) - keymap_opts[1] = nil - end +function M.cmd_executable(cmd, callback) + local executable = vim.fn.executable(cmd) == 1 + -- Check if a callback is provided and it is a function + if executable and callback and type(callback) == "function" then + callback() + end - if mode and keymap and cmd and keymap_opts then - vim.keymap.set(mode, keymap, cmd, keymap_opts) - end + -- Check if a callback is provided and it is a table + if type(callback) == "table" then + if executable and (callback[1] or callback[true]) then + -- Call the function associated with key 1 or true if the command is executable + local func = callback[1] or callback[true] + if type(func) == "function" then + func() + end + elseif not executable and (callback[2] or callback[false]) then + -- Call the function associated with key 2 or false if the command is not executable + local func = callback[2] or callback[false] + if type(func) == "function" then + func() end end end + + return executable end -- [1]: (string) lhs (required)