Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
feat!: support Neovim v0.9 (ayamir#697)
Browse files Browse the repository at this point in the history
* 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 (ayamir#633)

* feat(utils): use neovim builtin to get highlights (ayamir#632)

* fix: remove deprecated options for nvim-tree.

* fix(cmp): support dynamic `kind_text` from cmp source: `treesitter`, fix ayamir#624 ayamir#634 (ayamir#637)

* fix&feat: introduce suda.vim to write file with sudo

* chore(kind_text): cleanup (ayamir#648)

* feat(alpha): add custom highlight groups (ayamir#650)

* fix: install `psutils` by default for Windows users

* revert: bind `SudaWrite` to `<A-s>`

ref: ayamir#641 (comment)

* 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 `<nop>` at "n|Q"
2. use visual mode instead of visual-line mode for "n|<C-a>"

* 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 (ayamir#657)

* fix(icon): update invalid cmp icon (ayamir#665)

* chore/lspsaga_move (ayamir#667)

* fix: paint word boundary in python (ayamir#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 ayamir#639 (ayamir#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` (ayamir#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` (ayamir#687)

* fix(bufferline): use defaults for `get_element_icon` (ayamir#685)

* feat(auto-session): remember opened buffers (ayamir#688)

* revert(keymap): remove redundant mappings.

* fix(catppuccin): properly detect `g:colors_name` (ayamir#695)

Ref: upstream breaking change [catppuccin/nvim@7a7a664]

---------

Co-authored-by: ayamir <lgt986452565@gmail.com>
Co-authored-by: Charles Chiu <charleschiu@hey.com>
Co-authored-by: CharlesChiuGit <charleschiu2012@gmail.com>
Co-authored-by: Xie Zejian <xiezej@gmail.com>
Co-authored-by: AngelontheRoad <52699138+AngelontheRoad@users.noreply.github.com>
Co-authored-by: Saafo <46736350+Saafo@users.noreply.github.com>
(cherry picked from commit 08c4561)
  • Loading branch information
Jint-lzxy authored and boomker committed May 2, 2023
1 parent 4c7f008 commit ed8f130
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 144 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="https://github.com/neovim/neovim/releases/tag/stable">
<img
alt="NeoVim Version Capability"
src="https://img.shields.io/badge/Supports%20Nvim-v0.8-A6D895?style=for-the-badge&colorA=363A4F&logo=neovim&logoColor=D9E0EE">
src="https://img.shields.io/badge/Supports%20Nvim-v0.9-A6D895?style=for-the-badge&colorA=363A4F&logo=neovim&logoColor=D9E0EE">
</a>
<a href="https://github.com/ayamir/nvimdots/releases">
<img
Expand Down Expand Up @@ -38,14 +38,15 @@

This repo hosts my [NeoVim](https://neovim.io/) configuration for Linux, macOS, and Windows. `init.lua` is the config entry point.

It contains two branches:
Branch info:

<div align="center">

| 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 |

</div>

Expand Down
32 changes: 32 additions & 0 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -160,13 +163,42 @@ 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()
leader_map()

neovide_config()
clipboard_config()
shell_config()

require("core.options")
require("core.mapping")
Expand Down
42 changes: 23 additions & 19 deletions lua/core/mapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@ local def_orimap = {
["n|<A-]>"] = map_cr("vertical resize +5"):with_silent():with_desc("window: Resize +5 vertically"),
["n|<A-;>"] = map_cr("resize -2"):with_silent():with_desc("window: Resize -2 horizontally"),
["n|<A-'>"] = map_cr("resize +2"):with_silent():with_desc("window: Resize +2 horizontally"),
["n|<C-q>"] = map_cmd(":wq<CR>"):with_desc("editn: Save file and quit"),
["n|<A-S-q>"] = map_cmd(":q!<CR>"):with_desc("editn: Force quit"),
["n|<leader>o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("editn: Toggle spell check"),
["n|<C-q>"] = map_cr("wq"):with_desc("edit: Save file and quit"),
["n|<A-S-q>"] = map_cr("q!"):with_desc("edit: Force quit"),
["n|<leader>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|<C-u>"] = map_cmd("<C-G>u<C-U>"):with_noremap():with_desc("editi: Delete previous block"),
["i|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("editi: Move cursor to left"),
["i|<C-a>"] = map_cmd("<ESC>^i"):with_noremap():with_desc("editi: Move cursor to line start"),
["i|<C-s>"] = map_cmd("<Esc>:w<CR>"):with_desc("editi: Save file"),
["i|<C-q>"] = map_cmd("<Esc>:wq<CR>"):with_desc("editi: Save file and quit"),
["i|<C-u>"] = map_cmd("<C-G>u<C-U>"):with_noremap():with_desc("edit: Delete previous block"),
["i|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("edit: Move cursor to left"),
["i|<C-a>"] = map_cmd("<ESC>^i"):with_noremap():with_desc("edit: Move cursor to line start"),
["i|<C-s>"] = map_cmd("<Esc>:w<CR>"):with_desc("edit: Save file"),
["i|<C-q>"] = map_cmd("<Esc>:wq<CR>"):with_desc("edit: Save file and quit"),
-- Command mode
["c|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("editc: Left"),
["c|<C-f>"] = map_cmd("<Right>"):with_noremap():with_desc("editc: Right"),
["c|<C-a>"] = map_cmd("<Home>"):with_noremap():with_desc("editc: Home"),
["c|<C-e>"] = map_cmd("<End>"):with_noremap():with_desc("editc: End"),
["c|<C-d>"] = map_cmd("<Del>"):with_noremap():with_desc("editc: Delete"),
["c|<C-h>"] = map_cmd("<BS>"):with_noremap():with_desc("editc: Backspace"),
["c|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("edit: Left"),
["c|<C-f>"] = map_cmd("<Right>"):with_noremap():with_desc("edit: Right"),
["c|<C-a>"] = map_cmd("<Home>"):with_noremap():with_desc("edit: Home"),
["c|<C-e>"] = map_cmd("<End>"):with_noremap():with_desc("edit: End"),
["c|<C-d>"] = map_cmd("<Del>"):with_noremap():with_desc("edit: Delete"),
["c|<C-h>"] = map_cmd("<BS>"):with_noremap():with_desc("edit: Backspace"),
["c|<C-t>"] = map_cmd([[<C-R>=expand("%:p:h") . "/" <CR>]])
: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 '>+1<CR>gv=gv"):with_desc("editv: Move this line down"),
["v|K"] = map_cmd(":m '<-2<CR>gv=gv"):with_desc("editv: Move this line up"),
["v|<"] = map_cmd("<gv"):with_desc("editv: Decrease indent"),
["v|>"] = map_cmd(">gv"):with_desc("editv: Increase indent"),
["v|J"] = map_cmd(":m '>+1<CR>gv=gv"):with_desc("edit: Move this line down"),
["v|K"] = map_cmd(":m '<-2<CR>gv=gv"):with_desc("edit: Move this line up"),
["v|<"] = map_cmd("<gv"):with_desc("edit: Decrease indent"),
["v|>"] = map_cmd(">gv"):with_desc("edit: Increase indent"),
}

local core_map = {
Expand Down
7 changes: 4 additions & 3 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -74,6 +74,7 @@ local function load_options()
smarttab = true,
softtabstop = 4,
splitbelow = true,
splitkeep = "cursor",
splitright = true,
startofline = false,
swapfile = false,
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions lua/keymap/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ local plug_map = {
-- Plugin: tabout
["i|<A-l>"] = map_cmd("<Plug>(TaboutMulti)"):with_silent():with_noremap():with_desc("edit: Goto end of pair"),
["i|<A-h>"] = map_cmd("<Plug>(TaboutBackMulti)"):with_silent():with_noremap():with_desc("edit: Goto begin of pair"),

-- Plugin suda.vim
["n|<A-s>"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"),
}

bind.nvim_load_mapping(plug_map)
53 changes: 44 additions & 9 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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" },
Expand Down
30 changes: 21 additions & 9 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,22 +39,29 @@ 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

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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/modules/configs/completion/lspsaga.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions lua/modules/configs/editor/suda.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return function()
vim.g["suda#prompt"] = "Enter administrator password: "
end
2 changes: 1 addition & 1 deletion lua/modules/configs/tool/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit ed8f130

Please sign in to comment.