Merge branch 'dev' into mercury

nvim: add Telescope keymaps
        fix luassert prompt
        switch to lazy.nvim
        add TreeSitter parsers
This commit is contained in:
David JULIEN 2023-02-04 12:53:29 +01:00
commit 4a47c79be2
Signed by: swytch
GPG Key ID: 498590A3AA82A06F
13 changed files with 445 additions and 546 deletions

View File

@ -6,6 +6,7 @@
require("globals") -- ./lua/globals.lua
require("utils") -- ./lua/utils.lua
require("settings") -- ./lua/settings.lua
require("plugin.packer") -- ./lua/plugin/packer.lua
require("maps") -- ./lua/maps.lua
require("statusline") -- ./lua/statusline.lua
require("plugin")
require("lazy").setup("plugin")

View File

@ -61,8 +61,8 @@ vim.keymap.set("n", "<leader><enter>",
-- packer
vim.keymap.set("n", "<leader>u",
function() require("packer").sync() end,
{ desc = "Sync packer config and update plugins" }
function() require("lazy").sync() end,
{ desc = "Open up Lazy.nvim" }
)
-- telescope
@ -90,6 +90,16 @@ vim.keymap.set("n", "<leader>tl",
function() require("telescope.builtin").live_grep() end,
{ desc = "Grep interactively" }
)
vim.keymap.set("n", "<leader>tk",
function() require("telescope.builtin").keymaps() end,
{ desc = "Search through keymaps" }
)
vim.keymap.set("n", "<leader>tx",
function() require("telescope.builtin").diagnostics(
{ buffnr = 0 }
) end,
{ desc = "Search through LSP diagnostics" }
)
-- colorscheme
vim.keymap.set("n", "<leader>s",

View File

@ -1,95 +0,0 @@
-- Author : swytch
-- Created : Saturday Sept. 11, 2021 22:12:33 CET
-- License : GPLv3
-- Description : cmp plugin config file
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
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
-- Custom item icons
local icons = { }
cmp.setup {
completion = {
autocomplete = true
},
sources = {
{ name = "path" },
{ name = "luasnip" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "nvim_lua" },
{ name = "calc" },
{ name = "spell" },
{ name = "treesitter" },
},
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = "[lsp]",
nvim_lua = "[nvim]",
luasnip = "[snip]",
path = "[path]",
buffer = "[buff]",
calc = "[calc]",
spell = "[spel]",
treesitter = "[tree]",
})[entry.source.name]
return vim_item
end,
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
},
view = {
entries = {name = 'custom', selection_order = 'near_cursor' }
},
}

View File

@ -0,0 +1,17 @@
-- Author : swytch
-- Created : Sunday Jan. 29, 2023 00:50:17 CET
-- License : GPLv3
-- Description : colorscheme config file
local utils = require("utils")
local file = os.getenv("XDG_STATE_HOME") .. "/nvim_colorscheme"
local colorscheme = utils.lines_from(file)[0]
return {
{
dir = "~/.local/src/astronomy.nvim",
opts = {
variant = colorscheme,
}
},
}

View File

