Extensions for JetBrains' Kotlin Language Server (kotlin-lsp) support in Neovim
(>=0.11.0).
- Decompile and open class file contents using kotlin-lsp
decompile
command - Export workspace to JSON using kotlin-lsp
exportWorkspace
command - Toggle hints using the
KotlinHintsToggle
command - Support for custom JVM arguments
- Support kotlin-lsp installation from Mason
- Navigate to package folders from package declarations (opens the folder view with oil.nvim using LSP "go to definition")
- Automatic per-project workspace isolation to prevent LSP conflicts and improve performance
- Use
KotlinCleanWorkspace
command to clear cached indices for the current project
- Use
Note
Workspace isolation with the --system-path
parameter requires kotlin-lsp v0.253.10629 or later.
Install the plugin with your package manager:
{
"AlexandrosAlexiou/kotlin.nvim",
ft = { "kotlin" },
dependencies = { "mason.nvim", "mason-lspconfig.nvim", "oil.nvim" },
config = function()
require("kotlin").setup {
-- Optional: Specify root markers for multi-module projects
root_markers = {
"gradlew",
".git",
"mvnw",
"settings.gradle",
},
-- Optional: Specify a custom Java path to run the server
jre_path = os.getenv("JDK21"),
-- Optional: Specify additional JVM arguments
jvm_args = {
"-Xmx4g",
},
}
end,
},
The plugin supports two installation methods for kotlin-lsp:
You can easily install kotlin-lsp using Mason with the following command:
:MasonInstall kotlin-lsp
This is the recommended approach as Mason handles the installation automatically.
If you prefer not to use Mason or need to use a specific version of kotlin-lsp, you can install it manually and set the KOTLIN_LSP_DIR
environment variable to point to your installation directory:
export KOTLIN_LSP_DIR=/path/to/your/kotlin-lsp
The plugin will automatically detect and use your manual installation when the environment variable is set. Ensure your installation has the following structure:
$KOTLIN_LSP_DIR/
└── lib/
└── ... (jar files)
Tip
The plugin first checks for Mason installations, then falls back to the KOTLIN_LSP_DIR
environment variable if Mason isn't available or kotlin-lsp isn't installed through it.
Caution
If you use other tools like nvim-lspconfig or mason-lspconfig, make sure to explicitly exclude the kotlin_lsp
configuration there to avoid conflicts.