The Rise of Emacs for JVM Languages
For years, developers working with Scala and Kotlin have largely been tethered to JetBrains' IntelliJ IDEA. Its robust feature set, deep integration with the JVM ecosystem, and excellent language support have made it the de facto standard. However, a growing contingent of developers has sought to escape the confines of a monolithic IDE, yearning for the customizability and efficiency of a text editor like Emacs. Until recently, achieving a comparable development experience for Scala and Kotlin in Emacs was a significant challenge, often involving complex configurations and a patchwork of tools.
The landscape has shifted dramatically with the advent of sophisticated Language Server Protocol (LSP) implementations for these languages and their seamless integration with Emacs' Eglot package. Eglot acts as a client for various LSP servers, providing features like code completion, diagnostics, go-to-definition, and refactoring directly within the Emacs buffer. This development signifies a major step forward, enabling Emacs users to wield the full power of modern IDEs without leaving their preferred environment.

Scala Language Server: Empowering Emacs Users
The Scala Language Server (SCALA LS) is a crucial component in bringing a first-class Scala development experience to Emacs. Built on the Metals project, SCALA LS leverages the Java Virtual Machine (JVM) itself to provide rich language intelligence. Metals, a Scala language server, is designed to offer IDE features across various editors, and its underlying engine powers SCALA LS. This means that the same intelligence that powers IntelliJ's Scala support is now accessible through Emacs.
Integration with Eglot is straightforward. Once Eglot is installed and configured, users typically need to ensure SCALA LS is available in their environment. The server can often be installed via package managers or directly downloaded. Eglot then automatically detects and connects to the running SCALA LS instance when a Scala file is opened. The benefits are immediate and profound: accurate syntax highlighting, real-time error checking with clear diagnostics, intelligent code completion that understands your project's dependencies and types, and the ability to navigate your codebase with precision using go-to-definition and find-references functionalities.
For developers accustomed to IntelliJ's advanced refactoring capabilities, SCALA LS through Eglot offers a compelling alternative. Features like renaming symbols across a project, extracting methods, or introducing variables become available directly in Emacs, streamlining common coding tasks. This significantly reduces context switching, allowing developers to stay focused and productive within a single, highly personalized environment. The performance has also improved substantially; while LSP servers can sometimes be resource-intensive, the SCALA LS, when properly configured and with sufficient JVM resources, provides a responsive experience that rivals dedicated IDEs.
Kotlin Language Server: Bridging the Gap
Similarly, the Kotlin language server, often powered by the Kotlin Language Server (KLS) project, brings equivalent IDE-level features to Kotlin development within Emacs. KLS is developed by the JetBrains team and aims to provide a consistent language server implementation for various IDEs and editors, including Emacs via Eglot. This ensures that developers can enjoy a high-fidelity experience when working with Kotlin, whether they are building Android applications, server-side services with Ktor or Spring, or multiplatform projects.
The setup process mirrors that of SCALA LS. After installing Eglot, users install KLS. Eglot handles the connection, enabling features such as code completion, parameter hints, type information on hover, and diagnostics. The ability to quickly jump to the declaration of a class, function, or property is a fundamental productivity booster that KLS and Eglot provide. Furthermore, KLS supports code actions, which are context-aware suggestions for improving code, such as implementing interfaces, generating getters and setters, or making members public.
What's genuinely surprising is the speed at which these LSP implementations have matured. Just a few years ago, achieving this level of integration and functionality for JVM languages in Emacs felt like a distant dream. Now, the experience is not just functional but deeply integrated, offering a level of polish that can rival, and for some, surpass, the traditional IDE experience. This is largely due to the collaborative efforts of the open-source community and the language creators themselves, who recognize the value of supporting diverse development environments.
Configuration and Workflow Considerations
While the integration is powerful, it's not entirely set-and-forget. Developers will need to manage the installation and configuration of both Eglot and the respective language servers. This often involves adding snippets to their Emacs configuration files (e.g., `init.el` or `config.org`). For instance, one might add a hook to automatically start the Scala language server when a `.scala` file is opened:
(use-package eglot
:ensure t
:config
(add-hook 'scala-mode-hook (lambda () (require 'eglot) (eglot-ensure)))
;; Add similar hooks for kotlin-mode
)
Managing project dependencies and build tools like sbt or Gradle is also crucial. The language servers rely on these build tools to understand the project structure, dependencies, and compilation classpath. Ensuring that `sbt compile` or `gradle build` can run successfully from within Emacs (or that the LSP server can invoke them correctly) is key to unlocking the full potential of code intelligence. Some users might also configure Emacs to use specific build tool plugins that integrate more tightly with the LSP, such as `sbt-mode`.
The workflow shift involves embracing Emacs's keybindings and modes for tasks traditionally handled by an IDE's GUI. For example, running tests might involve specific Emacs commands that interact with the build tool, rather than clicking a button in a toolbar. Similarly, debugging sessions can be initiated and managed through Emacs interfaces, often leveraging Emacs's built-in debugger or specialized packages that integrate with language server debugging protocols.
The Unanswered Question: Long-Term Maintenance and Evolution
As impressive as this progress is, a lingering question remains: what is the long-term maintenance strategy for these LSP implementations and their integration with editors like Emacs? While Metals and KLS are actively developed, the responsibility of keeping them robust and feature-complete for a diverse editor ecosystem falls on a dedicated, often smaller, group of developers compared to the resources of a company like JetBrains. Ensuring backward compatibility, addressing bugs specific to editor integrations, and keeping pace with language evolution will be critical for sustained success.
The success of this approach hinges on continued community contributions and the commitment of language creators to maintain these servers. For developers who have made the leap from IntelliJ, this is a trade-off they are willing to make for the benefits of Emacs. However, for the broader adoption of Emacs as a primary IDE for Scala and Kotlin, a clear roadmap and sustained investment in these LSP integrations will be paramount.
