Smart code completion, diagnostics and more for Kotlin using the Language Server Protocol
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Added debug attach configuration for the language server Oct 30, 2018
gradle/wrapper Migrated to Gradle May 28, 2018
grammar Move old grammar Apr 19, 2018
images Describe features Apr 13, 2018
lib Working Java to Kotlin converter - fixes #24 Jun 29, 2018
scripts Better Kotlin DSL support Jun 1, 2018
src Fixed #45 (Decompiler crashing the language server) Oct 30, 2018
syntaxes Improved highlighting of control flow keywords Dec 8, 2018
vscode-extension-src Fixed incorrect operator precedence Oct 21, 2018
.gitignore Added kotlin-plugin from the JetBrains TeamCity CI Jun 29, 2018
.travis.yml Maven dependency list logging Jun 13, 2018
.vscodeignore Version 0.1.10 - More compact distribution and updated file permissio… Nov 28, 2018
BUILDING.md Updated BUILDING.md Oct 31, 2018
CHANGELOG.md Version 0.1.11 - Improved keyword highlighting Dec 8, 2018
Icon128.png Starts up and connects, pipes logs, immediately fails Mar 25, 2018
LICENSE.txt Externalized classpath finding Gradle DSL code and updated license Jun 11, 2018
README.md Added Gitter Oct 22, 2018
TODO.md Minor stylistic changes and updates to README May 29, 2018
build.gradle Version 0.1.10 - More compact distribution and updated file permissio… Nov 28, 2018
gradle.properties Added kotlin-plugin from the JetBrains TeamCity CI Jun 29, 2018
gradlew Fixed exec permissions with Gradle wrapper script Jun 12, 2018
gradlew.bat Migrated to Gradle May 28, 2018
package-lock.json Updated npm dependencies Nov 28, 2018
package.json Version 0.1.11 - Improved keyword highlighting Dec 8, 2018
settings.gradle Migrated to Gradle May 28, 2018
tsconfig.json Better Kotlin DSL support Jun 1, 2018

README.md

KotlinLanguageServer

A language server that provides IDE-independent smart code completion, diagnostics, hover, document symbols, method signature help and more for Kotlin and a VSCode extension that uses the language server.

Version Installs Build Status Gitter

Icon

Getting Started

This repository needs your help!

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:

  • Figuring out the dependencies
  • Incrementally re-compiling as the user types

The project uses the internal APIs of the Kotlin compiler.

Dependencies are determined by the findClassPath function, which invokes Maven or Gradle and tells it to output a list of dependencies. Currently, both Maven and Gradle projects are supported.

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:

  • Fully compile a file and store in CompiledFile:
    • val content: String A snapshot of the source code
    • val parse: KtFile The parsed AST
    • val compile: BindingContext Additional information about the AST from typechecking
  • After the user edits the file:
    • Find the smallest section the encompasses all the user changes
    • Get the LexicalScope encompassing this region from the BindingContext that was generated by the full-compile
    • Create a fake, in-memory .kt file with just the expression we want to re-compile
      • Add space at the top of the file so the line numbers match up
    • Re-compile this tiny fake file

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.

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