Editor Integration
January 17, 2025 ยท View on GitHub
Visual Studio Code
See vscode-kotlin or install the extension from the marketplace.
Sublime Text
See lsp-kotlin.
Emacs
using lsp-mode
There are two ways of setting up the language server with lsp-mode:
- Add the language server executable to your
PATH. This is useful for development and for always using the latest version from themain-branch. - Let
lsp-modedownload the server for you (kotlin-ls). This will use the latest release.
Run/debug code lenses
If you use dap-mode, you can set (setq lsp-kotlin-debug-adapter-enabled t) to enable the debug adapter. You will need to have Kotlin Debug Adapter on your system. A simple configuration of dap-mode for Kotlin may look like:
(require 'dap-kotlin)
(setq lsp-kotlin-debug-adapter-enabled t)
;; replace the path below to the path to your Kotlin Debug Adapter
(setq lsp-kotlin-debug-adapter-path "/path/to/kotlin-debug-adapter")
Then you can activate lsp-kotlin-lens-mode to see the Run/Debug code lenses at your main-functions.
Override members (e.g, toString and equals)
The language server provides a custom protocol extension for finding overridable members of a class (variables and methods). lsp-mode provides a function that uses this called lsp-kotlin-implement-member. You can run it while hovering a class name, and you will get a menu with all available overridable members. (protip: Bind this function to a key!). If you have Helm or Ivy installed, one of them will be utilized.
Vim
using LanguageClient-neovim
Add the language server to your PATH and include the following configuration in your .vimrc:
autocmd BufReadPost *.kt setlocal filetype=kotlin
let g:LanguageClient_serverCommands = {
\ 'kotlin': ["kotlin-language-server"],
\ }
using coc.nvim
Add the following to your coc-settings.json file:
{
"languageserver": {
"kotlin": {
"command": "[path to cloned language server]/server/build/install/server/bin/kotlin-language-server",
"filetypes": ["kotlin"]
}
}
}
Note that you may need to substitute kotlin-language-server with kotlin-language-server.bat on Windows.
You should also note, that you need a syntax highlighter like udalov/kotlin-vim or sheerun/vim-polyglot to work well with coc.
Neovim
Using Neovim's nvim-lspconfig, register the language server using the following.
require'lspconfig'.kotlin_language_server.setup{}
If desired, you can also pass in your own defined options to the setup function.
require'lspconfig'.kotlin_language_server.setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
Monaco Editor
See kotlin-monaco-language-server.
Helix
Using languages.toml
[language-server.kotlin-language-server]
command = "kotlin-language-server"
[[language]]
name = "kotlin"
scope = "source.kotlin"
file-types = ["kt", "kts"]
roots = ["settings.gradle", "settings.gradle.kts"]
comment-token = "//"
block-comment-tokens = { start = "/*", end = "*/" }
indent = { tab-width = 4, unit = " " }
language-servers = [ "kotlin-language-server" ]
[[grammar]]
name = "kotlin"
source = { git = "https://github.com/fwcd/tree-sitter-kotlin", rev = "a4f71eb9b8c9b19ded3e0e9470be4b1b77c2b569" }
Other Editors
Install a Language Server Protocol client for your tool. Then invoke the language server executable in a client-specific way.
The server can be launched in three modes:
Stdio(the default mode)- The language server uses the standard streams for JSON-RPC communication
TCP Server- The language server starts a server socket and listens on
--tcpServerPort
- The language server starts a server socket and listens on
TCP Client- The language server tries to connect to
--tcpClientHostand--tcpClientPort
- The language server tries to connect to
The mode is automatically determined by the arguments provided to the language server.