@ -1,57 +1,21 @@
-- Author : swytch
-- Created : Tuesday Oct. 12, 2021 19:07:36 CET
-- Created : Sunday Jan. 29, 2023 00:20:31 CET
-- License : GPLv3
-- Description : Comment plugin config file
-- Description : Mini.comment plugin config file
require("Comment").setup {
---Add a space b/w comment and the line
---@type boolean
padding = true,
---Lines to be ignored while comment/uncomment.
---Could be a regex string or a function that returns a regex string.
---Example: Use '^$' to ignore empty lines
---@type string|function
ignore = nil,
---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode
---@type table
return {
"echasnovski/mini.comment",
version = "*",
opts = {
mappings = {
---operator-pending mapping
---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}`
basic = true,
---extra mapping
---Includes `gco`, `gcO`, `gcA`
extra = true,
---extended mapping
---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}`
extended = false,
comment = "<leader>c",
comment_line = "<leader><Space>",
text_object = "gc",
},
---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode
---@type table
toggler = {
---line-comment toggle
line = "<leader><Space>",
---block-comment toggle
block = "<leader>bb",
},
---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode
---@type table
opleader = {
---line-comment opfunc mapping
line = "<leader>c",
---block-comment opfunc mapping
block = "<leader>b",
},
---Pre-hook, called before commenting the line
---@type function|nil
pre_hook = nil,
---Post-hook, called after commenting is done
---@type function|nil
post_hook = nil,
config = function(_, opts)
require("mini.comment").setup(opts)
end,
}

View File

@ -0,0 +1,151 @@
-- Author : swytch
-- Created : Sunday Jan. 29, 00:03:53 CET
-- License : GPLv3
-- Description : completion plugin config file
return {
{
"L3MON4D3/LuaSnip",
opts = function()
local types = require("luasnip.util.types")
return {
history = true,
-- Update more often, :h events for more info.
updateevents = "TextChanged,TextChangedI",
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { "", "LuaSnipChoice" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.functionNode] = {
active = {
virt_text = { { "", "LuaSnipFunction" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.insertNode] = {
active = {
virt_text = { { "", "LuaSnipInsert" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
},
-- treesitter-hl has 100, use something higher (default is 200).
ext_base_prio = 200,
-- minimal increase in priority.
ext_prio_increase = 1,
enable_autosnippets = true,
}
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-calc",
"ray-x/cmp-treesitter",
"f3fora/cmp-spell",
},
opts = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
local has_words_before = function()
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
return {
completion = {
autocomplete = true
},
sources = {
{ name = "path" },
{ name = "luasnip" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "nvim_lua" },
{ name = "calc" },
{ name = "spell" },
{ name = "treesitter" },
},
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = "[lsp]",
nvim_lua = "[nvim]",
luasnip = "[snip]",
path = "[path]",
buffer = "[buff]",
calc = "[calc]",
spell = "[spel]",
treesitter = "[tree]",
})[entry.source.name]
return vim_item
end,
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
},
view = {
entries = { name = 'custom', selection_order = 'near_cursor' }
},
}
end,
}
}

View File

@ -0,0 +1,20 @@
-- Author : swytch
-- Created : Friday Mar 12, 2021 22:28:34 CET
-- License : GPLv3
-- Description : neovim packer config file
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)
return {}

View File

@ -4,11 +4,34 @@
-- Description : neovim global lsp config file
local lspconfig = require("lspconfig")
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
local servers = {
"clangd",
"rust_analyzer",
"sumneko_lua",
"texlab",
}
return {
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
config = function()
vim.diagnostic.config({
underline = true,
update_in_insert = false,
severity_sort = true,
})
local lspconfig = require("lspconfig")
local globals = require("globals")
local signs = {
Error = globals.sign_error,
Warn = globals.sign_warn,
@ -25,10 +48,6 @@ for type, icon in pairs(signs) do
})
end
vim.diagnostic.config({
update_in_insert = true
})
local on_attach = function(_, bufnr)
local opts = { buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
@ -58,30 +77,6 @@ end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
local servers = {
"clangd",
"rust_analyzer",
"sumneko_lua",
"texlab",
}
mason.setup({
ui = {
icons = {
server_installed = "",
server_pending = "o",
server_uninstalled = ""
}
}
})
_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
mason_lspconfig.setup({
ensure_installed = servers,
})
for _, server in ipairs(servers) do
local opts = {
on_attach = on_attach,
@ -93,3 +88,23 @@ for _, server in ipairs(servers) do
lspconfig[server].setup(opts)
end
require("mason-lspconfig").setup({ ensure_installed = servers })
end
},
{
"williamboman/mason.nvim",
cmd = "Mason",
-- opts = { ensure_installed = servers },
opts = {
ui = {
icons = {
server_installed = "",
server_pending = "o",
server_uninstalled = ""
}
}
}
},
}

View File

@ -34,6 +34,7 @@ M.setup = function(opts)
-- Make the server aware of Neovim runtime files
library =
vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but
-- unique identifier

View File

@ -1,84 +0,0 @@
-- Author : swytch
-- Created : Friday Nov. 19, 2021 23:27:24 CET
-- License : GPLv3
-- Description : luasnip config file
local ls = require("luasnip")
-- some shorthands...
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local l = require("luasnip.extras").lambda
local r = require("luasnip.extras").rep
local p = require("luasnip.extras").partial
local m = require("luasnip.extras").match
local n = require("luasnip.extras").nonempty
local dl = require("luasnip.extras").dynamic_lambda
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local types = require("luasnip.util.types")
local conds = require("luasnip.extras.expand_conditions")
-- Every unspecified option will be set to the default.
ls.config.set_config({
history = true,
-- Update more often, :h events for more info.
updateevents = "TextChanged,TextChangedI",
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { "", "LuaSnipChoice" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.functionNode] = {
active = {
virt_text = { { "", "LuaSnipFunction" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.insertNode] = {
active = {
virt_text = { { "", "LuaSnipInsert" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
},
-- treesitter-hl has 100, use something higher (default is 200).
ext_base_prio = 200,
-- minimal increase in priority.
ext_prio_increase = 1,
enable_autosnippets = true,
})
-- Make sure to not pass an invalid command, as io.popen() may write over nvim-text.
local function bash(_, _, command)
local file = io.popen(command, "r")
local res = {}
for line in file:lines() do
table.insert(res, line)
end
return res
end
-- Returns a snippet_node wrapped around an insert_node whose initial
-- text value is set to the current date in the desired format.
local function date_input(fmt)
local format = fmt or "%Y-%m-%d"
return sn(nil, i(1, os.date(format)))
end
-- in a lua file: search lua-, then c-, then all-snippets.
ls.filetype_extend("lua", { "c" })
-- in a cpp file: search c-snippets, then all-snippets only (no cpp-snippets!!).
ls.filetype_set("cpp", { "c" })

View File

@ -1,125 +0,0 @@
-- Author : swytch
-- Created : Friday Mar 12, 2021 22:28:34 CET
-- License : GPLv3
-- Description : neovim packer config file
local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
print("Cloning packer...")
PACKER_BOOTSTRAP = vim.fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
vim.cmd([[packadd packer.nvim]])
print("Done.")
end
local packer = require("packer")
packer.init({
display = {
working_sym = '', -- The symbol for a plugin being installed/updated
error_sym = '', -- The symbol for a plugin with an error in installation/updating
done_sym = '', -- The symbol for a plugin which has completed installation/updating
removed_sym = '- ', -- The symbol for an unused plugin which was removed
moved_sym = '', -- The symbol for a plugin which was moved (e.g. from opt to start)
header_sym = '', -- The symbol for the header line in packer's display
open_fn = function()
return require('packer.util').float({ border = "single" })
end, -- Display in a floating window
},
})
local use = packer.use
return require("packer").startup(function()
-- packer manages itself
use "wbthomason/packer.nvim"
-- colorscheme
use {
"~/.local/src/astronomy.nvim",
config = function() require("colorscheme") end
}
-- tree-sitter
use {
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
config = function() require("plugin.treesitter") end
}
use { -- Additional text objects via treesitter
'nvim-treesitter/nvim-treesitter-textobjects',
after = 'nvim-treesitter',
}
-- telescope
use {
"nvim-telescope/telescope.nvim",
requires = {
{
"nvim-lua/plenary.nvim",
},
{
"nvim-telescope/telescope-fzf-native.nvim",
run = "make"
},
{
"nvim-telescope/telescope-file-browser.nvim",
}
},
config = function()
require("telescope")
require("telescope").load_extension("fzf")
require("telescope").load_extension("file_browser")
end
}
-- LSP
use {
"neovim/nvim-lspconfig",
requires = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
},
config = function() require("plugin.lsp") end
}
-- auto completion
use {
"hrsh7th/nvim-cmp",
requires = {
{
"L3MON4D3/LuaSnip",
config = function()
require("plugin.luasnip") end
},
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-calc",
"ray-x/cmp-treesitter",
"f3fora/cmp-spell",
},
config = function() require("plugin.cmp") end
}
-- commenting, simplified
use {
"numToStr/Comment.nvim",
config = function() require("plugin.comment") end
}
-- automatically setup the config after cloning
if PACKER_BOOTSTRAP then
require("packer").sync()
end
end)

View File

@ -1,22 +1,33 @@
-- Author : swytch
-- Created : Monday Dec. 26, 2022 18:39:16 CET
-- License : GPLv3
-- Description : treesitter config file
-- Description : telescope config file
require("telescope").setup {
return {
{
"nvim-telescope/telescope.nvim",
dependencies = {
{
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope-file-browser.nvim",
{
"nvim-telescope/telescope-fzf-native.nvim",
build = "make"
}
}
},
opts = {
extensions = {
file_browser = {
theme = "ivy",
-- disables netrw and use telescope-file-browser in its place
hijack_netrw = true,
mappings = {
["i"] = {
-- your custom insert mode mappings
},
["n"] = {
-- your custom normal mode mappings
},
},
},
},
}
}
},
config = function(_, opts)
require("telescope").setup(opts)
require("telescope").load_extension("fzf")
require("telescope").load_extension("file_browser")
end
}
}

View File

@ -3,8 +3,17 @@
-- License : GPLv3
-- Description : treesitter config file
require("nvim-treesitter.configs").setup {
ensure_installed = { "c", "lua", "rust", "bash", "vim" },
return {
"nvim-treesitter/nvim-treesitter",
dependencies = {
-- Additional text objects via treesitter
"nvim-treesitter/nvim-treesitter-textobjects",
},
build = ":TSUpdate",
opts = {
ensure_installed = {
"c", "cpp", "lua", "rust", "bash", "vim", "latex", "python",
},
highlight = {
enable = true,
},
@ -112,4 +121,8 @@ require("nvim-treesitter.configs").setup {
},
},
},
},
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end
}