From b414806e66efbf37c8e7edf832cb9a266f433d60 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 14 Mar 2017 11:21:35 +0100 Subject: [PATCH] nimsuggest: suggest types in a type section --- compiler/parser.nim | 1 + compiler/semstmts.nim | 6 +++++- compiler/suggest.nim | 4 ++-- nimsuggest/tests/ttype_decl.nim | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 nimsuggest/tests/ttype_decl.nim diff --git a/compiler/parser.nim b/compiler/parser.nim index 0503b29eb7..362a5c286c 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -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)) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 069ece6a64..9a1850932d 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 63f769c7cc..f9210cc93e 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -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) diff --git a/nimsuggest/tests/ttype_decl.nim b/nimsuggest/tests/ttype_decl.nim new file mode 100644 index 0000000000..846eb7b1b6 --- /dev/null +++ b/nimsuggest/tests/ttype_decl.nim @@ -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?