Skip to content
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

Merged
merged 21 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test.sh
.luarc.json
nvim
plugin/packer_compiled.lua
lazy-lock.json

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?

Copy link
Member Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor

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.

Copy link
Member Author

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

19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ This repo is meant to be used as a starting point for a user's own configuration
### Installation

* Backup your previous configuration
* Copy and paste the kickstart.nvim `init.lua` into `$HOME/.config/nvim/init.lua` (Linux) or `~/AppData/Local/nvim/init.lua` (Windows)
* Copy and paste the kickstart.nvim `init.lua` into `$HOME/.config/nvim/init.lua` (Linux/Mac) or `~/AppData/Local/nvim/init.lua` (Windows)

TODO: This isn't right anymore. Also, link to the sections about setting up the installation from the lazy readme
* Start Neovim (`nvim`) and run `:PackerInstall` - ignore any error message about missing plugins, `:PackerInstall` will fix that shortly

* Restart Neovim


If there are languages that you don't want to use, remove their configuration and notes from your `init.lua` after copy and pasting (for example, in the mason configuration).

Additional requirements:
- Make sure to review the readmes of the plugins in the plugin list if anything is missing. In particular:
- [ripgrep](https://github.com/BurntSushi/ripgrep#installation) is required for multiple [telescope](https://github.com/nvim-telescope/telescope.nvim#suggested-dependencies) pickers.

### Windows Installation

Installation may require installing build tools, and updating the run command for `telescope-fzf-native`
Expand Down Expand Up @@ -78,7 +85,9 @@ Each PR, especially those which increase the line count, should have a descripti

### FAQ

* What should I do if I already have a pre-existing neovim configuration?
* You should back it up, then delete all files associated with it.
* This includes your existing init.lua and the neovim files in `.local` which can be deleted with `rm -rf ~/.local/share/nvim/`

* What should I do if I already have a pre-existing neovim configuration?
* You should back it up, then delete all files associated with it.
* This includes your existing init.lua and the neovim files in `.local` which can be deleted with `rm -rf ~/.local/share/nvim/`
* Are there any cool videos about this plugin?
* Current iteration of kickstart (coming soon)
* Here is one about the previous iteration of kickstart: [video introduction to Kickstart.nvim](https://youtu.be/stqUbv-5u2s).
142 changes: 68 additions & 74 deletions init.lua
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',
Expand All @@ -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' } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version='*'

Copy link
Contributor

Choose a reason for hiding this comment

The 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 plenary.nvim. But as I mentioned earlier, since this is a lua dep, you could just skip it altogether.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

The 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 config.defaults.lazy = false.

So all good!

Copy link
Member Author

Choose a reason for hiding this comment

The 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`
Expand Down Expand Up @@ -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()`
Expand Down Expand Up @@ -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' })
Expand All @@ -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' } },
Expand Down Expand Up @@ -343,7 +335,7 @@ local servers = {
-- rust_analyzer = {},
-- tsserver = {},

sumneko_lua = {
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
Expand Down Expand Up @@ -385,6 +377,8 @@ require('fidget').setup()
local cmp = require 'cmp'
local luasnip = require 'luasnip'

luasnip.config.setup {}

cmp.setup {
snippet = {
expand = function(args)
Expand Down
61 changes: 61 additions & 0 deletions lua/kickstart/plugins/autoformat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
return {
'neovim/nvim-lspconfig',
Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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,
}
69 changes: 69 additions & 0 deletions lua/kickstart/plugins/debug.lua
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

@szechp szechp Feb 16, 2023

Choose a reason for hiding this comment

The 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

require('mason-nvim-dap').setup({ automatic_setup = true })
('mason-nvim-dap').setup_handlers()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is my full call to nvim-dap with packer, for clarification:

	use { 'mfussenegger/nvim-dap',
		requires = {
			'theHamsta/nvim-dap-virtual-text', -- Show variable values in virtual text
			'jay-babu/mason-nvim-dap.nvim', -- Automatic DAP configuration
			'williamboman/mason.nvim',
		},
		config = function()
			vim.fn.sign_define('DapBreakpoint', { text = '', texthl = 'Error' })
			vim.fn.sign_define('DapBreakpointCondition', { text = 'לּ', texthl = 'Error' })
			vim.fn.sign_define('DapLogPoint', { text = '', texthl = 'Directory' })
			vim.fn.sign_define('DapStopped', { text = 'ﰲ', texthl = 'TSConstant' })
			vim.fn.sign_define('DapBreakpointRejected', { text = '', texthl = 'Error' })

			-- Automatically set up installed DAP adapters
			require('mason-nvim-dap').setup({ automatic_setup = true })
			require('mason-nvim-dap').setup_handlers()
			-- DAP virtual text --
			require('nvim-dap-virtual-text').setup()
		end
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 return function(use) would allow Packer to ingest them despite their being in another file.

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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,
},
}