Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of @Language on (formatted-)string literals #117

Open
Martmists-GH opened this issue Nov 13, 2024 · 4 comments
Open

Allow use of @Language on (formatted-)string literals #117

Martmists-GH opened this issue Nov 13, 2024 · 4 comments
Assignees

Comments

@Martmists-GH
Copy link

No description provided.

@amaembo
Copy link
Collaborator

amaembo commented Nov 14, 2024

Could you please provide the code sample illustrating the desired behavior?

@Martmists-GH
Copy link
Author

// In ktor, one might want to do:
call.respondText(ContentType.Text.Html) {
    @Language("HTML")
    """
<html>
  <head>
    <!-- ... -->
  </head>
  <body>
    <!-- ... -->
  </body>
</html>
    """
}

// Or when doing code generation:
fun createFunction(name: String, body: FunctionBody): String {
    return @Language("Javascript") """
function $name() {
    ${createFunctionBody(body)}
}
    """
}

The latter case might be a bit more complex due to dealing for formatted values, but a reasonable solution would be to treat them as empty for the purposes for highlighting the string. While this could pose problems for some codebases which would use this, it provides a starting point which can then be expanded upon.

@amaembo
Copy link
Collaborator

amaembo commented Nov 14, 2024

Oh, it's Kotlin-specific. Reassigning to @serjsysoev for further evaluation

@amaembo
Copy link
Collaborator

amaembo commented Nov 14, 2024

Btw, can't you just write this way?

@Language("Javascript")
fun createFunction(name: String, body: FunctionBody): String {
    return """
function $name() {
    ${createFunctionBody(body)}
}
    """
}

Now, the return value is properly highlighted in IntelliJ for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants