From 42fcaf144d2319150d5919749af2b2d67afe6b53 Mon Sep 17 00:00:00 2001 From: Florian Teich Date: Fri, 21 Nov 2025 18:45:14 +0100 Subject: [PATCH] add scala --- init.lua | 3 +- .../plugins/{debug.lua => debug_python.lua} | 61 ++------- lua/kickstart/plugins/debug_scala.lua | 129 ++++++++++++++++++ 3 files changed, 141 insertions(+), 52 deletions(-) rename lua/kickstart/plugins/{debug.lua => debug_python.lua} (81%) create mode 100644 lua/kickstart/plugins/debug_scala.lua diff --git a/init.lua b/init.lua index 22f70d6a..d9af5f14 100644 --- a/init.lua +++ b/init.lua @@ -974,7 +974,8 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - require 'kickstart.plugins.debug', + require 'kickstart.plugins.debug_python', + require 'kickstart.plugins.debug_scala', -- require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug_python.lua similarity index 81% rename from lua/kickstart/plugins/debug.lua rename to lua/kickstart/plugins/debug_python.lua index ea11bd5f..f9d242cb 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug_python.lua @@ -24,57 +24,16 @@ return { 'mfussenegger/nvim-dap-python', }, keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - '', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - { - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - 'b', - function() - require('dap').toggle_breakpoint() - end, - desc = 'Debug: Toggle Breakpoint', - }, - { - 'B', - function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, - desc = 'Debug: Set Breakpoint', - }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, + -- Keymaps aligned with debug_scala.lua + { 'dc', function() require('dap').continue() end, desc = 'Debug: Start/Continue' }, + { 'dr', function() require('dap').repl.toggle() end, desc = 'Debug: Toggle REPL' }, + { 'dK', function() require('dap.ui.widgets').hover() end, desc = 'Debug: Hover Widget' }, + { 'dt', function() require('dap').toggle_breakpoint() end, desc = 'Debug: Toggle Breakpoint' }, + { 'dso', function() require('dap').step_over() end, desc = 'Debug: Step Over' }, + { 'dsi', function() require('dap').step_into() end, desc = 'Debug: Step Into' }, + { 'dl', function() require('dap').run_last() end, desc = 'Debug: Run Last' }, + { 'du', function() require('dapui').toggle() end, desc = 'Debug: Toggle DAP UI' }, + { 'dB', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, desc = 'Debug: Set Conditional Breakpoint' }, }, config = function() local dap = require 'dap' diff --git a/lua/kickstart/plugins/debug_scala.lua b/lua/kickstart/plugins/debug_scala.lua new file mode 100644 index 00000000..40532637 --- /dev/null +++ b/lua/kickstart/plugins/debug_scala.lua @@ -0,0 +1,129 @@ +return { + 'scalameta/nvim-metals', + dependencies = { + { + 'j-hui/fidget.nvim', + opts = {}, + }, + { + 'mfussenegger/nvim-dap', + config = function(self, opts) + -- Debug settings if you're using nvim-dap + local dap = require 'dap' + + dap.configurations.scala = { + { + type = 'scala', + request = 'launch', + name = 'RunOrTest', + metals = { + runType = 'runOrTestFile', + --args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example + }, + }, + { + type = 'scala', + request = 'launch', + name = 'Test Target', + metals = { + runType = 'testTarget', + }, + }, + } + end, + }, + }, + ft = { 'scala', 'sbt', 'java' }, + opts = function() + local metals_config = require('metals').bare_config() + + -- Example of settings + metals_config.settings = { + showImplicitArguments = true, + gradleScript = vim.fn.getcwd() .. '/gradlew', + customProjectRoot = vim.fn.getcwd(), + excludedPackages = { 'akka.actor.typed.javadsl', 'com.github.swagger.akka.javadsl' }, + } + + -- *READ THIS* + -- I *highly* recommend setting statusBarProvider to either "off" or "on" + -- + -- "off" will enable LSP progress notifications by Metals and you'll need + -- to ensure you have a plugin like fidget.nvim installed to handle them. + -- + -- "on" will enable the custom Metals status extension and you *have* to have + -- a have settings to capture this in your statusline or else you'll not see + -- any messages from metals. There is more info in the help docs about this + metals_config.init_options.statusBarProvider = 'off' + + -- Example if you are using cmp how to make sure the correct capabilities for snippets are set + metals_config.capabilities = require('cmp_nvim_lsp').default_capabilities() + + metals_config.on_attach = function(client, bufnr) + require('metals').setup_dap() + + -- LSP mappings + map('n', 'gD', vim.lsp.buf.definition) + map('n', 'K', vim.lsp.buf.hover) + map('n', 'gi', vim.lsp.buf.implementation) + map('n', 'gr', vim.lsp.buf.references) + map('n', 'gds', vim.lsp.buf.document_symbol) + map('n', 'gws', vim.lsp.buf.workspace_symbol) + map('n', 'cl', vim.lsp.codelens.run) + map('n', 'sh', vim.lsp.buf.signature_help) + map('n', 'rn', vim.lsp.buf.rename) + map('n', 'f', vim.lsp.buf.format) + map('n', 'ca', vim.lsp.buf.code_action) + + map('n', 'ws', function() + require('metals').hover_worksheet() + end) + + -- all workspace diagnostics + map('n', 'aa', vim.diagnostic.setqflist) + + -- all workspace errors + map('n', 'ae', function() + vim.diagnostic.setqflist { severity = 'E' } + end) + + -- all workspace warnings + map('n', 'aw', function() + vim.diagnostic.setqflist { severity = 'W' } + end) + + -- buffer diagnostics only + map('n', 'd', vim.diagnostic.setloclist) + + map('n', '[c', function() + vim.diagnostic.goto_prev { wrap = false } + end) + + map('n', ']c', function() + vim.diagnostic.goto_next { wrap = false } + end) + + -- Example mappings for usage with nvim-dap. If you don't use that, you can + -- skip these + map('n', 'dc', function() require('dap').continue() end, { desc = 'Debug: Start/Continue' }) + map('n', 'dr', function() require('dap').repl.toggle() end, { desc = 'Debug: Toggle REPL' }) + map('n', 'dK', function() require('dap.ui.widgets').hover() end, { desc = 'Debug: Hover Widget' }) + map('n', 'dt', function() require('dap').toggle_breakpoint() end, { desc = 'Debug: Toggle Breakpoint' }) + map('n', 'dso', function() require('dap').step_over() end, { desc = 'Debug: Step Over' }) + map('n', 'dsi', function() require('dap').step_into() end, { desc = 'Debug: Step Into' }) + map('n', 'dl', function() require('dap').run_last() end, { desc = 'Debug: Run Last' }) + end + + return metals_config + end, + config = function(self, metals_config) + local nvim_metals_group = vim.api.nvim_create_augroup('nvim-metals', { clear = true }) + vim.api.nvim_create_autocmd('FileType', { + pattern = self.ft, + callback = function() + require('metals').initialize_or_attach(metals_config) + end, + group = nvim_metals_group, + }) + end, +}