fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.67k stars 212 forks source link

Fix for #195. Add support for lambda expressions. #471

Closed markov closed 1 year ago

markov commented 1 year ago

This also fixes places where the language server incorrectly detects single > chars on a line as mismatched braces.

markov commented 1 year ago

Here is a before - after shot of what parts of the grammar this fixes.

Before - after

The separation of the operators in their own pattern matching was inspired by the java support: https://github.com/microsoft/vscode/blob/main/extensions/java/syntaxes/java.tmLanguage.json#L910

Here is the sample code if you'd like to test it yourself:

fun main() {
    intArrayOf(32, 42, 52).forEach { number ->
        when {
            number < 42 && number <= 42 -> println("Less than an answer!")
            number === 42 && number == 42 -> println("The Answer!")
            number !== 42 || number != 42 -> println("Not the Answer!")
            !!(number > 42 || number >= 42) -> println("More than an answer!")
        }
        var n = +number
        n = -n
        ++n++
        --n--
        n = n|number
        n = n&number
        n = n * 1 % n / 3 + 3 - 1
        n += n
        n -= n
        n %= n
        n *= 6
        n /= (1.0 / 7)
        for (m in n..number) break
    }
}
markov commented 1 year ago

closes #195

fwcd commented 1 year ago

Thanks!