WIP: Add a advanced compiler command 'ctags' (#6654)
This commit is contained in:
parent
e7c09512d2
commit
870567d083
4 changed files with 71 additions and 1 deletions
|
|
@ -608,6 +608,52 @@ proc generateJson*(d: PDoc, n: PNode) =
|
||||||
generateJson(d, lastSon(n.sons[0]))
|
generateJson(d, lastSon(n.sons[0]))
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
proc genTagsItem(d: PDoc, n, nameNode: PNode, k: TSymKind): string =
|
||||||
|
var
|
||||||
|
name = getName(d, nameNode)
|
||||||
|
|
||||||
|
result = name & "\n"
|
||||||
|
|
||||||
|
proc generateTags*(d: PDoc, n: PNode, r: var Rope) =
|
||||||
|
case n.kind
|
||||||
|
of nkCommentStmt:
|
||||||
|
if n.comment != nil and startsWith(n.comment, "##"):
|
||||||
|
let stripped = n.comment.substr(2).strip
|
||||||
|
r.add stripped
|
||||||
|
of nkProcDef:
|
||||||
|
when useEffectSystem: documentRaises(n)
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skProc)
|
||||||
|
of nkFuncDef:
|
||||||
|
when useEffectSystem: documentRaises(n)
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skFunc)
|
||||||
|
of nkMethodDef:
|
||||||
|
when useEffectSystem: documentRaises(n)
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skMethod)
|
||||||
|
of nkIteratorDef:
|
||||||
|
when useEffectSystem: documentRaises(n)
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skIterator)
|
||||||
|
of nkMacroDef:
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skMacro)
|
||||||
|
of nkTemplateDef:
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skTemplate)
|
||||||
|
of nkConverterDef:
|
||||||
|
when useEffectSystem: documentRaises(n)
|
||||||
|
r.add genTagsItem(d, n, n.sons[namePos], skConverter)
|
||||||
|
of nkTypeSection, nkVarSection, nkLetSection, nkConstSection:
|
||||||
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
if n.sons[i].kind != nkCommentStmt:
|
||||||
|
# order is always 'type var let const':
|
||||||
|
r.add genTagsItem(d, n.sons[i], n.sons[i].sons[0],
|
||||||
|
succ(skType, ord(n.kind)-ord(nkTypeSection)))
|
||||||
|
of nkStmtList:
|
||||||
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
generateTags(d, n.sons[i], r)
|
||||||
|
of nkWhenStmt:
|
||||||
|
# generate documentation for the first branch only:
|
||||||
|
if not checkForFalse(n.sons[0].sons[0]):
|
||||||
|
generateTags(d, lastSon(n.sons[0]), r)
|
||||||
|
else: discard
|
||||||
|
|
||||||
proc genSection(d: PDoc, kind: TSymKind) =
|
proc genSection(d: PDoc, kind: TSymKind) =
|
||||||
const sectionNames: array[skModule..skTemplate, string] = [
|
const sectionNames: array[skModule..skTemplate, string] = [
|
||||||
"Imports", "Types", "Vars", "Lets", "Consts", "Vars", "Procs", "Funcs",
|
"Imports", "Types", "Vars", "Lets", "Consts", "Vars", "Procs", "Funcs",
|
||||||
|
|
@ -745,6 +791,21 @@ proc commandJson*() =
|
||||||
#echo getOutFile(gProjectFull, JsonExt)
|
#echo getOutFile(gProjectFull, JsonExt)
|
||||||
writeRope(content, getOutFile(gProjectFull, JsonExt), useWarning = false)
|
writeRope(content, getOutFile(gProjectFull, JsonExt), useWarning = false)
|
||||||
|
|
||||||
|
proc commandTags*() =
|
||||||
|
var ast = parseFile(gProjectMainIdx, newIdentCache())
|
||||||
|
if ast == nil: return
|
||||||
|
var d = newDocumentor(gProjectFull, options.gConfigVars)
|
||||||
|
d.hasToc = true
|
||||||
|
var
|
||||||
|
content: Rope
|
||||||
|
generateTags(d, ast, content)
|
||||||
|
|
||||||
|
if optStdout in gGlobalOptions:
|
||||||
|
writeRope(stdout, content)
|
||||||
|
else:
|
||||||
|
#echo getOutFile(gProjectFull, TagsExt)
|
||||||
|
writeRope(content, getOutFile(gProjectFull, TagsExt), useWarning = false)
|
||||||
|
|
||||||
proc commandBuildIndex*() =
|
proc commandBuildIndex*() =
|
||||||
var content = mergeIndexes(gProjectFull).rope
|
var content = mergeIndexes(gProjectFull).rope
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,13 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
wantMainModule()
|
wantMainModule()
|
||||||
defineSymbol("nimdoc")
|
defineSymbol("nimdoc")
|
||||||
commandDoc2(graph, cache, true)
|
commandDoc2(graph, cache, true)
|
||||||
|
of "ctags":
|
||||||
|
wantMainModule()
|
||||||
|
gCmd = cmdDoc
|
||||||
|
loadConfigs(DocConfig, cache)
|
||||||
|
wantMainModule()
|
||||||
|
defineSymbol("nimdoc")
|
||||||
|
commandTags()
|
||||||
of "buildindex":
|
of "buildindex":
|
||||||
gCmd = cmdDoc
|
gCmd = cmdDoc
|
||||||
loadConfigs(DocConfig, cache)
|
loadConfigs(DocConfig, cache)
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ const
|
||||||
RodExt* = "rod"
|
RodExt* = "rod"
|
||||||
HtmlExt* = "html"
|
HtmlExt* = "html"
|
||||||
JsonExt* = "json"
|
JsonExt* = "json"
|
||||||
|
TagsExt* = "tags"
|
||||||
TexExt* = "tex"
|
TexExt* = "tex"
|
||||||
IniExt* = "ini"
|
IniExt* = "ini"
|
||||||
DefaultConfig* = "nim.cfg"
|
DefaultConfig* = "nim.cfg"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ Advanced commands:
|
||||||
//rst2html convert a reStructuredText file to HTML
|
//rst2html convert a reStructuredText file to HTML
|
||||||
//rst2tex convert a reStructuredText file to TeX
|
//rst2tex convert a reStructuredText file to TeX
|
||||||
//jsondoc extract the documentation to a json file
|
//jsondoc extract the documentation to a json file
|
||||||
//jsondoc2 extract documentation to a json file (uses doc2)
|
//jsondoc2 extract the documentation to a json file (uses doc2)
|
||||||
|
//ctags create a tags file
|
||||||
//buildIndex build an index for the whole documentation
|
//buildIndex build an index for the whole documentation
|
||||||
//run run the project (with Tiny C backend; buggy!)
|
//run run the project (with Tiny C backend; buggy!)
|
||||||
//genDepend generate a DOT file containing the
|
//genDepend generate a DOT file containing the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue