From 19094fdf43e0aa5be0bc3d8e7bf3e5ff1d36ce51 Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Sat, 22 Mar 2025 15:33:31 -0700 Subject: [PATCH] Updates and fixes to nvim plugins --- nvim/ftplugin/quarto.lua | 85 +++++++++++++++++++++++ nvim/init.lua | 22 +----- nvim/lua/custom/plugins/codecompanion.lua | 34 +++++++++ nvim/lua/custom/plugins/conform.lua | 33 ++++++++- nvim/lua/custom/plugins/neo-tree.lua | 22 ++++++ nvim/lua/custom/plugins/quarto.lua | 9 +++ nvim/lua/kickstart/plugins/neo-tree.lua | 25 ------- 7 files changed, 182 insertions(+), 48 deletions(-) create mode 100644 nvim/ftplugin/quarto.lua create mode 100644 nvim/lua/custom/plugins/codecompanion.lua create mode 100644 nvim/lua/custom/plugins/neo-tree.lua create mode 100644 nvim/lua/custom/plugins/quarto.lua delete mode 100644 nvim/lua/kickstart/plugins/neo-tree.lua diff --git a/nvim/ftplugin/quarto.lua b/nvim/ftplugin/quarto.lua new file mode 100644 index 0000000..127f354 --- /dev/null +++ b/nvim/ftplugin/quarto.lua @@ -0,0 +1,85 @@ +-- Copied from: +-- https://github.com/jmbuhr/quarto-nvim-kickstarter/blob/main/ftplugin/quarto.lua + +local api = vim.api +local ts = vim.treesitter + +vim.b.slime_cell_delimiter = '```' +vim.b['quarto_is_r_mode'] = nil +vim.b['reticulate_running'] = false + +-- wrap text, but by word no character +-- indent the wrappped line +vim.wo.wrap = true +vim.wo.linebreak = true +vim.wo.breakindent = true +vim.wo.showbreak = '|' + +-- don't run vim ftplugin on top +vim.api.nvim_buf_set_var(0, 'did_ftplugin', true) + +-- markdown vs. quarto hacks +local ns = vim.api.nvim_create_namespace 'QuartoHighlight' +vim.api.nvim_set_hl(ns, '@markup.strikethrough', { strikethrough = false }) +vim.api.nvim_set_hl(ns, '@markup.doublestrikethrough', { strikethrough = true }) +vim.api.nvim_win_set_hl_ns(0, ns) + +-- ts based code chunk highlighting uses a change +-- only availabl in nvim >= 0.10 +if vim.fn.has 'nvim-0.10.0' == 0 then + return +end + +-- highlight code cells similar to +-- 'lukas-reineke/headlines.nvim' +-- (disabled in lua/plugins/ui.lua) +local buf = api.nvim_get_current_buf() + +local parsername = 'markdown' +local parser = ts.get_parser(buf, parsername) +local tsquery = '(fenced_code_block)@codecell' + +-- vim.api.nvim_set_hl(0, '@markup.codecell', { bg = '#000055' }) +vim.api.nvim_set_hl(0, '@markup.codecell', { + link = 'CursorLine', +}) + +local function clear_all() + local all = api.nvim_buf_get_extmarks(buf, ns, 0, -1, {}) + for _, mark in ipairs(all) do + vim.api.nvim_buf_del_extmark(buf, ns, mark[1]) + end +end + +local function highlight_range(from, to) + for i = from, to do + vim.api.nvim_buf_set_extmark(buf, ns, i, 0, { + hl_eol = true, + line_hl_group = '@markup.codecell', + }) + end +end + +local function highlight_cells() + clear_all() + + local query = ts.query.parse(parsername, tsquery) + local tree = parser:parse() + local root = tree[1]:root() + for _, match, _ in query:iter_matches(root, buf, 0, -1, { all = true }) do + for _, nodes in pairs(match) do + for _, node in ipairs(nodes) do + local start_line, _, end_line, _ = node:range() + pcall(highlight_range, start_line, end_line - 1) + end + end + end +end + +highlight_cells() + +vim.api.nvim_create_autocmd({ 'ModeChanged', 'BufWrite' }, { + group = vim.api.nvim_create_augroup('QuartoCellHighlight', { clear = true }), + buffer = buf, + callback = highlight_cells, +}) diff --git a/nvim/init.lua b/nvim/init.lua index a5fd086..64c43f0 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -85,7 +85,7 @@ vim.keymap.set('n', 'f', 'nohlsearch') -- Diagnostic keymaps vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -local wiki_path = vim.fn.expand('~/Dropbox/wiki/zettel') +local wiki_path = vim.fn.expand '~/Dropbox/wiki/zettel' if vim.fn.isdirectory(wiki_path) == 1 then vim.g.wiki_root = wiki_path end @@ -110,11 +110,6 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the upper win -- Faster Esc vim.keymap.set('i', 'jj', '', { noremap = true }) --- Double leader writes the file -vim.keymap.set('n', '', function() - vim.cmd 'write' -end, { noremap = true }) - -- Prevent from entering Ex mode vim.keymap.set('n', 'Q', '', { noremap = true }) @@ -163,18 +158,6 @@ require('lazy').setup({ { 'catppuccin/nvim', name = 'catppuccin', priority = 1000 }, - { - 'jose-elias-alvarez/null-ls.nvim', - dependencies = { 'nvim-lua/plenary.nvim' }, - config = function() - local null_ls = require 'null-ls' - - null_ls.setup { - sources = {}, - } - end, - }, - -- NOTE: Plugins can also be added by using a table, -- with the first argument being the link and the following -- keys can be used to configure plugin behavior/loading/etc. @@ -446,7 +429,7 @@ require('lazy').setup({ local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, + pyright = {}, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -706,7 +689,6 @@ require('lazy').setup({ require 'kickstart.plugins.debug', require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` diff --git a/nvim/lua/custom/plugins/codecompanion.lua b/nvim/lua/custom/plugins/codecompanion.lua new file mode 100644 index 0000000..e002e20 --- /dev/null +++ b/nvim/lua/custom/plugins/codecompanion.lua @@ -0,0 +1,34 @@ +return { + 'olimorris/codecompanion.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-treesitter/nvim-treesitter', + }, + config = function() + require('codecompanion').setup { + adapters = { + qwern = function() + return require('codecompanion.adapters').extend('ollama', { + name = 'qwern', + schema = { + model = { + default = 'qwen2.5-coder:14b', + }, + }, + }) + end, + }, + strategies = { + chat = { + adapter = 'qwern', + }, + inline = { + adapter = 'qwern', + }, + agent = { + adapter = 'qwern', + }, + }, + } + end, +} diff --git a/nvim/lua/custom/plugins/conform.lua b/nvim/lua/custom/plugins/conform.lua index 337fad6..036b105 100644 --- a/nvim/lua/custom/plugins/conform.lua +++ b/nvim/lua/custom/plugins/conform.lua @@ -32,12 +32,39 @@ return { } end, formatters_by_ft = { + javascript = { 'prettierd' }, lua = { 'stylua' }, - yaml = { 'prettierd' }, - sql = { 'sqlfmt' }, markdown = { 'prettierd' }, python = { 'ruff_format', 'ruff_fix', 'ruff_organize_imports' }, - javascript = { 'prettierd' }, + quarto = { 'injected' }, + sql = { 'sqlfmt' }, + yaml = { 'prettierd' }, }, }, + -- See: + -- https://github.com/jmbuhr/quarto-nvim-kickstarter/blob/382b050e13eada7180ad048842386be37e820660/lua/plugins/editing.lua#L29-L81 + config = function() + require('conform').formatters.injected = { + -- Set the options field + options = { + -- Set to true to ignore errors + ignore_errors = false, + -- Map of treesitter language to file extension + -- A temporary file name with this extension will be generated during formatting + -- because some formatters care about the filename. + lang_to_ext = { + bash = 'sh', + javascript = 'js', + latex = 'tex', + markdown = 'md', + python = 'py', + r = 'r', + typescript = 'ts', + }, + -- Map of treesitter language to formatters to use + -- (defaults to the value from formatters_by_ft) + lang_to_formatters = {}, + }, + } + end, } diff --git a/nvim/lua/custom/plugins/neo-tree.lua b/nvim/lua/custom/plugins/neo-tree.lua new file mode 100644 index 0000000..2bb3095 --- /dev/null +++ b/nvim/lua/custom/plugins/neo-tree.lua @@ -0,0 +1,22 @@ +return { + 'nvim-neo-tree/neo-tree.nvim', + version = '*', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.nvim', + }, + cmd = 'Neotree', + keys = { + { 'e', 'Neotree reveal', desc = 'Open N[e]otree', silent = true }, + }, + opts = { + filesystem = { + window = { + mappings = { + ['e'] = 'close_window', + }, + }, + }, + }, +} diff --git a/nvim/lua/custom/plugins/quarto.lua b/nvim/lua/custom/plugins/quarto.lua new file mode 100644 index 0000000..da97c9a --- /dev/null +++ b/nvim/lua/custom/plugins/quarto.lua @@ -0,0 +1,9 @@ +return { + 'quarto-dev/quarto-nvim', + ft = { 'quarto' }, + dev = false, + opts = {}, + dependencies = { + 'jmbuhr/otter.nvim', + }, +} diff --git a/nvim/lua/kickstart/plugins/neo-tree.lua b/nvim/lua/kickstart/plugins/neo-tree.lua deleted file mode 100644 index bd44226..0000000 --- a/nvim/lua/kickstart/plugins/neo-tree.lua +++ /dev/null @@ -1,25 +0,0 @@ --- Neo-tree is a Neovim plugin to browse the file system --- https://github.com/nvim-neo-tree/neo-tree.nvim - -return { - 'nvim-neo-tree/neo-tree.nvim', - version = '*', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended - 'MunifTanjim/nui.nvim', - }, - cmd = 'Neotree', - keys = { - { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, - }, - opts = { - filesystem = { - window = { - mappings = { - ['\\'] = 'close_window', - }, - }, - }, - }, -}