From 3b1035fd35bad0845c9f4428ef1c157bf83756dd Mon Sep 17 00:00:00 2001 From: Niverton Date: Fri, 3 Nov 2023 21:04:02 +0100 Subject: [PATCH] init --- colorscheme.lua | 1 + highlights/init.lua | 12 +++++++ lsp/formatting.lua | 6 ++++ mappings.lua | 19 ++++++++++ options.lua | 35 ++++++++++++++++++ plugins/colors.lua | 60 +++++++++++++++++++++++++++++++ plugins/community.lua | 29 +++++++++++++++ plugins/heirline.lua | 82 +++++++++++++++++++++++++++++++++++++++++++ plugins/init.lua | 16 +++++++++ plugins/luasnip.lua | 10 ++++++ polish.lua | 33 +++++++++++++++++ snippets/package.json | 14 ++++++++ snippets/rust.json | 43 +++++++++++++++++++++++ updater.lua | 12 +++++++ 14 files changed, 372 insertions(+) create mode 100644 colorscheme.lua create mode 100644 highlights/init.lua create mode 100644 lsp/formatting.lua create mode 100644 mappings.lua create mode 100644 options.lua create mode 100644 plugins/colors.lua create mode 100644 plugins/community.lua create mode 100644 plugins/heirline.lua create mode 100644 plugins/init.lua create mode 100644 plugins/luasnip.lua create mode 100644 polish.lua create mode 100644 snippets/package.json create mode 100644 snippets/rust.json create mode 100644 updater.lua diff --git a/colorscheme.lua b/colorscheme.lua new file mode 100644 index 0000000..6bcd6e1 --- /dev/null +++ b/colorscheme.lua @@ -0,0 +1 @@ +return "astrobox" diff --git a/highlights/init.lua b/highlights/init.lua new file mode 100644 index 0000000..06a16b6 --- /dev/null +++ b/highlights/init.lua @@ -0,0 +1,12 @@ +return function() + -- Remove italic in documentation comments + local docComment = vim.api.nvim_get_hl(0, { name = "Comment" }) + docComment.italic = false + docComment.nocombine = true -- Don't merge missing attributes from inherited highlight group + return { + ["@comment.doc"] = docComment, + ["@comment.documentation"] = docComment, + ["@lsp.mod.documentation"] = docComment, + } +end + diff --git a/lsp/formatting.lua b/lsp/formatting.lua new file mode 100644 index 0000000..d70e816 --- /dev/null +++ b/lsp/formatting.lua @@ -0,0 +1,6 @@ +return { + -- control auto formatting on save + format_on_save = { + enabled = false, -- enable or disable format on save globally + }, +} diff --git a/mappings.lua b/mappings.lua new file mode 100644 index 0000000..94a99ef --- /dev/null +++ b/mappings.lua @@ -0,0 +1,19 @@ +return { + n = { + [""] = { + function() + vim.cmd([[cclose]]) + vim.cmd([[pclose]]) + vim.fn.setreg('/', '') + end, + desc = "Clean up" + } + }, + t = { + [''] = [[]], + [''] = [[h]], + [''] = [[j]], + [''] = [[k]], + [''] = [[l]], + }, +} diff --git a/options.lua b/options.lua new file mode 100644 index 0000000..fd6580f --- /dev/null +++ b/options.lua @@ -0,0 +1,35 @@ +return { + opt = { + -- laststatus = 2, + background = "dark", + clipboard = "", + cmdheight = 1, + expandtab = true, + foldenable = true, + foldlevelstart = 100, + foldmethod = "syntax", + foldnestmax = 150, + grepprg = "rg --vimgrep", + guifont = "VictorMono Nerd Font, Hack Nerd Font Mono:h10", + listchars = { tab = '> ', extends = '>', precedes = '<', space = 'ยท' }, + number = true, + relativenumber = false, + scrolloff = 0, + shiftwidth = 4, + signcolumn = "auto", + spell = false, + tabstop = 4, + textwidth = 80, + wrap = true, + }, + g = { + autoformat_enabled = false, + autopairs_enabled = true, + cmp_enabled = true, + diagnostics_enabled = true, + icons_enabled = true, + inlay_hints_enabled = true, + mapleader = " ", + status_diagnostics_enabled = true, + }, +} diff --git a/plugins/colors.lua b/plugins/colors.lua new file mode 100644 index 0000000..ca2e2be --- /dev/null +++ b/plugins/colors.lua @@ -0,0 +1,60 @@ +local function int_lerp(a, b, c) + return math.floor((1 - c) * a + c * b + 0.5) +end + +local function rgb_lerp(a, b, c) + return { + int_lerp(a[1], b[1], c), + int_lerp(a[2], b[2], c), + int_lerp(a[3], b[3], c), + } +end + +local function hex_to_rgb(hex) + local ret = {} + for i = 2,6,2 do -- Skip '#' + local s = hex:sub(i, i + 1) + table.insert(ret, tonumber(s, 16)) + end + return ret +end + +local function rgb_to_hex(rgb) + return string.format("#%x%x%x", unpack(rgb)) +end + +local function hex_lerp(a, b, c) + a = hex_to_rgb(a); + b = hex_to_rgb(b); + return rgb_to_hex(rgb_lerp(a, b, c)) +end + +return { + { + "AstroNvim/astrotheme", + optional = true, + opts = { + style = { + simple_syntax_colors = true, + inactive = false, + }, + palettes = { + astrobox = {}, + }, + highlights = { + global = { + modify_hl_groups = function(hl, c) + hl.DiffAdd = { bg = hex_lerp(hl.DiffAdd.bg, c.ui.base, 0.8)} + hl.DiffDelete = { bg = hex_lerp(hl.DiffDelete.bg, c.ui.base, 0.8)} + hl.DiffChange = { bg = hex_lerp(c.ui.blue, c.ui.base, 0.8)} + hl.DiffText = { bg = hex_lerp(hl.DiffText.bg, c.ui.base, 0.8)} + end, + }, + astrobox = {}, + }, + }, + }, + { + url = "https://git.niverton.tk/niverton/Astrobox.git" + }, +} diff --git a/plugins/community.lua b/plugins/community.lua new file mode 100644 index 0000000..e66b26c --- /dev/null +++ b/plugins/community.lua @@ -0,0 +1,29 @@ +-- Filter by hostname +local home = vim.fn.hostname() == "comanche" +local work = not home + +return { + "AstroNvim/astrocommunity", + + -- Language packs + { enabled = true, import = "astrocommunity.pack.cpp" }, + { enabled = true, import = "astrocommunity.pack.lua" }, + { enabled = true, import = "astrocommunity.pack.markdown" }, + -- { enabled = true, import = "astrocommunity.pack.rust" }, + { enabled = home, import = "astrocommunity.pack.bash" }, + { enabled = home, import = "astrocommunity.pack.html-css" }, + { enabled = home, import = "astrocommunity.pack.java" }, + { enabled = work, import = "astrocommunity.pack.cs" }, + { enabled = work, import = "astrocommunity.pack.ps1" }, + -- { enable = home, import = "astrocommunity.pack.wgsl" }, -- WebGLShaderLanguage + + -- DAP + { import = "astrocommunity.debugging.telescope-dap-nvim" }, + { import = "astrocommunity.debugging.nvim-dap-virtual-text" }, + { import = "astrocommunity.debugging.nvim-dap-repl-highlights" }, + + -- Others + -- TODO usefull? + { import = "astrocommunity.debugging.nvim-bqf" }, + +} diff --git a/plugins/heirline.lua b/plugins/heirline.lua new file mode 100644 index 0000000..bcef601 --- /dev/null +++ b/plugins/heirline.lua @@ -0,0 +1,82 @@ +return { + "rebelot/heirline.nvim", + opts = function(_, opts) + local status = require "astronvim.utils.status" + + opts.statusline = { + hl = { fg = "fg", bg = "bg" }, + status.component.mode { mode_text = { hl = { bold = true }, padding = { left = 1, right = 1 } } }, + status.component.file_info { + filetype = false, + filename = { + modify = ":~:." + }, + file_modified = {} + }, + status.component.diagnostics(), + status.component.fill(), + status.component.cmd_info(), + status.component.fill(), + status.component.lsp(), + status.component.treesitter{ padding = { right = 1 } }, -- Extra space to separate from next component + status.component.git_diff(), + status.component.git_branch(), + status.component.nav { scrollbar = false }, + } + + local get_file_path = status.provider.filename { + modify = ":~:.:h" -- Relative path and cut filename + } + -- Fix path separation on windows + local path_func = get_file_path + if vim.fn.has("win32") then + path_func = function(self) + local str = get_file_path(self) + return string.gsub(str, "\\", "/") + end + end + + opts.winbar = { + init = function(self) self.bufnr = vim.api.nvim_get_current_buf() end, + fallthrough = false, + { + condition = function() return not status.condition.is_active() end, + { + -- Set display priority to hide when component is too big to + -- fit + flexible = 1, + status.component.separated_path { + flexible = 2, + max_depth = 5, + path_func = path_func, + }, + status.component.separated_path { + flexible = 3, + max_depth = 3, + path_func = path_func, + }, + status.component.separated_path { + flexible = 4, + max_depth = 1, + path_func = path_func, + }, + { + -- Hide + provider = "" + } + }, + status.component.file_info { + file_icon = { hl = status.hl.file_icon "winbar", padding = { left = 0 } }, + file_modified = false, + file_read_only = false, + hl = status.hl.get_attributes("winbarnc", true), + surround = false, + update = "BufEnter", + }, + }, + status.component.breadcrumbs(), + } + + return opts + end, +} diff --git a/plugins/init.lua b/plugins/init.lua new file mode 100644 index 0000000..960daf2 --- /dev/null +++ b/plugins/init.lua @@ -0,0 +1,16 @@ +return { + { "echasnovski/mini.align", event = "User AstroFile", config = function() require("mini.align").setup {} end }, + { + "serenevoid/kiwi.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + { name = "main", path = "~/kiwi/main" }, + }, + keys = { + { "ww", ':lua require("kiwi").open_wiki_index()', desc = "Open Wiki index" }, + { "t", ':lua require("kiwi").todo.toggle()', desc = "Toggle Markdown Task" }, + }, + lazy = true, + }, + { "tpope/vim-abolish", event = "User AstroFile" }, +} diff --git a/plugins/luasnip.lua b/plugins/luasnip.lua new file mode 100644 index 0000000..be1d8f8 --- /dev/null +++ b/plugins/luasnip.lua @@ -0,0 +1,10 @@ +return { + { + "L3MON4D3/LuaSnip", + optional = true, + config = function(plugin, opts) + require "plugins.configs.luasnip"(plugin, opts) + require("luasnip.loaders.from_vscode").lazy_load { paths = { "./lua/user/snippets" } } + end, + } +} diff --git a/polish.lua b/polish.lua new file mode 100644 index 0000000..48bf818 --- /dev/null +++ b/polish.lua @@ -0,0 +1,33 @@ +return function() + --[[ + local function treesitter_is_parser_installed(filetype) + if not filetype then return false end + + local ok, parsers = pcall(require, "nvim-treesitter.parsers") + if not ok then return false end + local name = parsers.filetype_to_parsername[filetype] + return name and #vim.api.nvim_get_runtime_file("parser/" .. name .. ".so", false) > 0 + end + + -- Set foldmethod to treesitter only on BufEnter if we do have a parser and we're not in diffmode + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWinEnter' }, { + group = vim.api.nvim_create_augroup('TS_FOLD_WORKAROUND', {}), + callback = function() + if vim.wo.diff then return end + if treesitter_is_parser_installed(vim.bo.filetype) then + vim.wo.foldmethod = 'expr' + vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' + end + end + }) + --]] + + -- TODO Move to filetype plugin? + vim.api.nvim_create_autocmd("TermOpen", { + group = vim.api.nvim_create_augroup("term", { clear = true }), + callback = function() + vim.wo.number = false + vim.wo.spell = false + end + }) +end diff --git a/snippets/package.json b/snippets/package.json new file mode 100644 index 0000000..4b74e07 --- /dev/null +++ b/snippets/package.json @@ -0,0 +1,14 @@ +{ + "name": "user snippets", + "engines": { + "vscode": "^1.11.0" + }, + "contributes": { + "snippets": [ + { + "language": "rust", + "path": "./rust.json" + } + ] + } +} diff --git a/snippets/rust.json b/snippets/rust.json new file mode 100644 index 0000000..ae483db --- /dev/null +++ b/snippets/rust.json @@ -0,0 +1,43 @@ +{ + "New Yew function component": { + "prefix": "yewfc", + "body": [ + "#[derive(PartialEq, Properties)]", + "pub struct ${1:ComponentName}Props {}", + "", + "#[function_component]", + "pub fn $1(props: &${1}Props) -> Html {", + " let ${1}Props {} = props;", + " html! {", + " <${2:div}>$0", + " }", + "}" + ], + "description": "Create a minimal Yew function component" + }, + "New Yew struct component": { + "prefix": "yewsc", + "body": [ + "pub struct ${1:ComponentName};", + "", + "pub enum ${1}Msg {", + "}", + "", + "impl Component for ${1} {", + " type Message = ${1}Msg;", + " type Properties = ();", + "", + " fn create(ctx: &Context) -> Self {", + " Self", + " }", + "", + " fn view(&self, ctx: &Context) -> Html {", + " html! {", + " $0", + " }", + " }", + "}" + ], + "description": "Create a new Yew component with a message enum" + } +} diff --git a/updater.lua b/updater.lua new file mode 100644 index 0000000..89b4e71 --- /dev/null +++ b/updater.lua @@ -0,0 +1,12 @@ +return { + remote = "origin", + channel = "nightly", + version = "latest", + branch = "main", + commit = nil, + pin_plugins = nil, + skip_prompts = false, + show_changelog = true, + auto_reload = false, + auto_quit = false, +}