Add testing back, error fixed (hopefully)

This commit is contained in:
Janis Hutz 2025-02-21 14:39:36 +01:00
parent 3bec60aaa6
commit f37ac7a88f
2 changed files with 113 additions and 20 deletions

View File

@ -5,9 +5,11 @@ return {
dependencies = {
"hrsh7th/cmp-nvim-lsp",
{ "antosha417/nvim-lsp-file-operations", config = true },
"mfussenegger/nvim-jdtls",
-- "mfussenegger/nvim-jdtls",
"nvim-java/nvim-java"
},
config = function()
require('java').setup()
-- import lspconfig plugin
local lspconfig = require("lspconfig")
@ -130,29 +132,50 @@ return {
on_attach = on_attach,
})
-- lspconfig.ts_ls.setup({
-- capabilities = capabilities,
-- on_attach = on_attach,
-- })
local java_on_attach = function(client, bufnr)
opts.buffer = bufnr
-- local mason_registry = require('mason-registry')
-- local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server'
--
-- lspconfig.volar.setup({
-- capabilities = capabilities,
-- on_attach = on_attach,
-- -- cmd = { "vue-language-server", "--stdio" },
-- filetypes = { "vue" },
-- -- settings = {
-- -- typescript = {
-- -- tsdk = '/usr/lib/node_modules/typescript/lib'
-- -- }
-- -- }
-- })
-- Keybinds for testing, refactoring, java specific
opts.desc = "Java profiling"
keymap.set("n", "<leader>jp", ":JavaProfile<CR>", opts)
opts.desc = "Java Refactor: Extract Variable (create variable from cursor)"
keymap.set("n", "<leader>jev", ":JavaExtractVariable<CR>", opts)
opts.desc = "Java Refactor: Extract Variable all occurrences (create variable from cursor)"
keymap.set("n", "<leader>jea", ":JavaExtractVariableAllOccurrence<CR>", opts)
opts.desc = "Java Refactor: Extract Const (create const from cursor)"
keymap.set("n", "<leader>jec", ":JavaExtractConst<CR>", opts)
opts.desc = "Java Refactor: Extract Method (create method from cursor)"
keymap.set("n", "<leader>jev", ":JavaExtractMethod<CR>", opts)
opts.desc = "Java Refactor: Extract Field (create field from cursor)"
keymap.set("n", "<leader>jev", ":JavaExtractField<CR>", opts)
-- Java testing, Debugging
opts.desc = "Java Testing: Run test class in buffer"
keymap.set("n", "<leader>jtc", ":JavaTestRunCurrentClass<CR>", opts)
opts.desc = "Java Testing: Debug test class in buffer"
keymap.set("n", "<leader>jdc", ":JavaTestDebugCurrentClass<CR>", opts)
opts.desc = "Java Testing: Run current method in buffer"
keymap.set("n", "<leader>jtm", ":JavaTestRunCurrentMethod<CR>", opts)
opts.desc = "Java Testing: Debug current method in buffer"
keymap.set("n", "<leader>jdm", ":JavaTestDebugCurrentMethod<CR>", opts)
opts.desc = "Java Testing: View last report"
keymap.set("n", "<leader>jtv", ":JavaTestViewLastReport<CR>", opts)
on_attach(client, bufnr)
end
lspconfig.jdtls.setup({
capabilities = capabilities,
on_attach = on_attach,
on_attach = java_on_attach,
})
lspconfig.texlab.setup{

70
nvim/lua/plugins/neotest.lua Executable file
View File

@ -0,0 +1,70 @@
-- plugins/neotest_config.lua
return {
-- Load neotest
{
"nvim-neotest/neotest",
dependencies = {
-- For JavaScript, TypeScript (Vite)
"marilari88/neotest-vitest",
-- For Python
"nvim-neotest/neotest-python",
-- For C, C++, Rust
"orjangj/neotest-ctest",
"rouge8/neotest-rust",
},
config = function()
local neotest = require("neotest")
local keymap = vim.keymap.set
-- General setup for neotest
neotest.setup({
adapters = {
-- Vite Adapter for JavaScript/TypeScript
require("neotest-vitest"),
-- Python Adapter
require("neotest-python"),
-- C/C++ Adapter
require("neotest-ctest"),
-- Rust Adapter
require("neotest-rust"),
},
})
-- Keybinding Setup
local opts = { noremap = true, silent = true }
-- Run nearest test
opts.desc = "Run nearest test"
keymap("n", "<leader><leader>tr", '<cmd>lua require("neotest").run.run()<cr>', opts)
-- Run all tests in the current file
opts.desc = "Run all tests in current file"
keymap("n", "<leader><leader>tf", '<cmd>lua require("neotest").run.run(vim.fn.expand("%"))', opts)
-- Run all tests in the entire project
opts.desc = "Run all tests in project"
keymap("n", "<leader><leader>ta", "<cmd>Neotest run<cr>", opts)
-- Stop running tests
opts.desc = "Stop tests"
keymap("n", "<leader><leader>ts", "<cmd>Neotest stop<cr>", opts)
opts.desc = "Jump to next test"
keymap("n", "<leader><leader>tn", "<cmd>Neotest jump next<cr>", opts)
opts.desc = "Jump to previous test"
keymap("n", "<leader><leader>tp", "<cmd>Neotest jump prev<cr>", opts)
-- Show test summary
opts.desc = "Show neotest test summary"
keymap("n", "<leader><leader>tv", "<cmd>Neotest summary<cr>", opts)
-- Toggle the Neotest panel
opts.desc = "Show neotest output"
keymap("n", "<leader><leader>to", "<cmd>Neotest output<cr>", opts)
opts.desc = "Show neotest output as panel"
keymap("n", "<leader><leader>tn", "<cmd>Neotest output-panel<cr>", opts)
end,
},
}