Skip to content

Commit c7cf5d4

Browse files
Danil Yarantsevnarimiran
authored andcommitted
Fix compiles for nimsuggest [backport] (#14527)
* Handle nimsuggest in tryExpr * Added test (cherry picked from commit 00ec433)
1 parent 5610920 commit c7cf5d4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

compiler/semexprs.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,10 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
20342034

20352035
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
20362036
# watch out, hacks ahead:
2037+
when defined(nimsuggest):
2038+
# Remove the error hook so nimsuggest doesn't report errors there
2039+
let tempHook = c.graph.config.structuredErrorHook
2040+
c.graph.config.structuredErrorHook = nil
20372041
let oldErrorCount = c.config.errorCounter
20382042
let oldErrorMax = c.config.errorMax
20392043
let oldCompilesId = c.compilesContextId
@@ -2080,6 +2084,9 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
20802084
c.config.m.errorOutputs = oldErrorOutputs
20812085
c.config.errorCounter = oldErrorCount
20822086
c.config.errorMax = oldErrorMax
2087+
when defined(nimsuggest):
2088+
# Restore the error hook
2089+
c.graph.config.structuredErrorHook = tempHook
20832090

20842091
proc semCompiles(c: PContext, n: PNode, flags: TExprFlags): PNode =
20852092
# we replace this node by a 'true' or 'false' node:

nimsuggest/tests/tchk_compiles.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
discard compiles(2 + "hello")
2+
3+
#[!]#
4+
discard """
5+
$nimsuggest --tester $file
6+
>chk $1
7+
chk;;skUnknown;;;;Hint;;???;;0;;-1;;"tchk_compiles [Processing]";;0
8+
"""

0 commit comments

Comments
 (0)