nimsuggest: suggest types in a type section

This commit is contained in:
Andreas Rumpf
2017-03-14 11:21:35 +01:00
parent f162ff7773
commit b414806e66
4 changed files with 23 additions and 3 deletions

View File

@@ -1846,6 +1846,7 @@ proc parseTypeDef(p: var TParser): PNode =
else:
addSon(result, ast.emptyNode)
if p.tok.tokType == tkEquals:
result.info = parLineInfo(p)
getTok(p)
optInd(p, result)
addSon(result, parseTypeDefAux(p))

View File

@@ -717,7 +717,11 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) =
# we even look at the type definitions on the right
for i in countup(0, sonsLen(n) - 1):
var a = n.sons[i]
if gCmd == cmdIdeTools: suggestStmt(c, a)
when defined(nimsuggest):
if gCmd == cmdIdeTools:
inc c.inTypeContext
suggestStmt(c, a)
dec c.inTypeContext
if a.kind == nkCommentStmt: continue
if a.kind != nkTypeDef: illFormedAst(a)
checkSonsLen(a, 3)

View File

@@ -72,7 +72,7 @@ template origModuleName(m: PSym): string = m.name.s
proc findDocComment(n: PNode): PNode =
if n == nil: return nil
if not isNil(n.comment): return n
if n.kind in {nkStmtList, nkStmtListExpr} and n.len > 0:
if n.kind in {nkStmtList, nkStmtListExpr, nkObjectTy, nkRecList} and n.len > 0:
result = findDocComment(n.sons[0])
if result != nil: return
if n.len > 1:
@@ -194,7 +194,7 @@ proc suggestResult(s: Suggest) =
proc produceOutput(a: var Suggestions) =
if gIdeCmd in {ideSug, ideCon}:
a.sort cmpSuggestions
when false:
when defined(debug):
# debug code
writeStackTrace()
if a.len > suggestMaxResults: a.setLen(suggestMaxResults)

View File

@@ -0,0 +1,15 @@
discard """
$nimsuggest --tester --maxresults:3 $file
>sug $1
sug;;skType;;ttype_decl.Other;;Other;;$file;;10;;2;;"";;0;;None
sug;;skType;;system.int;;int;;$lib/system.nim;;25;;2;;"";;0;;None
sug;;skType;;system.string;;string;;$lib/system.nim;;48;;2;;"";;0;;None
"""
import strutils
type
Other = object ## My other object.
Foo = #[!]#
proc main(f: Foo) =
# XXX why no doc comments?