Skip to content

Commit

Permalink
Merge pull request #19 from TonyWu20/ayamir-main
Browse files Browse the repository at this point in the history
ayamir main
  • Loading branch information
TonyWu20 authored Jun 4, 2023
2 parents 42bccce + f53d64a commit 4b2fe46
Show file tree
Hide file tree
Showing 23 changed files with 680 additions and 373 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,26 @@ It's strongly recommended to read [Wiki: Prerequisites](https://github.com/ayami
</p>
<br>

<p align="center">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/code_action.png" alt="Code Action">
<em>Code Action</em>
</p>
<br>

<p align="center">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/dap.png" alt="Debugging">
<em>Debugging</em>
</p>
<br>

<p align="center">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/gitui.png" alt="Lazygit">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/lazygit.png" alt="Lazygit">
<em>Lazygit with built-in Terminal</em>
</p>
<br>

<p align="center">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/legendary.png" alt="Legendary">
<img src="https://raw.githubusercontent.com/ayamir/blog-imgs/main/command_ref.png" alt="Command quickref">
<em>Command quickref</em>
</p>

Expand Down
1 change: 0 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
if not vim.g.vscode then
require("core")
-- Release note
end
450 changes: 360 additions & 90 deletions lazy-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lua/core/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ function autocmd.load_autocmds()
"*",
[[if &cursorline && &filetype !~# '^\(dashboard\|clap_\)' && ! &pvw | setlocal nocursorline | endif]],
},
-- Force write shada on leaving nvim
-- Attempt to write shada when leaving nvim
{
"VimLeave",
"*",
[[if has('nvim') | wshada! | else | wviminfo! | endif]],
[[if has('nvim') | wshada | else | wviminfo! | endif]],
},
-- Check if file changed when its window is focus, more eager than 'autoread'
{ "FocusGained", "* checktime" },
Expand Down
10 changes: 5 additions & 5 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ local clipboard_config = function()
}
elseif global.is_wsl then
vim.g.clipboard = {
name = "psyank-wsl",
name = "win32yank-wsl",
copy = {
["+"] = "clip.exe",
["*"] = "clip.exe",
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf",
},
paste = {
["+"] = [[powershell.exe -NoProfile -NoLogo -NonInteractive -Command [console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))]],
["*"] = [[powershell.exe -NoProfile -NoLogo -NonInteractive -Command [console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))]],
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf",
},
cache_enabled = 0,
}
Expand Down
2 changes: 1 addition & 1 deletion lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ local function load_options()
ruler = true,
scrolloff = 2,
sessionoptions = "buffers,curdir,help,tabpages,winsize",
shada = "!,'300,<50,@100,s10,h",
shada = "!,'500,<50,@100,s10,h",
shiftround = true,
shiftwidth = 4,
shortmess = "aoOTIcF",
Expand Down
28 changes: 19 additions & 9 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ settings["use_ssh"] = true
---@type boolean
settings["format_on_save"] = true

-- Set it to false if diagnostics virtual text is annoying for you
-- Set it to false if the notification after formatting is annoying.
---@type boolean
settings["diagnostics_virtual_text"] = true
settings["format_notify"] = true

-- Set it to false if diagnostics virtual text is annoying.
-- If disabled, you may browse lsp diagnostics using trouble.nvim (press `gt` to toggle it).
---@type boolean
settings["diagnostics_virtual_text"] = false

-- Set it to one of the values below if you want to change the visible severity level of lsp diagnostics.
-- Priority: `Error` > `Warning` > `Information` > `Hint`.
-- > e.g. if you set this option to `Warning`, only lsp warnings and errors will be shown.
-- NOTE: This entry only works when `diagnostics_virtual_text` is true.
---@type "Error"|"Warning"|"Information"|"Hint"
settings["diagnostics_level"] = "Hint"

-- Set the format disabled directories here, files under these dirs won't be formatted on save.
---@type string[]
Expand Down Expand Up @@ -51,22 +63,21 @@ settings["background"] = "dark"
---@type string
settings["external_browser"] = "chrome-cli open"

-- Filetypes in this list will skip lsp formatting if rhs is true
-- Filetypes in this list will skip lsp formatting if rhs is true.
---@type table<string, boolean>
settings["formatter_block_list"] = {
lua = false, -- example
}

