nimsuggest: revert cpFuzzy bailouts

This commit is contained in:
Andreas Rumpf 2017-03-09 11:30:36 +01:00
commit da821a22d9
4 changed files with 26 additions and 24 deletions

View file

@ -113,7 +113,6 @@ type
recursiveDep*: string recursiveDep*: string
suggestionsMade*: bool suggestionsMade*: bool
inTypeContext*: int inTypeContext*: int
suggestionNode*: PNode
proc makeInstPair*(s: PSym, inst: PInstantiation): TInstantiationPair = proc makeInstPair*(s: PSym, inst: PInstantiation): TInstantiationPair =
result.genericSym = s result.genericSym = s

View file

@ -405,13 +405,16 @@ proc inCheckpoint*(current: TLineInfo): TCheckPointResult =
if current.line >= gTrackPos.line: if current.line >= gTrackPos.line:
return cpFuzzy return cpFuzzy
proc findClosestDot(n: PNode): PNode = proc findClosestDot(n: PNode; inType: var bool): PNode =
if n.kind == nkDotExpr and inCheckpoint(n.info) == cpExact: if n.kind == nkDotExpr and inCheckpoint(n.info) == cpExact:
result = n result = n
else: else:
for i in 0.. <safeLen(n): for i in 0.. <safeLen(n):
result = findClosestDot(n.sons[i]) result = findClosestDot(n.sons[i], inType)
if result != nil: return if result != nil:
#if n.kind == nkIdentDefs and i == n.len-2:
# inType = true
return
proc findClosestCall(n: PNode): PNode = proc findClosestCall(n: PNode): PNode =
if n.kind in nkCallKinds and inCheckpoint(n.info) == cpExact: if n.kind in nkCallKinds and inCheckpoint(n.info) == cpExact:
@ -526,8 +529,11 @@ proc safeSemExpr*(c: PContext, n: PNode): PNode =
result = ast.emptyNode result = ast.emptyNode
proc sugExpr(c: PContext, node: PNode, outputs: var Suggestions; cp: TCheckPointResult) = proc sugExpr(c: PContext, node: PNode, outputs: var Suggestions; cp: TCheckPointResult) =
var n = findClosestDot(node) var inTypeSection = false
var n = findClosestDot(node, inTypeSection)
if n == nil: n = node if n == nil: n = node
if inTypeSection: inc c.inTypeContext
echo "came here ", n.kind
if n.kind == nkDotExpr: if n.kind == nkDotExpr:
var obj = safeSemExpr(c, n.sons[0]) var obj = safeSemExpr(c, n.sons[0])
# it can happen that errnously we have collected the fieldname # it can happen that errnously we have collected the fieldname
@ -546,16 +552,13 @@ proc sugExpr(c: PContext, node: PNode, outputs: var Suggestions; cp: TCheckPoint
#else: #else:
let prefix = if cp == cpExact: n else: nil let prefix = if cp == cpExact: n else: nil
suggestEverything(c, n, prefix, outputs) suggestEverything(c, n, prefix, outputs)
if inTypeSection: dec c.inTypeContext
proc suggestExpr*(c: PContext, node: PNode) = proc suggestExpr*(c: PContext, node: PNode) =
if gTrackPos.line < 0: return if gTrackPos.line < 0: return
var cp = inCheckpoint(node.info) var cp = inCheckpoint(node.info)
if cp == cpNone: return if cp == cpNone: return
# This keeps semExpr() from coming here recursively: # This keeps semExpr() from coming here recursively:
if cp == cpFuzzy:
c.suggestionNode = node
return
if c.compilesContextId > 0: return if c.compilesContextId > 0: return
inc(c.compilesContextId) inc(c.compilesContextId)
var outputs: Suggestions = @[] var outputs: Suggestions = @[]
@ -589,19 +592,16 @@ proc suggestSentinel*(c: PContext) =
if c.compilesContextId > 0: return if c.compilesContextId > 0: return
inc(c.compilesContextId) inc(c.compilesContextId)
var outputs: Suggestions = @[] var outputs: Suggestions = @[]
if c.suggestionNode != nil: # suggest everything:
sugExpr(c, c.suggestionNode, outputs, cpExact) var isLocal = true
else: var scopeN = 0
# suggest everything: for scope in walkScopes(c.currentScope):
var isLocal = true if scope == c.topLevelScope: isLocal = false
var scopeN = 0 dec scopeN
for scope in walkScopes(c.currentScope): for it in items(scope.symbols):
if scope == c.topLevelScope: isLocal = false var pm: PrefixMatch
dec scopeN if filterSymNoOpr(it, nil, pm):
for it in items(scope.symbols): outputs.add(symToSuggest(it, isLocal = isLocal, $ideSug, 0, PrefixMatch.None, false, scopeN))
var pm: PrefixMatch
if filterSymNoOpr(it, nil, pm):
outputs.add(symToSuggest(it, isLocal = isLocal, $ideSug, 0, PrefixMatch.None, false, scopeN))
dec(c.compilesContextId) dec(c.compilesContextId)
produceOutput(outputs) produceOutput(outputs)

View file

@ -291,10 +291,13 @@ proc transformBreak(c: PTransf, n: PNode): PTransNode =
else: else:
result = newTransNode(n.kind, n.info, 1) result = newTransNode(n.kind, n.info, 1)
result[0] = lablCopy.PTransNode result[0] = lablCopy.PTransNode
else: elif c.breakSyms.len > 0:
# this check can fail for 'nim check'
let labl = c.breakSyms[c.breakSyms.high] let labl = c.breakSyms[c.breakSyms.high]
result = transformSons(c, n) result = transformSons(c, n)
result[0] = newSymNode(labl).PTransNode result[0] = newSymNode(labl).PTransNode
else:
result = n.PTransNode
proc unpackTuple(c: PTransf, n: PNode, father: PTransNode) = proc unpackTuple(c: PTransf, n: PNode, father: PTransNode) =
# XXX: BUG: what if `n` is an expression with side-effects? # XXX: BUG: what if `n` is an expression with side-effects?

View file

@ -11,4 +11,4 @@ type
x, y: int x, y: int
proc main(f: Foo) = proc main(f: Foo) =
f.#[!]# if f.#[!]#: