Retour au classement

fwcd/kotlin-language-server

Kotlin

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol

kotlinlanguage-serveratomautocompletelspvscodelanguage-server-protocolidecode-completion
Croissance des étoiles
Étoiles
2k
Forks
249
Croissance hebdomadaire
Issues
191
1k2k
mai 2018janv. 2021oct. 2023juil. 2026
README

[!IMPORTANT] There is now an official language server, so this project can be considered deprecated.

Kotlin Language Server

Release Build Downloads Chat

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.

Getting Started

Packaging

Packaging status

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.

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

  • Example of the ~/.config/kotlin-language-server/classpath on Linux:
#!/bin/bash
echo /my/path/kotlin-compiler-1.4.10/lib/kotlin-stdlib.jar:/my/path/my-lib.jar
  • Example of the %HOMEPATH%\.config\kotlin-language-server\classpath.bat on Windows:
@echo off
echo C:\my\path\kotlin-compiler-1.4.10\lib\kotlin-stdlib.jar;C:\my\path\my-lib.jar

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:

  • 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.

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

Dépôts similaires
justjavac/free-programming-books-zh_CN

:books: 免费的计算机编程类中文书籍,欢迎投稿

GNU General Public License v3.0pythonjavascript
weibo.com/justjavac
117.7k28.2k
JetBrains/kotlin

The Kotlin Programming Language.

Kotlinkotlinprogramming-language
kotlinlang.org
53.2k6.4k
lysine-dev/okhttp

A meticulous HTTP client for the JVM, Android, and GraalVM.

KotlinApache License 2.0javaandroid
lysine.dev/okhttp/
47k9.3k
square/okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

KotlinApache License 2.0javaandroid
square.github.io/okhttp/
46.2k9.2k
gkd-kit/gkd

基于无障碍,高级选择器,订阅规则的自定义屏幕点击安卓应用 | An Android APP with custom screen tapping based on Accessibility, Advanced Selectors, and Subscription Rules

KotlinGNU General Public License v3.0androidkotlin
gkd.li
40.3k1.9k
yuliskov/SmartTube

Browse media content with your own rules on Android TV

JavaMavenMIT Licenseandroidandroid-tv
smarttubeapp.github.io
31.4k1.8k
square/leakcanary

A memory leak detection library for Android.

KotlinApache License 2.0androidmemory-leak
square.github.io/leakcanary
29.9k4k
JunkFood02/Seal

🦭 Video/Audio Downloader for Android, based on yt-dlp

KotlinGNU General Public License v3.0androidjetpack-compose
27.7k1.3k
NativeScript/NativeScript

⚡ Write Native with TypeScript ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Flutter and you name it compatible.

TypeScriptnpmMIT Licensenativescriptandroid
nativescript.org
25.6k1.7k
mihonapp/mihon

Free and open source manga reader for Android

KotlinApache License 2.0androidkotlin
22.1k1.3k
google/iosched

The Google I/O Android App

KotlinApache License 2.0kotlinarchitecture
21.6k6.1k
android/nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose

KotlinApache License 2.0androidjetpack-compose
21.6k4.5k