From ed8f1308ffb293c9855f2ac69ce14b9a3a3bff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E9=85=94=E9=96=91=E5=90=9F?= <50296129+Jint-lzxy@users.noreply.github.com> Date: Sun, 30 Apr 2023 22:24:03 +0800 Subject: [PATCH] feat!: support Neovim v0.9 (#697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(README): bump supported version * feat(options): support new options shipped with v0.9 * feat(scripts): support v0.9 * feat!: add initial support for lsp semantic tokens (#633) * feat(utils): use neovim builtin to get highlights (#632) * fix: remove deprecated options for nvim-tree. * fix(cmp): support dynamic `kind_text` from cmp source: `treesitter`, fix #624 #634 (#637) * fix&feat: introduce suda.vim to write file with sudo * chore(kind_text): cleanup (#648) * feat(alpha): add custom highlight groups (#650) * fix: install `psutils` by default for Windows users * revert: bind `SudaWrite` to `` ref: https://github.com/ayamir/nvimdots/pull/641#issuecomment-1503431723 * fix(cmp): nil `vim_item` * perf(core-mapping): add some useful mapping * fix(nvim-tree): `hide_root_folder` is deprecated * perf: load fidget.nvim after `LspAttach` * minor fix 1. remove `` at "n|Q" 2. use visual mode instead of visual-line mode for "n|" * perf: align style * perf(0.9): `stabilize.nvim` had been upstream to `0.9` * chore(project.nvim): update legacy code * chore(README): update branch info * chore(mapping): cleanup (#657) * fix(icon): update invalid cmp icon (#665) * chore/lspsaga_move (#667) * fix: paint word boundary in python (#669) * fix(bufferline): `show_buffer_default_icon` is now deprecate * feat(formatting): notify users for files under disabled dirs * chore(formatting): rephrase messages * fix(font-encoding): fix invalid characters on windows, fix #639 (#659) Co-authored-by: 冷酔閑吟 <50296129+Jint-lzxy@users.noreply.github.com> * pref: unify code style for PowerShell commands * perf: better guidance to `Discussions` and `Wiki` (#680) * pref(ISSUE_TEMPLATE): fix typos and format with prettier * fixup! pref(ISSUE_TEMPLATE): fix typos and format with prettier * feat(scripts): abort for nvim v0.7 and its antecedent * feat(settings): allow customization of `transparent_background` (#687) * fix(bufferline): use defaults for `get_element_icon` (#685) * feat(auto-session): remember opened buffers (#688) * revert(keymap): remove redundant mappings. * fix(catppuccin): properly detect `g:colors_name` (#695) Ref: upstream breaking change [https://github.com/catppuccin/nvim/commit/7a7a6646769e0c0be5d443cf55c04970f90fd230] --------- Co-authored-by: ayamir Co-authored-by: Charles Chiu Co-authored-by: CharlesChiuGit Co-authored-by: Xie Zejian Co-authored-by: AngelontheRoad <52699138+AngelontheRoad@users.noreply.github.com> Co-authored-by: Saafo <46736350+Saafo@users.noreply.github.com> (cherry picked from commit 08c4561df43b13ab30b44456a18a93ca7f147b4e) --- .github/ISSUE_TEMPLATE/config.yml | 6 +- README.md | 13 +++-- lua/core/init.lua | 32 +++++++++++ lua/core/mapping.lua | 42 +++++++------- lua/core/options.lua | 7 ++- lua/core/settings.lua | 4 ++ lua/keymap/editor.lua | 3 + lua/modules/configs/completion/cmp.lua | 53 ++++++++++++++--- lua/modules/configs/completion/formatting.lua | 30 +++++++--- lua/modules/configs/completion/lspsaga.lua | 1 + lua/modules/configs/editor/suda.lua | 3 + lua/modules/configs/tool/project.lua | 2 +- lua/modules/configs/ui/alpha.lua | 10 ++-- lua/modules/configs/ui/bufferline.lua | 1 - lua/modules/configs/ui/catppuccin.lua | 17 ++++-- lua/modules/configs/ui/edge.lua | 2 +- lua/modules/configs/ui/nord.lua | 2 +- lua/modules/configs/ui/paint.lua | 2 +- lua/modules/plugins/completion.lua | 3 +- lua/modules/plugins/ui.lua | 2 +- lua/modules/utils/icons.lua | 17 ++++-- lua/modules/utils/init.lua | 57 +++++-------------- scripts/install.ps1 | 47 ++++++++++----- scripts/install.sh | 53 +++++++++++------ 24 files changed, 265 insertions(+), 144 deletions(-) create mode 100644 lua/modules/configs/editor/suda.lua diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 75ee6b713..1c7e9246d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ -blank_issues_enabled: false +blank_issues_enabled: true contact_links: - name: GitHub Discussions url: https://github.com/ayamir/nvimdots/discussions/new/choose - about: Any issue that does not fall into the above categories shall go here. + about: Any issue that does not fall into the above categories shall go here - name: GitHub Wiki url: https://github.com/ayamir/nvimdots/wiki - about: Make sure you have checked our documentation first. To be explicit, the "Issues" section. + about: Make sure you have checked our documentation first. To be explicit, the "Issues" section \ No newline at end of file diff --git a/README.md b/README.md index 9ce3fc4cf..b93c1ddff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ NeoVim Version Capability + src="https://img.shields.io/badge/Supports%20Nvim-v0.9-A6D895?style=for-the-badge&colorA=363A4F&logo=neovim&logoColor=D9E0EE"> -| Branch | Completion Solution | -| :----: | :------------------------: | -| main | config for nvim 0.8 stable | -| 0.7 | config for nvim 0.7 stable | +| Branch | Supported neovim version | +| :----: | :----------------------: | +| main | nvim 0.9 stable | +| 0.8 | nvim 0.8 | +| 0.7 | nvim 0.7 | diff --git a/lua/core/init.lua b/lua/core/init.lua index 4edf669c7..f721b613b 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -62,6 +62,9 @@ local disable_distribution_plugins = function() -- Disable sql omni completion. vim.g.loaded_sql_completion = 1 + -- Disable EditorConfig support + vim.g.editorconfig = 1 + -- Disable remote plugins -- NOTE: Disabling rplugin.vim will show error for `wilder.nvim` in :checkhealth, -- NOTE: but since it's config doesn't require python rtp, it's fine to ignore. @@ -160,6 +163,34 @@ local clipboard_config = function() end end +local shell_config = function() + if global.is_windows then + if not (vim.fn.executable("pwsh") or vim.fn.executable("powershell")) then + vim.notify( + [[ +Failed to setup terminal config + +PowerShell is either not installed, missing from PATH, or not executable; +cmd.exe will be used instead for `:!` (shell bang) and toggleterm.nvim. + +You're recommended to install PowerShell for better experience.]], + vim.log.levels.WARN, + { title = "[core] Runtime error" } + ) + return + end + + local basecmd = "-NoLogo -MTA -ExecutionPolicy RemoteSigned" + local ctrlcmd = "-Command [console]::InputEncoding = [console]::OutputEncoding = [System.Text.Encoding]::UTF8" + vim.api.nvim_set_option_value("shell", vim.fn.executable("pwsh") and "pwsh" or "powershell", {}) + vim.api.nvim_set_option_value("shellcmdflag", string.format("%s %s;", basecmd, ctrlcmd), {}) + vim.api.nvim_set_option_value("shellredir", "-RedirectStandardOutput %s -NoNewWindow -Wait", {}) + vim.api.nvim_set_option_value("shellpipe", "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", {}) + vim.api.nvim_set_option_value("shellquote", nil, {}) + vim.api.nvim_set_option_value("shellxquote", nil, {}) + end +end + local load_core = function() createdir() disable_distribution_plugins() @@ -167,6 +198,7 @@ local load_core = function() neovide_config() clipboard_config() + shell_config() require("core.options") require("core.mapping") diff --git a/lua/core/mapping.lua b/lua/core/mapping.lua index 215a4ea28..2401dcd41 100644 --- a/lua/core/mapping.lua +++ b/lua/core/mapping.lua @@ -30,30 +30,34 @@ local def_orimap = { ["n|"] = map_cr("vertical resize +5"):with_silent():with_desc("window: Resize +5 vertically"), ["n|"] = map_cr("resize -2"):with_silent():with_desc("window: Resize -2 horizontally"), ["n|"] = map_cr("resize +2"):with_silent():with_desc("window: Resize +2 horizontally"), - ["n|"] = map_cmd(":wq"):with_desc("editn: Save file and quit"), - ["n|"] = map_cmd(":q!"):with_desc("editn: Force quit"), - ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("editn: Toggle spell check"), + ["n|"] = map_cr("wq"):with_desc("edit: Save file and quit"), + ["n|"] = map_cr("q!"):with_desc("edit: Force quit"), + ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), + ["n|tn"] = map_cr("tabnew"):with_noremap():with_silent():with_desc("tab: Create a new tab"), + ["n|tk"] = map_cr("tabnext"):with_noremap():with_silent():with_desc("tab: Move to next tab"), + ["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent():with_desc("tab: Move to previous tab"), + ["n|to"] = map_cr("tabonly"):with_noremap():with_silent():with_desc("tab: Only keep current tab"), -- Insert mode - ["i|"] = map_cmd("u"):with_noremap():with_desc("editi: Delete previous block"), - ["i|"] = map_cmd(""):with_noremap():with_desc("editi: Move cursor to left"), - ["i|"] = map_cmd("^i"):with_noremap():with_desc("editi: Move cursor to line start"), - ["i|"] = map_cmd(":w"):with_desc("editi: Save file"), - ["i|"] = map_cmd(":wq"):with_desc("editi: Save file and quit"), + ["i|"] = map_cmd("u"):with_noremap():with_desc("edit: Delete previous block"), + ["i|"] = map_cmd(""):with_noremap():with_desc("edit: Move cursor to left"), + ["i|"] = map_cmd("^i"):with_noremap():with_desc("edit: Move cursor to line start"), + ["i|"] = map_cmd(":w"):with_desc("edit: Save file"), + ["i|"] = map_cmd(":wq"):with_desc("edit: Save file and quit"), -- Command mode - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: Left"), - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: Right"), - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: Home"), - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: End"), - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: Delete"), - ["c|"] = map_cmd(""):with_noremap():with_desc("editc: Backspace"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Left"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Right"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Home"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: End"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Delete"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Backspace"), ["c|"] = map_cmd([[=expand("%:p:h") . "/" ]]) :with_noremap() - :with_desc("editc: Complete path of current file"), + :with_desc("edit: Complete path of current file"), -- Visual mode - ["v|J"] = map_cmd(":m '>+1gv=gv"):with_desc("editv: Move this line down"), - ["v|K"] = map_cmd(":m '<-2gv=gv"):with_desc("editv: Move this line up"), - ["v|<"] = map_cmd(""] = map_cmd(">gv"):with_desc("editv: Increase indent"), + ["v|J"] = map_cmd(":m '>+1gv=gv"):with_desc("edit: Move this line down"), + ["v|K"] = map_cmd(":m '<-2gv=gv"):with_desc("edit: Move this line up"), + ["v|<"] = map_cmd(""] = map_cmd(">gv"):with_desc("edit: Increase indent"), } local core_map = { diff --git a/lua/core/options.lua b/lua/core/options.lua index 401069233..7e0d546dd 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -26,7 +26,7 @@ local function load_options() conceallevel = 0, cursorcolumn = true, cursorline = true, - diffopt = "filler,iwhite,internal,algorithm:patience", + diffopt = "filler,iwhite,internal,linematch:60,algorithm:patience", display = "lastline", encoding = "utf-8", equalalways = false, @@ -59,7 +59,7 @@ local function load_options() relativenumber = true, ruler = true, scrolloff = 10, - sessionoptions = "curdir,help,tabpages,winsize", + sessionoptions = "buffers,curdir,help,tabpages,winsize", shada = "!,'300,<50,@100,s10,h", shiftround = true, shiftwidth = 4, @@ -74,6 +74,7 @@ local function load_options() smarttab = true, softtabstop = 4, splitbelow = true, + splitkeep = "cursor", splitright = true, startofline = false, swapfile = false, @@ -125,7 +126,7 @@ local function load_options() -- Fix sqlite3 missing-lib issue on Windows if global.is_windows then -- Download the DLLs form https://www.sqlite.org/download.html - vim.g.sqlite_clib_path = global.home .. "/Documents/sqlite-dll-win64-x64-3400100/sqlite3.dll" + vim.g.sqlite_clib_path = global.home .. "/Documents/sqlite-dll-win64-x64-3400200/sqlite3.dll" end end diff --git a/lua/core/settings.lua b/lua/core/settings.lua index a9877416f..c1fb3c488 100644 --- a/lua/core/settings.lua +++ b/lua/core/settings.lua @@ -30,6 +30,10 @@ settings["palette_overwrite"] = {} -- Available values are: `catppuccin`, `catppuccin-latte`, `catppucin-mocha`, `catppuccin-frappe`, `catppuccin-macchiato`, `edge`, `nord`. settings["colorscheme"] = "catppuccin-frappe" +-- Set it to true if your terminal has transparent background. +---@type boolean +settings["transparent_background"] = false + -- Set background color to use here. -- Useful if you would like to use a colorscheme that has a light and dark variant like `edge`. -- Valid values are: `dark`, `light`. diff --git a/lua/keymap/editor.lua b/lua/keymap/editor.lua index b98235aaf..37f56aeab 100644 --- a/lua/keymap/editor.lua +++ b/lua/keymap/editor.lua @@ -84,6 +84,9 @@ local plug_map = { -- Plugin: tabout ["i|"] = map_cmd("(TaboutMulti)"):with_silent():with_noremap():with_desc("edit: Goto end of pair"), ["i|"] = map_cmd("(TaboutBackMulti)"):with_silent():with_noremap():with_desc("edit: Goto begin of pair"), + + -- Plugin suda.vim + ["n|"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"), } bind.nvim_load_mapping(plug_map) diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index e2128f13b..aeb33202c 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -41,7 +41,35 @@ return function() return (diff < 0) end - local lspkind = require("lspkind") + local function cmp_format(opts) + opts = opts or {} + + return function(entry, vim_item) + if opts.before then + vim_item = opts.before(entry, vim_item) + end + + local kind_symbol = opts.symbol_map[vim_item.kind] or icons.kind.Undefined + local source_symbol = opts.symbol_map[entry.source.name] or icons.cmp.undefined + + vim_item.menu = " " .. source_symbol .. " |" + vim_item.kind = string.format(" 〔 %s %s 〕", kind_symbol, vim_item.kind) + + if opts.maxwidth ~= nil then + if opts.ellipsis_char == nil then + vim_item.abbr = string.sub(vim_item.abbr, 1, opts.maxwidth) + else + local label = vim_item.abbr + local truncated_label = vim.fn.strcharpart(label, 0, opts.maxwidth) + if truncated_label ~= label then + vim_item.abbr = truncated_label .. opts.ellipsis_char + end + end + end + return vim_item + end + end + local cmp = require("cmp") cmp.setup({ @@ -72,16 +100,13 @@ return function() }, }, formatting = { - fields = { "kind", "abbr", "menu" }, + fields = { "menu", "abbr", "kind" }, format = function(entry, vim_item) - local kind = lspkind.cmp_format({ - mode = "symbol_text", + local kind_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp) + local kind = cmp_format({ maxwidth = 50, - symbol_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp), + symbol_map = kind_map, })(entry, vim_item) - local strings = vim.split(kind.kind, "%s", { trimempty = true }) - kind.kind = " " .. strings[1] .. " " - kind.menu = " (" .. strings[2] .. ")" return kind end, }, @@ -123,7 +148,17 @@ return function() { name = "nvim_lua" }, { name = "luasnip" }, { name = "path" }, - { name = "treesitter" }, + { + name = "treesitter", + entry_filter = function(entry) + local ignore_list = { + "Error", + "Comment", + } + local kind = entry:get_completion_item().cmp.kind_text + return not vim.tbl_contains(ignore_list, kind) + end, + }, { name = "spell" }, -- { name = "tmux" }, -- { name = "orgmode" }, diff --git a/lua/modules/configs/completion/formatting.lua b/lua/modules/configs/completion/formatting.lua index 66b7bbd5e..42dfe4c3d 100644 --- a/lua/modules/configs/completion/formatting.lua +++ b/lua/modules/configs/completion/formatting.lua @@ -15,7 +15,7 @@ vim.api.nvim_create_user_command("FormatterToggleFt", function(opts) vim.notify( string.format("[LSP] Formatter for [%s] has been recorded in list and disabled.", opts.args), vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } + { title = "LSP Formatter Warning" } ) block_list[opts.args] = true else @@ -39,14 +39,17 @@ function M.enable_format_on_save(is_configured) group = "format_on_save", pattern = opts.pattern, callback = function() - require("completion.formatting").format({ timeout_ms = opts.timeout, filter = M.format_filter }) + require("completion.formatting").format({ + timeout_ms = opts.timeout, + filter = M.format_filter, + }) end, }) if not is_configured then vim.notify( "Successfully enabled format-on-save", vim.log.levels.INFO, - { title = "Settings modification success!" } + { title = "Settings modification success" } ) end end @@ -54,7 +57,11 @@ end function M.disable_format_on_save() pcall(vim.api.nvim_del_augroup_by_name, "format_on_save") if format_on_save then - vim.notify("Disabled format-on-save", vim.log.levels.INFO, { title = "Settings modification success!" }) + vim.notify( + "Successfully disabled format-on-save", + vim.log.levels.INFO, + { title = "Settings modification success" } + ) end end @@ -95,6 +102,11 @@ function M.format(opts) local cwd = vim.fn.getcwd() for i = 1, #disabled_workspaces do if cwd.find(cwd, disabled_workspaces[i]) ~= nil then + vim.notify( + string.format("[LSP] Formatting support for all files under [%s] is disabled.", disabled_workspaces[i]), + vim.log.levels.WARN, + { title = "LSP Formatter Warning" } + ) return end end @@ -122,7 +134,7 @@ function M.format(opts) vim.notify( "[LSP] Format request failed, no matching language servers.", vim.log.levels.WARN, - { title = "Formatting Failed!" } + { title = "Formatting Failed" } ) end @@ -136,7 +148,7 @@ function M.format(opts) vim.bo.filetype ), vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } + { title = "LSP Formatter Warning" } ) return end @@ -145,15 +157,15 @@ function M.format(opts) if result and result.result then vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding) vim.notify( - string.format("[LSP] Format successfully with [%s]!", client.name), + string.format("[LSP] Format successfully with %s!", client.name), vim.log.levels.INFO, - { title = "LSP Format Success!" } + { title = "LSP Format Success" } ) elseif err then vim.notify( string.format("[LSP][%s] %s", client.name, err), vim.log.levels.ERROR, - { title = "LSP Format Error!" } + { title = "LSP Format Error" } ) end end diff --git a/lua/modules/configs/completion/lspsaga.lua b/lua/modules/configs/completion/lspsaga.lua index 325d1cba9..55eb9427e 100644 --- a/lua/modules/configs/completion/lspsaga.lua +++ b/lua/modules/configs/completion/lspsaga.lua @@ -118,6 +118,7 @@ return function() frequency = 12, }, ui = { + title = false, border = "single", -- Can be single, double, rounded, solid, shadow. winblend = 0, actionfix = icons.ui.Spell, diff --git a/lua/modules/configs/editor/suda.lua b/lua/modules/configs/editor/suda.lua new file mode 100644 index 000000000..bf77b65b1 --- /dev/null +++ b/lua/modules/configs/editor/suda.lua @@ -0,0 +1,3 @@ +return function() + vim.g["suda#prompt"] = "Enter administrator password: " +end diff --git a/lua/modules/configs/tool/project.lua b/lua/modules/configs/tool/project.lua index 281f1a25e..153d023ee 100644 --- a/lua/modules/configs/tool/project.lua +++ b/lua/modules/configs/tool/project.lua @@ -3,7 +3,7 @@ return function() manual_mode = false, detection_methods = { "lsp", "pattern" }, patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, - ignore_lsp = { "efm", "copilot" }, + ignore_lsp = { "null-ls", "copilot" }, exclude_dirs = {}, show_hidden = false, silent_chdir = true, diff --git a/lua/modules/configs/ui/alpha.lua b/lua/modules/configs/ui/alpha.lua index 8e68b75fe..3d5a6eabe 100644 --- a/lua/modules/configs/ui/alpha.lua +++ b/lua/modules/configs/ui/alpha.lua @@ -1,6 +1,7 @@ return function() local alpha = require("alpha") local dashboard = require("alpha.themes.dashboard") + require("modules.utils").gen_alpha_hl() dashboard.section.header.val = { [[UUUUUUUU UUUUUUUU CCCCCCCCCCCCC dddddddd ]], @@ -20,7 +21,7 @@ return function() [[ UU:::::::::UU v:::v CCC::::::::::::Coo:::::::::::oo d:::::::::ddd::::d ee:::::::::::::e ]], [[ UUUUUUUUU vvv CCCCCCCCCCCCC ooooooooooo ddddddddd ddddd eeeeeeeeeeeeee ]], } - dashboard.section.header.opts.hl = "Type" + dashboard.section.header.opts.hl = "AlphaHeader" local function button(sc, txt, leader_txt, keybind, keybind_opts) local sc_after = sc:gsub("%s", ""):gsub(leader_txt, "") @@ -31,7 +32,8 @@ return function() cursor = 5, width = 50, align_shortcut = "right", - hl_shortcut = "Keyword", + hl = "AlphaButton", + hl_shortcut = "AlphaAttr", } if nil == keybind then @@ -114,7 +116,7 @@ return function() end, }), } - dashboard.section.buttons.opts.hl = "String" + dashboard.section.buttons.opts.hl = "AlphaButton" local function footer() local stats = require("lazy").stats() @@ -134,7 +136,7 @@ return function() end dashboard.section.footer.val = footer() - dashboard.section.footer.opts.hl = "Function" + dashboard.section.footer.opts.hl = "AlphaFooter" local head_butt_padding = 2 local occu_height = #dashboard.section.header.val + 2 * #dashboard.section.buttons.val + head_butt_padding diff --git a/lua/modules/configs/ui/bufferline.lua b/lua/modules/configs/ui/bufferline.lua index e9c47965f..a81b5f07d 100644 --- a/lua/modules/configs/ui/bufferline.lua +++ b/lua/modules/configs/ui/bufferline.lua @@ -14,7 +14,6 @@ return function() color_icons = true, show_buffer_icons = true, show_buffer_close_icons = true, - -- show_buffer_default_icon = true, show_close_icon = true, show_tab_indicators = true, enforce_regular_tabs = true, diff --git a/lua/modules/configs/ui/catppuccin.lua b/lua/modules/configs/ui/catppuccin.lua index ff97973e8..8f196d3fb 100644 --- a/lua/modules/configs/ui/catppuccin.lua +++ b/lua/modules/configs/ui/catppuccin.lua @@ -1,6 +1,4 @@ return function() - local transparent_background = false -- Set background transparency here! - require("catppuccin").setup({ flavour = "frappe", -- Can be one of: latte, frappe, macchiato, mocha background = { light = "latte", dark = "frappe" }, @@ -11,7 +9,7 @@ return function() shade = "dark", percentage = 0.15, }, - transparent_background = transparent_background, + transparent_background = require("core.settings").transparent_background, show_end_of_buffer = false, -- show the '~' characters after the end of buffers term_colors = true, compile_path = vim.fn.stdpath("cache") .. "/catppuccin", @@ -77,7 +75,7 @@ return function() nvimtree = true, overseer = false, pounce = false, - semantic_tokens = false, + semantic_tokens = true, symbols_outline = false, telekasten = false, telescope = true, @@ -153,6 +151,17 @@ return function() illuminatedWord = { bg = "#4b5d6b" }, + -- For lsp semantic tokens + ["@lsp.type.comment"] = { fg = cp.overlay0 }, + ["@lsp.type.enum"] = { link = "@type" }, + ["@lsp.type.property"] = { link = "@property" }, + ["@lsp.type.macro"] = { link = "@constant" }, + ["@lsp.typemod.function.defaultLibrary"] = { fg = cp.blue, style = { "bold", "italic" } }, + ["@lsp.typemod.function.defaultLibrary.c"] = { fg = cp.blue, style = { "bold" } }, + ["@lsp.typemod.function.defaultLibrary.cpp"] = { fg = cp.blue, style = { "bold" } }, + ["@lsp.typemod.method.defaultLibrary"] = { link = "@lsp.typemod.function.defaultLibrary" }, + ["@lsp.typemod.variable.defaultLibrary"] = { fg = cp.flamingo }, + -- For treesitter. ["@field"] = { fg = cp.rosewater }, ["@property"] = { fg = cp.yellow }, diff --git a/lua/modules/configs/ui/edge.lua b/lua/modules/configs/ui/edge.lua index 216899a8e..6f63356be 100644 --- a/lua/modules/configs/ui/edge.lua +++ b/lua/modules/configs/ui/edge.lua @@ -4,5 +4,5 @@ return function() vim.g.edge_disable_italic_comment = 1 vim.g.edge_show_eob = 1 vim.g.edge_better_performance = 1 - vim.g.edge_transparent_background = 1 + vim.g.edge_transparent_background = require("core.settings").transparent_background and 2 or 0 end diff --git a/lua/modules/configs/ui/nord.lua b/lua/modules/configs/ui/nord.lua index 522d3f7c0..17f535539 100644 --- a/lua/modules/configs/ui/nord.lua +++ b/lua/modules/configs/ui/nord.lua @@ -2,7 +2,7 @@ return function() vim.g.nord_contrast = true vim.g.nord_borders = false vim.g.nord_cursorline_transparent = true - vim.g.nord_disable_background = false + vim.g.nord_disable_background = require("core.settings").transparent_background vim.g.nord_enable_sidebar_background = true vim.g.nord_italic = true end diff --git a/lua/modules/configs/ui/paint.lua b/lua/modules/configs/ui/paint.lua index 1fda36cb1..434355659 100644 --- a/lua/modules/configs/ui/paint.lua +++ b/lua/modules/configs/ui/paint.lua @@ -12,7 +12,7 @@ return function() }, { filter = { filetype = "python" }, - pattern = "%s*(%w+:)", + pattern = "%s*([_%w]+:)", hl = "Constant", }, }, diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index 0a355841b..a7d755b48 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -10,7 +10,7 @@ completion["neovim/nvim-lspconfig"] = { { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, { - "glepnir/lspsaga.nvim", + "nvimdev/lspsaga.nvim", config = require("completion.lspsaga"), }, }, @@ -46,7 +46,6 @@ completion["hrsh7th/nvim-cmp"] = { dependencies = { "rafamadriz/friendly-snippets" }, config = require("completion.luasnip"), }, - { "onsails/lspkind.nvim" }, { "lukas-reineke/cmp-under-comparator" }, { "saadparwaiz1/cmp_luasnip" }, { "hrsh7th/cmp-nvim-lsp" }, diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index b5a58c9c0..ac51d6960 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -21,7 +21,7 @@ ui["catppuccin/nvim"] = { } ]] ui["j-hui/fidget.nvim"] = { lazy = true, - event = "BufReadPost", + event = "LspAttach", config = require("ui.fidget"), } ui["lewis6991/gitsigns.nvim"] = { diff --git a/lua/modules/utils/icons.lua b/lua/modules/utils/icons.lua index c59b14975..3d5703e67 100644 --- a/lua/modules/utils/icons.lua +++ b/lua/modules/utils/icons.lua @@ -28,6 +28,7 @@ local data = { Text = "", TypeParameter = "", Unit = "", + Undefined = "", Value = "", Variable = "", -- ccls-specific icons. @@ -162,15 +163,23 @@ local data = { cmp = { Codeium = "", TabNine = "", - Copilot = "", - Copilot_alt = "", + Copilot = "", + -- Add source-specific icons here + buffer = "", + cmp_tabnine = "", + codeium = "", + copilot = "", + copilot_alt = "", + latex_symbols = "", + luasnip = "", nvim_lsp = "", nvim_lua = "", + orgmode = "", path = "", - buffer = "", spell = "暈", - luasnip = "", + tmux = "", treesitter = "", + undefined = "", }, dap = { Breakpoint = "", diff --git a/lua/modules/utils/init.lua b/lua/modules/utils/init.lua index 26c91af3a..47da69d8e 100644 --- a/lua/modules/utils/init.lua +++ b/lua/modules/utils/init.lua @@ -80,44 +80,6 @@ local function hexToRgb(c) return { tonumber(c:sub(2, 3), 16), tonumber(c:sub(4, 5), 16), tonumber(c:sub(6, 7), 16) } end ----Parse the `style` string into nvim_set_hl options ----@param style string @The style config ----@return table -local function parse_style(style) - if not style or style == "NONE" then - return {} - end - - local result = {} - for field in string.gmatch(style, "([^,]+)") do - result[field] = true - end - - return result -end - ----Wrapper function for nvim_get_hl_by_name ----@param hl_group string @Highlight group name ----@return table -local function get_highlight(hl_group) - local hl = vim.api.nvim_get_hl_by_name(hl_group, true) - if hl.link then - return get_highlight(hl.link) - end - - local result = parse_style(hl.style) - result.fg = hl.foreground and string.format("#%06x", hl.foreground) - result.bg = hl.background and string.format("#%06x", hl.background) - result.sp = hl.special and string.format("#%06x", hl.special) - for attr, val in pairs(hl) do - if type(attr) == "string" and attr ~= "foreground" and attr ~= "background" and attr ~= "special" then - result[attr] = val - end - end - - return result -end - ---Blend foreground with background ---@param foreground string @The foreground color ---@param background string @The background color to blend with @@ -143,10 +105,10 @@ end ---@return string function M.hl_to_rgb(hl_group, use_bg, fallback_hl) local hex = fallback_hl or "#000000" - local hlexists = pcall(vim.api.nvim_get_hl_by_name, hl_group, true) + local hlexists = pcall(vim.api.nvim_get_hl, 0, { name = hl_group, link = false }) if hlexists then - local result = get_highlight(hl_group) + local result = vim.api.nvim_get_hl(0, { name = hl_group, link = false }) if use_bg then hex = result.bg and result.bg or "NONE" else @@ -161,12 +123,12 @@ end ---@param name string @Target highlight group name ---@param def table @Attributes to be extended function M.extend_hl(name, def) - local hlexists = pcall(vim.api.nvim_get_hl_by_name, name, true) + local hlexists = pcall(vim.api.nvim_get_hl, 0, { name = name, link = false }) if not hlexists then -- Do nothing if highlight group not found return end - local current_def = get_highlight(name) + local current_def = vim.api.nvim_get_hl(0, { name = name, link = false }) local combined_def = vim.tbl_deep_extend("force", current_def, def) vim.api.nvim_set_hl(0, name, combined_def) @@ -183,6 +145,7 @@ function M.get_palette(overwrite) end end +-- Generate highlight groups for lspsaga. Existing attributes will NOT be overwritten function M.gen_lspkind_hl() local colors = M.get_palette() local dat = { @@ -227,6 +190,16 @@ function M.gen_lspkind_hl() end end +-- Generate highlight groups for alpha. Existing attributes will NOT be overwritten +function M.gen_alpha_hl() + local colors = M.get_palette() + + vim.api.nvim_set_hl(0, "AlphaHeader", { fg = colors.blue, default = true }) + vim.api.nvim_set_hl(0, "AlphaButton", { fg = colors.green, default = true }) + vim.api.nvim_set_hl(0, "AlphaAttr", { fg = colors.pink, italic = true, default = true }) + vim.api.nvim_set_hl(0, "AlphaFooter", { fg = colors.yellow, default = true }) +end + ---Convert number (0/1) to boolean ---@param value number @The value to check ---@return boolean|nil @Returns nil if failed diff --git a/scripts/install.ps1 b/scripts/install.ps1 index a431964cf..953849c53 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -8,12 +8,13 @@ Set-StrictMode -Version 3.0 $ErrorActionPreference = "Stop" # Exit when command fails # global-scope vars -$REQUIRED_NVIM_VERSION = [version]'0.8.0' +$REQUIRED_NVIM_VERSION = [version]'0.9.0' +$REQUIRED_NVIM_VERSION_LEGACY = [version]'0.8.0' $USE_SSH = $True # package mgr vars -$choco_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "node" = "nodejs"; "pip" = "python3"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust-ms" } -$scoop_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "node" = "nodejs"; "pip" = "python"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust" } +$choco_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python3"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust-ms" } +$scoop_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust" } $installer_pkg_matrix = @{ "NodeJS" = "npm"; "Python" = "pip"; "Ruby" = "gem" } # env vars @@ -58,6 +59,7 @@ function info_ext ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [str function warn ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [string]$Msg) { Write-Host "Warning" -ForegroundColor Yellow -NoNewline; Write-Host ": $(_chomp -Str $Msg)"; } + function warn_ext ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [string]$Msg) { Write-Host " $(_chomp -Str $Msg)" } @@ -254,6 +256,7 @@ function fetch_deps { check_and_fetch_exec -PkgName "git" check_and_fetch_exec -PkgName "nvim" check_and_fetch_exec -PkgName "make" + check_and_fetch_exec -PkgName "sudo" check_and_fetch_exec -PkgName "node" check_and_fetch_exec -PkgName "pip" check_and_fetch_exec -PkgName "fzf" @@ -270,14 +273,14 @@ function fetch_deps { $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } -function is_latest { +function check_nvim_version ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [version]$RequiredVersionMin) { $nvim_version = Invoke-Command -ErrorAction SilentlyContinue -ScriptBlock { nvim --version } # First get neovim version $nvim_version = $nvim_version.Split([System.Environment]::NewLine) | Select-Object -First 1 # Then do head -n1 $nvim_version = $nvim_version.Split('-') | Select-Object -First 1 # Special for dev branches $nvim_version = $nvim_version -replace '[^(\d+(\.\d+)*)]','' # Then do regex replacement similar to sed $nvim_version = [version]$nvim_version - return ($nvim_version -ge $REQUIRED_NVIM_VERSION) + return ($nvim_version -ge $RequiredVersionMin) } function ring_bell { @@ -311,7 +314,7 @@ function _main { # Check dependencies if (-not (check_in_path -WithName "nvim")) { _abort -Msg "Required executable not found." -Type "NotInstalled" -Info_msg @' -You must install NeoVim before installing this Nvim config. See: +You must install Neovim before installing this Nvim config. See: https://github.com/neovim/neovim/wiki/Installing-Neovim ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ [INFO] "nvim" is either not installed, missing from PATH, or not executable. @@ -351,20 +354,34 @@ You must install Git before installing this Nvim config. See: info -Msg "Fetching in progress..." if ($USE_SSH) { - if ((is_latest)) { + if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) { safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" 'git@github.com:ayamir/nvimdots.git' "$env:CCDEST_DIR" } - } else { + } elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) { warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)." - info -Msg "Automatically redirecting you to legacy version..." - safe_execute -WithCmd { git clone --progress -b 0.7 "$env:CCLONE_ATTR" 'git@github.com:ayamir/nvimdots.git' "$env:CCDEST_DIR" } + info -Msg "Automatically redirecting you to the latest compatible version..." + safe_execute -WithCmd { git clone --progress -b 0.8 "$env:CCLONE_ATTR" 'git@github.com:ayamir/nvimdots.git' "$env:CCDEST_DIR" } + } else { + warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)." + _abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @" +You have a legacy Neovim distribution installed. +Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least. + +"@ } } else { - if ((is_latest)) { + if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) { safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" 'https://github.com/ayamir/nvimdots.git' "$env:CCDEST_DIR" } - } else { + } elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) { warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)." - info -Msg "Automatically redirecting you to legacy version..." - safe_execute -WithCmd { git clone --progress -b 0.7 "$env:CCLONE_ATTR" 'https://github.com/ayamir/nvimdots.git' "$env:CCDEST_DIR" } + info -Msg "Automatically redirecting you to the latest compatible version..." + safe_execute -WithCmd { git clone --progress -b 0.8 "$env:CCLONE_ATTR" 'https://github.com/ayamir/nvimdots.git' "$env:CCDEST_DIR" } + } else { + warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)." + _abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @" +You have a legacy Neovim distribution installed. +Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least. + +"@ } } @@ -379,7 +396,7 @@ You must install Git before installing this Nvim config. See: } } - info -Msg "Spawning neovim and fetching plugins... (You'll be redirected shortly)" + info -Msg "Spawning Neovim and fetching plugins... (You'll be redirected shortly)" info -Msg 'To make sqlite work with lua, manually grab the dlls from "https://www.sqlite.org/download.html" and' info_ext -Msg 'replace vim.g.sqlite_clib_path with your path at the bottom of `lua/core/options.lua`' info -Msg 'If lazy.nvim failed to fetch any plugin(s), maunally execute `:Lazy sync` until everything is up-to-date.' diff --git a/scripts/install.sh b/scripts/install.sh index 64dc4d6d1..0cedade42 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -10,7 +10,8 @@ set -u DEST_DIR="${HOME}/.config/nvim" BACKUP_DIR="${DEST_DIR}_backup-$(date +%Y%m%dT%H%M%S)" CLONE_ATTR=("--progress") -REQUIRED_NVIM_VERSION=0.8 +REQUIRED_NVIM_VERSION=0.9.0 +REQUIRED_NVIM_VERSION_LEGACY=0.8.0 USE_SSH=1 abort() { @@ -118,7 +119,7 @@ version_ge() { prompt_confirm() { while true; do read -r -p "$1 [Y/n]: " USR_CHOICE - case "$USR_CHOICE" in + case "${USR_CHOICE}" in [yY][eE][sS] | [yY]) return 1 ;; @@ -126,10 +127,10 @@ prompt_confirm() { return 0 ;; *) - if [[ -z "$USR_CHOICE" ]]; then + if [[ -z "${USR_CHOICE}" ]]; then return 1 fi - printf "${tty_red}%s\n\n${tty_reset}" "Invalid input! Please enter one of: '[yY]/[yY][eE][sS] / [nN]/[nN][oO]'" + printf "${tty_red}%s\n\n${tty_reset}" "Invalid input! Please enter one of: '[y/yes] / [n/no]'" ;; esac done @@ -154,10 +155,10 @@ clone_pref() { fi } -is_latest() { +check_nvim_version() { local nvim_version nvim_version="$(nvim --version | head -n1 | sed -e 's|^[^0-9]*||' -e 's| .*||')" - if version_ge "$(major_minor "${nvim_version##* }")" "$(major_minor "${REQUIRED_NVIM_VERSION}")"; then + if version_ge "$(major_minor "${nvim_version##* }")" "$(major_minor "$1")"; then return 0 else return 1 @@ -203,7 +204,7 @@ fi if ! command -v nvim >/dev/null; then abort "$( cat <