commit 2e508489385ce6fab411dbed25efe2745c8bb4c8 Author: Aria Nolan Date: Fri Jul 14 20:41:08 2023 -0400 initial commit, support for C/C++ and Latex diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e033bc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lazy-lock.json diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..8d96798 --- /dev/null +++ b/config.lua @@ -0,0 +1,91 @@ +-- Read the docs: https://www.lunarvim.org/docs/configuration +-- Example configs: https://github.com/LunarVim/starter.lvim +-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6 +-- Forum: https://www.reddit.com/r/lunarvim/ +-- Discord: https://discord.com/invite/Xb9B4Ny + +require("user.c") +require("user.latex") + +lvim.colorscheme = "catppuccin-frappe" +vim.opt.rnu = true -- relative numbers +vim.opt.cb = "unnamedplus" +vim.opt.nf = "alpha,octal,hex,bin,unsigned" +vim.opt.si = true +vim.opt.backup = false +lvim.builtin.nvimtree.active = false -- NOTE: using neo-tree +lvim.builtin.indentlines.active = true + +vim.opt.ts = 2 +vim.opt.sw = 2 +vim.opt.et = false + +lvim.keys.normal_mode[""] = ":NeoTreeFocusToggle" +lvim.keys.normal_mode[""] = ":BufferLineCyclePrev" +lvim.keys.normal_mode[""] = ":BufferLineCycleNext" + +lvim.format_on_save = false +vim.diagnostic.config( { virtual_text = true } ) + +lvim.builtin.treesitter.highlight.enable = true + +-- auto install treesitter parsers +lvim.builtin.treesitter.ensure_installed = { "cpp", "c", "latex" } + +-- Additional Plugins +table.insert(lvim.plugins, { + "p00f/clangd_extensions.nvim", + "catppuccin/nvim", + "nyoom-engineering/oxocarbon.nvim", + "rose-pine/neovim", + { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + config = function() + require("neo-tree").setup({ + close_if_last_window = true, + window = { + width = 30, + }, + buffers = { + follow_current_file = true, + }, + filesystem = { + follow_current_file = true, + filtered_items = { + hide_dotfiles = false, + hide_gitignored = false, + hide_by_name = { + "node_modules" + }, + never_show = { + ".DS_Store", + "thumbs.db" + }, + }, + }, + }) + end + }, + "lervag/vimtex", + "kdheepak/cmp-latex-symbols", + "KeitaNakamura/tex-conceal.vim", + "SirVer/ultisnips", + { + "ggandor/leap.nvim", + name = "leap", + config = function() + require("leap").add_default_mappings() + end, + }, + { + "mrjones2014/nvim-ts-rainbow", + }, +}) + +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "clangd" }) diff --git a/lua/user/c.lua b/lua/user/c.lua new file mode 100644 index 0000000..4df0b11 --- /dev/null +++ b/lua/user/c.lua @@ -0,0 +1,102 @@ +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "clangd" }) + +-- some settings can only passed as commandline flags, see `clangd --help` +local clangd_flags = { + "--background-index", + "--fallback-style=Google", + "--all-scopes-completion", + "--clang-tidy", + "--log=error", + "--suggest-missing-includes", + "--cross-file-rename", + "--completion-style=detailed", + "--pch-storage=memory", -- could also be disk + "--folding-ranges", + "--enable-config", -- clangd 11+ supports reading from .clangd configuration file + "--offset-encoding=utf-16", --temporary fix for null-ls + -- "--limit-references=1000", + -- "--limit-resutls=1000", + -- "--malloc-trim", + -- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type", + -- "--header-insertion=never", + -- "--query-driver=" +} + +local provider = "clangd" + +local custom_on_attach = function(client, bufnr) + require("lvim.lsp").common_on_attach(client, bufnr) + + local opts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set("n", "lh", "ClangdSwitchSourceHeader", opts) + vim.keymap.set("x", "lA", "ClangdAST", opts) + vim.keymap.set("n", "lH", "ClangdTypeHierarchy", opts) + vim.keymap.set("n", "lt", "ClangdSymbolInfo", opts) + vim.keymap.set("n", "lm", "ClangdMemoryUsage", opts) + + require("clangd_extensions.inlay_hints").setup_autocmd() + require("clangd_extensions.inlay_hints").set_inlay_hints() +end + +local status_ok, project_config = pcall(require, "rhel.clangd_wrl") +if status_ok then + clangd_flags = vim.tbl_deep_extend("keep", project_config, clangd_flags) +end + +local custom_on_init = function(client, bufnr) + require("lvim.lsp").common_on_init(client, bufnr) + require("clangd_extensions.config").setup {} + require("clangd_extensions.ast").init() + vim.cmd [[ + command ClangdToggleInlayHints lua require('clangd_extensions.inlay_hints').toggle_inlay_hints() + command -range ClangdAST lua require('clangd_extensions.ast').display_ast(, ) + command ClangdTypeHierarchy lua require('clangd_extensions.type_hierarchy').show_hierarchy() + command ClangdSymbolInfo lua require('clangd_extensions.symbol_info').show_symbol_info() + command -nargs=? -complete=customlist,s:memuse_compl ClangdMemoryUsage lua require('clangd_extensions.memory_usage').show_memory_usage('' == 'expand_preamble') + ]] +end + +local opts = { + cmd = { provider, unpack(clangd_flags) }, + on_attach = custom_on_attach, + on_init = custom_on_init, +} + +require("lvim.lsp.manager").setup("clangd", opts) + +-- install codelldb with :MasonInstall codelldb +-- configure nvim-dap (codelldb) +lvim.builtin.dap.on_config_done = function(dap) + dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + -- provide the absolute path for `codelldb` command if not using the one installed using `mason.nvim` + command = "codelldb", + args = { "--port", "${port}" }, + + -- On windows you may have to uncomment this: + -- detached = false, + }, + } + + dap.configurations.cpp = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + local path + vim.ui.input({ prompt = "Path to executable: ", default = vim.loop.cwd() .. "/build/" }, function(input) + path = input + end) + vim.cmd [[redraw]] + return path + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + }, + } + + dap.configurations.c = dap.configurations.cpp +end diff --git a/lua/user/latex.lua b/lua/user/latex.lua new file mode 100644 index 0000000..64d07b6 --- /dev/null +++ b/lua/user/latex.lua @@ -0,0 +1,87 @@ +-- Setup Lsp. +local capabilities = require("lvim.lsp").common_capabilities() +require("lvim.lsp.manager").setup("texlab", { + on_attach = require("lvim.lsp").common_on_attach, + on_init = require("lvim.lsp").common_on_init, + capabilities = capabilities, +}) + +-- Setup formatters. +local formatters = require("lvim.lsp.null-ls.formatters") +formatters.setup({ + { command = "latexindent", filetypes = { "tex" } }, +}) + +-- Set a linter. +local linters = require("lvim.lsp.null-ls.linters") +linters.setup({ + { command = "chktex", filetypes = { "tex" } }, +}) + +-- UltiSnip configuration. +vim.cmd([[ + let g:UltiSnipsExpandTrigger="" + let g:UltiSnipsJumpForwardTrigger="(ultisnips_jump_forward)" + let g:UltiSnipsJumpBackwardTrigger="(ultisnips_jump_backward)" + let g:UltiSnipsListSnippets="" + let g:UltiSnipsRemoveSelectModeMappings=0 + let g:UltiSnipsEditSplit="tabdo" + let g:UltiSnipsSnippetDirectories=[$HOME."/.config/nvim/UltiSnips"] +]]) + +-- Vimtex configuration. +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, +}) + +-- Mappings +lvim.builtin.which_key.mappings["C"] = { + name = "LaTeX", + m = { "VimtexContextMenu", "Open Context Menu" }, + u = { "VimtexCountLetters", "Count Letters" }, + w = { "VimtexCountWords", "Count Words" }, + d = { "VimtexDocPackage", "Open Doc for package" }, + e = { "VimtexErrors", "Look at the errors" }, + s = { "VimtexStatus", "Look at the status" }, + a = { "VimtexToggleMain", "Toggle Main" }, + v = { "VimtexView", "View pdf" }, + i = { "VimtexInfo", "Vimtex Info" }, + l = { + name = "Clean", + l = { "VimtexClean", "Clean Project" }, + c = { "VimtexClean", "Clean Cache" }, + }, + c = { + name = "Compile", + c = { "VimtexCompile", "Compile Project" }, + o = { + "VimtexCompileOutput", + "Compile Project and Show Output", + }, + s = { "VimtexCompileSS", "Compile project super fast" }, + e = { "VimtexCompileSelected", "Compile Selected" }, + }, + r = { + name = "Reload", + r = { "VimtexReload", "Reload" }, + s = { "VimtexReloadState", "Reload State" }, + }, + o = { + name = "Stop", + p = { "VimtexStop", "Stop" }, + a = { "VimtexStopAll", "Stop All" }, + }, + t = { + name = "TOC", + o = { "VimtexTocOpen", "Open TOC" }, + t = { "VimtexTocToggle", "Toggle TOC" }, + }, +}