nishtahir / language-kotlin

Textmate language grammar for the Kotlin programming language
Apache License 2.0
12 stars 6 forks source link

Content after triple quotes highlighted as string #53

Closed starsep closed 3 years ago

starsep commented 3 years ago

Another issue similar to #26 From highlighting it seems that content of a string after newline is interpreted as a Kotlin code.

    private fun lastChecked(yearsAgo: Double): String = """
        older today -$yearsAgo years
        or ${LAST_CHECK_DATE_KEYS.joinToString(" or ") { "$it < today -$yearsAgo years" }}
    """.trimIndent()
    private fun hasAnyName(tags: Map<String, String>?): Boolean =
        tags?.let { featureDictionaryFuture.get().byTags(it).find().isNotEmpty() } ?: false

Source: https://github.com/streetcomplete/StreetComplete/blob/07137c1f506530dc86a500faa4ee04bda91215e5/app/src/main/java/de/westnordost/streetcomplete/quests/existence/CheckExistence.kt#L101-L107

Animeshz commented 3 years ago

Interesting enough it only happens if the string is returned from a function 👀

   val str: String = """
        older today -$yearsAgo years
        or ${LAST_CHECK_DATE_KEYS.joinToString(" or ") { "$it < today -$yearsAgo years" }}
    """.trimIndent()
    private fun hasAnyName(tags: Map<String, String>?): Boolean =
        tags?.let { featureDictionaryFuture.get().byTags(it).find().isNotEmpty() } ?: false

Assignment or any other type of literals are detected as expected. PS: The single-double-quoted string does the same with function return.

Animeshz commented 3 years ago

Ok it seems like, after : String return type there, equals is not highlighted. Indicating that single expression return type is not handled.

TWiStErRob commented 3 years ago

I was about to report a similar issue. We're on a self-hosted GitHub Enterprise, so I guess it didn't propagate there yet. Would it have been a duplicate then?

Looks good here:

private fun Exception.isNetworkError(): Boolean {
    val message = this.message ?: return false 
    return message.startsWith("""Unable to resolve host "api.host.net"""") ||
           message.startsWith("failed to connect to api.host.net")
}

This is what I see in our PR: image

Animeshz commented 3 years ago

@TWiStErRob Which PR messed it? The upstream (master branch) grammar seems to work fine in the lightshow:

image

Animeshz commented 3 years ago

Oh sorry I didn't read the comment fully, your issue is dup of #26 the triple quotation mark ends as soon as possible, so next (4th quote) was getting considered as beginning of new string. This is strange that it have been merged back in December yet is not updated in gh enterprise 🤔 I guess you could raise a ticket there to pull and apply the changes.

TWiStErRob commented 3 years ago

I'll double-check, maybe it's just my company's updates that's lagging. Thanks for the confirm of dupe.