bugfix: consider type contexts properly
This commit is contained in:
parent
0596c11775
commit
4d0d6c47bd
2 changed files with 42 additions and 33 deletions
|
|
@ -113,6 +113,7 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -525,37 +525,42 @@ proc safeSemExpr*(c: PContext, n: PNode): PNode =
|
||||||
except ERecoverableError:
|
except ERecoverableError:
|
||||||
result = ast.emptyNode
|
result = ast.emptyNode
|
||||||
|
|
||||||
|
proc sugExpr(c: PContext, node: PNode, outputs: var Suggestions; cp: TCheckPointResult) =
|
||||||
|
var n = findClosestDot(node)
|
||||||
|
if n == nil: n = node
|
||||||
|
if n.kind == nkDotExpr:
|
||||||
|
var obj = safeSemExpr(c, n.sons[0])
|
||||||
|
# it can happen that errnously we have collected the fieldname
|
||||||
|
# of the next line, so we check the 'field' is actually on the same
|
||||||
|
# line as the object to prevent this from happening:
|
||||||
|
let prefix = if n.len == 2 and n[1].info.line == n[0].info.line: n[1] else: nil
|
||||||
|
suggestFieldAccess(c, obj, prefix, outputs)
|
||||||
|
|
||||||
|
#if optIdeDebug in gGlobalOptions:
|
||||||
|
# echo "expression ", renderTree(obj), " has type ", typeToString(obj.typ)
|
||||||
|
#writeStackTrace()
|
||||||
|
else:
|
||||||
|
#let m = findClosestSym(node)
|
||||||
|
#if m != nil:
|
||||||
|
# suggestPrefix(c, m, outputs)
|
||||||
|
#else:
|
||||||
|
let prefix = if cp == cpExact: n else: nil
|
||||||
|
suggestEverything(c, n, prefix, outputs)
|
||||||
|
|
||||||
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 = @[]
|
||||||
if gIdeCmd == ideSug:
|
if gIdeCmd == ideSug:
|
||||||
var n = findClosestDot(node)
|
sugExpr(c, node, outputs, cp)
|
||||||
if n == nil: n = node
|
|
||||||
if n.kind == nkDotExpr:
|
|
||||||
var obj = safeSemExpr(c, n.sons[0])
|
|
||||||
# it can happen that errnously we have collected the fieldname
|
|
||||||
# of the next line, so we check the 'field' is actually on the same
|
|
||||||
# line as the object to prevent this from happening:
|
|
||||||
let prefix = if n.len == 2 and n[1].info.line == n[0].info.line: n[1] else: nil
|
|
||||||
suggestFieldAccess(c, obj, prefix, outputs)
|
|
||||||
|
|
||||||
#if optIdeDebug in gGlobalOptions:
|
|
||||||
# echo "expression ", renderTree(obj), " has type ", typeToString(obj.typ)
|
|
||||||
#writeStackTrace()
|
|
||||||
else:
|
|
||||||
#let m = findClosestSym(node)
|
|
||||||
#if m != nil:
|
|
||||||
# suggestPrefix(c, m, outputs)
|
|
||||||
#else:
|
|
||||||
let prefix = if cp == cpExact: n else: nil
|
|
||||||
suggestEverything(c, n, prefix, outputs)
|
|
||||||
|
|
||||||
elif gIdeCmd == ideCon:
|
elif gIdeCmd == ideCon:
|
||||||
var n = findClosestCall(node)
|
var n = findClosestCall(node)
|
||||||
if n == nil: n = node
|
if n == nil: n = node
|
||||||
|
|
@ -583,17 +588,20 @@ proc suggestSentinel*(c: PContext) =
|
||||||
if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex: return
|
if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex: return
|
||||||
if c.compilesContextId > 0: return
|
if c.compilesContextId > 0: return
|
||||||
inc(c.compilesContextId)
|
inc(c.compilesContextId)
|
||||||
# suggest everything:
|
|
||||||
var isLocal = true
|
|
||||||
var outputs: Suggestions = @[]
|
var outputs: Suggestions = @[]
|
||||||
var scopeN = 0
|
if c.suggestionNode != nil:
|
||||||
for scope in walkScopes(c.currentScope):
|
sugExpr(c, c.suggestionNode, outputs, cpExact)
|
||||||
if scope == c.topLevelScope: isLocal = false
|
else:
|
||||||
dec scopeN
|
# suggest everything:
|
||||||
for it in items(scope.symbols):
|
var isLocal = true
|
||||||
var pm: PrefixMatch
|
var scopeN = 0
|
||||||
if filterSymNoOpr(it, nil, pm):
|
for scope in walkScopes(c.currentScope):
|
||||||
outputs.add(symToSuggest(it, isLocal = isLocal, $ideSug, 0, PrefixMatch.None, false, scopeN))
|
if scope == c.topLevelScope: isLocal = false
|
||||||
|
dec scopeN
|
||||||
|
for it in items(scope.symbols):
|
||||||
|
var pm: PrefixMatch
|
||||||
|
if filterSymNoOpr(it, nil, pm):
|
||||||
|
outputs.add(symToSuggest(it, isLocal = isLocal, $ideSug, 0, PrefixMatch.None, false, scopeN))
|
||||||
|
|
||||||
produceOutput(outputs)
|
|
||||||
dec(c.compilesContextId)
|
dec(c.compilesContextId)
|
||||||
|
produceOutput(outputs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue