2023-06-15 19:46:01 +00:00
|
|
|
-- What: Mono-file nvim configuration file Why: Easy to see through everything without needing to navigate thru files Features: - LSP
|
2022-08-16 01:59:31 +00:00
|
|
|
-- - Auto-complete (in insert mode: ctrl-space, navigate w/ Tab+S-Tab, confirm: Enter)
|
2022-09-24 23:49:40 +00:00
|
|
|
-- - <leader>df to format document
|
2022-08-22 09:17:11 +00:00
|
|
|
-- - Harpoon marks: Navigate through main files within each project
|
2022-09-07 06:06:13 +00:00
|
|
|
--
|
2022-08-16 01:59:31 +00:00
|
|
|
|
2023-06-12 04:21:01 +00:00
|
|
|
-- Auto-installs vim-plug
|
2022-08-14 08:57:04 +00:00
|
|
|
vim.cmd([[
|
2022-11-22 03:09:44 +00:00
|
|
|
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
|
2022-11-22 08:12:15 +00:00
|
|
|
let plug_path = data_dir . '/autoload/plug.vim'
|
|
|
|
if empty(glob(plug_path))
|
2023-06-13 06:58:03 +00:00
|
|
|
execute '!curl -fLo '.plug_path.' --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
|
|
|
|
execute 'so '.plug_path
|
2022-08-14 08:57:04 +00:00
|
|
|
endif
|
2022-08-14 07:48:17 +00:00
|
|
|
]])
|
2022-11-22 08:12:15 +00:00
|
|
|
|
2022-11-22 06:21:46 +00:00
|
|
|
-- vim-plug
|
2022-08-14 08:57:04 +00:00
|
|
|
local Plug = vim.fn['plug#']
|
2022-11-22 05:36:18 +00:00
|
|
|
|
2023-06-12 04:21:01 +00:00
|
|
|
-- prepare a list of installed plugins from rtp
|
2023-07-25 20:24:49 +00:00
|
|
|
--- @type table<string, boolean>
|
2023-06-12 04:21:01 +00:00
|
|
|
local installed_plugins = {}
|
|
|
|
-- NOTE: nvim_list_runtime_paths will expand wildcard paths for us.
|
|
|
|
for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do
|
2023-06-13 06:58:03 +00:00
|
|
|
local last_folder_start = path:find("/[^/]*$")
|
|
|
|
if last_folder_start then
|
2023-07-25 20:24:49 +00:00
|
|
|
local plugin_name = string.lower(path:sub(last_folder_start + 1))
|
2023-06-13 06:58:03 +00:00
|
|
|
installed_plugins[plugin_name] = true
|
|
|
|
end
|
2023-06-12 04:21:01 +00:00
|
|
|
end
|
|
|
|
|
2023-06-15 19:46:01 +00:00
|
|
|
local wplug_log = require('plenary.log').new({ plugin = 'wplug_log', level = 'debug', use_console = false })
|
2023-06-12 04:21:01 +00:00
|
|
|
-- Do Plug if plugin not yet linked in `rtp`. This takes care of Nix-compatibility
|
|
|
|
local function WPlug(plugin_path, ...)
|
2023-07-25 20:24:49 +00:00
|
|
|
-- hrsh7th/cmp-nvim -> cmp-nvim
|
2023-06-13 06:58:03 +00:00
|
|
|
local plugin_name = string.lower(plugin_path:match("/([^/]+)$"))
|
|
|
|
if not installed_plugins[plugin_name] then
|
2023-07-25 20:24:49 +00:00
|
|
|
wplug_log.info("Missing in rtp: " .. plugin_name .. " path: " .. plugin_path)
|
2023-06-13 06:58:03 +00:00
|
|
|
Plug(plugin_path, ...)
|
|
|
|
end
|
2023-07-25 20:24:49 +00:00
|
|
|
installed_plugins[plugin_name] = false
|
2023-06-12 04:21:01 +00:00
|
|
|
end
|
|
|
|
|
2023-07-25 20:24:49 +00:00
|
|
|
-- Borked, reason unknown
|
|
|
|
-- for plugin, plugged in pairs(installed_plugins) do
|
|
|
|
-- if plugged ~= false then
|
|
|
|
-- wplug_log.info("Plugin " .. plugin .. " added to rtp but not WPlug-ed")
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
2022-11-22 08:12:15 +00:00
|
|
|
vim.call('plug#begin')
|
2022-09-24 23:49:40 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- libs and dependencies
|
2023-07-09 01:28:13 +00:00
|
|
|
WPlug('nvim-lua/plenary.nvim') -- The base of all plugins
|
|
|
|
WPlug('MunifTanjim/nui.nvim') -- For some .so or .dylib neovim UI action
|
2023-06-20 21:10:00 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
-- plugins
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('tjdevries/nlua.nvim') -- adds symbols of vim stuffs in init.lua
|
|
|
|
WPlug('nvim-treesitter/nvim-treesitter') -- language parser engine for highlighting
|
|
|
|
WPlug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects
|
|
|
|
WPlug('nvim-telescope/telescope.nvim', { branch = '0.1.x' }) -- file browser
|
2023-01-10 15:30:52 +00:00
|
|
|
-- TODO: this might need to be taken extra care in our Nix config
|
2023-06-12 04:21:01 +00:00
|
|
|
-- What this WPlug declaration means is this repo needs to be built on our running environment
|
2023-01-10 15:30:52 +00:00
|
|
|
-- -----
|
|
|
|
-- What to do:
|
|
|
|
-- - Run `make` at anytime before Nix is done on this repository
|
2023-06-13 06:58:03 +00:00
|
|
|
-- - Might mean that we fetch this repository, run make, and copy to destination folder
|
2023-06-12 04:21:01 +00:00
|
|
|
-- - Make sure that if we run `make` at first WPlug run, that `make` is idempotent
|
2023-01-10 15:30:52 +00:00
|
|
|
-- OR
|
2023-06-13 06:58:03 +00:00
|
|
|
-- Make sure that WPlug does not run `make` and use the output it needs
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('nvim-telescope/telescope-fzf-native.nvim',
|
2023-06-13 06:58:03 +00:00
|
|
|
{ ['do'] = 'make >> /tmp/log 2>&1' })
|
2023-09-14 05:14:16 +00:00
|
|
|
WPlug('nvim-telescope/telescope-live-grep-args.nvim')
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('nvim-telescope/telescope-file-browser.nvim')
|
2022-09-24 23:49:40 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- cmp: auto-complete/suggestions
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('neovim/nvim-lspconfig') -- built-in LSP configurations
|
|
|
|
WPlug('hrsh7th/cmp-nvim-lsp')
|
|
|
|
WPlug('hrsh7th/cmp-path')
|
2023-06-12 19:14:59 +00:00
|
|
|
WPlug('hrsh7th/cmp-buffer') -- Recommends words within the buffer
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('hrsh7th/cmp-cmdline')
|
|
|
|
WPlug('hrsh7th/nvim-cmp')
|
2023-06-13 06:58:03 +00:00
|
|
|
WPlug('hrsh7th/cmp-nvim-lsp-signature-help')
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('onsails/lspkind-nvim')
|
|
|
|
WPlug('yioneko/nvim-yati', { tag = '*' }) -- copium: fix Python indent auto-correct from smart-indent
|
|
|
|
WPlug('nathanalderson/yang.vim')
|
|
|
|
-- WPlug('tzachar/cmp-tabnine', { ['do'] = './install.sh' })
|
2022-09-24 23:49:40 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- DevExp
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('windwp/nvim-autopairs') -- matches pairs like [] (),...
|
|
|
|
WPlug('windwp/nvim-ts-autotag') -- matches tags <body>hello</body>
|
|
|
|
WPlug('NMAC427/guess-indent.nvim') -- guesses the indentation of an opened buffer
|
|
|
|
WPlug('j-hui/fidget.nvim') -- Progress bar for LSP
|
|
|
|
WPlug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines
|
|
|
|
WPlug('lewis6991/gitsigns.nvim') -- add git info to sign columns
|
|
|
|
WPlug('tpope/vim-fugitive') -- git commands in nvim
|
|
|
|
WPlug('williamboman/mason.nvim') -- LSP, debuggers,... package manager
|
|
|
|
WPlug('williamboman/mason-lspconfig.nvim') -- lsp config for mason
|
|
|
|
WPlug('ThePrimeagen/harpoon') -- 1-click through marked files per project
|
|
|
|
WPlug('TimUntersberger/neogit') -- Easy-to-see git status
|
|
|
|
WPlug('folke/trouble.nvim') -- File-grouped workspace diagnostics
|
|
|
|
WPlug('tpope/vim-dispatch') -- Allows quick build/compile/test vim commands
|
|
|
|
WPlug('clojure-vim/vim-jack-in') -- Clojure: ":Boot", ":Clj", ":Lein"
|
|
|
|
WPlug('radenling/vim-dispatch-neovim') -- Add support for neovim's terminal emulator
|
2023-06-13 06:58:03 +00:00
|
|
|
-- WPlug('Olical/conjure') -- REPL on the source for Clojure (and other LISPs)
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('gennaro-tedesco/nvim-jqx') -- JSON formatter (use :Jqx*)
|
|
|
|
WPlug('kylechui/nvim-surround') -- surrounds with tags/parenthesis
|
|
|
|
WPlug('simrat39/rust-tools.nvim') -- config rust-analyzer and nvim integration
|
2023-06-20 21:10:00 +00:00
|
|
|
WPlug('tjdevries/sg.nvim') -- Cody and other cool sourcegraph stuffs
|
2022-08-15 06:45:08 +00:00
|
|
|
|
|
|
|
-- UI & colorscheme
|
2023-06-13 06:58:03 +00:00
|
|
|
WPlug('simrat39/inlay-hints.nvim') -- type-hints with pseudo-virtual texts
|
|
|
|
WPlug('gruvbox-community/gruvbox') -- theme provider
|
|
|
|
WPlug('nvim-lualine/lualine.nvim') -- fancy status line
|
|
|
|
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
|
2023-06-18 03:32:15 +00:00
|
|
|
WPlug('roobert/tailwindcss-colorizer-cmp.nvim') -- color for tailiwnd for compe
|
2022-08-15 06:45:08 +00:00
|
|
|
|
2022-09-24 23:49:40 +00:00
|
|
|
-- other utilities
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('nvim-treesitter/nvim-treesitter-context') -- Top one-liner context of func/class scope
|
|
|
|
WPlug('nvim-treesitter/playground') -- Sees Treesitter AST - less hair pulling, more PRs
|
|
|
|
WPlug('saadparwaiz1/cmp_luasnip') -- snippet engine
|
|
|
|
WPlug('L3MON4D3/LuaSnip') -- snippet engine
|
2023-06-18 03:32:15 +00:00
|
|
|
WPlug('folke/neodev.nvim') -- Neovim + lua development setup
|
2023-01-10 15:30:52 +00:00
|
|
|
-- Switch cases:
|
|
|
|
-- `gsp` -> PascalCase (classes), `gsc` -> camelCase (Java), `gs_` -> snake_case (C/C++/Rust)
|
|
|
|
-- `gsu` -> UPPER_CASE (CONSTs), `gsk` -> kebab-case (Clojure), `gsK` -> Title-Kebab-Case
|
|
|
|
-- `gs.` -> dot.case (R)
|
2023-06-12 04:21:01 +00:00
|
|
|
WPlug('arthurxavierx/vim-caser') -- switch cases
|
2022-08-15 06:45:08 +00:00
|
|
|
|
|
|
|
---------
|
2022-08-14 08:57:04 +00:00
|
|
|
vim.call('plug#end')
|
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
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 })
|
|
|
|
|
2022-11-22 08:12:15 +00:00
|
|
|
vim.cmd([[
|
2022-11-24 00:18:38 +00:00
|
|
|
if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
2023-06-13 06:58:03 +00:00
|
|
|
PlugInstall --sync | autocmd VimEnter * so $MYVIMRC
|
2022-11-24 00:18:38 +00:00
|
|
|
endif
|
2022-11-22 08:12:15 +00:00
|
|
|
]])
|
2022-11-22 05:36:18 +00:00
|
|
|
|
2022-12-30 03:19:02 +00:00
|
|
|
-- special terminals, place them at 4..=7 for ergonomics
|
2023-06-13 06:58:03 +00:00
|
|
|
-- 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
|
2023-01-10 15:30:52 +00:00
|
|
|
vim.api.nvim_create_autocmd({ "VimEnter" }, {
|
2023-06-13 06:58:03 +00:00
|
|
|
callback = function()
|
|
|
|
local function named_term(term_idx, term_name)
|
|
|
|
require('harpoon.term').gotoTerminal(term_idx)
|
|
|
|
vim.cmd([[:exe ":file ]] .. term_name .. [[" | :bfirst]])
|
2022-12-30 03:19:02 +00:00
|
|
|
end
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
-- term:ctl at 4
|
|
|
|
named_term(4, "term:ctl")
|
|
|
|
-- term:dev at 5
|
|
|
|
named_term(5, "term:dev")
|
|
|
|
-- term:repl at 7
|
|
|
|
named_term(7, "term:repl")
|
|
|
|
-- term:repl at 6
|
|
|
|
named_term(6, "term:repl2")
|
|
|
|
end
|
2022-12-30 03:19:02 +00:00
|
|
|
})
|
|
|
|
|
2023-03-20 04:25:41 +00:00
|
|
|
vim.g.gruvbox_contrast_dark = "soft";
|
|
|
|
vim.g.gruvbox_contrast_light = "soft";
|
2023-01-15 12:48:11 +00:00
|
|
|
vim.opt.ignorecase = true;
|
|
|
|
vim.opt.smartcase = true;
|
|
|
|
vim.opt.incsearch = true;
|
|
|
|
vim.opt.number = true;
|
|
|
|
vim.opt.relativenumber = true;
|
|
|
|
vim.opt.autoindent = true;
|
|
|
|
vim.opt.smartindent = true;
|
|
|
|
vim.opt.expandtab = true;
|
|
|
|
vim.opt.exrc = true;
|
|
|
|
|
|
|
|
vim.opt.tabstop = 4;
|
|
|
|
vim.opt.softtabstop = 4;
|
|
|
|
vim.opt.shiftwidth = 4;
|
|
|
|
vim.opt.scrolloff = 30;
|
|
|
|
vim.opt.signcolumn = "yes";
|
|
|
|
vim.opt.colorcolumn = "80";
|
|
|
|
|
2023-04-02 06:35:11 +00:00
|
|
|
vim.opt.background = "dark";
|
2023-01-15 12:48:11 +00:00
|
|
|
|
|
|
|
vim.api.nvim_create_user_command('Dark', function(opts)
|
2023-06-13 06:58:03 +00:00
|
|
|
-- opts: {name, args: str, fargs: Splited<str>, range, ...}
|
|
|
|
---@type string
|
|
|
|
local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_dark;
|
|
|
|
vim.g.gruvbox_contrast_dark = contrast;
|
|
|
|
vim.opt.background = "dark";
|
|
|
|
end,
|
|
|
|
{ nargs = "?", })
|
2023-01-15 12:48:11 +00:00
|
|
|
|
|
|
|
vim.api.nvim_create_user_command('Light', function(opts)
|
2023-06-13 06:58:03 +00:00
|
|
|
-- opts: {name, args: str, fargs: Splited<str>, range, ...}
|
|
|
|
---@type string
|
|
|
|
local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_light;
|
|
|
|
vim.g.gruvbox_contrast_light = contrast;
|
|
|
|
vim.opt.background = "light";
|
|
|
|
end,
|
|
|
|
{ nargs = "?", })
|
2023-01-15 12:48:11 +00:00
|
|
|
|
2022-11-22 05:36:18 +00:00
|
|
|
vim.opt.lazyredraw = true
|
|
|
|
vim.opt.termguicolors = true
|
|
|
|
vim.opt.cursorline = true
|
|
|
|
-- some plugins misbehave when we do swap files
|
|
|
|
vim.opt.swapfile = false
|
|
|
|
vim.opt.backup = false
|
2023-03-20 04:25:41 +00:00
|
|
|
vim.opt.undodir = vim.fn.stdpath('state') .. '/.vim/undodir'
|
2022-11-22 05:36:18 +00:00
|
|
|
vim.opt.undofile = true
|
2023-06-13 06:58:03 +00:00
|
|
|
-- 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" }
|
2023-06-05 16:04:08 +00:00
|
|
|
|
|
|
|
|
2022-11-22 05:36:18 +00:00
|
|
|
-- vim.opt.clipboard = "unnamedplus"
|
2023-06-18 11:22:11 +00:00
|
|
|
|
|
|
|
-- more aggressive swap file writing. ThePrimeagen believes higher number leads to low DX
|
2022-11-24 00:18:38 +00:00
|
|
|
vim.opt.updatetime = 50
|
2022-11-22 05:36:18 +00:00
|
|
|
|
|
|
|
vim.g.mapleader = ' '
|
|
|
|
vim.g.maplocalleader = ','
|
|
|
|
|
|
|
|
-- basic keymaps
|
2022-12-30 10:08:04 +00:00
|
|
|
-- Since we use space for leader, we're asserting that this does nothing by itself
|
|
|
|
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
|
2022-12-30 14:10:55 +00:00
|
|
|
-- make :terminal escape out. For zsh-vi-mode, just use Alt-Z or any keybind
|
2022-12-30 10:08:04 +00:00
|
|
|
-- that does not collide with vi-motion keybind. This is because
|
|
|
|
-- <Alt-x> -> ^[x; while <Esc> on the terminal is ^[
|
|
|
|
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>)')
|
2023-01-10 15:30:52 +00:00
|
|
|
vim.keymap.set({ 'n', 'i', 'v' }, '<c-l>', '<Cmd>mode<Cr>', { desc = "" }) -- redraw on every mode
|
2022-11-22 05:36:18 +00:00
|
|
|
|
|
|
|
-- diagnostics (errors/warnings to be shown)
|
|
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
|
|
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
|
|
|
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) -- opens diag in box (floating)
|
|
|
|
-- vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist) -- opens list of diags
|
|
|
|
-- vim.keymap.set('n', '<leader>wq', vim.diagnostic.setqflist) -- workspace diags
|
|
|
|
vim.keymap.set('n', '<leader>q', '<cmd>TroubleToggle loclist<cr>')
|
|
|
|
vim.keymap.set('n', '<leader>wq', '<cmd>TroubleToggle workspace_diagnostics<cr>')
|
2023-05-16 16:26:57 +00:00
|
|
|
vim.keymap.set('n', '<leader>gg', '<cmd>GuessIndent<cr>')
|
2022-11-22 05:36:18 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- color, highlighting, UI stuffs
|
2023-03-20 04:25:41 +00:00
|
|
|
vim.cmd([[
|
2022-11-22 05:36:18 +00:00
|
|
|
colorscheme gruvbox
|
|
|
|
]])
|
2022-09-12 23:20:01 +00:00
|
|
|
require('hlargs').setup()
|
2022-09-24 23:49:40 +00:00
|
|
|
require('nvim-web-devicons').setup()
|
2023-06-18 03:32:15 +00:00
|
|
|
require('trouble').setup {
|
2023-09-14 05:14:16 +00:00
|
|
|
position = "bottom", -- position of the list can be: bottom, top, left, right
|
|
|
|
height = 10, -- height of the trouble list when position is top or bottom
|
|
|
|
width = 50, -- width of the list when position is left or right
|
|
|
|
icons = true, -- use devicons for filenames
|
2023-07-09 01:28:13 +00:00
|
|
|
mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist"
|
2023-09-14 05:14:16 +00:00
|
|
|
severity = nil, -- nil (ALL) or vim.diagnostic.severity.ERROR | WARN | INFO | HINT
|
|
|
|
fold_open = "", -- icon used for open folds
|
|
|
|
fold_closed = "", -- icon used for closed folds
|
|
|
|
group = true, -- group results by file
|
|
|
|
padding = true, -- add an extra new line on top of the list
|
2023-06-18 03:32:15 +00:00
|
|
|
action_keys = {
|
2023-07-09 01:28:13 +00:00
|
|
|
-- key mappings for actions in the trouble list
|
2023-06-18 03:32:15 +00:00
|
|
|
-- map to {} to remove a mapping, for example:
|
|
|
|
-- close = {},
|
|
|
|
close = "q", -- close the list
|
|
|
|
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
|
|
|
|
refresh = "r", -- manually refresh
|
|
|
|
jump = { "<cr>", "<tab>" }, -- jump to the diagnostic or open / close folds
|
|
|
|
open_split = { "<c-x>" }, -- open buffer in new split
|
|
|
|
open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
|
|
|
|
open_tab = { "<c-t>" }, -- open buffer in new tab
|
|
|
|
jump_close = { "o" }, -- jump to the diagnostic and close the list
|
|
|
|
toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
|
|
|
|
switch_severity = "s", -- switch "diagnostics" severity filter level to HINT / INFO / WARN / ERROR
|
|
|
|
toggle_preview = "P", -- toggle auto_preview
|
|
|
|
hover = "K", -- opens a small popup with the full multiline message
|
|
|
|
preview = "p", -- preview the diagnostic location
|
|
|
|
close_folds = { "zM", "zm" }, -- close all folds
|
|
|
|
open_folds = { "zR", "zr" }, -- open all folds
|
|
|
|
toggle_fold = { "zA", "za" }, -- toggle fold of current file
|
|
|
|
previous = "k", -- previous item
|
|
|
|
next = "j" -- next item
|
|
|
|
},
|
|
|
|
indent_lines = true, -- add an indent guide below the fold icons
|
|
|
|
auto_open = false, -- automatically open the list when you have diagnostics
|
|
|
|
auto_close = false, -- automatically close the list when you have no diagnostics
|
|
|
|
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> to close preview and go back to last window
|
|
|
|
auto_fold = false, -- automatically fold a file trouble list at creation
|
|
|
|
auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result
|
|
|
|
signs = {
|
|
|
|
-- icons / text used for a diagnostic
|
|
|
|
error = "",
|
|
|
|
warning = "",
|
|
|
|
hint = "",
|
|
|
|
information = "",
|
|
|
|
other = "",
|
|
|
|
},
|
2023-07-09 01:28:13 +00:00
|
|
|
use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client
|
2023-06-18 03:32:15 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 23:08:44 +00:00
|
|
|
|
|
|
|
-- TODO: Any way to collect all the TODOs and its variants?
|
2022-09-24 23:49:40 +00:00
|
|
|
require('todo-comments').setup()
|
2022-08-14 08:57:04 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- plugin keymaps
|
2022-09-12 23:20:01 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
local function remap(mode, key_cmd, binded_fn, opts)
|
2023-06-13 06:58:03 +00:00
|
|
|
opts = opts or { remap = true }
|
|
|
|
return vim.keymap.set(mode, key_cmd, binded_fn, opts)
|
2022-08-15 06:45:08 +00:00
|
|
|
end
|
2022-08-15 09:05:14 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- Comment.nvim
|
|
|
|
require('Comment').setup()
|
|
|
|
-- lukas-reineke/indent-blankline.nvim
|
2022-08-16 01:59:31 +00:00
|
|
|
vim.opt.list = true
|
|
|
|
vim.opt.listchars:append "space:⋅"
|
|
|
|
vim.opt.listchars:append "eol:↴"
|
|
|
|
|
|
|
|
require("indent_blankline").setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
show_end_of_line = true,
|
|
|
|
space_char_blankline = " ",
|
2023-06-15 19:46:01 +00:00
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
}
|
2022-09-24 23:49:40 +00:00
|
|
|
-- User command that transform into 2-spaces by translating to tabstop
|
|
|
|
vim.api.nvim_create_user_command(
|
2023-06-13 06:58:03 +00:00
|
|
|
'HalfSpaces',
|
|
|
|
function(opts)
|
|
|
|
vim.api.nvim_command("set ts=2 sts=2 noet")
|
|
|
|
vim.api.nvim_command("retab!")
|
|
|
|
vim.api.nvim_command("set ts=1 sts=1 et")
|
|
|
|
vim.api.nvim_command("retab")
|
|
|
|
vim.api.nvim_command("GuessIndent")
|
|
|
|
end,
|
|
|
|
{ nargs = 0 }
|
2022-09-24 23:49:40 +00:00
|
|
|
)
|
|
|
|
vim.api.nvim_create_user_command(
|
2023-06-13 06:58:03 +00:00
|
|
|
'DoubleSpaces',
|
|
|
|
function(opts)
|
|
|
|
-- cannot really do 1-space tab. The minimum is 2-space to begin
|
|
|
|
-- doubling
|
|
|
|
vim.api.nvim_command("set ts=2 sts=2 noet")
|
|
|
|
vim.api.nvim_command("retab!")
|
|
|
|
vim.api.nvim_command("set ts=4 sts=4 et")
|
|
|
|
vim.api.nvim_command("retab")
|
|
|
|
vim.api.nvim_command("GuessIndent")
|
|
|
|
end,
|
|
|
|
{ nargs = 0 }
|
2022-09-24 23:49:40 +00:00
|
|
|
)
|
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- telescope
|
2022-08-22 09:17:11 +00:00
|
|
|
local fb_actions = require "telescope".extensions.file_browser.actions
|
2023-06-16 23:12:54 +00:00
|
|
|
local tel_actions = require("telescope.actions")
|
2023-09-24 07:48:54 +00:00
|
|
|
local tel_action_state = require("telescope.actions.state")
|
2023-06-16 23:12:54 +00:00
|
|
|
local tel_actionset = require("telescope.actions.set")
|
|
|
|
|
2023-09-24 07:48:54 +00:00
|
|
|
-- telescope + harpoon mark
|
|
|
|
local function default_harpoon_mark()
|
|
|
|
require('harpoon.mark').add_file()
|
|
|
|
end
|
|
|
|
|
|
|
|
local harpoon_keymap = '<leader>m'
|
|
|
|
|
|
|
|
local function telescope_multi_selection(prompt_bufnr)
|
|
|
|
local picker = tel_action_state.get_current_picker(prompt_bufnr)
|
|
|
|
---@class telescope.make_entry.Entry
|
|
|
|
---@field value any
|
|
|
|
---@field valid boolean | nil
|
|
|
|
---@field ordinal string for filtering and (fuzzy) search-friendly string
|
|
|
|
---@field display string|function
|
|
|
|
---@field filename string | nil
|
|
|
|
---@field bufnr number | nil
|
|
|
|
---@field lum number | nil
|
|
|
|
---@field col number | nil
|
|
|
|
|
|
|
|
---@class telescope.make_entry.gen_from_file__rv: telescope.make_entry.Entry
|
|
|
|
---@field cwd string | nil
|
|
|
|
---@field path string via __index
|
|
|
|
---@field __index function
|
|
|
|
|
|
|
|
---@type telescope.make_entry.gen_from_file__rv[]
|
|
|
|
local rv = picker:get_multi_selection()
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
|
|
|
local function mark_telescope_selections(prompt_bufnr)
|
|
|
|
-- NOTE: This works for both bulitin Telescope file browser and fuzzy search
|
|
|
|
local selections = telescope_multi_selection(prompt_bufnr)
|
|
|
|
--[[
|
|
|
|
local entries = {}
|
|
|
|
for k, e in ipairs(selections) do
|
|
|
|
table.insert(entries, { k = k, e = e })
|
|
|
|
end
|
|
|
|
print(vim.inspect({
|
|
|
|
prompt_bufnr = prompt_bufnr,
|
|
|
|
selections = selections,
|
|
|
|
entries = entries,
|
|
|
|
}))
|
|
|
|
|
|
|
|
stdout> (builtin.__file)
|
|
|
|
{
|
|
|
|
entries = { { "native_configs/ssh/authorized_keys",
|
|
|
|
index = 6,
|
|
|
|
<metatable> = <1>{
|
|
|
|
__index = <function 1>,
|
|
|
|
cwd = "/Users/hungtran/local_repos/dotfiles",
|
|
|
|
display = <function 2>
|
|
|
|
}
|
|
|
|
}, { "native_configs/ssh/config", index = 7, <metatable> = <table 1> } },
|
|
|
|
prompt_bufnr = 56
|
|
|
|
}
|
|
|
|
--]]
|
|
|
|
|
|
|
|
---@type string[]
|
|
|
|
local filenames = {}
|
|
|
|
|
|
|
|
for _, entry in ipairs(selections) do
|
|
|
|
local has_path, path = pcall(function() return entry:__index("path") --[[ @as string ]] end)
|
|
|
|
if has_path then
|
|
|
|
table.insert(filenames, path)
|
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
|
|
|
|
-- invariant: pcall on has_path false will assign second rv as the error
|
|
|
|
-- payload. Most of the time, this is a string, but for safety, we could
|
|
|
|
-- not assume so.
|
|
|
|
local err = path
|
|
|
|
log.warn("No `.path` for entry `" .. vim.inspect(entry) .. "`: " .. vim.inspect(err))
|
|
|
|
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
|
|
|
|
log.debug(vim.inspect(filenames))
|
|
|
|
|
|
|
|
|
|
|
|
for _, filename in pairs(filenames) do
|
|
|
|
require('harpoon.mark').add_file(filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-16 23:12:54 +00:00
|
|
|
local function term_height()
|
|
|
|
return vim.opt.lines:get()
|
|
|
|
end
|
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
require('telescope').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
defaults = {
|
|
|
|
mappings = {
|
2023-06-16 23:12:54 +00:00
|
|
|
n = {
|
|
|
|
['<C-u>'] = function(prompt_bufnr) tel_actionset.shift_selection(prompt_bufnr, -math.floor(term_height() / 2)) end,
|
|
|
|
['<C-d>'] = function(prompt_bufnr) tel_actionset.shift_selection(prompt_bufnr, math.floor(term_height() / 2)) end,
|
2023-09-24 07:48:54 +00:00
|
|
|
[harpoon_keymap] = function(prompt_bufnr)
|
|
|
|
mark_telescope_selections(prompt_bufnr)
|
|
|
|
end,
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
2022-10-12 00:06:09 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
|
|
|
extensions = {
|
2023-09-14 05:14:16 +00:00
|
|
|
live_grep_args = {
|
|
|
|
auto_quoting = true,
|
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
fzf = {
|
|
|
|
fuzzy = true, -- allow fuzzy matches
|
|
|
|
override_generic_sorter = true,
|
|
|
|
override_file_sorter = true,
|
|
|
|
case_mode = 'smart_case'
|
|
|
|
},
|
|
|
|
file_browser = {
|
|
|
|
theme = require('telescope.themes').get_ivy().theme,
|
|
|
|
hiject_netrw = true, -- disables netrw and use file-browser instead
|
|
|
|
mappings = {
|
|
|
|
["i"] = {}, -- disable any shortcut in insert mode for now
|
|
|
|
["n"] = {
|
|
|
|
["c"] = fb_actions.create,
|
|
|
|
["r"] = fb_actions.rename,
|
|
|
|
["m"] = fb_actions.move,
|
|
|
|
["y"] = fb_actions.copy,
|
|
|
|
["d"] = fb_actions.remove,
|
|
|
|
["o"] = fb_actions.open,
|
|
|
|
["g"] = fb_actions.goto_parent_dir,
|
|
|
|
["e"] = fb_actions.goto_home_dir,
|
|
|
|
["w"] = fb_actions.goto_cwd,
|
|
|
|
["t"] = fb_actions.change_cwd,
|
|
|
|
["f"] = fb_actions.toggle_browser,
|
|
|
|
["h"] = fb_actions.toggle_hidden,
|
|
|
|
["s"] = fb_actions.toggle_all,
|
2022-08-22 09:17:11 +00:00
|
|
|
}
|
2023-06-13 06:58:03 +00:00
|
|
|
}
|
2022-08-15 06:45:08 +00:00
|
|
|
}
|
2023-06-13 06:58:03 +00:00
|
|
|
}
|
2022-08-15 06:45:08 +00:00
|
|
|
}
|
2022-08-27 12:34:55 +00:00
|
|
|
|
2022-09-07 06:06:13 +00:00
|
|
|
-- Telescope key remap stuffs
|
2022-08-15 06:45:08 +00:00
|
|
|
pcall(require('telescope').load_extension, 'fzf')
|
2022-08-22 09:17:11 +00:00
|
|
|
pcall(require('telescope').load_extension, 'file_browser')
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<C-p>', '<cmd>Telescope<cr>', { desc = 'Open Telescope general search' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
|
|
|
remap('n', '<leader>fm', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require("telescope").extensions.file_browser.file_browser({})
|
2022-08-22 09:17:11 +00:00
|
|
|
end, { desc = '[F]ile [M]utation' })
|
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<leader>ff', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').find_files({
|
|
|
|
hidden = false,
|
|
|
|
no_ignore = false,
|
|
|
|
follow = false,
|
|
|
|
})
|
2022-08-22 09:17:11 +00:00
|
|
|
end, { desc = '[F]ind [F]ile' })
|
|
|
|
|
|
|
|
remap('n', '<leader>fa', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').find_files({
|
|
|
|
hidden = true,
|
|
|
|
no_ignore = true,
|
|
|
|
follow = true,
|
|
|
|
})
|
2022-08-31 14:39:47 +00:00
|
|
|
end, { desc = '[F]ind [A]ll files' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<leader>fg', function()
|
2023-09-24 07:48:54 +00:00
|
|
|
require('telescope').extensions.live_grep_args.live_grep_args()
|
2023-06-16 23:12:54 +00:00
|
|
|
end, { desc = '[F]ind thru [G]rep' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
2023-09-24 07:48:54 +00:00
|
|
|
|
2023-06-05 04:40:47 +00:00
|
|
|
remap('n', '<leader>fug', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
-- This relies on many factors: We use `rg` and that `-g '**/*'` effectively
|
|
|
|
-- drops ignore rules like the default `.gitignore` rule.
|
2023-09-24 07:48:54 +00:00
|
|
|
vim.notify("fuzzy unrestricted grep is deprecated, use Find thru Grep with `-uuu` query instead")
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').live_grep({ glob_pattern = '**/*' })
|
2023-06-16 23:12:54 +00:00
|
|
|
end, { desc = '[F]ind thru [u]nrestricted [G]rep' })
|
2023-06-05 04:40:47 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<leader>fb', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').buffers()
|
2022-08-15 09:05:14 +00:00
|
|
|
end, { desc = '[F]ind existing [B]uffers' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<leader>fh', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').help_tags()
|
2022-08-15 09:05:14 +00:00
|
|
|
end, { desc = '[F]ind [H]elp' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
remap('n', '<leader>fd', function()
|
2023-06-13 06:58:03 +00:00
|
|
|
require('telescope.builtin').diagnostics()
|
2022-08-15 09:05:14 +00:00
|
|
|
end, { desc = '[F]ind [D]iagnostics' })
|
2022-08-22 09:17:11 +00:00
|
|
|
|
2023-06-05 16:04:08 +00:00
|
|
|
-- tab management {{{
|
|
|
|
|
|
|
|
-- Jump to specific tab with <C-t>[number]
|
|
|
|
for i = 1, 9 do
|
2023-06-13 06:58:03 +00:00
|
|
|
vim.api.nvim_set_keymap('n', '<C-t>' .. i, ':tabn ' .. i .. '<CR>', { noremap = true, silent = true })
|
2023-06-05 16:04:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Show tab number in tab display
|
|
|
|
vim.o.showtabline = 1
|
|
|
|
vim.o.tabline = '%!v:lua.my_tabline()'
|
|
|
|
|
|
|
|
function _G.my_tabline()
|
2023-06-13 06:58:03 +00:00
|
|
|
local s = ''
|
|
|
|
for i = 1, vim.fn.tabpagenr('$') do
|
|
|
|
if i == vim.fn.tabpagenr() then
|
|
|
|
s = s .. '%' .. i .. 'T%#TabLineSel#'
|
|
|
|
else
|
|
|
|
s = s .. '%' .. i .. 'T%#TabLine#'
|
|
|
|
end
|
|
|
|
local tab = vim.fn.gettabinfo(i)[1]
|
|
|
|
local tabbuf = tab.variables.buffers
|
|
|
|
local bufname = "<unknown>"
|
|
|
|
if tabbuf then
|
|
|
|
bufname = tabbuf[tab.curwin].name
|
2023-06-05 16:04:08 +00:00
|
|
|
end
|
2023-06-13 06:58:03 +00:00
|
|
|
-- Canonicalize tab/buf name
|
|
|
|
s = s .. ' ' .. i .. ' ' .. vim.fn.fnamemodify(bufname, ':t')
|
|
|
|
if i ~= vim.fn.tabpagenr('$') then
|
|
|
|
s = s .. '%#TabLine#|%#TabLine#'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return s .. '%T%#TabLineFill#%='
|
2023-06-05 16:04:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Close all tabs except the first one
|
|
|
|
vim.api.nvim_set_keymap('n', '<C-t>x', ':tabdo if tabpagenr() > 1 | tabclose | endif<CR>',
|
2023-06-16 23:12:54 +00:00
|
|
|
{ noremap = true, silent = true, desc = "Close all tabs except the first one", })
|
2023-06-05 16:04:08 +00:00
|
|
|
|
|
|
|
-- }}}
|
|
|
|
|
2022-08-15 06:45:08 +00:00
|
|
|
-- treesitter
|
2022-11-24 00:18:38 +00:00
|
|
|
require 'treesitter-context'
|
2022-08-15 06:45:08 +00:00
|
|
|
require('nvim-treesitter.configs').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
yati = {
|
|
|
|
enable = true,
|
|
|
|
default_lazy = true,
|
|
|
|
default_fallback = "auto",
|
|
|
|
disable = { "nix" }
|
|
|
|
},
|
|
|
|
indent = { enable = false },
|
|
|
|
highlight = {
|
|
|
|
enable = true,
|
|
|
|
enable_vim_regex_highlighting = true,
|
|
|
|
},
|
|
|
|
incremental_selection = {
|
|
|
|
enable = true,
|
|
|
|
keymaps = {
|
|
|
|
init_selection = '<C-space>',
|
|
|
|
node_incremental = '<C-space>',
|
|
|
|
node_decremental = '<C-backspace>',
|
|
|
|
scope_incremental = '<C-S>'
|
2022-11-24 00:26:22 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
|
|
|
textobjects = {
|
|
|
|
select = {
|
|
|
|
enable = true,
|
|
|
|
lookahead = true,
|
|
|
|
keymaps = {
|
|
|
|
['af'] = '@function.outer',
|
|
|
|
['if'] = '@function.inner',
|
|
|
|
['ac'] = '@class.outer',
|
|
|
|
['ic'] = '@class.inner',
|
|
|
|
},
|
2022-08-15 06:45:08 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
|
|
|
playground = {
|
|
|
|
enable = true,
|
|
|
|
disable = {}
|
|
|
|
},
|
|
|
|
-- automatically close and modify HTML and TSX tags
|
|
|
|
autotag = {
|
|
|
|
enable = true,
|
|
|
|
},
|
2022-08-15 06:45:08 +00:00
|
|
|
}
|
2022-08-31 14:39:47 +00:00
|
|
|
|
|
|
|
require('nvim-autopairs').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
check_ts = true,
|
2022-09-02 14:00:54 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 06:06:13 +00:00
|
|
|
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
|
2022-09-12 23:20:01 +00:00
|
|
|
parser_config.tsx.filetype_to_parsername = { "javascript", "typescript.tsx" }
|
2022-10-12 00:06:09 +00:00
|
|
|
parser_config.astro.filetype_to_parsername = { "javascript", "typescript.tsx", "astro" }
|
2022-09-07 06:06:13 +00:00
|
|
|
|
|
|
|
|
2022-09-02 14:00:54 +00:00
|
|
|
require('guess-indent').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
auto_cmd = true,
|
|
|
|
filetype_exclude = { -- A list of filetypes for which the auto command gets disabled
|
|
|
|
"netrw",
|
|
|
|
"tutor",
|
|
|
|
},
|
|
|
|
|
|
|
|
-- buftype_exclude = { -- A list of buffer types for which the auto command gets disabled
|
|
|
|
-- "help",
|
|
|
|
-- "nofile",
|
|
|
|
-- "terminal",
|
|
|
|
-- -- "prompt",
|
|
|
|
-- },
|
2022-08-31 14:39:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 04:34:19 +00:00
|
|
|
-- harpoon: O(1) buffer/terminal switching
|
2023-09-24 07:48:54 +00:00
|
|
|
remap('n', harpoon_keymap, function()
|
|
|
|
local is_err, err = pcall(require('harpoon.mark').add_file)
|
|
|
|
if is_err then
|
|
|
|
log.warn(vim.inspect(err))
|
|
|
|
end
|
|
|
|
end, { desc = "[H]arpoon [M]ark" })
|
2022-08-27 12:34:55 +00:00
|
|
|
local function harpoon_nav(key, nav_file_index, lead_keybind)
|
2023-06-13 06:58:03 +00:00
|
|
|
lead_keybind = lead_keybind or '<leader>h'
|
|
|
|
assert(type(key) == "string", "expect key to be string(keybind)")
|
|
|
|
assert(type(nav_file_index) == "number" and nav_file_index >= 1, "expect 1-indexed number for file index")
|
|
|
|
return remap('n', lead_keybind .. key,
|
|
|
|
function() require('harpoon.ui').nav_file(nav_file_index) end,
|
|
|
|
{ desc = "[H]arpoon navigate " .. tostring(nav_file_index) })
|
2022-08-27 12:34:55 +00:00
|
|
|
end
|
2022-08-31 14:39:47 +00:00
|
|
|
|
2022-08-27 12:34:55 +00:00
|
|
|
-- remap letters to index. Inspired by alternating number of Dvorak programmer
|
|
|
|
-- best practices: try to keep marked files to be around 4
|
|
|
|
harpoon_nav('f', 1)
|
|
|
|
harpoon_nav('j', 2)
|
|
|
|
harpoon_nav('d', 3)
|
|
|
|
harpoon_nav('k', 4)
|
2022-08-22 09:17:11 +00:00
|
|
|
remap('n', '<leader>hh', function() require('harpoon.ui').toggle_quick_menu() end)
|
2022-12-29 23:22:16 +00:00
|
|
|
for i = 1, 10 do
|
2023-06-13 06:58:03 +00:00
|
|
|
-- harpoon: navigate files by numbers
|
|
|
|
harpoon_nav(tostring(i % 10), i)
|
|
|
|
-- harpoon: navigate terms by numbers
|
|
|
|
remap('n', '<leader>t' .. tostring(i % 10), function()
|
|
|
|
require('harpoon.term').gotoTerminal(i)
|
|
|
|
end)
|
2022-12-29 23:22:16 +00:00
|
|
|
end
|
2022-08-15 06:45:08 +00:00
|
|
|
|
2022-12-13 05:26:42 +00:00
|
|
|
-- neogit: easy-to-see git status. Provides only productivity on staging/unstage
|
2022-09-24 06:03:47 +00:00
|
|
|
require('neogit').setup {}
|
2022-12-29 23:22:16 +00:00
|
|
|
remap('n', '<leader>gs', function() require('neogit').open({}) end, { desc = "[G]it [S]tatus" });
|
2022-09-24 06:03:47 +00:00
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
-- LSP settings
|
2022-09-24 23:49:40 +00:00
|
|
|
-- This function gets run when an LSP connects to a particular buffer.
|
2022-11-23 17:02:56 +00:00
|
|
|
require("inlay-hints").setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
-- renderer to use
|
|
|
|
-- possible options are dynamic, eol, virtline and custom
|
|
|
|
-- renderer = "inlay-hints/render/dynamic",
|
2023-06-15 19:46:01 +00:00
|
|
|
renderer = "inlay-hints/render/eol",
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
2022-11-23 17:02:56 +00:00
|
|
|
}
|
2022-10-26 12:09:47 +00:00
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
local nmap = function(keys, func, desc)
|
|
|
|
if desc then
|
|
|
|
desc = 'LSP: ' .. desc
|
2022-08-15 09:05:14 +00:00
|
|
|
end
|
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
vim.keymap.set('n', keys, func, { noremap = true, buffer = bufnr, desc = desc })
|
|
|
|
end
|
|
|
|
|
|
|
|
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
|
|
|
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
|
|
|
-- NOTE: I have no clue what this does again
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
nmap('<leader>df', function() vim.lsp.buf.format({ async = true }) end, '[D]ocument [F]ormat')
|
|
|
|
|
|
|
|
-- symbols and gotos
|
|
|
|
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
|
|
|
nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
|
|
|
nmap('gr', require('telescope.builtin').lsp_references)
|
|
|
|
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
|
|
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
|
|
|
|
|
|
|
-- documentations & helps
|
|
|
|
-- NOTE: When you press K, it shows in-line Documentation
|
|
|
|
-- 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')
|
|
|
|
|
|
|
|
-- Less likely LSP functionality to be used
|
|
|
|
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
|
|
|
nmap('gtd', vim.lsp.buf.type_definition, '[G]oto [T]ype [D]efinition')
|
|
|
|
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
|
|
|
--
|
|
|
|
-- Very rarely used
|
|
|
|
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
|
|
|
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
|
|
|
nmap('<leader>wl', function()
|
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end, '[W]orkspace [L]ist Folders')
|
|
|
|
|
|
|
|
-- enable inlay hints if available
|
|
|
|
require('inlay-hints').on_attach(client, bufnr)
|
2022-08-15 09:05:14 +00:00
|
|
|
end
|
2023-06-20 21:10:00 +00:00
|
|
|
|
|
|
|
require("sg").setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
}
|
2022-11-21 22:16:34 +00:00
|
|
|
-- nvim-cmp
|
2023-06-13 06:58:03 +00:00
|
|
|
|
2022-11-21 22:16:34 +00:00
|
|
|
local cmp = require 'cmp'
|
|
|
|
local luasnip = require 'luasnip'
|
|
|
|
local lspkind = require('lspkind')
|
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
lspkind.init {
|
|
|
|
symbol_map = {
|
|
|
|
Copilot = "",
|
|
|
|
},
|
|
|
|
}
|
2022-11-28 02:04:38 +00:00
|
|
|
cmp.event:on(
|
2023-06-13 06:58:03 +00:00
|
|
|
"confirm_done",
|
|
|
|
require('nvim-autopairs.completion.cmp').on_confirm_done()
|
2022-11-28 02:04:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-06-15 19:46:01 +00:00
|
|
|
---@alias EntryFilter {id: integer, compe: lsp.CompletionItem, return_type: string, return_type2: string, score: number, label: string, source_name: string, bufnr: number?, offset: number?, kind: lsp.CompletionItemKind }
|
|
|
|
---@param entry cmp.Entry
|
|
|
|
---@return EntryFilter
|
|
|
|
local function entry_filter_sync(entry)
|
|
|
|
local compe = entry:get_completion_item()
|
|
|
|
local return_type = compe.data and compe.data.return_type
|
|
|
|
local return_type2 = compe.detail
|
|
|
|
local score = entry.score
|
|
|
|
local label = compe.label
|
|
|
|
local source_name = entry.source.name
|
|
|
|
local bufnr = entry.context.bufnr
|
|
|
|
local offset = entry:get_offset()
|
|
|
|
local kind = entry:get_kind()
|
|
|
|
local id = entry.id
|
|
|
|
return {
|
|
|
|
id = id,
|
|
|
|
compe = compe,
|
|
|
|
return_type = return_type,
|
|
|
|
return_type2 = return_type2,
|
|
|
|
score = score,
|
|
|
|
label = label,
|
|
|
|
source_name = source_name,
|
|
|
|
bufnr = bufnr,
|
|
|
|
offset = offset,
|
|
|
|
kind = kind,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param entry cmp.Entry
|
|
|
|
---@param callback fun(entry: EntryFilter): any
|
|
|
|
local function entry_filter(entry, callback)
|
|
|
|
entry:resolve(function()
|
|
|
|
callback(entry_filter_sync(entry))
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
---@type cmp.ConfigSchema
|
|
|
|
local cmp_config = {
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
2023-06-15 19:46:01 +00:00
|
|
|
['<C-l'] = cmp.mapping(function(fallback)
|
2023-06-13 06:58:03 +00:00
|
|
|
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(),
|
|
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
2022-11-21 22:16:34 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
-- 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({ behavior = cmp.SelectBehavior.Select })
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
['<C-k>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
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)
|
|
|
|
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)
|
2023-06-15 19:46:01 +00:00
|
|
|
|
|
|
|
-- copium that this will force resolve for entry
|
2023-09-24 09:06:11 +00:00
|
|
|
-- entry_filter(entry, function(entry)
|
|
|
|
-- if entry.source_name == "nvim_lsp" then
|
|
|
|
-- log.debug('format:entry: ' .. vim.inspect(entry, { depth = 2 }))
|
|
|
|
-- end
|
|
|
|
-- end)
|
2023-06-15 19:46:01 +00:00
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
return require('tailwindcss-colorizer-cmp').formatter(entry, vim_item)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
sources = cmp.config.sources( --[[@as cmp.SourceConfig[]] {
|
2023-06-15 19:46:01 +00:00
|
|
|
{ name = 'nvim_lsp', max_item_count = 30, },
|
2023-06-13 06:58:03 +00:00
|
|
|
{ name = 'nvim_lsp_signature_help' },
|
|
|
|
-- NOTE: Path is triggered by `.` and `/`, so when it comes up, it's
|
|
|
|
-- usually desirable.
|
2023-06-15 19:46:01 +00:00
|
|
|
{ name = 'path', max_item_count = 20, },
|
|
|
|
{ name = 'luasnip', max_item_count = 20, },
|
2023-06-13 06:58:03 +00:00
|
|
|
{
|
|
|
|
name = 'buffer',
|
|
|
|
option = {
|
|
|
|
-- default is only in the current buffer. This grabs recommendations
|
|
|
|
-- from all visible buffers
|
|
|
|
get_bufnrs = function()
|
|
|
|
-- 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
|
2022-11-21 22:16:34 +00:00
|
|
|
end
|
2023-06-13 06:58:03 +00:00
|
|
|
end
|
|
|
|
return vim.tbl_keys(bufs)
|
2022-11-21 22:16:34 +00:00
|
|
|
end,
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
2023-06-15 19:46:01 +00:00
|
|
|
max_item_count = 20,
|
|
|
|
}
|
2023-06-13 06:58:03 +00:00
|
|
|
-- 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 = {
|
|
|
|
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,
|
2023-06-12 19:14:59 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
2022-11-21 22:16:34 +00:00
|
|
|
}
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
cmp.setup(vim.tbl_deep_extend("force", require('cmp.config.default')(), cmp_config))
|
2023-06-15 19:46:01 +00:00
|
|
|
-- set max autocomplete height. this prevents huge recommendations to take over the screen
|
|
|
|
vim.o.pumheight = 15 -- 15/70 is good enough ratio for me. I generally go with 80-90 max height, though
|
2023-06-16 23:12:54 +00:00
|
|
|
vim.o.pumblend = 10 -- semi-transparent for the art, nothing too useful (neovim recommends 0-30)
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
-- `/` 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', '!' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
-- nvim-cmp supports additional completion capabilities
|
2022-11-22 01:09:48 +00:00
|
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
2022-10-12 00:06:09 +00:00
|
|
|
-- local tabnine = require('cmp_tabnine.config')
|
|
|
|
-- tabnine.setup({
|
2023-06-13 06:58:03 +00:00
|
|
|
-- max_lines = 1000,
|
|
|
|
-- max_num_results = 20,
|
|
|
|
-- sort = true,
|
|
|
|
-- run_on_every_keystroke = true,
|
|
|
|
-- snippet_placeholder = '..',
|
|
|
|
-- ignored_file_types = {},
|
|
|
|
-- show_prediction_strength = true,
|
2022-10-12 00:06:09 +00:00
|
|
|
-- })
|
2022-08-15 09:05:14 +00:00
|
|
|
-- default language servers
|
2022-11-24 00:18:38 +00:00
|
|
|
local servers = {
|
2023-06-13 06:58:03 +00:00
|
|
|
'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'lua_ls', 'cmake', 'tailwindcss', 'prismals',
|
2023-06-18 06:31:47 +00:00
|
|
|
'nil_ls', 'eslint', 'terraformls', 'tflint', 'svelte', 'astro', 'clojure_lsp', "bashls", 'yamlls', "ansiblels",
|
2023-06-13 06:58:03 +00:00
|
|
|
"jsonls", "denols", "gopls", "nickel_ls", 'pylsp',
|
2022-11-23 23:43:44 +00:00
|
|
|
}
|
2022-08-15 09:05:14 +00:00
|
|
|
require("mason").setup({
|
2023-06-13 06:58:03 +00:00
|
|
|
ui = {
|
|
|
|
icons = {
|
|
|
|
package_installed = "✓",
|
|
|
|
package_pending = "➜",
|
|
|
|
package_uninstalled = "✗"
|
2022-12-03 07:03:20 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
check_outdated_packages_on_open = true,
|
|
|
|
},
|
|
|
|
-- NOTE: The default settings is "prepend" https://github.com/williamboman/mason.nvim#default-configuration
|
|
|
|
-- Which means Mason's installed path is prioritized against our local install
|
|
|
|
-- see: https://git.pegasust.com/pegasust/aoc/commit/b45dc32c74d84c9f787ebce7a174c9aa1d411fc2
|
|
|
|
-- This introduces some pitfalls, so we'll take the approach of trusting user's local installation
|
|
|
|
PATH = "append",
|
2022-08-15 09:05:14 +00:00
|
|
|
})
|
|
|
|
require('mason-lspconfig').setup({
|
2023-06-13 06:58:03 +00:00
|
|
|
-- ensure_installed = servers,
|
2023-06-16 23:12:54 +00:00
|
|
|
ensure_installed = {
|
|
|
|
"pylsp", "pyright", "tailwindcss", "svelte", "astro", "lua_ls", "tsserver",
|
|
|
|
"ansiblels", "yamlls", "docker_compose_language_service", "jsonls",
|
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
automatic_installation = false,
|
2022-08-15 09:05:14 +00:00
|
|
|
})
|
2022-11-30 11:46:32 +00:00
|
|
|
|
2022-11-22 03:48:24 +00:00
|
|
|
local inlay_hint_tsjs = {
|
2023-06-13 06:58:03 +00:00
|
|
|
includeInlayEnumMemberValueHints = true,
|
|
|
|
includeInlayFunctionLikeReturnTypeHints = true,
|
|
|
|
includeInlayFunctionParameterTypeHints = true,
|
|
|
|
includeInlayParameterNameHints = 'all', -- "none" | "literals" | "all"
|
|
|
|
inlcudeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
|
|
|
includeInlayPropertyDeclarationTypeHints = true,
|
|
|
|
includeInlayVariableTypeHints = true,
|
2022-11-22 03:48:24 +00:00
|
|
|
};
|
|
|
|
|
2023-07-10 09:08:36 +00:00
|
|
|
local setup = {
|
|
|
|
["nil_ls"] = function()
|
|
|
|
require('lspconfig').nil_ls.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
--- refer to https://github.com/oxalica/nil/blob/main/docs/configuration.md
|
|
|
|
--- for the list of configurations available for `nil_ls`
|
|
|
|
settings = {
|
|
|
|
["nil"] = {
|
|
|
|
formatting = {
|
2023-07-25 20:24:49 +00:00
|
|
|
-- NOTE: nil_ls automatically adds the specific path to the filename
|
|
|
|
-- at the end, so we couldn't really have a fallback mechanism without
|
|
|
|
-- wrapping.
|
|
|
|
command = {
|
|
|
|
"nix", "run", "nixpkgs#alejandra"
|
|
|
|
},
|
2023-07-10 09:08:36 +00:00
|
|
|
},
|
|
|
|
nix = {
|
|
|
|
flake = {
|
|
|
|
-- calls `nix flake archive` to put a flake and its output to store
|
|
|
|
autoArchive = true,
|
|
|
|
-- auto eval flake inputs for improved completion
|
|
|
|
autoEvalInputs = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end,
|
2023-07-21 07:49:04 +00:00
|
|
|
["gopls"] = function()
|
2023-07-22 08:37:24 +00:00
|
|
|
local lspconfig = require('lspconfig')
|
|
|
|
lspconfig.gopls.setup {
|
|
|
|
cmd = { "gopls" },
|
|
|
|
settings = {
|
|
|
|
gopls = {
|
|
|
|
analyses = {
|
|
|
|
unusedparams = true,
|
|
|
|
},
|
|
|
|
staticcheck = true,
|
2023-07-21 07:49:04 +00:00
|
|
|
},
|
2023-07-22 08:37:24 +00:00
|
|
|
},
|
|
|
|
root_dir = lspconfig.util.root_pattern('.git', 'go.mod'),
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
2023-07-21 07:49:04 +00:00
|
|
|
}
|
|
|
|
end
|
2023-07-10 09:08:36 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 01:59:31 +00:00
|
|
|
require('mason-lspconfig').setup_handlers({
|
2023-06-13 06:58:03 +00:00
|
|
|
-- default handler
|
|
|
|
function(server_name)
|
|
|
|
require('lspconfig')[server_name].setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
["lua_ls"] = function()
|
|
|
|
require('lspconfig').lua_ls.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
path = vim.split(package.path, ";"),
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = { "vim" }
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file('', true),
|
|
|
|
-- Don't prompt me to select
|
|
|
|
checkThirdParty = false,
|
|
|
|
},
|
|
|
|
telemetry = { enable = false },
|
|
|
|
hint = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
format = {
|
|
|
|
enable = true,
|
|
|
|
defaultConfig = {
|
|
|
|
indent_style = "space",
|
|
|
|
indent_size = 4,
|
2023-06-18 03:32:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
}
|
|
|
|
end,
|
|
|
|
["pyright"] = function()
|
|
|
|
require('lspconfig').pyright.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
pyright = {
|
|
|
|
disableLanguageServices = false,
|
|
|
|
disableOrganizeImports = false,
|
|
|
|
},
|
|
|
|
python = {
|
|
|
|
analysis = {
|
|
|
|
autoImportCompletions = true,
|
|
|
|
autoSearchPaths = true,
|
|
|
|
diagnosticMode = "openFilesOnly",
|
|
|
|
-- diagnosticSeverityOverrides =
|
|
|
|
extraPaths = {},
|
|
|
|
logLevel = "Information",
|
|
|
|
stubPath = "typings",
|
|
|
|
typeCheckingMode = "basic",
|
|
|
|
typeshedPaths = {},
|
|
|
|
useLibraryCodeForTypes = false,
|
|
|
|
pythonPath = "python",
|
|
|
|
venvPath = "",
|
|
|
|
},
|
|
|
|
linting = {
|
|
|
|
mypyEnabled = true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
["tsserver"] = function()
|
|
|
|
require('lspconfig').tsserver.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
-- TODO: Have to figure out an alternative config for monorepo to prevent
|
|
|
|
-- Deno from injecting TS projects.
|
|
|
|
-- Monorepo support: spawn one instance of lsp within the git
|
|
|
|
-- repos.
|
|
|
|
-- root_dir = require('lspconfig.util').root_pattern('.git'),
|
|
|
|
root_dir = require('lspconfig.util').root_pattern('package.json'),
|
|
|
|
settings = {
|
|
|
|
javascript = inlay_hint_tsjs,
|
|
|
|
typescript = inlay_hint_tsjs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
["denols"] = function()
|
|
|
|
require('lspconfig').denols.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
root_dir = require('lspconfig.util').root_pattern("deno.json", "deno.jsonc"),
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
["yamlls"] = function()
|
|
|
|
require('lspconfig').yamlls.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
yaml = {
|
|
|
|
keyOrdering = false,
|
2023-03-20 04:25:41 +00:00
|
|
|
}
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end,
|
2022-08-16 01:59:31 +00:00
|
|
|
})
|
2023-07-09 01:28:13 +00:00
|
|
|
|
2023-07-10 09:08:36 +00:00
|
|
|
setup["nil_ls"]()
|
2023-07-21 07:51:35 +00:00
|
|
|
setup["gopls"]()
|
2022-10-26 12:09:47 +00:00
|
|
|
require("rust-tools").setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
tools = {
|
|
|
|
-- rust-tools options
|
|
|
|
|
|
|
|
-- how to execute terminal commands
|
|
|
|
-- options right now: termopen / quickfix
|
|
|
|
executor = require("rust-tools/executors").termopen,
|
|
|
|
-- callback to execute once rust-analyzer is done initializing the workspace
|
|
|
|
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
|
|
|
|
on_initialized = function()
|
|
|
|
require('inlay-hints').set_all()
|
|
|
|
end,
|
|
|
|
-- automatically call RustReloadWorkspace when writing to a Cargo.toml file.
|
|
|
|
reload_workspace_from_cargo_toml = true,
|
|
|
|
-- These apply to the default RustSetInlayHints command
|
|
|
|
inlay_hints = {
|
|
|
|
-- automatically set inlay hints (type hints)
|
|
|
|
-- default: true
|
|
|
|
auto = false,
|
|
|
|
-- Only show inlay hints for the current line
|
|
|
|
only_current_line = true,
|
|
|
|
-- whether to show parameter hints with the inlay hints or not
|
|
|
|
-- default: true
|
|
|
|
show_parameter_hints = true,
|
|
|
|
-- prefix for parameter hints
|
|
|
|
-- default: "<-"
|
|
|
|
parameter_hints_prefix = "<- ",
|
|
|
|
-- prefix for all the other hints (type, chaining)
|
|
|
|
-- default: "=>"
|
|
|
|
other_hints_prefix = "=> ",
|
|
|
|
-- whether to align to the length of the longest line in the file
|
|
|
|
max_len_align = false,
|
|
|
|
-- padding from the left if max_len_align is true
|
|
|
|
max_len_align_padding = 1,
|
|
|
|
-- 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,
|
|
|
|
-- The color of the hints use `:highlight` for a pick-and-choose menu
|
|
|
|
highlight = "NonText",
|
|
|
|
},
|
|
|
|
-- options same as lsp hover / vim.lsp.util.open_floating_preview()
|
|
|
|
hover_actions = {
|
|
|
|
-- the border that is used for the hover window
|
|
|
|
-- see vim.api.nvim_open_win()
|
|
|
|
border = {
|
|
|
|
{ "╭", "FloatBorder" },
|
|
|
|
{ "─", "FloatBorder" },
|
|
|
|
{ "╮", "FloatBorder" },
|
|
|
|
{ "│", "FloatBorder" },
|
|
|
|
{ "╯", "FloatBorder" },
|
|
|
|
{ "─", "FloatBorder" },
|
|
|
|
{ "╰", "FloatBorder" },
|
|
|
|
{ "│", "FloatBorder" },
|
|
|
|
},
|
|
|
|
-- whether the hover action window gets automatically focused
|
|
|
|
-- default: false
|
|
|
|
auto_focus = false,
|
2022-10-12 00:06:09 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
-- settings for showing the crate graph based on graphviz and the dot
|
|
|
|
-- command
|
|
|
|
crate_graph = {
|
|
|
|
-- Backend used for displaying the graph
|
|
|
|
-- see: https://graphviz.org/docs/outputs/
|
|
|
|
-- default: x11
|
|
|
|
backend = "x11",
|
|
|
|
-- where to store the output, nil for no output stored (relative
|
|
|
|
-- path from pwd)
|
|
|
|
-- default: nil
|
|
|
|
output = nil,
|
|
|
|
-- true for all crates.io and external crates, false only the local
|
|
|
|
-- crates
|
|
|
|
-- default: true
|
|
|
|
full = true,
|
|
|
|
-- List of backends found on: https://graphviz.org/docs/outputs/
|
|
|
|
-- Is used for input validation and autocompletion
|
|
|
|
-- Last updated: 2021-08-26
|
|
|
|
enabled_graphviz_backends = {
|
|
|
|
"bmp",
|
|
|
|
"cgimage",
|
|
|
|
"canon",
|
|
|
|
"dot",
|
|
|
|
"gv",
|
|
|
|
"xdot",
|
|
|
|
"xdot1.2",
|
|
|
|
"xdot1.4",
|
|
|
|
"eps",
|
|
|
|
"exr",
|
|
|
|
"fig",
|
|
|
|
"gd",
|
|
|
|
"gd2",
|
|
|
|
"gif",
|
|
|
|
"gtk",
|
|
|
|
"ico",
|
|
|
|
"cmap",
|
|
|
|
"ismap",
|
|
|
|
"imap",
|
|
|
|
"cmapx",
|
|
|
|
"imap_np",
|
|
|
|
"cmapx_np",
|
|
|
|
"jpg",
|
|
|
|
"jpeg",
|
|
|
|
"jpe",
|
|
|
|
"jp2",
|
|
|
|
"json",
|
|
|
|
"json0",
|
|
|
|
"dot_json",
|
|
|
|
"xdot_json",
|
|
|
|
"pdf",
|
|
|
|
"pic",
|
|
|
|
"pct",
|
|
|
|
"pict",
|
|
|
|
"plain",
|
|
|
|
"plain-ext",
|
|
|
|
"png",
|
|
|
|
"pov",
|
|
|
|
"ps",
|
|
|
|
"ps2",
|
|
|
|
"psd",
|
|
|
|
"sgi",
|
|
|
|
"svg",
|
|
|
|
"svgz",
|
|
|
|
"tga",
|
|
|
|
"tiff",
|
|
|
|
"tif",
|
|
|
|
"tk",
|
|
|
|
"vml",
|
|
|
|
"vmlz",
|
|
|
|
"wbmp",
|
|
|
|
"webp",
|
|
|
|
"xlib",
|
|
|
|
"x11",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
-- all the opts to send to nvim-lspconfig
|
|
|
|
-- these override the defaults set by rust-tools.nvim
|
|
|
|
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
|
|
|
|
server = {
|
|
|
|
-- standalone file support
|
|
|
|
-- setting it to false may improve startup time
|
|
|
|
standalone = true,
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
local nmap = function(keys, func, desc)
|
|
|
|
if desc then
|
|
|
|
desc = 'LSP: ' .. desc
|
|
|
|
end
|
2022-10-26 12:09:47 +00:00
|
|
|
|
2023-06-13 06:58:03 +00:00
|
|
|
vim.keymap.set('n', keys, func, { noremap = true, buffer = bufnr, desc = desc })
|
|
|
|
end
|
|
|
|
on_attach(client, bufnr)
|
|
|
|
nmap('K', require 'rust-tools'.hover_actions.hover_actions, 'Hover Documentation')
|
|
|
|
end,
|
|
|
|
capabilities = capabilities,
|
|
|
|
cmd = { "rust-analyzer" },
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
-- enable clippy on save
|
|
|
|
checkOnSave = {
|
|
|
|
command = "clippy",
|
|
|
|
extraArgs = { "--all", "--", "-W", "clippy::all" },
|
|
|
|
},
|
|
|
|
rustfmt = {
|
|
|
|
extraArgs = { "+nightly" },
|
2023-05-02 17:26:53 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
cargo = {
|
|
|
|
loadOutDirsFromCheck = true,
|
2022-10-26 12:09:47 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
procMacro = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, -- rust-analyzer options
|
|
|
|
|
|
|
|
-- debugging stuff
|
|
|
|
dap = {
|
|
|
|
adapter = {
|
|
|
|
type = "executable",
|
|
|
|
command = "lldb-vscode",
|
|
|
|
name = "rt_lldb",
|
2022-10-26 12:09:47 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
2022-10-26 12:09:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 09:05:14 +00:00
|
|
|
-- Gitsigns
|
|
|
|
require('gitsigns').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
signs = {
|
|
|
|
add = { text = '+' },
|
|
|
|
change = { text = '~' },
|
|
|
|
delete = { text = '_' },
|
|
|
|
topdelete = { text = '‾' },
|
|
|
|
changedelete = { text = '~' },
|
|
|
|
}
|
2022-08-15 09:05:14 +00:00
|
|
|
}
|
|
|
|
require('lualine').setup {
|
2023-06-13 06:58:03 +00:00
|
|
|
options = {
|
|
|
|
icons_enabled = true,
|
|
|
|
},
|
|
|
|
sections = {
|
|
|
|
lualine_a = { 'mode' },
|
|
|
|
lualine_b = { 'branch', 'diff', 'diagnostics' },
|
|
|
|
lualine_c = {
|
|
|
|
{
|
|
|
|
'filename',
|
|
|
|
file_status = true,
|
|
|
|
newfile_status = false,
|
|
|
|
path = 1,
|
|
|
|
symbols = {
|
|
|
|
modified = '[+]',
|
|
|
|
readonly = '[-]',
|
|
|
|
unnamed = '[Unnamed]',
|
|
|
|
newfile = '[New]',
|
2022-09-24 06:03:47 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
2022-09-24 06:03:47 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
lualine_x = { 'encoding', 'fileformat', 'filetype', },
|
|
|
|
lualine_y = { 'progress' },
|
|
|
|
lualine_z = { 'location' },
|
|
|
|
},
|
|
|
|
inactive_sections = {
|
|
|
|
lualine_a = {},
|
|
|
|
lualine_b = {},
|
|
|
|
lualine_c = { { 'filename', path = 1, file_status = true, }, },
|
|
|
|
lualine_x = { 'location' },
|
|
|
|
lualine_y = {},
|
|
|
|
lualine_z = {},
|
|
|
|
}
|
2022-08-15 09:05:14 +00:00
|
|
|
}
|
2022-10-13 00:47:16 +00:00
|
|
|
|
|
|
|
require('nvim-surround').setup {}
|
2023-06-07 04:19:13 +00:00
|
|
|
require('fidget').setup({
|
2023-06-13 06:58:03 +00:00
|
|
|
text = {
|
2023-09-14 05:14:16 +00:00
|
|
|
spinner = "moon", -- animation shown when tasks are ongoing
|
|
|
|
done = "✔", -- character shown when all tasks are complete
|
|
|
|
commenced = "Started", -- message shown when task starts
|
2023-06-13 06:58:03 +00:00
|
|
|
completed = "Completed", -- message shown when task completes
|
|
|
|
},
|
|
|
|
align = {
|
|
|
|
bottom = true, -- align fidgets along bottom edge of buffer
|
|
|
|
right = true, -- align fidgets along right edge of buffer
|
|
|
|
},
|
|
|
|
timer = {
|
|
|
|
spinner_rate = 125, -- frame rate of spinner animation, in ms
|
|
|
|
fidget_decay = 2000, -- how long to keep around empty fidget, in ms
|
|
|
|
task_decay = 1000, -- how long to keep around completed task, in ms
|
|
|
|
},
|
|
|
|
window = {
|
|
|
|
relative = "editor", -- where to anchor, either "win" or "editor"
|
|
|
|
blend = 100, -- &winblend for the window
|
|
|
|
zindex = nil, -- the zindex value for the window
|
|
|
|
border = "none", -- style of border for the fidget window
|
|
|
|
},
|
|
|
|
fmt = {
|
|
|
|
leftpad = true, -- right-justify text in fidget box
|
|
|
|
stack_upwards = true, -- list of tasks grows upwards
|
|
|
|
max_width = 0, -- maximum width of the fidget box
|
|
|
|
fidget = -- function to format fidget title
|
|
|
|
function(fidget_name, spinner)
|
|
|
|
return string.format("%s %s", spinner, fidget_name)
|
|
|
|
end,
|
|
|
|
task = -- function to format each task line
|
|
|
|
function(task_name, message, percentage)
|
|
|
|
return string.format(
|
|
|
|
"%s%s [%s]",
|
|
|
|
message,
|
|
|
|
percentage and string.format(" (%s%%)", percentage) or "",
|
|
|
|
task_name
|
|
|
|
)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
-- Sources to configure
|
|
|
|
['*'] = { -- Name of source
|
|
|
|
ignore = false, -- Ignore notifications from this source
|
2023-06-07 04:19:13 +00:00
|
|
|
},
|
2023-06-13 06:58:03 +00:00
|
|
|
},
|
|
|
|
debug = {
|
|
|
|
logging = false, -- whether to enable logging, for debugging
|
|
|
|
strict = false, -- whether to interpret LSP strictly
|
|
|
|
},
|
2023-06-07 04:19:13 +00:00
|
|
|
})
|
2023-06-13 06:58:03 +00:00
|
|
|
|
|
|
|
-- 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)))
|
2023-06-15 19:46:01 +00:00
|
|
|
print("Attempted paths: %s", vim.inspect(logfile))
|
2023-06-13 06:58:03 +00:00
|
|
|
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 = {},
|
|
|
|
}
|