nimsuggest: suggest types in a type section
This commit is contained in:
parent
f162ff7773
commit
b414806e66
4 changed files with 23 additions and 3 deletions
|
|
@ -1846,6 +1846,7 @@ proc parseTypeDef(p: var TParser): PNode =
|
||||||
else:
|
else:
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
if p.tok.tokType == tkEquals:
|
if p.tok.tokType == tkEquals:
|
||||||
|
result.info = parLineInfo(p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
addSon(result, parseTypeDefAux(p))
|
addSon(result, parseTypeDefAux(p))
|
||||||
|
|
|
||||||
|
|
@ -717,7 +717,11 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) =
|
||||||
# we even look at the type definitions on the right
|
# we even look at the type definitions on the right
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
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 == nkCommentStmt: continue
|
||||||
if a.kind != nkTypeDef: illFormedAst(a)
|
if a.kind != nkTypeDef: illFormedAst(a)
|
||||||
checkSonsLen(a, 3)
|
checkSonsLen(a, 3)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ template origModuleName(m: PSym): string = m.name.s
|
||||||
proc findDocComment(n: PNode): PNode =
|
proc findDocComment(n: PNode): PNode =
|
||||||
if n == nil: return nil
|
if n == nil: return nil
|
||||||
if not isNil(n.comment): return n
|
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])
|
result = findDocComment(n.sons[0])
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
if n.len > 1:
|
if n.len > 1:
|
||||||
|
|
@ -194,7 +194,7 @@ proc suggestResult(s: Suggest) =
|
||||||
proc produceOutput(a: var Suggestions) =
|
proc produceOutput(a: var Suggestions) =
|
||||||
if gIdeCmd in {ideSug, ideCon}:
|
if gIdeCmd in {ideSug, ideCon}:
|
||||||
a.sort cmpSuggestions
|
a.sort cmpSuggestions
|
||||||
when false:
|
when defined(debug):
|
||||||
# debug code
|
# debug code
|
||||||
writeStackTrace()
|
writeStackTrace()
|
||||||
if a.len > suggestMaxResults: a.setLen(suggestMaxResults)
|
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?
|
||||||
Loading…
Add table
Add a link
Reference in a new issue