Skip to content

Commit

Permalink
fixes #21923; nimsuggest "outline" output does not list templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lou15b authored and ringabout committed Jan 24, 2025
1 parent d6d28a9 commit cf25381
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
15 changes: 15 additions & 0 deletions compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,21 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode,
dec(c.config.evalTemplateCounter)
discard c.friendModules.pop()

proc getLineInfo(n: PNode): TLineInfo =
case n.kind
of nkPostfix:
if len(n) > 1:
result = getLineInfo(n[1])
else:
result = n.info
of nkAccQuoted, nkPragmaExpr:
if len(n) > 0:
result = getLineInfo(n[0])
else:
result = n.info
else:
result = n.info

const
errMissingGenericParamsForTemplate = "'$1' has unspecified generic parameters"

Expand Down
13 changes: 1 addition & 12 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,8 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind, reportToNimsuggest = tru
incl(result.flags, sfGlobal)
result.options = c.config.options

proc getLineInfo(n: PNode): TLineInfo =
case n.kind
of nkPostfix:
if len(n) > 1:
return getLineInfo(n[1])
of nkAccQuoted, nkPragmaExpr:
if len(n) > 0:
return getLineInfo(n[0])
else:
discard
result = n.info
let info = getLineInfo(n)
if reportToNimsuggest:
let info = getLineInfo(n)
suggestSym(c.graph, info, result, c.graph.usageSym)

proc checkNilable(c: PContext; v: PSym) =
Expand Down
3 changes: 3 additions & 0 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
s = semIdentVis(c, skTemplate, n[namePos], {})
assert s.kind == skTemplate

let info = getLineInfo(n[namePos])
suggestSym(c.graph, info, s, c.graph.usageSym)

styleCheckDef(c, s)
onDef(n[namePos].info, s)
# check parameter list:
Expand Down
15 changes: 15 additions & 0 deletions nimsuggest/tests/t21923.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
discard """
$nimsuggest --tester $file
>outline $file
outline;;skProc;;t21923.foo;;proc (x: int){.gcsafe, raises: <inferred> [].};;/home/blue/Nim/nimsuggest/tests/t21923.nim;;8;;5;;"";;100
outline;;skTemplate;;t21923.foo2;;;;/home/blue/Nim/nimsuggest/tests/t21923.nim;;11;;9;;"";;100
"""

proc foo(x: int) =
echo "foo"

template foo2(x: int) =
echo "foo2"

foo(12)
foo2(12)

0 comments on commit cf25381

Please sign in to comment.