Skip to content

AlexandrosAlexiou/kotlin.nvim

Repository files navigation


rustaceanvim


Explore the docs »

Extensions for JetBrains' Kotlin Language Server (kotlin-lsp) support in Neovim
(>=0.11.0).

Neovim Lua Kotlin

GPL3 License Issues

🧩 Extensions

  • 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

Note

Workspace isolation with the --system-path parameter requires kotlin-lsp v0.253.10629 or later.

📦 Installation

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,
},

📥 Language Server Installation

The plugin supports two installation methods for kotlin-lsp:

Option 1: Mason Installation (Recommended)

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.

Option 2: Manual Installation

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.

💐 Credits

About

Extensions for JetBrains' kotlin-lsp support in Neovim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages