nvim: add neotest

This commit is contained in:
Fabio Lenherr / DashieTM 2023-09-21 19:26:09 +02:00
parent 993bd794f0
commit 46f4fdcc69
12 changed files with 333 additions and 196 deletions

View file

@ -31,15 +31,25 @@ map("n", "<leader>dc", ':lua require("dap").continue()<CR>', { desc = "Continue"
map("n", "<leader>dt", ':lua require("dap").continue()<CR> :lua require("dapui").toggle()<CR>', { desc = "Open DAP" })
map("n", "<leader>dq", ':lua require("dapui").toggle()<CR> :lua require("dap").close()<CR>', { desc = "Close DAP" })
-- window movement
map("n", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("n", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("n", "<A-t>", [[<Cmd>wincmd j<CR>]], opts)
map("i", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("i", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("i", "<A-k>", [[<Cmd>wincmd j<CR>]], opts)
-- file tree
map("n", "<A-f>", function()
require("nvim-tree.api").tree.toggle()
end, opts)
-- toggle terminal
map("n", "<C-t>", function()
require("toggleterm").toggle(1)
end, { desc = "Toggle Terminal" })
local lazyterm = function()
Util.float_term(nil, { cwd = Util.get_root() })
end
map("n", "<c-t>", lazyterm, { desc = "Terminal (root dir)" })
map("t", "<C-t>", "<cmd>close<cr>", { desc = "Hide Terminal" })
-- semicolon thing
-- map("i","<C-m>" ,"<C-o>A;<CR>", {desc = "add semi and newline"})
@ -78,37 +88,6 @@ map("n", "<leader>gb", function()
vim.cmd(":GitBlameToggle")
end, { desc = "gitui (cwd)" })
-- window switching
function _G.set_terminal_maps()
local opts = { buffer = 0 }
vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)
vim.keymap.set("t", "jk", [[<C-\><C-n>]], opts)
vim.keymap.set("t", "<A-h>", [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set("t", "<A-j>", [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set("n", "<C-t>", function()
require("toggleterm").toggle(1)
end, opts)
vim.keymap.set("i", "<C-t>", function()
require("toggleterm").toggle(1)
end, opts)
vim.keymap.set("t", "<C-t>", function()
require("toggleterm").toggle(1)
end, opts)
end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd("autocmd! TermOpen term://* lua set_terminal_maps()")
map("t", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("t", "<A-k>", [[<Cmd>wincmd j<CR>]], opts)
map("t", "<A-l>", [[<Cmd>wincmd k<CR>]], opts)
map("t", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("n", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("n", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("n", "<A-t>", [[<Cmd>wincmd j<CR>]], opts)
map("i", "<A-j>", [[<Cmd>wincmd h<CR>]], opts)
map("i", "<A-;>", [[<Cmd>wincmd l<CR>]], opts)
map("i", "<A-k>", [[<Cmd>wincmd j<CR>]], opts)
-- harpoon man
map("n", "<leader>h1", function()
require("harpoon.ui").nav_file(1)

View file

@ -11,12 +11,13 @@ require("lazy").setup({
spec = {
-- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "plugins.plugins" },
{ import = "plugins" },
-- import any extras modules here
-- { import = "lazyvim.plugins.extras.lang.typescript" },
-- { import = "lazyvim.plugins.extras.lang.json" },
-- { import = "lazyvim.plugins.extras.ui.mini-animate" },
-- import/override with your plugins
{ import = "plugins" },
},
defaults = {
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
@ -27,7 +28,7 @@ require("lazy").setup({
version = false, -- always use the latest git commit
-- version = "*", -- try installing the latest stable version for plugins that support semver
},
install = { colorscheme = { "tokyonight", "habamax" } },
install = { colorscheme = { "tokyonight", "catppuccin-mocha" } },
checker = { enabled = true, notify = false },
change_detection = { enabled = true, notify = false }, --know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
performance = {

View file

@ -7,9 +7,8 @@ M._keys = nil
function M.get()
local format = require("lazyvim.plugins.lsp.format").format
if not M._keys then
---@class PluginLspKeys
-- stylua: ignore
M._keys = {
---@class PluginLspKeys
M._keys = {
{ "<leader>cld", vim.diagnostic.open_float, desc = "Line Diagnostics" },
{ "<leader>cl", "<cmd>LspInfo<cr>", desc = "Lsp Info" },
{ "<leader>ca", "<cmd>Telescope lsp_definitions<cr>", desc = "Goto Definition", has = "definition" },
@ -28,23 +27,44 @@ function M.get()
{ "[w", M.diagnostic_goto(false, "WARN"), desc = "Prev Warning" },
{ "<F4>", format, desc = "Format Document", has = "documentFormatting" },
-- { "<leader>cf", format, desc = "Format Range", mode = "v", has = "documentRangeFormatting" },
{ "<leader>cq",function()
vim.lsp.buf.code_action({
{
"<leader>cq",
function()
vim.lsp.buf.code_action({
context = {
only = {
"quickfix",
"quickfix.ltex",
"source",
"source.fixAll",
"source.organizeImports",
"",
},
diagnostics = {},
},
})
end, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" },
})
end,
desc = "Fix",
mode = { "n", "v" },
has = "codeAction",
},
{
"<leader>cQ",
vim.lsp.buf.code_action,
desc = "Source Action",
function()
vim.lsp.buf.code_action({
context = {
only = {
"refactor",
"refactor.inline",
"refactor.extract",
"refactor.rewrite",
},
},
})
end,
desc = "Refactor",
mode = { "n", "v" },
has = "codeAction",
}
},
}
if require("lazyvim.util").has("inc-rename.nvim") then
M._keys[#M._keys + 1] = {

View file

@ -102,7 +102,12 @@ return {
},
},
},
typst_lsp = {},
typst_lsp = {
settings = {
experimentalFormatterMode = "On",
exportPdf = "onSave",
},
},
ltex = {
settings = {
ltex = {
@ -120,6 +125,7 @@ return {
"tex",
"pandoc",
"typst",
"typ",
},
},
texlab = {},
@ -156,7 +162,7 @@ return {
require("lazyvim.plugins.lsp.format").autoformat = opts.autoformat
-- setup formatting and keymaps
require("lazyvim.util").on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.format").setup(opts)
require("lazyvim.plugins.lsp.format").setup(opts)
require("config.lsp-keymap").on_attach(client, buffer)
end)

View file

@ -3,6 +3,7 @@ return {
"LazyVim/LazyVim",
opts = {
colorscheme = "tokyonight-night",
-- colorscheme = "catppuccin-mocha",
},
},
{
@ -15,31 +16,6 @@ return {
require("telescope").setup(opts)
end,
},
{
"akinsho/toggleterm.nvim",
lazy = true,
opts = {
autochdir = true,
},
},
{
"brenoprata10/nvim-highlight-colors",
lazy = true,
event = { "BufReadPre", "BufNewFile" },
config = function(_, _)
require("nvim-highlight-colors").setup({
enable_tailwind = true,
})
vim.cmd(":hi clear CursorLine")
vim.cmd(":hi clear CursorLineFold")
vim.cmd(":hi clear CursorLineSign")
end,
},
{
"gpanders/editorconfig.nvim",
event = { "BufReadPre", "BufNewFile" },
lazy = true,
},
{
"lvimuser/lsp-inlayhints.nvim",
event = { "BufReadPre", "BufNewFile" },
@ -107,7 +83,6 @@ return {
{
"lervag/vimtex",
config = function()
-- require("vimtex").setup()
vim.cmd("let g:vimtex_quickfix_mode=0")
vim.cmd("let g:vimtex_view_general_viewer = 'evince'")
vim.cmd("let g:vimtex_compiler_method = 'latexmk'")
@ -212,4 +187,169 @@ return {
{
"mg979/vim-visual-multi",
},
{
"rouge8/neotest-rust",
},
{
"Issafalcon/neotest-dotnet",
},
{
"andy-bell101/neotest-java",
},
{
"nvim-neotest/neotest-go",
},
{
"nvim-neotest/neotest-python",
},
{
"nvim-neotest/neotest",
dependencies = {
"rouge8/neotest-rust",
"Issafalcon/neotest-dotnet",
"andy-bell101/neotest-java",
"nvim-neotest/neotest-go",
"nvim-neotest/neotest-python",
},
opts = {
adapters = {
["neotest-rust"] = {},
["neotest-dotnet"] = {},
["neotest-java"] = {},
["neotest-go"] = {},
["neotest-python"] = {},
},
status = { virtual_text = true },
output = { open_on_run = true },
quickfix = {
open = function()
if require("lazyvim.util").has("trouble.nvim") then
vim.cmd("Trouble quickfix")
else
vim.cmd("copen")
end
end,
},
},
config = function(_, opts)
local neotest_ns = vim.api.nvim_create_namespace("neotest")
vim.diagnostic.config({
virtual_text = {
format = function(diagnostic)
-- Replace newline and tab characters with space for more compact diagnostics
local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
return message
end,
},
}, neotest_ns)
if opts.adapters then
local adapters = {}
for name, config in pairs(opts.adapters or {}) do
if type(name) == "number" then
if type(config) == "string" then
config = require(config)
end
adapters[#adapters + 1] = config
elseif config ~= false then
local adapter = require(name)
if type(config) == "table" and not vim.tbl_isempty(config) then
local meta = getmetatable(adapter)
if adapter.setup then
adapter.setup(config)
elseif meta and meta.__call then
adapter(config)
else
error("Adapter " .. name .. " does not support setup")
end
end
adapters[#adapters + 1] = adapter
end
end
opts.adapters = adapters
end
require("neotest").setup(opts)
end,
-- stylua: ignore
keys = {
{ "<leader>tT", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
{ "<leader>tt", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Run All Test Files" },
{ "<leader>tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
{ "<leader>ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
{ "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
{ "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "Toggle Output Panel" },
{ "<leader>tS", function() require("neotest").run.stop() end, desc = "Stop" },
},
},
{
"echasnovski/mini.hipatterns",
event = "BufReadPre",
opts = function()
local hi = require("mini.hipatterns")
return {
-- custom LazyVim option to enable the tailwind integration
tailwind = {
enabled = true,
ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" },
-- full: the whole css class will be highlighted
-- compact: only the color will be highlighted
style = "full",
},
highlighters = {
hex_color = hi.gen_highlighter.hex_color({ priority = 2000 }),
},
}
end,
config = function(_, opts)
-- backward compatibility
if opts.tailwind == true then
opts.tailwind = {
enabled = true,
ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" },
style = "full",
}
end
if type(opts.tailwind) == "table" and opts.tailwind.enabled then
-- reset hl groups when colorscheme changes
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
M.hl = {}
end,
})
opts.highlighters.tailwind = {
pattern = function()
if not vim.tbl_contains(opts.tailwind.ft, vim.bo.filetype) then
return
end
if opts.tailwind.style == "full" then
return "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]"
elseif opts.tailwind.style == "compact" then
return "%f[%w:-][%w:-]+%-()[a-z%-]+%-%d+()%f[^%w:-]"
end
end,
group = function(_, _, m)
---@type string
local match = m.full_match
---@type string, number
local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)")
shade = tonumber(shade)
local bg = vim.tbl_get(M.colors, color, shade)
if bg then
local hl = "MiniHipatternsTailwind" .. color .. shade
if not M.hl[hl] then
M.hl[hl] = true
local bg_shade = shade == 500 and 950 or shade < 500 and 900 or 100
local fg = vim.tbl_get(M.colors, color, bg_shade)
vim.api.nvim_set_hl(0, hl, { bg = "#" .. bg, fg = "#" .. fg })
end
return hl
end
end,
priority = 2000,
}
end
require("mini.hipatterns").setup(opts)
end,
},
}