-- Servers in this list will skip setting formatting capabilities if rhs is true
-- Servers in this list will skip setting formatting capabilities if rhs is true.
---@type table<string, boolean>
settings["server_formatting_block_list"] = {
lua_ls = true,
tsserver = true,
clangd = true,
pylsp = true,
}

-- Set the language servers that will be installed during bootstrap here
-- Set the language servers that will be installed during bootstrap here.
-- check the below link for all the supported LSPs:
-- https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/server_configurations
---@type string[]
Expand All @@ -80,13 +91,12 @@ settings["lsp_deps"] = {
-- "gopls",
}

-- Set the general-purpose servers that will be installed during bootstrap here
-- check the below link for all supported sources
-- Set the general-purpose servers that will be installed during bootstrap here.
-- Check the below link for all supported sources.
-- in `code_actions`, `completion`, `diagnostics`, `formatting`, `hover` folders:
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins
---@type string[]
settings["null_ls_deps"] = {
"black",
"clang_format",
"prettier",
"rustfmt",
Expand Down
99 changes: 44 additions & 55 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ return function()

local border = function(hl)
return {
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
}
end
Expand All @@ -32,47 +32,18 @@ return function()
return (diff < 0)
end

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({
preselect = cmp.PreselectMode.Item,
window = {
completion = {
border = border("Normal"),
max_width = 80,
max_height = 20,
border = border("PmenuBorder"),
winhighlight = "Normal:Pmenu,CursorLine:PmenuSel,Search:PmenuSel",
scrollbar = false,
},
documentation = {
border = border("CmpDocBorder"),
winhighlight = "Normal:CmpDoc",
},
},
sorting = {
Expand All @@ -96,19 +67,47 @@ return function()
},
},
formatting = {
fields = { "menu", "abbr", "kind" },
fields = { "abbr", "kind", "menu" },
format = function(entry, vim_item)
local kind_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp)
local kind = cmp_format({
maxwidth = 50,
symbol_map = kind_map,
})(entry, vim_item)
return kind
local lspkind_icons = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp)
-- load lspkind icons
vim_item.kind =
string.format(" %s %s", lspkind_icons[vim_item.kind] or icons.cmp.undefined, vim_item.kind or "")

vim_item.menu = setmetatable({
cmp_tabnine = "[TN]",
copilot = "[CPLT]",
buffer = "[BUF]",
orgmode = "[ORG]",
nvim_lsp = "[LSP]",
nvim_lua = "[LUA]",
path = "[PATH]",
tmux = "[TMUX]",
treesitter = "[TS]",
luasnip = "[SNIP]",
spell = "[SPELL]",
}, {
__index = function()
return "[BTN]" -- builtin/unknown source names
end,
})[entry.source.name]

local label = vim_item.abbr
local truncated_label = vim.fn.strcharpart(label, 0, 80)
if truncated_label ~= label then
vim_item.abbr = truncated_label .. "..."
end

return vim_item
end,
},
matching = {
disallow_partial_fuzzy_matching = false,
},
performance = {
async_budget = 1,
max_view_entries = 150,
},
-- You can set mappings if you want
mapping = cmp.mapping.preset.insert({
["<CR>"] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }),
Expand Down Expand Up @@ -143,21 +142,11 @@ return function()
},
-- You should specify your *installed* sources.
sources = {
{ name = "nvim_lsp", max_item_count = 350 },
{ name = "nvim_lsp" },
{ name = "nvim_lua" },
{ name = "luasnip" },
{ name = "path" },
{
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 = "treesitter" },
{ name = "spell" },
{ name = "tmux" },
{ name = "orgmode" },
Expand Down
13 changes: 8 additions & 5 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local M = {}

local settings = require("core.settings")
local format_notify = settings.format_notify
local disabled_workspaces = settings.format_disabled_dirs
local format_on_save = settings.format_on_save
local server_formatting_block_list = settings.server_formatting_block_list
Expand Down Expand Up @@ -156,11 +157,13 @@ function M.format(opts)
local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr)
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),
vim.log.levels.INFO,
{ title = "LSP Format Success" }
)
if format_notify then
vim.notify(
string.format("[LSP] Format successfully with %s!", client.name),
vim.log.levels.INFO,
{ title = "LSP Format Success" }
)
end
elseif err then
vim.notify(
string.format("[LSP][%s] %s", client.name, err),
Expand Down
Loading

0 comments on commit 4b2fe46

Please sign in to comment.