hey folks, i'm working on migrating some PSI code...
# k2-adopters
s
hey folks, i'm working on migrating some PSI code from K1 to K2. The usecase is this:
Copy code
fun foo() {
  GlobalScope.launch {
    // anonymous suspend function <===
    try {
      delay(1_000)
    } catch (_: Exception) {
      // general error handling
    }
  }
}
I need to be able to tell if the try-block is running within a suspend function (as is this case). I have this so far:
Copy code
// visitTryExpression
val function = expression.getParentOfType<KtFunction>(strict = true) ?: return
analyze(function) {
  val symbol: KaAnonymousFunctionSymbol = function.symbol
  // symbol.isSuspend does not exist
}
I noticed that
KaAnonymousFunctionSymbol.isSuspend
does not exist, even though
KaNamedFunctionSymbol.isSuspend
exists. My question is: how does one get whether an anonymous function/lambda is a suspend function in the analysis API?e
r
Hi! Unfortunately there’s no easy “built-in” way to do the thing that you want to do via Analysis API Let me share some utilities with you which we use internally to solve the same task
Please note that this code was copied verbatium from the https://github.com/JetBrains/intellij-community
s
Oh thank you so so much for this. I'll give it a try and get back
👍 1