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

fix(suggest): file level cmds don't leak internal syms #944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/front/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ type
when defined(nimDebugUnreportedErrors):
unreportedErrors*: OrderedTable[NodeId, PNode]

const
IdeLocCmds* = {ideSug, ideCon, ideDef, ideUse, ideDus}
## IDE commands requiring source locations, related `MsgConfig.trackPos`

template `[]`*(conf: ConfigRef, idx: FileIndex): TFileInfo =
conf.m.fileInfos[idx.uint32]

Expand Down
19 changes: 10 additions & 9 deletions compiler/sem/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,20 @@ proc deltaTrace(stopProc, indent: string, entries: seq[StackTraceEntry])
echo:
"$1| $2 $3($4)" % [indent, $e.procname, $e.filename, $e.line]

template semIdeForTemplateOrGenericCheck(conf, n, requiresCheck) =
# we check quickly if the node is where the cursor is
template semIdeForTemplateOrGenericCheck(conf, n, cursorInBody) =
# use only for idetools support; detecting cursor in generic or template body
# if so call `semIdeForTemplateOrGeneric` for semantic checking
when defined(nimsuggest):
if n.info.fileIndex == conf.m.trackPos.fileIndex and n.info.line == conf.m.trackPos.line:
requiresCheck = true
if conf.ideCmd in IdeLocCmds and
n.info.fileIndex == conf.m.trackPos.fileIndex and
n.info.line == conf.m.trackPos.line:
cursorInBody = true

template semIdeForTemplateOrGeneric(c: PContext; n: PNode;
requiresCheck: bool) =
# use only for idetools support; this is pretty slow so generics and
# templates perform some quick check whether the cursor is actually in
# the generic or template.
cursorInBody: bool) =
# provide incomplete information for idetools support in generic or template
when defined(nimsuggest):
if c.config.cmd == cmdIdeTools and requiresCheck:
if c.config.cmd == cmdIdeTools and cursorInBody:
bung87 marked this conversation as resolved.
Show resolved Hide resolved
#if optIdeDebug in gGlobalOptions:
# echo "passing to safeSemExpr: ", renderTree(n)
discard safeSemExpr(c, n)
Expand Down
27 changes: 27 additions & 0 deletions nimsuggest/tests/toutline_generic.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Regression test for symbols within template and generic bodies being
# wrongfully reported by `outline`.

proc generic[T]() =
var x = 0 #[!]#
return # <- when no cursor is provided, this triggered `x` being reported

template templ() =
var x = 0 #[!]#
return # <- when no cursor is provided, this triggered `x` being reported

# try both with and without a specified cursor position, they should be the same

discard """
$nimsuggest --tester $file
>outline $1
outline;;skProc;;toutline_generic.generic;;*;;4;;5;;"";;100
outline;;skTemplate;;toutline_generic.templ;;*;;8;;9;;"";;100

>outline $2
outline;;skProc;;toutline_generic.generic;;*;;4;;5;;"";;100
outline;;skTemplate;;toutline_generic.templ;;*;;8;;9;;"";;100

>outline $path/toutline_generic.nim
outline;;skProc;;toutline_generic.generic;;*;;4;;5;;"";;100
outline;;skTemplate;;toutline_generic.templ;;*;;8;;9;;"";;100
"""
Loading