many neovim changes and vimplugins nightly overlay

std
Hung 2023-06-12 23:58:03 -07:00
parent 7f0611d186
commit f04388f562
5 changed files with 989 additions and 809 deletions

View File

@ -4,9 +4,6 @@
-- - <leader>df to format document
-- - Harpoon marks: Navigate through main files within each project
--
-- REQUIREMENTS:
-- - zk @ https://github.com/mickael-menu/zk
-- - prettierd @ npm install -g @fsouza/prettierd
-- Auto-installs vim-plug
vim.cmd([[
@ -70,6 +67,7 @@ WPlug('hrsh7th/cmp-path')
WPlug('hrsh7th/cmp-buffer') -- Recommends words within the buffer
WPlug('hrsh7th/cmp-cmdline')
WPlug('hrsh7th/nvim-cmp')
WPlug('hrsh7th/cmp-nvim-lsp-signature-help')
WPlug('onsails/lspkind-nvim')
WPlug('yioneko/nvim-yati', { tag = '*' }) -- copium: fix Python indent auto-correct from smart-indent
WPlug('nathanalderson/yang.vim')
@ -104,6 +102,8 @@ WPlug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines
WPlug('kyazdani42/nvim-web-devicons') -- icons for folder and filetypes
WPlug('m-demare/hlargs.nvim') -- highlights arguments; great for func prog
WPlug('folke/todo-comments.nvim') -- Highlights TODO
WPlug('NvChad/nvim-colorizer.lua') -- color highlighter with tailwind support
WPlug('roobert/tailwindcss-colorizer-cmp.nvim') -- color highlighter with tailwind support
-- other utilities
WPlug('nvim-treesitter/nvim-treesitter-context') -- Top one-liner context of func/class scope
@ -121,6 +121,10 @@ WPlug('~/local_repos/ts-ql') -- workspace code intelligence
---------
vim.call('plug#end')
local PLUGIN_URI = 'gh:pegasust:dotfiles'
local PLUGIN_LEVEL = 'debug'
local log = require('plenary.log').new({ plugin = PLUGIN_URI, level = PLUGIN_LEVEL, use_console = false })
vim.cmd([[
if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
PlugInstall --sync | autocmd VimEnter * so $MYVIMRC
@ -128,6 +132,10 @@ endif
]])
-- special terminals, place them at 4..=7 for ergonomics
-- NOTE: this requires a flawless startup, otherwise, it's going to throw errors
-- since we're basically simulating keystrokes
-- TODO: The correct behavior is to register terminal keystroke with an assigned
-- buffer
vim.api.nvim_create_autocmd({ "VimEnter" }, {
callback = function()
local function named_term(term_idx, term_name)
@ -193,7 +201,10 @@ vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = vim.fn.stdpath('state') .. '/.vim/undodir'
vim.opt.undofile = true
vim.opt.completeopt = 'menuone,noselect'
-- show menu even if there's 1 selection, and default to no selection
-- Note that we're not setitng `noinsert`, which allows us to "foresee" what the
-- completion would give us. This is faithful to VSCode
vim.opt.completeopt = { "menu", "menuone", "noselect", "noinsert" }
-- vim.opt.clipboard = "unnamedplus"
@ -438,7 +449,7 @@ require('nvim-treesitter.configs').setup {
init_selection = '<C-space>',
node_incremental = '<C-space>',
node_decremental = '<C-backspace>',
pscope_incremental = '<C-S>'
scope_incremental = '<C-S>'
},
},
textobjects = {
@ -521,11 +532,49 @@ remap('n', '<leader>gs', function() require('neogit').open({}) end, { desc = "[G
-- LSP settings
-- This function gets run when an LSP connects to a particular buffer.
require("inlay-hints").setup {
-- renderer to use
-- possible options are dynamic, eol, virtline and custom
-- renderer = "inlay-hints/render/dynamic",
renderer = "inlay-hints/render/dynamic",
hints = {
parameter = {
show = true,
highlight = "whitespace",
},
type = {
show = true,
highlight = "Whitespace",
},
},
-- Only show inlay hints for the current line
only_current_line = false,
eol = {
-- whether to align to the extreme right or not
right_align = false,
-- padding from the right if right_align is true
right_align_padding = 7,
parameter = {
separator = ", ",
format = function(hints)
return string.format(" <- (%s)", hints)
end,
},
type = {
separator = ", ",
format = function(hints)
return string.format(" => %s", hints)
end,
},
},
}
}
local on_attach = function(client, bufnr)
local nmap = function(keys, func, desc)
if desc then
@ -553,7 +602,7 @@ local on_attach = function(client, bufnr)
-- This is to stay faithful with vim's default keybind for help.
-- See `:help K` for even more info on Vim's original keybindings for help
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Less likely LSP functionality to be used
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
@ -571,30 +620,39 @@ local on_attach = function(client, bufnr)
require('inlay-hints').on_attach(client, bufnr)
end
-- nvim-cmp
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require('lspkind')
local source_mapping = {
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
nvim_lua = '[Lua]',
-- cmp_tabnine = '[T9]',
path = '[Path]',
}
lspkind.init {
symbol_map = {
Copilot = "",
},
}
cmp.event:on(
"confirm_done",
require('nvim-autopairs.completion.cmp').on_confirm_done()
)
cmp.setup {
---@type cmp.ConfigSchema
local cmp_config = {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-l'] = cmp.mapping(function(_)
if cmp.visible() then
cmp.refresh()
else
fallback()
end
-- 'i': insert, 's': select, 'c': command
end, { 'i', 's' }),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-space>'] = cmp.mapping.complete(),
@ -602,47 +660,61 @@ cmp.setup {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
-- NOTE: rebind tab and shift-tab since it may break whenever we
-- need to peform manual indentation
['<C-j>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
['<C-k>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
performance = {
debounce = 60,
throttle = 30,
},
formatting = {
fields = { 'abbr', 'kind', 'menu' },
-- vim_items: complete-items (`:h complete-items`)
-- word, abbr, menu, info, kind, icase, equal, dup, empty, user_data
format = function(entry, vim_item)
vim_item.kind = lspkind.symbolic(vim_item.kind, { mode = 'symbol' })
vim_item.menu = source_mapping[entry.source_name]
-- if entry.source.name == "cmp_tabnine" then
-- local detail = (entry.completion_item.data or {}).detail
-- vim_item.kind = ""
-- if detail and detail:find('.*%%.*') then
-- vim_item.kind = vim_item.kind .. ' ' .. detail
-- end
--
-- if (entry.completion_item.data or {}).multiline then
-- vim_item.kind = vim_item.kind .. ' ' .. '[ML]'
-- end
-- end
local maxwidth = 80
vim_item.abbr = string.sub(vim_item.abbr, 1, maxwidth)
return vim_item
local kind_fn = lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[LSP]",
nvim_lua = "[api]",
path = "[path]",
luasnip = "[snip]",
gh_issues = "[issues]",
tn = "[TabNine]",
eruby = "[erb]",
nvim_lsp_signature_help = "[sig]",
}
}
vim_item = kind_fn(entry, vim_item)
return require('tailwindcss-colorizer-cmp').formatter(entry, vim_item)
end,
},
sources = cmp.config.sources {
{ name = 'nvim_lsp' },
sources = cmp.config.sources( --[[@as cmp.SourceConfig[]] {
{ name = 'nvim_lsp', },
{ name = 'nvim_lsp_signature_help' },
-- NOTE: Path is triggered by `.` and `/`, so when it comes up, it's
-- usually desirable.
{ name = 'path' },
{ name = 'luasnip' },
{
name = 'buffer',
@ -650,9 +722,9 @@ cmp.setup {
-- default is only in the current buffer. This grabs recommendations
-- from all visible buffers
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
-- Must always have current buffer
local bufs = { [0] = true }
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
local byte_size = vim.api.nvim_buf_get_offset(buf, vim.api.nvim_buf_line_count(buf))
if byte_size <= 1024 * 1024 then -- 1 MiB max
bufs[buf] = true
@ -660,19 +732,57 @@ cmp.setup {
end
return vim.tbl_keys(bufs)
end,
}
},
{ name = 'path' },
-- { name = "conjure" },
},
-- NOTE: I don't like cmdline that much. Most of the time, it recommends more harm than good
-- { name = 'cmp_tabnine' },
},
-- { name = "conjure" },
}),
experimental = { ghost_text = { hl_group = "Comment" }, },
sorting = {
comparators = {
-- Optimize searches by recommending things that are closer to the current cursor
function(...) require('cmp-buffer'):compare_locality(...) end,
}
---@param lhs_entry cmp.Entry
---@param rhs_entry cmp.Entry
function(lhs_entry, rhs_entry)
return nil
end,
cmp.config.compare.exact,
cmp.config.compare.recently_used,
cmp.config.compare.offset,
cmp.config.compare.score,
cmp.config.compare.kind,
cmp.config.compare.locality,
cmp.config.compare.sort_text,
cmp.config.compare.scope,
},
},
}
cmp.setup(vim.tbl_deep_extend("force", require('cmp.config.default')(), cmp_config))
-- `/` cmdline search.
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- `:` cmdline vim command.
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{
name = 'cmdline',
option = {
ignore_cmds = { 'Man', '!' }
}
}
})
})
-- nvim-cmp supports additional completion capabilities
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- local tabnine = require('cmp_tabnine.config')
@ -708,7 +818,8 @@ require("mason").setup({
})
require('mason-lspconfig').setup({
-- ensure_installed = servers,
automatic_installation = false
ensure_installed = { "pylsp", "pyright", "tailwindcss", "svelte", "astro", "lua_ls" },
automatic_installation = false,
})
local inlay_hint_tsjs = {
@ -743,7 +854,9 @@ require('mason-lspconfig').setup_handlers({
globals = { "vim" }
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true)
library = vim.api.nvim_get_runtime_file('', true),
-- Don't prompt me to select
checkThirdParty = false,
},
telemetry = { enable = false },
hint = {
@ -1102,7 +1215,6 @@ require('lualine').setup {
}
require('nvim-surround').setup {}
require('tsql').setup()
require('fidget').setup({
text = {
spinner = "moon", -- animation shown when tasks are ongoing
@ -1154,3 +1266,65 @@ require('fidget').setup({
strict = false, -- whether to interpret LSP strictly
},
})
-- Messaages as buf because it's so limiting to work with builtin view menu from neovim
vim.api.nvim_create_user_command('ShowLogs', function(opts)
local plugin_name = opts.fargs[1] or PLUGIN_URI
local min_level = opts.fargs[2] or PLUGIN_LEVEL
local logfile = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), plugin_name)
-- Ensure that the logfile exists
local file = io.open(logfile, 'r')
if not file then
print(string.format("No logfile found for plugin '%s'", vim.inspect(plugin_name)))
print("min_level: " .. vim.inspect(min_level))
return
end
file:close()
vim.cmd('vnew ' .. logfile)
-- Load messages from the log file
local file_messages = vim.fn.readfile(logfile)
local levels = { trace = 1, debug = 2, info = 3, warn = 4, error = 5, fatal = 6 }
local min_index = levels[min_level] or 3
local filtered_messages = {}
for _, message in ipairs(file_messages) do
local level = message:match("^%[([a-z]+)")
if levels[level] and levels[level] >= min_index then
table.insert(filtered_messages, message)
end
end
vim.api.nvim_buf_set_lines(0, 0, -1, false, filtered_messages)
vim.cmd('setlocal ft=log')
vim.cmd('setlocal nomodifiable')
end, { nargs = "*", })
require("colorizer").setup {
filetypes = { "*" },
user_default_options = {
RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes
names = true, -- "Name" codes like Blue or blue
RRGGBBAA = true, -- #RRGGBBAA hex codes
AARRGGBB = true, -- 0xAARRGGBB hex codes
rgb_fn = true, -- CSS rgb() and rgba() functions
hsl_fn = true, -- CSS hsl() and hsla() functions
css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn
-- Available modes for `mode`: foreground, background, virtualtext
mode = "background", -- Set the display mode.
-- Available methods are false / true / "normal" / "lsp" / "both"
-- True is same as normal
tailwind = true, -- Enable tailwind colors
-- parsers can contain values used in |user_default_options|
sass = { enable = true, parsers = { "css" }, }, -- Enable sass colors
virtualtext = "",
-- update color values even if buffer is not focused
-- example use: cmp_menu, cmp_docs
always_update = false
},
-- all the sub-options of filetypes apply to buftypes
buftypes = {},
}

View File

@ -1,5 +1,4 @@
# TODO: vim-plug and Mason supports laziness. Probably worth it to explore incremental dependencies based on the project
# TODO: just install these things, then symlink to mason's bin directory
# TODO: vim-plug and Mason supports laziness. Probably worth it to explore incremental dependencies based on the project TODO: just install these things, then symlink to mason's bin directory
#
# One thing to consider, though, /nix/store of `nix-shell` or `nix-develop`
# might be different from `home-manager`'s (~/.nix_profile/bin/jq)

View File

@ -58,11 +58,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1684981077,
"narHash": "sha256-68X9cFm0RTZm8u0rXPbeBzOVUH5OoUGAfeHHVoxGd9o=",
"lastModified": 1686186025,
"narHash": "sha256-SuQjKsO1G87qM5j8VNtq6kIw4ILYE03Y8yL/FoKwR+4=",
"owner": "ipetkov",
"repo": "crane",
"rev": "35110cccf28823320f4fd697fcafcb5038683982",
"rev": "057d95721ee67d421391dda7031977d247ddec28",
"type": "github"
},
"original": {
@ -570,11 +570,11 @@
"systems": "systems_2"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {
@ -818,11 +818,11 @@
]
},
"locked": {
"lastModified": 1686562199,
"narHash": "sha256-FG6kCtVjCh0dHnV4AsVfhfSyPhjnSVXucwqCdTpMASE=",
"lastModified": 1686638670,
"narHash": "sha256-+/5lqVzqeOguJlX/57LU2e3tChw5L/jpAOzyNsiveVg=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "b0cdae4e9baa188d69ba84aa1b7406b7bebe37f6",
"rev": "c8dafb187b7b010bf279a7bf0842eaadf3e387a8",
"type": "github"
},
"original": {
@ -953,11 +953,11 @@
"topiary": "topiary"
},
"locked": {
"lastModified": 1686315162,
"narHash": "sha256-KZZRTXSpxJDDGVbEdyTR/4Mu2COSMtrim+5iL7qwDTw=",
"lastModified": 1686564419,
"narHash": "sha256-DJGvo1wDBRQSjAHAiNb8dD/77/CHwpeBzBYasIb51Hk=",
"owner": "tweag",
"repo": "nickel",
"rev": "9fed1326c9306d7c339884584702ce570764beaf",
"rev": "25c509e0b19f5b38b61a28765f62ce5c20e3e476",
"type": "github"
},
"original": {
@ -1037,11 +1037,11 @@
]
},
"locked": {
"lastModified": 1685764721,
"narHash": "sha256-CIy1iwQTEKfZRrid4gBLA+r/LPGA9IUFo0lKJVyECGI=",
"lastModified": 1686574167,
"narHash": "sha256-hxE8z+S9E4Qw03D2VQRaJUmj9zep3FvhKz316JUZuPA=",
"owner": "mic92",
"repo": "nix-index-database",
"rev": "669ca1f2e2bc401abab6b837ae9c51503edc9b49",
"rev": "7e83b70f31f4483c07e6939166cb667ecb8d05d5",
"type": "github"
},
"original": {
@ -1150,16 +1150,16 @@
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1678872516,
"narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=",
"lastModified": 1685801374,
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8",
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
@ -1245,11 +1245,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1685655444,
"narHash": "sha256-6EujQNAeaUkWvpEZZcVF8qSfQrNVWFNNGbUJxv/A5a8=",
"lastModified": 1686412476,
"narHash": "sha256-inl9SVk6o5h75XKC79qrDCAobTD1Jxh6kVYTZKHzewA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e635192892f5abbc2289eaac3a73cdb249abaefd",
"rev": "21951114383770f96ae528d0ae68824557768e81",
"type": "github"
},
"original": {
@ -1513,11 +1513,11 @@
"nixpkgs-stable": "nixpkgs-stable_2"
},
"locked": {
"lastModified": 1685361114,
"narHash": "sha256-4RjrlSb+OO+e1nzTExKW58o3WRwVGpXwj97iCta8aj4=",
"lastModified": 1686213770,
"narHash": "sha256-Re6xXLEqQ/HRnThryumyGzEf3Uv0Pl4cuG50MrDofP8=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "ca2fdbf3edda2a38140184da6381d49f8206eaf4",
"rev": "182af51202998af5b64ddecaa7ff9be06425399b",
"type": "github"
},
"original": {
@ -1599,11 +1599,11 @@
]
},
"locked": {
"lastModified": 1683080331,
"narHash": "sha256-nGDvJ1DAxZIwdn6ww8IFwzoHb2rqBP4wv/65Wt5vflk=",
"lastModified": 1685759304,
"narHash": "sha256-I3YBH6MS3G5kGzNuc1G0f9uYfTcNY9NYoRc3QsykLk4=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "d59c3fa0cba8336e115b376c2d9e91053aa59e56",
"rev": "c535b4f3327910c96dcf21851bbdd074d0760290",
"type": "github"
},
"original": {
@ -1624,11 +1624,11 @@
]
},
"locked": {
"lastModified": 1685759304,
"narHash": "sha256-I3YBH6MS3G5kGzNuc1G0f9uYfTcNY9NYoRc3QsykLk4=",
"lastModified": 1686364106,
"narHash": "sha256-h4gCQg+jizmAbdg6UPlhxQVk4A7Ar/zoLa0wx3wBya0=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "c535b4f3327910c96dcf21851bbdd074d0760290",
"rev": "ba011dd1c5028dbb880bc3b0f427e0ff689e6203",
"type": "github"
},
"original": {
@ -1768,11 +1768,11 @@
"nixpkgs": "nixpkgs_13"
},
"locked": {
"lastModified": 1686537156,
"narHash": "sha256-mJD80brS6h6P4jzwdKID0S9RvfyiruxgJbXvPPIDqF0=",
"lastModified": 1686623191,
"narHash": "sha256-x2gQcKtSgfbZlcTaVvdMPbrXMRjUEYIV88yzsFww6D4=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e75da5cfc7da874401decaa88f4ccb3b4d64d20d",
"rev": "e279547de84413ca1a65cec3f0f879709c8c65eb",
"type": "github"
},
"original": {
@ -1973,11 +1973,11 @@
"rust-overlay": "rust-overlay_4"
},
"locked": {
"lastModified": 1685522994,
"narHash": "sha256-OJQ16KpYT3jGyP0WSI+jZQMU55/cnbzdYZKVBfx9wNk=",
"lastModified": 1686167925,
"narHash": "sha256-2OU00zeoIS2jFBdXKak1Y2txC6IXEP0LsIUKSvr0qbc=",
"owner": "tweag",
"repo": "topiary",
"rev": "b2399161f60c1eb3404e487b4471ff76455d7a94",
"rev": "61d076c216422af7f865e2ade3bbdb4729e767ef",
"type": "github"
},
"original": {

View File

@ -15,6 +15,7 @@
description = "simple home-manager config";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-latest.url = "github:nixos/nixpkgs";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
@ -52,6 +53,7 @@
, neovim-nightly-overlay
, nickel
, nix-boost
, nixpkgs-latest
, ...
}:
let

View File

@ -5,6 +5,7 @@ flake_input@{ kpcli-py
, system
, nickel
, nix-boost
, nixpkgs-latest
, ...
}:
let
@ -63,6 +64,10 @@ let
inherit (flake_input.nickel.packages.${system})
lsp-nls nickel nickelWasm;
});
vimPlugins = (final: prev: {
inherit (nixpkgs-latest) vimPlugins;
});
in
[
nix-boost.overlays.default