mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
nimsuggest: suggest types in a type section
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
15
nimsuggest/tests/ttype_decl.nim
Normal file
15
nimsuggest/tests/ttype_decl.nim
Normal 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?
|
||||
Reference in New Issue
Block a user