1
1
package effekt
2
2
3
3
import effekt .context .{Annotations , Context }
4
- import effekt .source .{FunDef , Include , ModuleDecl , Span , Tree }
5
- import effekt .symbols .Hole
4
+ import effekt .source .{FunDef , Include , Maybe , ModuleDecl , Span , Tree }
5
+ import effekt .symbols .{ CaptureSet , Hole }
6
6
import kiama .util .{Position , Source }
7
7
import effekt .symbols .scopes .Scope
8
8
@@ -182,7 +182,7 @@ trait Intelligence {
182
182
C .annotationOption(Annotations .CaptureForFile , src).getOrElse(Nil )
183
183
184
184
// For now, we only show captures of function definitions and calls to box
185
- def getInferredCaptures (range : kiama.util.Range )(using C : Context ): List [( Position , CaptureSet ) ] =
185
+ def getInferredCaptures (range : kiama.util.Range )(using C : Context ): List [CaptureInfo ] =
186
186
val src = range.from.source
187
187
allCaptures(src).filter {
188
188
// keep only captures in the current range
@@ -192,14 +192,13 @@ trait Intelligence {
192
192
}.collect {
193
193
case (t : source.FunDef , c) => for {
194
194
pos <- C .positions.getStart(t)
195
- } yield (pos, c)
195
+ } yield CaptureInfo (pos, c)
196
196
case (t : source.DefDef , c) => for {
197
197
pos <- C .positions.getStart(t)
198
- } yield (pos, c)
199
- case (source.Box (None , block), _) if C .inferredCaptureOption(block).isDefined => for {
200
- pos <- C .positions.getStart(block)
198
+ } yield CaptureInfo (pos, c)
199
+ case (source.Box (Maybe (None , span), block), _) if C .inferredCaptureOption(block).isDefined => for {
201
200
capt <- C .inferredCaptureOption(block)
202
- } yield (pos , capt)
201
+ } yield CaptureInfo (span.range.from , capt, true )
203
202
}.flatten
204
203
205
204
def getInfoOf (sym : Symbol )(using C : Context ): Option [SymbolInfo ] = PartialFunction .condOpt(resolveCallTarget(sym)) {
@@ -354,4 +353,13 @@ object Intelligence {
354
353
terms ++ other.terms,
355
354
types ++ other.types)
356
355
}
356
+
357
+ case class CaptureInfo (
358
+ position : Position ,
359
+ captures : CaptureSet ,
360
+ /**
361
+ * Whether this capture set could be written into the source code at `position` using the `at { captures }` syntax
362
+ */
363
+ atSyntax : Boolean = false ,
364
+ )
357
365
}
0 commit comments