Introduce a separate Neovim config in Lua

This commit is contained in:
Danielle McLean 2023-10-31 12:07:27 +11:00
parent 26e53a077d
commit 7b68372b35
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
7 changed files with 320 additions and 5 deletions

View file

@ -0,0 +1,58 @@
local cmp = require "cmp"
local luasnip = require "luasnip"
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local mapping = cmp.mapping.preset.insert{
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {"i", "s"}),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
}
local config = {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
sources = cmp.config.sources{
{name = "nvim_lsp"},
{name = "luasnip"},
},
mapping = mapping,
}
return {
setup = function()
require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {}
cmp.setup(config)
end,
}

View file

@ -0,0 +1,53 @@
local union = require"pl.tablex".union
local neodev = require "neodev"
local lspconfig = require "lspconfig"
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
---@param _ any the vim.lsp.client object that got attached, but Neovim doesn't expose that type properly?
---@param bufnr number the number of the buffer the LSP client just attached to
local function on_attach(_, bufnr)
local telescope = require('telescope.builtin')
---@param lhs string LHS like you'd pass to vim.keymap.set
---@param func fun(): nil The function to be called when the mapping is invoked
---@param desc? string Human-readable description of what this mapping does
local function nmap(lhs, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', lhs, func, { buffer = bufnr, desc = desc })
end
nmap('gd', telescope.lsp_definitions, '[G]oto [D]efinition')
nmap('gr', telescope.lsp_references, '[G]oto [R]eferences')
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
end
local servers = {
lua_ls = {},
jsonls = {},
perlls = {},
perlnavigator = {cmd = {"perlnavigator"}},
phpactor = {},
pylsp = {},
solargraph = {},
taplo = {},
tsserver = {},
yamlls = {},
}
return {
setup = function()
neodev.setup{}
for name, opts in pairs(servers) do
lspconfig[name].setup(union({
capabilities = capabilities,
on_attach = on_attach,
}, opts))
end
end,
}

View file

@ -0,0 +1,111 @@
local LspAttach = "LspAttach"
local VeryLazy = "VeryLazy"
return {
-- Penlight is a Lua utility library. It's not Neovim-specific, but installing it like this still makes require("pl") work anywhere else in your config. :)
"lunarmodules/penlight",
-- Familiar Vim plugins for Git integration and smart indentation.
"tpope/vim-fugitive",
"tpope/vim-sleuth",
-- Comment toggle plugin, like tpope/vim-commentary.
{"numToStr/Comment.nvim", opts = {}},
-- Adds Neovim's Lua package directories to 'path' when editing a Neovim Lua file.
"sam4llis/nvim-lua-gf",
-- Reminder popups as you type multiple-key mappings
{"folke/which-key.nvim", event = VeryLazy, init = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
end, opts = {}},
-- Unimpaired's handy bracket mappings, but also which-key.nvim knows about them and can remind me of them.
{"afreakk/unimpaired-which-key.nvim", dependencies = {"tpope/vim-unimpaired"}, config = function()
local wk = require "which-key"
local uwk = require "unimpaired-which-key"
wk.register(uwk.normal_mode)
wk.register(uwk.normal_and_visual_mode, {mode = {"n", "v"}})
end},
-- Fuzzy finder for all sorts of things. Files, buffers, LSP references and definitions, the list goes on.
{"nvim-telescope/telescope.nvim",
branch = '0.1.x',
dependencies = {
"nvim-lua/plenary.nvim",
-- This small native binary is technically optional but is highly recommended to improve Telescope's performance.
{"nvim-telescope/telescope-fzf-native.nvim", build = "make"},
},
opts = {
extensions = {
fzf = {},
},
},
init = function()
local telescope = require('telescope')
telescope.load_extension('fzf')
end
},
-- Indicate which parts of the buffer have changed according to Git in the left margin. Basically the same thing as mhinz/vim-signify.
{"lewis6991/gitsigns.nvim", opts = {
signs = {
add = {text = "+"},
change = {text = "~"},
delete = {text = "_"},
topdelete = {text = ""},
changedelete = {text = "~"},
},
}},
{"navarasu/onedark.nvim",
priority = 1000,
init = function()
require("onedark").load()
end,
opts = {
transparent = true,
ending_tildes = true,
}
},
{"nvim-lualine/lualine.nvim",
dependencies = {
{"nvim-tree/nvim-web-devicons", opts = {}},
},
opts = {
options = {
icons_enabled = true,
theme = "onedark",
},
extensions = {
"fugitive",
"lazy",
"quickfix",
},
},
},
-- Basically a Neovim clone of tpope's vim-surround. The original tpope plugin does work in Neovim, but this one integrates better with other Neovim plugins like which-key.nvim.
{"kylechui/nvim-surround", event = VeryLazy, opts = {}},
{"neovim/nvim-lspconfig", dependencies = {
-- UI for feedback on running language servers.
{"j-hui/fidget.nvim", tag = "legacy", event = LspAttach, opts = {}},
-- Better support for using lua_ls with Neovim itself.
"folke/neodev.nvim",
}},
{"hrsh7th/nvim-cmp", dependencies = {
-- nvim-cmp *requires* a snippet engine to work. We'll use LuaSnip.
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
}},
{"nvim-treesitter/nvim-treesitter", dependencies = {
"RRethy/nvim-treesitter-textsubjects",
}, build = ":TSUpdate"},
}

View file

@ -0,0 +1,41 @@
local setup = function()
local config = {
ensure_installed = {
"c", "cpp", "make",
"css", "html", "http", "javascript", "typescript",
"elixir", "erlang",
"csv", "json", "jq", "toml", "yaml",
"git_config", "gitattributes", "gitignore",
"lua", "luadoc",
"perl", "php", "python", "ruby",
},
auto_install = false,
sync_install = false,
ignore_install = {},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = {enable = true},
textsubjects = {
enable = true,
prev_selection = ",",
keymaps = {
["."] = {"textsubjects-smart", desc = "textsubjects subject"},
["a;"] = {"textsubjects-container-outer", desc = "container (class, function, etc.)"},
["i;"] = {"textsubjects-container-inner", desc = "container (class, function, etc.)"},
},
},
}
require("nvim-treesitter.configs").setup(config)
end
local defer_setup = function()
vim.defer_fn(setup, 0)
end
return {
setup = setup,
defer_setup = defer_setup,
}