-
Notifications
You must be signed in to change notification settings - Fork 23k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: move to lazy and fix many issues #178
Changes from 9 commits
c6629b4
4f11281
68a0332
1afbeca
69d7d4a
4d218e3
d6ad146
36e99fb
1a2a96b
0d7e4da
5ba0db5
e40d704
c33d911
eea0adb
a740052
ba5786c
775ff6a
e5c03b4
bdbe2f3
33469ef
d8784b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ test.sh | |
.luarc.json | ||
nvim | ||
plugin/packer_compiled.lua | ||
lazy-lock.json | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
-- Install packer | ||
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' | ||
local is_bootstrap = false | ||
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then | ||
is_bootstrap = true | ||
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } | ||
vim.cmd [[packadd packer.nvim]] | ||
end | ||
-- TODO BEFORE MERGE: | ||
-- - [ ] Document an example of adding your own custom plugins (for example, autopairs) | ||
|
||
require('packer').startup(function(use) | ||
-- Package manager | ||
use 'wbthomason/packer.nvim' | ||
-- Set <space> as the leader key | ||
-- See `:help mapleader` | ||
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) | ||
vim.g.mapleader = ' ' | ||
vim.g.maplocalleader = ' ' | ||
|
||
-- Install package manager | ||
-- https://github.com/folke/lazy.nvim | ||
-- `:help lazy.nvim.txt` for more info | ||
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | ||
if not vim.loop.fs_stat(lazypath) then | ||
vim.fn.system { | ||
'git', | ||
'clone', | ||
'--filter=blob:none', | ||
'https://github.com/folke/lazy.nvim.git', | ||
'--branch=stable', -- latest stable release | ||
lazypath, | ||
} | ||
end | ||
vim.opt.rtp:prepend(lazypath) | ||
|
||
use { -- LSP Configuration & Plugins | ||
require('lazy').setup({ | ||
---@diagnostic disable-next-line: assign-type-mismatch | ||
{ -- LSP Configuration & Plugins | ||
'neovim/nvim-lspconfig', | ||
requires = { | ||
dependencies = { | ||
-- Automatically install LSPs to stdpath for neovim | ||
'williamboman/mason.nvim', | ||
'williamboman/mason-lspconfig.nvim', | ||
|
@@ -24,73 +38,53 @@ require('packer').startup(function(use) | |
-- Additional lua configuration, makes nvim stuff amazing | ||
'folke/neodev.nvim', | ||
}, | ||
} | ||
|
||
use { -- Autocompletion | ||
}, | ||
{ -- Autocompletion | ||
'hrsh7th/nvim-cmp', | ||
requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, | ||
} | ||
dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, | ||
}, | ||
|
||
use { -- Highlight, edit, and navigate code | ||
{ -- Highlight, edit, and navigate code | ||
'nvim-treesitter/nvim-treesitter', | ||
run = function() | ||
dependencies = { | ||
'nvim-treesitter/nvim-treesitter-textobjects', | ||
}, | ||
config = function() | ||
pcall(require('nvim-treesitter.install').update { with_sync = true }) | ||
end, | ||
} | ||
|
||
use { -- Additional text objects via treesitter | ||
'nvim-treesitter/nvim-treesitter-textobjects', | ||
after = 'nvim-treesitter', | ||
} | ||
}, | ||
|
||
-- Git related plugins | ||
use 'tpope/vim-fugitive' | ||
use 'tpope/vim-rhubarb' | ||
use 'lewis6991/gitsigns.nvim' | ||
'tpope/vim-fugitive', | ||
'tpope/vim-rhubarb', | ||
'lewis6991/gitsigns.nvim', | ||
|
||
use 'navarasu/onedark.nvim' -- Theme inspired by Atom | ||
use 'nvim-lualine/lualine.nvim' -- Fancier statusline | ||
use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines | ||
use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines | ||
use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically | ||
'navarasu/onedark.nvim', -- Theme inspired by Atom | ||
'nvim-lualine/lualine.nvim', -- Fancier statusline | ||
'lukas-reineke/indent-blankline.nvim', -- Add indentation guides even on blank lines | ||
'numToStr/Comment.nvim', -- "gc" to comment visual regions/lines | ||
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically | ||
|
||
-- Fuzzy Finder (files, lsp, etc) | ||
use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } } | ||
{ 'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim' } }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: you can also just specify the name of a dependency, so just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't I need to put it as a dependency to make sure something installs plenary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just leave it as is. Just wanted to make sure you knew about the auto-loading of lua plugins, but to be fair it wouldn't make a difference here anyway, since So all good! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 awesome, thanks |
||
|
||
-- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available | ||
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 } | ||
{ | ||
'nvim-telescope/telescope-fzf-native.nvim', | ||
build = 'make', | ||
cond = function() | ||
return vim.fn.executable 'make' == 1 | ||
end, | ||
}, | ||
|
||
-- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua | ||
local has_plugins, plugins = pcall(require, 'custom.plugins') | ||
if has_plugins then | ||
plugins(use) | ||
end | ||
-- Next Step: Add additional "plugins" for kickstart | ||
require 'kickstart.plugins.autoformat', | ||
-- require('kickstart.plugins.debug'), | ||
|
||
if is_bootstrap then | ||
require('packer').sync() | ||
end | ||
end) | ||
|
||
-- When we are bootstrapping a configuration, it doesn't | ||
-- make sense to execute the rest of the init.lua. | ||
-- | ||
-- You'll need to restart nvim, and then it will work. | ||
if is_bootstrap then | ||
print '==================================' | ||
print ' Plugins are being installed' | ||
print ' Wait until Packer completes,' | ||
print ' then restart nvim' | ||
print '==================================' | ||
return | ||
end | ||
|
||
-- Automatically source and re-compile packer whenever you save this init.lua | ||
local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) | ||
vim.api.nvim_create_autocmd('BufWritePost', { | ||
command = 'source <afile> | silent! LspStop | silent! LspStart | PackerCompile', | ||
group = packer_group, | ||
pattern = vim.fn.expand '$MYVIMRC', | ||
}) | ||
-- TODO: | ||
-- { import = 'kickstart.plugins' }, | ||
-- { import = 'custom.plugins' }, | ||
}, {}) | ||
|
||
-- [[ Setting options ]] | ||
-- See `:help vim.o` | ||
|
@@ -126,11 +120,6 @@ vim.cmd [[colorscheme onedark]] | |
vim.o.completeopt = 'menuone,noselect' | ||
|
||
-- [[ Basic Keymaps ]] | ||
-- Set <space> as the leader key | ||
-- See `:help mapleader` | ||
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) | ||
vim.g.mapleader = ' ' | ||
vim.g.maplocalleader = ' ' | ||
|
||
-- Keymaps for better default experience | ||
-- See `:help vim.keymap.set()` | ||
|
@@ -209,7 +198,7 @@ vim.keymap.set('n', '<leader>/', function() | |
winblend = 10, | ||
previewer = false, | ||
}) | ||
end, { desc = '[/] Fuzzily search in current buffer]' }) | ||
end, { desc = '[/] Fuzzily search in current buffer' }) | ||
|
||
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
|
@@ -221,7 +210,10 @@ vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { de | |
-- See `:help nvim-treesitter` | ||
require('nvim-treesitter.configs').setup { | ||
-- Add languages to be installed here that you want installed for treesitter | ||
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'help', 'vim' }, | ||
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'help', 'vim' }, | ||
|
||
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
auto_install = false, | ||
|
||
highlight = { enable = true }, | ||
indent = { enable = true, disable = { 'python' } }, | ||
|
@@ -343,7 +335,7 @@ local servers = { | |
-- rust_analyzer = {}, | ||
-- tsserver = {}, | ||
|
||
sumneko_lua = { | ||
lua_ls = { | ||
Lua = { | ||
workspace = { checkThirdParty = false }, | ||
telemetry = { enable = false }, | ||
|
@@ -385,6 +377,8 @@ require('fidget').setup() | |
local cmp = require 'cmp' | ||
local luasnip = require 'luasnip' | ||
|
||
luasnip.config.setup {} | ||
|
||
cmp.setup { | ||
snippet = { | ||
expand = function(args) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
return { | ||
'neovim/nvim-lspconfig', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: For myself, could add null-ls here since I know that's a big hang up for a lot of people There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meh, i think i'll do this later if I want it |
||
|
||
config = function() | ||
-- Switch for controlling whether you want autoformatting. | ||
-- Use :KickstartFormatToggle to toggle autoformatting on or off | ||
local format_is_enabled = true | ||
vim.api.nvim_create_user_command('KickstartFormatToggle', function() | ||
format_is_enabled = not format_is_enabled | ||
print('Setting autoformatting to: ' .. tostring(format_is_enabled)) | ||
end, {}) | ||
|
||
-- Create an augroup that is used for managing our formatting autocmds. | ||
-- We need one augroup per client to make sure that multiple clients | ||
-- can attach to the same buffer without interfering with each other. | ||
local _augroups = {} | ||
local get_augroup = function(client) | ||
if not _augroups[client.id] then | ||
local group_name = 'kickstart-lsp-format-' .. client.name | ||
local id = vim.api.nvim_create_augroup(group_name, { clear = true }) | ||
_augroups[client.id] = id | ||
end | ||
|
||
return _augroups[client.id] | ||
end | ||
|
||
vim.api.nvim_create_autocmd('LspAttach', { | ||
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }), | ||
|
||
-- This is where we attach the autoformatting for reasonable clients | ||
callback = function(args) | ||
local client_id = args.data.client_id | ||
local client = vim.lsp.get_client_by_id(client_id) | ||
local bufnr = args.buf | ||
|
||
-- Only attach to clients that support document formatting | ||
if not client.server_capabilities.documentFormattingProvider then | ||
return | ||
end | ||
|
||
-- Tsserver usually works poorly. Sorry you work with bad languages | ||
-- You can remove this line if you know what you're doing :) | ||
if client.name == 'tsserver' then | ||
return | ||
end | ||
|
||
vim.api.nvim_create_autocmd('BufWritePre', { | ||
group = get_augroup(client), | ||
buffer = bufnr, | ||
callback = function() | ||
if not format_is_enabled then | ||
return | ||
end | ||
|
||
vim.lsp.buf.format { async = false } | ||
end, | ||
}) | ||
end, | ||
}) | ||
end, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
return { | ||
{ | ||
enabled = true, | ||
config = function() | ||
-- Optional debug adapter setup | ||
-- | ||
-- To enable setup, change `disable = true` in the packer section | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guessing you'll want to update 'in the packer section' to something lazy.nvim specific? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, i will make it so the debug config works with lazy -- this was leftover from an old PR that I never submitted |
||
-- of the init.lua. You'll also want to copy this file into your | ||
-- config at ~/.config/nvim/after/plugin/dap.lua | ||
|
||
local dapui = require 'dapui' | ||
|
||
require('mason-nvim-dap').setup { | ||
-- Makes a best effort to setup the various debuggers with | ||
-- reasonable debug configurations | ||
automatic_setup = true, | ||
|
||
-- You'll need to check that you have the required things installed | ||
-- online, please don't ask me how to install them :) | ||
ensure_installed = { | ||
-- Update this to ensure that you have the debuggers for the langs you want | ||
'delve', | ||
}, | ||
} | ||
|
||
-- You can provide additional configuration to the handlers, | ||
-- see mason-nvim-dap README for more information | ||
require('mason-nvim-dap').setup_handlers() | ||
|
||
-- Basic debugging keymaps, feel free to change to your liking! | ||
vim.keymap.set('n', '<F5>', require('dap').continue) | ||
vim.keymap.set('n', '<F1>', require('dap').step_into) | ||
vim.keymap.set('n', '<F2>', require('dap').step_over) | ||
vim.keymap.set('n', '<F3>', require('dap').step_out) | ||
vim.keymap.set('n', '<leader>b', require('dap').toggle_breakpoint) | ||
vim.keymap.set('n', '<leader>B', function() | ||
require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') | ||
end) | ||
|
||
-- Dap UI setup | ||
-- For more information, see |:help nvim-dap-ui| | ||
dapui.setup { | ||
-- Set icons to characters that are more likely to work in every terminal. | ||
-- Feel free to remove or use ones that you like more! :) | ||
-- Don't feel like these are good choices. | ||
icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, | ||
controls = { | ||
icons = { | ||
pause = '⏸', | ||
play = '▶', | ||
step_into = '⏎', | ||
step_over = '⏭', | ||
step_out = '⏮', | ||
step_back = 'b', | ||
run_last = '▶▶', | ||
terminate = '⏹', | ||
}, | ||
}, | ||
} | ||
|
||
dap.listeners.after.event_initialized['dapui_config'] = dapui.open | ||
dap.listeners.before.event_terminated['dapui_config'] = dapui.close | ||
dap.listeners.before.event_exited['dapui_config'] = dapui.close | ||
|
||
-- Install golang specific config | ||
require('dap-go').setup() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pardon my ignorance, but will it be clear to folks where they should add the require().setup() for their own favorite languages? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well you'll have to emulate what I've done here for golang -- i can list a few examples and the wiki entries to explore. I haven't done a bunch of DAP stuff for other languages There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you add mason-nvim-dap and the following in your config for nvim-dap, then you can just install daps from mason, and they work out of the box. A very GUI-way of doing things, but for beginners its really cool. you would not need to configure anything in init.lua
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is my full call to nvim-dap with packer, for clarification:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but some of the plugins give you additional configuration that allow you to do different types of debugging (like attaching to running process, run individual unit tests, etc) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something I've struggled with and hope to contribute back to help other newbies :) Specifically, I find it tremendously confusing to understand how to express the configuration for any given plugin, and I think the root of the confusion is understaning what lua lexical/function closure/scope a given plugin wants for its configuration. Take this for example - it took me forever to understand that wrapping all my extra 'use' directives in a Is there a way to signpost this for new users? Will Lazy make this easier? Thanks so much for all your hard work. kickstart.nvim & neovim have made me a more productive developer == PRICELESS :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the new method is much simpler and less error prone. I will add docs as well before I merge |
||
end, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! Thanks for the awesome setup, this is awesome for the community!
I think the lazy-lock should probably be committed to maintain versions across multiple machines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I want to commit mine. Users can commit their own though by modifying the gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tjdevries I have the same problem for LazyVim. I don't add the lockfile to .gitignore and simply never add mine to the repo. This way for users, they won't forget to add the lockfile to git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm just thinking contributors and others will end up adding it on accident constantly haha