Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

fwcd/kotlin-language-server

Repository files navigation

Important

There is now anofficial language server, so this project can be considered deprecated.

Kotlin Language Server

ReleaseBuildDownloadsChat

Alanguage server that provides smart code completion, diagnostics, hover, document symbols, definition lookup, method signature help and more forKotlin.

Icon

Any editor conforming to LSP is supported, includingVSCode andAtom.

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 theKotlin compiler.

Figuring out the dependencies

Dependencies are determined by theDefaultClassPathResolver.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/bashecho /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:
@echooffecho 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 sameKotlinCoreEnvironment alive between compilations inCompiler.kt. There is a performance benchmark inOneFilePerformance.kt that verifies this works.

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

  • Fully compile a file and store inCompiledFile:
    • 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 theLexicalScope encompassing this region from theBindingContext 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 inCompiledFile.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 behavioraltests, 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

NameDescription
serverThe language server executable
sharedClasspath resolution and utilities

Scripts

NameCommandDescription
release_version.pypython3 scripts/release_version.pyCreates a tag for the current version and bumps the development version

Protocol Extensions

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

Initialization Options

The Kotlin language server supports some custom initialization options via theinitializationOptions property in theinitialize request parameters. SeeInitializationOptions inConfiguration 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors61

Languages


[8]ページ先頭

©2009-2025 Movatter.jp