From 2e3c750979aeabc37d65688f5a3f82bffd4b6345 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 18 Nov 2024 08:33:38 -0500 Subject: [PATCH] feat: Updates to nvim config and snippets --- nvim/m-housh/init.lua | 6 -- nvim/m-housh/lua/user/autocmd.lua | 104 ++++++------------- nvim/m-housh/lua/user/keymaps.lua | 38 ------- nvim/m-housh/lua/user/plugin/cmp.lua | 5 + nvim/m-housh/lua/user/plugin/init.lua | 31 +----- nvim/m-housh/lua/user/plugin/lsp.lua | 2 + nvim/m-housh/lua/user/plugin/oil.lua | 8 +- nvim/m-housh/lua/user/plugin/telescope.lua | 6 +- nvim/m-housh/lua/user/plugin/xcodebuild.lua | 43 -------- nvim/m-housh/lua/user/plugins.lua | 89 ++++++++-------- nvim/m-housh/lua/user/snippets/swift.lua | 108 +++++++++++++++----- 11 files changed, 176 insertions(+), 264 deletions(-) diff --git a/nvim/m-housh/init.lua b/nvim/m-housh/init.lua index d2e0f10..f155935 100755 --- a/nvim/m-housh/init.lua +++ b/nvim/m-housh/init.lua @@ -16,9 +16,3 @@ require("user.theme") -- Common settings require("user.settings") - --- Snippets are setup in the luasnip settings, they get loaded from the snippets directory --- based on filetype. ---require("user.snippets") - -vim.o.shiftwidth = 2 diff --git a/nvim/m-housh/lua/user/autocmd.lua b/nvim/m-housh/lua/user/autocmd.lua index 279cd13..d10c7c6 100755 --- a/nvim/m-housh/lua/user/autocmd.lua +++ b/nvim/m-housh/lua/user/autocmd.lua @@ -1,85 +1,41 @@ local defaultGroupOptions = { clear = true } local markdownGroup = vim.api.nvim_create_augroup("MyMarkdownGroup", defaultGroupOptions) -local spellGroup = vim.api.nvim_create_augroup('SpellGroup', defaultGroupOptions) +local spellGroup = vim.api.nvim_create_augroup("SpellGroup", defaultGroupOptions) local createCmd = vim.api.nvim_create_autocmd -local swiftGroup = vim.api.nvim_create_augroup('swift_lsp', { clear = true }) - --- Remove all trailing whitespace on save -vim.api.nvim_exec([[ - augroup TrimWhiteSpace - au! - autocmd BufWritePre * :%s/\s\+$//e - augroup END - ]], false) - --- Prevent new line to also start with a comment -vim.api.nvim_exec([[ - augroup NewLineComment - au! - au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o - augroup END - ]], false) -- Spell check -createCmd( - "BufEnter", - { - pattern = { '*.md', '*.markdown', '*.txt', '*.tex' }, - group = spellGroup, - callback = function(_) - vim.cmd.setlocal('textwidth=80') - vim.cmd.setlocal('spell spelllang=en_us') - end, - } -) +createCmd("BufEnter", { + pattern = { "*.md", "*.markdown", "*.txt", "*.tex" }, + group = spellGroup, + callback = function(_) + vim.cmd.setlocal("textwidth=80") + vim.cmd.setlocal("spell spelllang=en_us") + end, +}) -- Markdown -createCmd( - "BufWritePost", - { - pattern = { "*.md", "*.markdown" }, - group = markdownGroup, - callback = function(_) - local cursor = vim.fn.getpos('.') - vim.cmd("FormatWrite") - vim.fn.setpos('.', cursor) - end, - } -) +createCmd("BufWritePost", { + pattern = { "*.md", "*.markdown" }, + group = markdownGroup, + callback = function(_) + local cursor = vim.fn.getpos(".") + vim.cmd("FormatWrite") + vim.fn.setpos(".", cursor) + end, +}) -- Go -createCmd( - "BufWritePre", - { - pattern = "*.go", - callback = function() - require('go.format').goimport() - end, - group = vim.api.nvim_create_augroup("GoFormat", defaultGroupOptions) - } -) +createCmd("BufWritePre", { + pattern = "*.go", + callback = function() + require("go.format").goimport() + end, + group = vim.api.nvim_create_augroup("GoFormat", defaultGroupOptions), +}) -vim.api.nvim_exec([[ +vim.api.nvim_exec2( + [[ autocmd BufNewFile,BufRead /private/**/gopass** setlocal noswapfile nobackup noundofile shada="" - ]], false) - --- Swift --- createCmd( --- "FileType", --- { --- pattern = { 'swift' }, --- callback = function() --- local root_dir = vim.fs.dirname(vim.fs.find({ --- "Package.swift", --- ".git", --- }, { upward = true })[1]) --- local client = vim.lsp.start({ --- name = "sourcekit-lsp", --- cmd = { "sourcekit-lsp" }, --- root_dir = root_dir --- }) --- vim.lsp.buf_attach_client(0, client) --- end, --- group = swiftGroup --- } --- ) + ]], + {} +) diff --git a/nvim/m-housh/lua/user/keymaps.lua b/nvim/m-housh/lua/user/keymaps.lua index 97c2afe..e4a9e17 100755 --- a/nvim/m-housh/lua/user/keymaps.lua +++ b/nvim/m-housh/lua/user/keymaps.lua @@ -36,7 +36,6 @@ wk_add("n", { { "n", ":noh", desc = "[N]o highlighting" }, { "s", ":set spell!", desc = "[S]pell check toggle" }, - --{ "", ":Neotree toggle", desc = "Toggle Neotree" }, { "", ":write", desc = "[S]ave" }, { "J", ":move .+1==", desc = "Move line down" }, @@ -62,14 +61,7 @@ wk_add("n", { -------------------------------------------------------------------------------- -- Visual Mode -------------------------------------------------------------------------------- --- wk_add("v", { --- { "p", "\"_dP", desc = "[P]aste" }, --- }) --- wk_add("v", { --- { "K", ":move '<-2", desc = "Move selected block up" }, --- { "J", ":move '>+1", desc = "Move selected block down" }, --- }) vim.keymap.set("v", "K", ":move '<-2gv=gv", { desc = "Move selected block up.", silent = true, noremap = true }) vim.keymap.set("v", "J", ":move '>+1gv=gv", { desc = "Move selected block up.", silent = true, noremap = true }) @@ -79,33 +71,3 @@ function _G.set_terminal_keymaps() keymap("t", "", [[]], opts) end vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()") - --- LuaSnip Keymaps ---local ls = require('luasnip') - --- to expand snippets. --- This will expand the snippet or jump to the next item within the snippet. --- vim.keymap.set({ "i", "s" }, "", function() --- if ls.expand_or_jumpable() then --- ls.expand_or_jump() --- end --- end, { silent = true }) - --- --- This will jump backwards in the snippet. --- vim.keymap.set({ "i", "s" }, "", function() --- if ls.jumpable(-1) then --- ls.jump(-1) --- end --- end, { silent = true }) - --- --- This is for selecting withing a list of options. --- vim.keymap.set("i", "", function() --- if ls.choice_active() then --- ls.change_choice(1) --- end --- end, { silent = true }) - --- Reload the snippets. ---vim.keymap.set("n", "s", "source ~/.config/m-housh/lua/snippets/init.lua") diff --git a/nvim/m-housh/lua/user/plugin/cmp.lua b/nvim/m-housh/lua/user/plugin/cmp.lua index e405003..fc6576e 100755 --- a/nvim/m-housh/lua/user/plugin/cmp.lua +++ b/nvim/m-housh/lua/user/plugin/cmp.lua @@ -14,6 +14,8 @@ return { local luasnip = require("luasnip") local lspkind = require("lspkind") + -- TODO: This is implemented in LuaSnip config, does it need to be here? + -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) require("luasnip.loaders.from_vscode").lazy_load() @@ -32,6 +34,9 @@ return { [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace }), + -- TODO: + -- The next two mappings are also implemented in the LuaSnip configuration, + -- as and do they actually need to be here?? [""] = cmp.mapping(function(fallback) if luasnip.jumpable(-1) then luasnip.jump(-1) diff --git a/nvim/m-housh/lua/user/plugin/init.lua b/nvim/m-housh/lua/user/plugin/init.lua index 17d5b3f..da94064 100755 --- a/nvim/m-housh/lua/user/plugin/init.lua +++ b/nvim/m-housh/lua/user/plugin/init.lua @@ -1,31 +1,2 @@ -- This file contains plugin's that don't require much configuration. -return { --- { --- "L3MON4D3/LuaSnip", --- version = "2.*", --- build = "make install_jsregexp", --- event = { 'BufReadPre', 'BufNewFile' }, --- config = function() --- local luasnip = require('luasnip') --- local types = require('luasnip.util.types') --- luasnip.config.set_config { --- history = true, --- updateevents = "TextChanged,TextChangedI", --- enable_autosnippets = true, --- ext_opts = { --- [types.choiceNode] = { --- active = { --- virt_text = { { "<-", "Error" } }, --- }, --- }, --- }, --- } --- end --- }, - { - "hrsh7th/vim-vsnip", - config = function() - vim.g.vsnip_snippet_dir = os.getenv('HOME') .. '/.config/m-housh/lua/snippets/' - end - }, -} +return {} diff --git a/nvim/m-housh/lua/user/plugin/lsp.lua b/nvim/m-housh/lua/user/plugin/lsp.lua index 987ecb6..81d3d14 100755 --- a/nvim/m-housh/lua/user/plugin/lsp.lua +++ b/nvim/m-housh/lua/user/plugin/lsp.lua @@ -74,6 +74,7 @@ return { -- more details: https://github.com/neovim/neovim/issues/19237#issuecomment-2237037154 client.offset_encoding = "utf-8" end, + cmd = lsp == "sourcekit" and { vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")) } or nil, }) end @@ -84,6 +85,7 @@ return { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end + -- For some reason I was having trouble getting this to work inside the on-attach, so it's here. vim.keymap.set("n", "rn", vim.lsp.buf.rename, { desc = "[R]e-[N]ame" }) end, } diff --git a/nvim/m-housh/lua/user/plugin/oil.lua b/nvim/m-housh/lua/user/plugin/oil.lua index 9cb74fd..d91311d 100644 --- a/nvim/m-housh/lua/user/plugin/oil.lua +++ b/nvim/m-housh/lua/user/plugin/oil.lua @@ -11,9 +11,8 @@ return { [""] = "actions.select_split", }, view_options = { - --show_hidden = true, - is_hidden_file = function(name, bufnr) - -- Don't show .DS_STORE in output. + is_hidden_file = function(name, _) -- second arg is bufnr, but not currently used. + -- Don't show .DS_Store in output. local is_ds_store = name ~= ".DS_Store" return not is_ds_store end, @@ -25,5 +24,8 @@ return { -- Open parent directory in floating window. vim.keymap.set("n", "-", require("oil").toggle_float) + + -- Old habits die hard, map what used to toggle neo-tree to just open a float. + vim.keymap.set("n", "", require("oil").toggle_float) end, } diff --git a/nvim/m-housh/lua/user/plugin/telescope.lua b/nvim/m-housh/lua/user/plugin/telescope.lua index 00d8742..40854a3 100755 --- a/nvim/m-housh/lua/user/plugin/telescope.lua +++ b/nvim/m-housh/lua/user/plugin/telescope.lua @@ -27,14 +27,18 @@ return { }, mappings = { i = { - -- Close on first esc instead of gonig to normal mode + -- Close on first esc instead of going to normal mode [""] = actions.close, [""] = actions.send_selected_to_qflist, [""] = actions.send_to_qflist, [""] = actions.toggle_selection + actions.move_selection_next, [""] = actions.toggle_selection + actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, }, n = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, [""] = actions.toggle_selection + actions.move_selection_next, [""] = actions.toggle_selection + actions.move_selection_previous, [""] = actions.send_selected_to_qflist, diff --git a/nvim/m-housh/lua/user/plugin/xcodebuild.lua b/nvim/m-housh/lua/user/plugin/xcodebuild.lua index 1caabf6..6107a9a 100644 --- a/nvim/m-housh/lua/user/plugin/xcodebuild.lua +++ b/nvim/m-housh/lua/user/plugin/xcodebuild.lua @@ -77,46 +77,3 @@ return { vim.keymap.set("n", "xa", "XcodebuildCodeActions", { desc = "Show Code Actions" }) end, } --- return { --- "wojciech-kulik/xcodebuild.nvim", --- dependencies = { --- "nvim-telescope/telescope.nvim", --- "MunifTanjim/nui.nvim", --- "nvim-neo-tree/neo-tree.nvim", -- (optional) to manage project files --- "stevearc/oil.nvim", -- (optional) to manage project files --- "nvim-treesitter/nvim-treesitter", -- (optional) for Quick tests support (required Swift parser) --- }, --- config = function() --- require("xcodebuild").setup({ --- -- put some options here or leave it empty to use default settings --- code_coverage = { --- enabled = true --- } --- }) --- --- vim.keymap.set("n", "X", "XcodebuildPicker", { desc = "Show Xcodebuild Actions" }) --- vim.keymap.set("n", "xf", "XcodebuildProjectManager", { desc = "Show Project Manager Actions" }) --- --- vim.keymap.set("n", "xb", "XcodebuildBuild", { desc = "Build Project" }) --- vim.keymap.set("n", "xB", "XcodebuildBuildForTesting", { desc = "Build For Testing" }) --- vim.keymap.set("n", "xr", "XcodebuildBuildRun", { desc = "Build & Run Project" }) --- --- vim.keymap.set("n", "xt", "XcodebuildTest", { desc = "Run Tests" }) --- vim.keymap.set("v", "xt", "XcodebuildTestSelected", { desc = "Run Selected Tests" }) --- vim.keymap.set("n", "xT", "XcodebuildTestClass", { desc = "Run Current Test Class" }) --- vim.keymap.set("n", "x.", "XcodebuildTestRepeat", { desc = "Repeat Last Test Run" }) --- --- vim.keymap.set("n", "xl", "XcodebuildToggleLogs", { desc = "Toggle Xcodebuild Logs" }) --- vim.keymap.set("n", "xc", "XcodebuildToggleCodeCoverage", { desc = "Toggle Code Coverage" }) --- vim.keymap.set("n", "xC", "XcodebuildShowCodeCoverageReport", { desc = "Show Code Coverage Report" }) --- vim.keymap.set("n", "xe", "XcodebuildTestExplorerToggle", { desc = "Toggle Test Explorer" }) --- vim.keymap.set("n", "xs", "XcodebuildFailingSnapshots", { desc = "Show Failing Snapshots" }) --- --- vim.keymap.set("n", "xd", "XcodebuildSelectDevice", { desc = "Select Device" }) --- vim.keymap.set("n", "xp", "XcodebuildSelectTestPlan", { desc = "Select Test Plan" }) --- vim.keymap.set("n", "xq", "Telescope quickfix", { desc = "Show QuickFix List" }) --- --- vim.keymap.set("n", "xx", "XcodebuildQuickfixLine", { desc = "Quickfix Line" }) --- vim.keymap.set("n", "xa", "XcodebuildCodeActions", { desc = "Show Code Actions" }) --- end, --- } diff --git a/nvim/m-housh/lua/user/plugins.lua b/nvim/m-housh/lua/user/plugins.lua index 8242455..2040eb0 100755 --- a/nvim/m-housh/lua/user/plugins.lua +++ b/nvim/m-housh/lua/user/plugins.lua @@ -1,57 +1,56 @@ -- Bootstrap Lazy. local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ - dev = { - path = '~/LocalProjects/plugins', - fallback = true - }, - -- Import all the plugin configs in the 'plugin' directory - { import = 'user.plugin' }, - -- Plugins that don't have a configuration file. - { - "folke/zen-mode.nvim", - opts = { } - }, - { - "christoomey/vim-tmux-navigator", - lazy = false, - }, - { - "NMAC427/guess-indent.nvim", - opts = { } - }, - { "NoahTheDuke/vim-just", ft = { "just" } }, - { - 'chipsenkbeil/distant.nvim', - branch = 'v0.3', - config = function() - require('distant'):setup() - end - }, - - -- LSP, formatting, etc. -- - { 'folke/neodev.nvim', opts = {} }, + dev = { + path = "~/LocalProjects/plugins", + fallback = true, + }, + -- Import all the plugin configs in the 'plugin' directory + { import = "user.plugin" }, + -- Plugins that don't have a configuration file. + { + "folke/zen-mode.nvim", + opts = {}, + }, + { + "christoomey/vim-tmux-navigator", + lazy = false, + }, + -- { + -- "NMAC427/guess-indent.nvim", + -- opts = { } + -- }, + { "NoahTheDuke/vim-just", ft = { "just" } }, + { + "chipsenkbeil/distant.nvim", + branch = "v0.3", + config = function() + require("distant"):setup() + end, + }, + -- LSP, formatting, etc. -- + { "folke/neodev.nvim", opts = {} }, }, { - checker = { - enabled = true, - notify = false - }, - change_detection = { - notify = false - } + checker = { + enabled = true, + notify = false, + }, + change_detection = { + notify = false, + }, }) vim.keymap.set("n", "ll", "Lazy", { desc = "Open [L]azy" }) diff --git a/nvim/m-housh/lua/user/snippets/swift.lua b/nvim/m-housh/lua/user/snippets/swift.lua index fca3832..6c9ca16 100644 --- a/nvim/m-housh/lua/user/snippets/swift.lua +++ b/nvim/m-housh/lua/user/snippets/swift.lua @@ -15,50 +15,110 @@ ls.add_snippets("swift", { s("@d", fmt("@Dependency(\\.{}) var {}", { i(1), rep(1) })), -- Add a dependency client. - s("@dc", fmt([[ + s( + { + trig = "@dc", + desc = "Add a dependency client.", + }, + fmt( + [[ public extension DependencyValues {{ var {}: {} {{ - get: {{ self[{}.self] }} - set: {{ self[{}.self] = newValue }} + get {{ self[{}.self] }} + set {{ self[{}.self] = newValue }} }} }} @DependencyClient - struct {} {{ + public struct {} {{ + // Insert interface here. + {} }} extension {}: TestDependencyKey {{ - static let testValue: {} = Self() + public static let testValue: {} = Self() }} - ]], { - i(1, ""), - i(2, ""), - rep(2), - rep(2), - rep(2), - rep(2), - rep(2), - }) + ]], + { + i(1, ""), + i(2, ""), + rep(2), + rep(2), + rep(2), + i(0), + rep(2), + rep(2), + } + ) ), - -- Add spi modifier snippet. - s("spi", fmt("@_spi({})", { i(1, "name") })), + s( + { trig = "str", desc = "Add a struct" }, + fmt( + [[ + struct {}: {} {{ + {} + }} + ]], + { i(1, ""), i(2, ""), i(0) } + ) + ), - -- Add spi import modifier snippet. - s("sii", fmt("@_spi({}) import {}", { i(1, "name"), i(2, "modlue") })), + s({ trig = "spi", desc = "Add spi modifier." }, fmt("@_spi({})", { i(1, "name") })), - -- Document a function. - s("doc", fmt([[ + s( + { trig = "sii", desc = "Import with spi." }, + fmt( + [[ + @_spi({}) import {} + {} + ]], + { i(1, "name"), i(2, "modlue"), i(0) } + ) + ), + + s( + { trig = "docf", desc = "Document a function." }, + fmt( + [[ /// {} /// /// - Parameters: /// - {}: {} - ]], { i(1, "A short description."), i(2, ""), i(3, "") } - )), + ]], + { i(1, "A short description."), i(2, ""), i(3, "") } + ) + ), - s("param", fmt([[ + s( + { trig = "param", desc = "Add a parameter to documentation" }, + fmt( + [[ /// - {}: {} - ]], { i(1, ""), i(2, "") })), + ]], + { i(1, ""), i(2, "") } + ) + ), + s( + { trig = "wd", desc = "withDependencies" }, + fmt( + [[ + withDependencies {{ + $0.{} = {} + }} operation: {{ + @Dependency(\.{}) var {} + {} + }} + ]], + { + i(1, ""), + i(2, ""), + rep(1), + rep(1), + i(0), + } + ) + ), })