From c33e0fa84266061053843acd829a722545a54b25 Mon Sep 17 00:00:00 2001 From: Aria Nolan Date: Fri, 15 Sep 2023 10:59:34 -0400 Subject: [PATCH] i forgor --- config.lua | 19 +++- init.vim | 0 lua/user/cmp.lua | 222 ++++++++++++++++++++++++++++++++++++++++++++ lua/user/latex.lua | 30 +++--- lua/user/python.lua | 24 +++-- 5 files changed, 272 insertions(+), 23 deletions(-) create mode 100644 init.vim create mode 100644 lua/user/cmp.lua diff --git a/config.lua b/config.lua index 15c0aa9..1acae1d 100644 --- a/config.lua +++ b/config.lua @@ -6,6 +6,7 @@ require("user.c") require("user.python") +require("user.latex") lvim.transparent_window = true lvim.colorscheme = "rose-pine-moon" @@ -14,13 +15,15 @@ vim.opt.cb = "unnamedplus" vim.opt.nf = "alpha,octal,hex,bin,unsigned" vim.opt.si = true vim.opt.backup = false +vim.opt.cc = "+1" +vim.opt.textwidth = 80 lvim.builtin.nvimtree.active = false -- NOTE: using neo-tree lvim.builtin.indentlines.active = true vim.o.timeoutlen = 250 vim.opt.ts = 2 vim.opt.sw = 2 -vim.opt.et = true +vim.opt.et = false lvim.keys.normal_mode[""] = ":NeoTreeFocusToggle" lvim.keys.normal_mode[""] = ":BufferLineCyclePrev" @@ -35,7 +38,7 @@ vim.diagnostic.config({ virtual_text = true }) lvim.builtin.treesitter.highlight.enable = true -- auto install treesitter parsers -lvim.builtin.treesitter.ensure_installed = { "cpp", "c", "python"} +lvim.builtin.treesitter.ensure_installed = { "cpp", "c", "python" } -- Additional Plugins table.insert(lvim.plugins, { @@ -101,9 +104,6 @@ table.insert(lvim.plugins, { }) end }, - -- "lervag/vimtex", - -- "kdheepak/cmp-latex-symbols", - -- "KeitaNakamura/tex-conceal.vim", "SirVer/ultisnips", { "ggandor/leap.nvim", @@ -134,6 +134,15 @@ table.insert(lvim.plugins, { vim.g.rnvimr_bw_enable = 1 end, }, + "ChristianChiarulli/swenv.nvim", + "stevearc/dressing.nvim", + "mfussenegger/nvim-dap-python", + "nvim-neotest/neotest", + "nvim-neotest/neotest-python", + "lervag/vimtex", + -- "kdheepak/cmp-latex-symbols", -- caused an issue with cmp + "KeitaNakamura/tex-conceal.vim", + "SirVer/ultisnips", }) vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "clangd" }) diff --git a/init.vim b/init.vim new file mode 100644 index 0000000..e69de29 diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 0000000..8efec63 --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,222 @@ +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil +end + +local function jumpable(dir) + local luasnip_ok, luasnip = pcall(require, "luasnip") + if not luasnip_ok then + return false + end + + local win_get_cursor = vim.api.nvim_win_get_cursor + local get_current_buf = vim.api.nvim_get_current_buf + + ---sets the current buffer's luasnip to the one nearest the cursor + ---@return boolean true if a node is found, false otherwise + local function seek_luasnip_cursor_node() + -- TODO(kylo252): upstream this + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snippet = node.parent.snippet + local exit_node = snippet.insert_nodes[0] + + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 + + -- exit early if we're past the exit node + if exit_node then + local exit_pos_end = exit_node.mark:pos_end() + if (pos[1] > exit_pos_end[1]) or (pos[1] == exit_pos_end[1] and pos[2] > exit_pos_end[2]) then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + node = snippet.inner_first:jump_into(1, true) + while node ~= nil and node.next ~= nil and node ~= snippet do + local n_next = node.next + local next_pos = n_next and n_next.mark:pos_begin() + local candidate = n_next ~= snippet and next_pos and (pos[1] < next_pos[1]) + or (pos[1] == next_pos[1] and pos[2] < next_pos[2]) + + -- Past unmarked exit node, exit early + if n_next == nil or n_next == snippet.next then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + + if candidate then + luasnip.session.current_nodes[get_current_buf()] = node + return true + end + + local ok + ok, node = pcall(node.jump_from, node, 1, true) -- no_move until last stop + if not ok then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + -- No candidate, but have an exit node + if exit_node then + -- to jump to the exit node, seek to snippet + luasnip.session.current_nodes[get_current_buf()] = snippet + return true + end + + -- No exit node, exit from snippet + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + return false + end + + if dir == -1 then + return luasnip.in_snippet() and luasnip.jumpable(-1) + else + return luasnip.in_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable(1) + end +end + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + + +local status_cmp_ok, cmp = pcall(require, "cmp") +if not status_cmp_ok then + return +end +local status_luasnip_ok, luasnip = pcall(require, "luasnip") +if not status_luasnip_ok then + return +end + +local setup = { + confirm_opts = lvim.builtin.cmp.confirm_opts, + completion = { + keyword_length = 1, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + max_width = 0, + kind_icons = lvim.icons.kind, + source_names = { + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + ultisnips = "(Snippet)", + latex_symbols = "(LaTeX)", + buffer = "(Buffer)", + tmux = "(TMUX)", + }, + duplicates = lvim.builtin.cmp.duplicates, + duplicates_default = 0, + format = lvim.builtin.cmp.format, + }, + snippet = { + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) + end, + }, + window = lvim.builtin.cmp.window, + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "ultisnips" }, + { name = "latex_symbols" }, + { name = "crates" }, + { name = "tmux" }, + }, + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, { "i" }), + [""] = cmp.mapping(cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, { "i" }), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping { + i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, + c = function(fallback) + if cmp.visible() then + cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } + else + fallback() + end + end, + }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["UltiSnips#CanJumpForwards"]() == 1 then + vim.api.nvim_feedkeys(t("(ultisnips_jump_forward)"), "m", true) + elseif has_words_before() then + fallback() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then + vim.api.nvim_feedkeys(t("(ultisnips_jump_backward)"), "m", true) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + local confirm_opts = vim.deepcopy(lvim.builtin.cmp.confirm_opts) -- avoid mutating the original opts below + local is_insert_mode = function() + return vim.api.nvim_get_mode().mode:sub(1, 1) == "i" + end + if is_insert_mode() then -- prevent overwriting brackets + confirm_opts.behavior = cmp.ConfirmBehavior.Insert + end + if cmp.confirm(confirm_opts) then + return -- success, exit early + end + end + + if jumpable(1) and luasnip.jump(1) then + return -- success, exit early + end + fallback() -- if not exited early, always fallback + end), + }, +} + +require("cmp").setup(setup) diff --git a/lua/user/latex.lua b/lua/user/latex.lua index 64d07b6..e06aa29 100644 --- a/lua/user/latex.lua +++ b/lua/user/latex.lua @@ -1,3 +1,11 @@ +lvim.format_on_save = false +vim.diagnostic.virtual_text = true + +lvim.builtin.treesitter.highlight.enable = true + +-- Auto install treesitter parsers. +lvim.builtin.treesitter.ensure_installed = { "latex" } + -- Setup Lsp. local capabilities = require("lvim.lsp").common_capabilities() require("lvim.lsp.manager").setup("texlab", { @@ -13,10 +21,10 @@ formatters.setup({ }) -- Set a linter. -local linters = require("lvim.lsp.null-ls.linters") -linters.setup({ - { command = "chktex", filetypes = { "tex" } }, -}) +-- local linters = require("lvim.lsp.null-ls.linters") +-- linters.setup({ +-- { command = "chktex", filetypes = { "tex" } }, +-- }) -- UltiSnip configuration. vim.cmd([[ @@ -34,13 +42,13 @@ vim.g.vimtex_view_method = "zathura" vim.g.vimtex_quickfix_enabled = 0 -- Setup cmp. -vim.api.nvim_create_autocmd("FileType", { - group = vim.api.nvim_create_augroup("LaTeXGroup", { clear = true }), - pattern = "tex", - callback = function() - require("user.cmp") - end, -}) +-- vim.api.nvim_create_autocmd("FileType", { +-- group = vim.api.nvim_create_augroup("LaTeXGroup", { clear = true }), +-- pattern = "tex", +-- callback = function() +-- require("cmp") +-- end, +-- }) -- Mappings lvim.builtin.which_key.mappings["C"] = { diff --git a/lua/user/python.lua b/lua/user/python.lua index de80130..298397d 100644 --- a/lua/user/python.lua +++ b/lua/user/python.lua @@ -1,11 +1,11 @@ -- install plugins -table.insert(lvim.plugins, { - "ChristianChiarulli/swenv.nvim", - "stevearc/dressing.nvim", - "mfussenegger/nvim-dap-python", - "nvim-neotest/neotest", - "nvim-neotest/neotest-python", -}) +-- table.insert(lvim.plugins, { +-- "ChristianChiarulli/swenv.nvim", +-- "stevearc/dressing.nvim", +-- "mfussenegger/nvim-dap-python", +-- "nvim-neotest/neotest", +-- "nvim-neotest/neotest-python", +-- }) -- automatically install python syntax highlighting -- lvim.builtin.treesitter.ensure_installed = { @@ -29,12 +29,22 @@ pcall(function() require("dap-python").setup(mason_path .. "packages/debugpy/venv/bin/python") end) +require('dap-python').resolve_python = function() + if vim.fn.empty(vim.fn.getenv('VIRTUAL_ENV')) == 1 then + return '/usr/bin/python' + else + return vim.fn.getenv('VIRTUAL_ENV') + end +end + + -- setup testing require("neotest").setup({ adapters = { require("neotest-python")({ -- Extra arguments for nvim-dap configuration -- See https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for values + python = "/usr/bin/python", dap = { justMyCode = false, console = "integratedTerminal",