Kotlin
info
You can enable the extra with the :LazyExtras
command.
Plugins marked as optional will only be configured if they are installed.
Alternatively, you can add it to your lazy.nvim
imports
lua/config/lazy.lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.lang.kotlin" },
{ import = "plugins" },
},
})
Below you can find a list of included plugins and their default settings.
caution
You don't need to copy the default settings to your config. They are only shown here for reference.
mason.nvim
Add packages(linting, debug adapter)
- Options
- Full Spec
opts = { ensure_installed = { "ktlint" } }
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "ktlint" } },
}
nvim-treesitter
Add syntax highlighting
- Options
- Full Spec
opts = { ensure_installed = { "kotlin" } }
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "kotlin" } },
}
nvim-lspconfig
Add language server
- Options
- Full Spec
opts = {
servers = {
kotlin_language_server = {},
},
}
{
"neovim/nvim-lspconfig",
opts = {
servers = {
kotlin_language_server = {},
},
},
}
nvim-lint (optional)
Add linting
- Options
- Full Spec
opts = {
linters_by_ft = { kotlin = { "ktlint" } },
}
{
"mfussenegger/nvim-lint",
optional = true,
dependencies = "williamboman/mason.nvim",
opts = {
linters_by_ft = { kotlin = { "ktlint" } },
},
}
conform.nvim (optional)
Add formatting
- Options
- Full Spec
opts = {
formatters_by_ft = { kotlin = { "ktlint" } },
}
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = { kotlin = { "ktlint" } },
},
}
none-ls.nvim (optional)
Add formatting and linting
- Options
- Full Spec
opts = function(_, opts)
local nls = require("null-ls")
opts.sources = vim.list_extend(opts.sources or {}, {
nls.builtins.formatting.ktlint,
nls.builtins.diagnostics.ktlint,
})
end
{
"nvimtools/none-ls.nvim",
optional = true,
opts = function(_, opts)
local nls = require("null-ls")
opts.sources = vim.list_extend(opts.sources or {}, {
nls.builtins.formatting.ktlint,
nls.builtins.diagnostics.ktlint,
})
end,
}
nvim-dap (optional)
Add debugger
- Options
- Full Spec
opts = function()
local dap = require("dap")
if not dap.adapters.kotlin then
dap.adapters.kotlin = {
type = "executable",
command = "kotlin-debug-adapter",
options = { auto_continue_if_many_stopped = false },
}
end
dap.configurations.kotlin = {
{
type = "kotlin",
request = "launch",
name = "This file",
-- may differ, when in doubt, whatever your project structure may be,
-- it has to correspond to the class file located at `build/classes/`
-- and of course you have to build before you debug
mainClass = function()
local root = vim.fs.find("src", { path = vim.uv.cwd(), upward = true, stop = vim.env.HOME })[1] or ""
local fname = vim.api.nvim_buf_get_name(0)
-- src/main/kotlin/websearch/Main.kt -> websearch.MainKt
return fname:gsub(root, ""):gsub("main/kotlin/", ""):gsub(".kt", "Kt"):gsub("/", "."):sub(2, -1)
end,
projectRoot = "${workspaceFolder}",
jsonLogFile = "",
enableJsonLogging = false,
},
{
-- Use this for unit tests
-- First, run
-- ./gradlew --info cleanTest test --debug-jvm
-- then attach the debugger to it
type = "kotlin",
request = "attach",
name = "Attach to debugging session",
port = 5005,
args = {},
projectRoot = vim.fn.getcwd,
hostName = "localhost",
timeout = 2000,
},
}
end
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = "williamboman/mason.nvim",
opts = function()
local dap = require("dap")
if not dap.adapters.kotlin then
dap.adapters.kotlin = {
type = "executable",
command = "kotlin-debug-adapter",
options = { auto_continue_if_many_stopped = false },
}
end
dap.configurations.kotlin = {
{
type = "kotlin",
request = "launch",
name = "This file",
-- may differ, when in doubt, whatever your project structure may be,
-- it has to correspond to the class file located at `build/classes/`
-- and of course you have to build before you debug
mainClass = function()
local root = vim.fs.find("src", { path = vim.uv.cwd(), upward = true, stop = vim.env.HOME })[1] or ""
local fname = vim.api.nvim_buf_get_name(0)
-- src/main/kotlin/websearch/Main.kt -> websearch.MainKt
return fname:gsub(root, ""):gsub("main/kotlin/", ""):gsub(".kt", "Kt"):gsub("/", "."):sub(2, -1)
end,
projectRoot = "${workspaceFolder}",
jsonLogFile = "",
enableJsonLogging = false,
},
{
-- Use this for unit tests
-- First, run
-- ./gradlew --info cleanTest test --debug-jvm
-- then attach the debugger to it
type = "kotlin",
request = "attach",
name = "Attach to debugging session",
port = 5005,
args = {},
projectRoot = vim.fn.getcwd,
hostName = "localhost",
timeout = 2000,
},
}
end,
}