ref #5617 add lineinfo to complete (#16102)

This commit is contained in:
flywind 2020-11-24 00:49:40 +08:00 • committed by GitHub
commit 7fc0c3dfbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,13 @@
import macros, strutils, asyncfutures import macros, strutils, asyncfutures
# TODO: Ref https://github.com/nim-lang/Nim/issues/5617
# TODO: Add more line infos
proc newCallWithLineInfo(fromNode: NimNode; theProc: NimNode, args: varargs[NimNode]): NimNode =
result = newCall(theProc, args)
result.copyLineInfo(fromNode)
template createCb(retFutureSym, iteratorNameSym, template createCb(retFutureSym, iteratorNameSym,
strName, identName, futureVarCompletions: untyped) = strName, identName, futureVarCompletions: untyped) =
bind finished bind finished
@ -52,15 +59,13 @@ proc createFutureVarCompletions(futureVarIdents: seq[NimNode],
# Add calls to complete each FutureVar parameter. # Add calls to complete each FutureVar parameter.
for ident in futureVarIdents: for ident in futureVarIdents:
# Only complete them if they have not been completed already by the user. # Only complete them if they have not been completed already by the user.
# TODO: Once https://github.com/nim-lang/Nim/issues/5617 is fixed.
# TODO: Add line info to the complete() call!
# In the meantime, this was really useful for debugging :) # In the meantime, this was really useful for debugging :)
#result.add(newCall(newIdentNode("echo"), newStrLitNode(fromNode.lineinfo))) #result.add(newCall(newIdentNode("echo"), newStrLitNode(fromNode.lineinfo)))
result.add newIfStmt( result.add newIfStmt(
( (
newCall(newIdentNode("not"), newCall(newIdentNode("not"),
newDotExpr(ident, newIdentNode("finished"))), newDotExpr(ident, newIdentNode("finished"))),
newCall(newIdentNode("complete"), ident) newCallWithLineInfo(fromNode, newIdentNode("complete"), ident)
) )
) )