kotlin-community-tools / kotlin-language-server

MIT License
7 stars 2 forks source link

Kotlin Language Server

Release Build Downloads Chat

Notice and status

This is fork of currently almost unmaintained upstream repo: https://github.com/fwcd/kotling-language-server

This fork is being maintained in developers' spare time. Our goal is to make this extension usable and feature complete. We do not aim for full feature parity with JetBrains ide's Kotlin support.

We do support only Linux and MacOS. Windows is not tested but still may work. Windows only issues has least priority.

Kotlin Language Server

A language server that provides smart code completion, diagnostics, hover, document symbols, definition lookup, method signature help and more for Kotlin.

Icon

Any editor conforming to LSP is supported, including VSCode and Atom.

Scope of the project

This project is strictly limited by Language Server Protocol capabilities. We aim to provide complete language server experience.

Some features, that our users may expect, lies outside of our responsibility. We won't deliver any features related to code and test running, project building. These tasks should be performed by other means. We offload these features to editor specific extensions.

Getting Started

Packaging

Packaging status

This repository needs your help!

See CONTRIBUTION.md

The original author created this project while he was considering using Kotlin in his work. He ended up deciding not to and is not really using Kotlin these days though this is a pretty fully-functional language server that just needs someone to use it every day for a while and iron out the last few pesky bugs.

There are two hard parts of implementing a language server:

The project uses the internal APIs of the Kotlin compiler.

Figuring out the dependencies

Dependencies are determined by the DefaultClassPathResolver.kt, which invokes Maven or Gradle to get a list of classpath JARs. Alternatively, projects can also 'manually' provide a list of dependencies through a shell script, located either at [project root]/kls-classpath or [config root]/kotlin-language-server/classpath, which outputs a list of JARs. Depending on your platform, the scripts also can be suffixed with .{sh,bat,cmd}.

Incrementally re-compiling as the user types

I get incremental compilation at the file-level by keeping the same KotlinCoreEnvironment alive between compilations in Compiler.kt. There is a performance benchmark in OneFilePerformance.kt that verifies this works.

Getting incremental compilation at the expression level is a bit more complicated:

The incremental expression compilation logic is all in CompiledFile.kt. The Kotlin AST has a built-in repair API, which seems to be how IntelliJ works, but as far as I can tell this API does not work if the surrounding IntelliJ machinery is not present. Hence I created the "fake tiny file" incremental-compilation mechanism, which seems to be quite fast and predictable.

There is an extensive suite of behavioral tests, which are all implemented in terms of the language server protocol, so you should be able to refactor the code any way you like and the tests should still work.

Modules

Name Description
server The language server executable
shared Classpath resolution and utilities

Scripts

Name Command Description
release_version.py python3 scripts/release_version.py Creates a tag for the current version and bumps the development version

Protocol Extensions

The Kotlin language server supports some non-standard requests through LSP. See KotlinProtocolExtensions for a description of the interface. The general syntax for these methods is kotlin/someCustomMethod.

Initialization Options

The Kotlin language server supports some custom initialization options via the initializationOptions property in the initialize request parameters. See InitializationOptions in Configuration for a list of supported properties.

Features

Autocomplete

Autocomplete

Signature help

Signature Help

Hover

Hover

Go-to-definition, find all references

Find all references

Document symbols

Document symbols

Global symbols

Global symbols

Authors

Current maintainers team

Original authors