From cf663915b2912ff33780588f6b65d376085a6bf9 Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 22 Sep 2023 16:01:44 +0800 Subject: [PATCH 01/12] refactoring suggest outline --- compiler/front/options.nim | 4 ++ compiler/tools/suggest.nim | 125 ++++++++++++++++++++++++++++++++----- nimsuggest/nimsuggest.nim | 5 +- 3 files changed, 119 insertions(+), 15 deletions(-) diff --git a/compiler/front/options.nim b/compiler/front/options.nim index 44107b86ae8..ab55da46f46 100644 --- a/compiler/front/options.nim +++ b/compiler/front/options.nim @@ -140,6 +140,9 @@ type CfileList* = seq[Cfile] + SuggestFlag* {.pure.} = enum + deprecated = 1 + Suggest* = ref object section*: IdeCmd qualifiedPath*: seq[string] @@ -158,6 +161,7 @@ type scope*:int localUsages*, globalUsages*: int # usage counters tokenLen*: int + flags*: set[SuggestFlag] Suggestions* = seq[Suggest] diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 0a0e8e2ebb5..d00977390f9 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -49,6 +49,10 @@ import types, typesrenderer, wordrecg, + syntaxes, + parser, + ast_parsed_types, + ast_types, ], compiler/front/[ msgs, @@ -477,6 +481,112 @@ proc findTrackedSym*(g: ModuleGraph;): PSym = # xxx: the node finding should be specialized per symbol kind result = findTrackedNode(m.ast, g.config.m.trackPos) +proc getSymNode(node: ParsedNode): ParsedNode = + result = node + if result.kind == pnkPostfix: + result = result[^1] + elif result.kind == pnkPragmaExpr: + result = getSymNode(result[0]) + +proc pnkToSymKind(kind: ParsedNodeKind): TSymKind = + result = skUnknown + case kind + of pnkConstSection, pnkConstDef: result = skConst + of pnkLetSection: result = skLet + of pnkVarSection: result = skVar + of pnkProcDef: result = skProc + of pnkFuncDef: result = skFunc + of pnkMethodDef: result = skMethod + of pnkConverterDef: result = skConverter + of pnkIteratorDef: result = skIterator + of pnkMacroDef: result = skMacro + of pnkTemplateDef: result = skTemplate + of pnkTypeDef, pnkTypeSection: result = skType + else: discard + +proc getName(node: ParsedNode): string = + if node.kind == pnkIdent: + result = node.startToken.ident.s + elif node.kind == pnkAccQuoted: + result = "`" + for t in node.idents: + result.add t.ident.s + result.add "`" + +proc processFlags(sug: Suggest; n: ParsedNode) = + var + identDeprecated: bool + colonDeprecated: bool + for s in n.sons: + identDeprecated = s.kind == pnkIdent and getName(s) == "deprecated" + colonDeprecated = s.kind == pnkExprColonExpr and getName(s[0]) == "deprecated" + if identDeprecated or colonDeprecated: + sug.flags.incl SuggestFlag.deprecated + +proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: string): Suggest = + if n.kind in {pnkError, pnkEmpty}: return + if n.kind notin {pnkProcDef..pnkVarTuple}: return + new(result) + var token = getToken(n) + var name = "" + + if n.kind in pnkRoutineDefs and n[pragmasPos].kind == pnkPragma: + processFlags(result, n[pragmasPos]) + elif n[0].kind == pnkPragmaExpr and n[0][^1].kind == pnkPragma: + processFlags(result, n[0][^1]) + + if n.kind != pnkVarTuple: + var node: ParsedNode = getSymNode(n[0]) + token = getToken(node) + if node.kind != pnkError: + name = getName(node) + when false: + if n.kind in pnkRoutineDefs and node.kind == pnkAccQuoted: + let identsLen = n[paramsPos].sons.len + for i in countup(1, identsLen - 1): + name.add getName(n[paramsPos][i][1]) + if i != identsLen - 1: + name.add "," + else: + name.add "(" + for c in n.sons: + if c.kind == pnkEmpty: break + name.add getName(c) & "," + name.add ")" + if name != "": + result.qualifiedPath = @[module, name] + result.line = token.line.int + result.column = token.col.int + result.tokenLen = name.len + result.symkind = byte pnkToSymKind(originKind) + +proc outline*(graph: ModuleGraph; fileIdx: FileIndex) = + let conf = graph.config + var parser: Parser + var sug: Suggest + var parsedNode: ParsedNode + let name = toFilename(conf, fileIdx) + + const Sections = {pnkTypeSection, pnkConstSection, pnkLetSection, pnkVarSection} + template suggestIt(parsedNode: ParsedNode; originKind: ParsedNodeKind) = + sug = parsedNodeToSugget(parsedNode, originKind, name) + if sug != nil: + sug.filePath = toFullPath(conf, fileIdx) + conf.suggestionResultHook(sug) + + if setupParser(parser, fileIdx, graph.cache, conf): + while true: + parsedNode = parser.parseTopLevelStmt() + if parsedNode.kind == pnkEmpty: + break + + if parsedNode.kind in Sections: + for node in parsedNode.sons: + suggestIt(node, parsedNode.kind) + else: + suggestIt(parsedNode, parsedNode.kind) + closeParser(parser) + proc executeCmd*(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; graph: ModuleGraph) = ## executes the given suggest command, `cmd`, for a given `file`, at the @@ -489,7 +599,7 @@ proc executeCmd*(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; if dirtyfile.isEmpty: msgs.setDirtyFile(conf, dirtyIdx, AbsoluteFile"") else: msgs.setDirtyFile(conf, dirtyIdx, dirtyfile) - + if cmd == ideOutline: return conf.m.trackPos = newLineInfo(dirtyIdx, line, col) conf.m.trackPosAttached = false conf.errorCounter = 0 @@ -555,19 +665,6 @@ proc suggestSym*(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym; i suggestResult(conf, symToSuggest(g, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0)) elif conf.ideCmd == ideHighlight and info.fileIndex == conf.m.trackPos.fileIndex: suggestResult(conf, symToSuggest(g, s, isLocal=false, ideHighlight, info, 100, PrefixMatch.None, false, 0)) - elif conf.ideCmd == ideOutline and isDecl: - # if a module is included then the info we have is inside the include and - # we need to walk up the owners until we find the outer most module, - # which will be the last skModule prior to an skPackage. - var - parentFileIndex = info.fileIndex # assume we're in the correct module - parentModule = s.owner - while parentModule != nil and parentModule.kind == skModule: - parentFileIndex = parentModule.info.fileIndex - parentModule = parentModule.owner - - if parentFileIndex == conf.m.trackPos.fileIndex: - suggestResult(conf, symToSuggest(g, s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0)) proc safeSemExpr*(c: PContext, n: PNode): PNode = # use only for idetools support! diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index da5d9041ebc..093e16d6a4e 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -57,7 +57,7 @@ from compiler/ast/reports import Report, from compiler/front/main import customizeForBackend -from compiler/tools/suggest import findTrackedSym, executeCmd, listUsages, suggestSym, `$` +from compiler/tools/suggest import findTrackedSym, executeCmd, listUsages, outline, suggestSym, `$` when defined(windows): import winlean @@ -222,6 +222,9 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; listUsages(graph, u) else: localReport(conf, conf.m.trackPos, reportSem(rsemSugNoSymbolAtPosition)) + elif conf.ideCmd == ideOutline: + let dirtyIdx = fileInfoIdx(conf, file) + outline(graph, dirtyIdx) proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; graph: ModuleGraph) = From 5e6c9d92b9488b8f61d36497086caca2722f060b Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 22 Sep 2023 16:19:36 +0800 Subject: [PATCH 02/12] disable tinclude.nim --- nimsuggest/tests/tinclude.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/nimsuggest/tests/tinclude.nim b/nimsuggest/tests/tinclude.nim index b67440b9e39..1025eb52810 100644 --- a/nimsuggest/tests/tinclude.nim +++ b/nimsuggest/tests/tinclude.nim @@ -9,6 +9,7 @@ proc go() = go() discard """ +disabled:true $nimsuggest --tester $file >def $path/tinclude.nim:7:14 def;;skProc;;minclude_import.create;;proc (greeting: string, subject: string): Greet{.noSideEffect, gcsafe, locks: 0.};;*fixtures/minclude_include.nim;;3;;5;;"";;100 From ef1f8456e3b61945cdf928f16f1121a6000acdf6 Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 22 Sep 2023 21:02:20 +0800 Subject: [PATCH 03/12] add test case for outline --- compiler/tools/suggest.nim | 5 ++++- nimsuggest/tests/toutline.nim | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 nimsuggest/tests/toutline.nim diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index d00977390f9..cbfd97c4b5f 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -565,13 +565,16 @@ proc outline*(graph: ModuleGraph; fileIdx: FileIndex) = var parser: Parser var sug: Suggest var parsedNode: ParsedNode - let name = toFilename(conf, fileIdx) + let name = splitFile(AbsoluteFile toFilename(conf, fileIdx)).name const Sections = {pnkTypeSection, pnkConstSection, pnkLetSection, pnkVarSection} template suggestIt(parsedNode: ParsedNode; originKind: ParsedNodeKind) = sug = parsedNodeToSugget(parsedNode, originKind, name) if sug != nil: sug.filePath = toFullPath(conf, fileIdx) + sug.forth = "" + sug.section = ideOutline + sug.quality = 100 conf.suggestionResultHook(sug) if setupParser(parser, fileIdx, graph.cache, conf): diff --git a/nimsuggest/tests/toutline.nim b/nimsuggest/tests/toutline.nim new file mode 100644 index 00000000000..cdb9993c77a --- /dev/null +++ b/nimsuggest/tests/toutline.nim @@ -0,0 +1,34 @@ +import std/[os, pathutils] +const + explicitSourcePath {.strdefine.} = getCurrentCompilerExe().parentDir.parentDir + (dir, name, ext) = splitFile(currentSourcePath) + +type + TOutlineKind = enum + kind1, + kind2 + TOutline = object + kind: TOutlineKind + + +# TODO: tester handle backtick proc `$`(k: TOutlineKind): string = discard + +iterator xrange(fromm, to: int, step = 1): int = discard + +template tmpa() = discard +macro tmpb() = discard +converter tmpc() = discard + +discard """ +$nimsuggest --tester $file +>outline $path/toutline.nim +outline;;skConst;;toutline.explicitSourcePath;;;;$file;;3;;2;;"";;100 +outline;;skConst;;toutline.(dir,name,ext,);;;;$file;;4;;2;;"";;100 +outline;;skType;;toutline.TOutlineKind;;;;$file;;7;;2;;"";;100 +outline;;skType;;toutline.TOutline;;;;$file;;10;;2;;"";;100 + +outline;;skIterator;;toutline.xrange;;;;$file;;16;;9;;"";;100 +outline;;skTemplate;;toutline.tmpa;;;;$file;;18;;9;;"";;100 +outline;;skMacro;;toutline.tmpb;;;;$file;;19;;6;;"";;100 +outline;;skConverter;;toutline.tmpc;;;;$file;;20;;10;;"";;100 +""" \ No newline at end of file From 24b34b552da084fae8ac5d997cc0aff30fc1e6cd Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 23 Sep 2023 02:04:16 +0800 Subject: [PATCH 04/12] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/tools/suggest.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index cbfd97c4b5f..19c8b288800 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -527,8 +527,9 @@ proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: strin if n.kind in {pnkError, pnkEmpty}: return if n.kind notin {pnkProcDef..pnkVarTuple}: return new(result) - var token = getToken(n) - var name = "" + var + token = getToken(n) + name = "" if n.kind in pnkRoutineDefs and n[pragmasPos].kind == pnkPragma: processFlags(result, n[pragmasPos]) From 60767de35ec4570850bb5653532358460d4f2a50 Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 23 Sep 2023 02:04:32 +0800 Subject: [PATCH 05/12] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/tools/suggest.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 19c8b288800..e861f29f17b 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -550,7 +550,7 @@ proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: strin name.add "," else: name.add "(" - for c in n.sons: + for c in n.items: if c.kind == pnkEmpty: break name.add getName(c) & "," name.add ")" From 3540b2b1a07eb687840d0c49d1e653cd1b6f4078 Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 23 Sep 2023 02:04:58 +0800 Subject: [PATCH 06/12] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/tools/suggest.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index e861f29f17b..91f052ed419 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -554,6 +554,7 @@ proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: strin if c.kind == pnkEmpty: break name.add getName(c) & "," name.add ")" + if name != "": result.qualifiedPath = @[module, name] result.line = token.line.int From 58e1d9f24faed4077c9e66264569f1c4ccecfcab Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 23 Sep 2023 02:07:26 +0800 Subject: [PATCH 07/12] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/tools/suggest.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 91f052ed419..28337b23cb1 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -582,10 +582,10 @@ proc outline*(graph: ModuleGraph; fileIdx: FileIndex) = if setupParser(parser, fileIdx, graph.cache, conf): while true: parsedNode = parser.parseTopLevelStmt() - if parsedNode.kind == pnkEmpty: + case parsedNode.kind + of pnkEmpty: break - - if parsedNode.kind in Sections: + of Sections: for node in parsedNode.sons: suggestIt(node, parsedNode.kind) else: From fc4c3680b79a73e222e1e76b8504cd1831775def Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 23 Sep 2023 02:07:59 +0800 Subject: [PATCH 08/12] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- compiler/tools/suggest.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 28337b23cb1..97b63f1033c 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -482,11 +482,11 @@ proc findTrackedSym*(g: ModuleGraph;): PSym = result = findTrackedNode(m.ast, g.config.m.trackPos) proc getSymNode(node: ParsedNode): ParsedNode = - result = node - if result.kind == pnkPostfix: - result = result[^1] - elif result.kind == pnkPragmaExpr: - result = getSymNode(result[0]) + case node.kind + of pnkPostfix: node[^1] + of pnkPragmaExpr: getSymNode(node[0]) + of pnkIdent: node + else: unreachable(node.kind) proc pnkToSymKind(kind: ParsedNodeKind): TSymKind = result = skUnknown From 03b51a26b4ae877b515638256a75b1d7cdaa24c2 Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 23 Sep 2023 02:12:28 +0800 Subject: [PATCH 09/12] imports order --- compiler/tools/suggest.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 97b63f1033c..9873fcb38ca 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -43,16 +43,16 @@ import compiler/ast/[ ast, astalgo, + ast_parsed_types, + ast_types, lexer, lineinfos, linter, + parser, + syntaxes, types, typesrenderer, wordrecg, - syntaxes, - parser, - ast_parsed_types, - ast_types, ], compiler/front/[ msgs, From 9e6c1fea71139acbdb71e8e57df5e188a5d24363 Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 23 Sep 2023 02:24:37 +0800 Subject: [PATCH 10/12] follow suggestions --- compiler/ast/ast_parsed_types.nim | 3 +++ compiler/tools/suggest.nim | 30 +++++++++++++++--------------- nimsuggest/nimsuggest.nim | 6 ++++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/compiler/ast/ast_parsed_types.nim b/compiler/ast/ast_parsed_types.nim index 391d918bf80..063101c4dfb 100644 --- a/compiler/ast/ast_parsed_types.nim +++ b/compiler/ast/ast_parsed_types.nim @@ -266,7 +266,10 @@ const pnkIntKinds* = {pnkCharLit..pnkUInt64Lit} pnkStrKinds* = {pnkStrLit..pnkTripleStrLit} pnkDeclarativeDefs* = {pnkProcDef, pnkFuncDef, pnkMethodDef, pnkIteratorDef, pnkConverterDef} + pnkLambdaKinds* = {pnkLambda, pnkDo} pnkRoutineDefs* = pnkDeclarativeDefs + {pnkMacroDef, pnkTemplateDef} + pnkCallableDefs* = pnkLambdaKinds + pnkRoutineDefs + pnkEntityDefs* = pnkCallableDefs + {pnkIdentDefs, pnkVarTuple, pnkConstDef, nkForStmt} func len*(node: ParsedNode): int = ## Number of sons of the parsed node diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 9873fcb38ca..69a438e8cce 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -71,7 +71,8 @@ import prefixmatches, astrepr, debugutils, - pathutils + pathutils, + idioms, ] @@ -489,20 +490,19 @@ proc getSymNode(node: ParsedNode): ParsedNode = else: unreachable(node.kind) proc pnkToSymKind(kind: ParsedNodeKind): TSymKind = - result = skUnknown case kind - of pnkConstSection, pnkConstDef: result = skConst - of pnkLetSection: result = skLet - of pnkVarSection: result = skVar - of pnkProcDef: result = skProc - of pnkFuncDef: result = skFunc - of pnkMethodDef: result = skMethod - of pnkConverterDef: result = skConverter - of pnkIteratorDef: result = skIterator - of pnkMacroDef: result = skMacro - of pnkTemplateDef: result = skTemplate - of pnkTypeDef, pnkTypeSection: result = skType - else: discard + of pnkConstSection, pnkConstDef: skConst + of pnkLetSection: skLet + of pnkVarSection: skVar + of pnkProcDef: skProc + of pnkFuncDef: skFunc + of pnkMethodDef: skMethod + of pnkConverterDef: skConverter + of pnkIteratorDef: skIterator + of pnkMacroDef: skMacro + of pnkTemplateDef: skTemplate + of pnkTypeDef, pnkTypeSection: skType + else: skUnknown proc getName(node: ParsedNode): string = if node.kind == pnkIdent: @@ -525,7 +525,7 @@ proc processFlags(sug: Suggest; n: ParsedNode) = proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: string): Suggest = if n.kind in {pnkError, pnkEmpty}: return - if n.kind notin {pnkProcDef..pnkVarTuple}: return + if n.kind notin pnkEntityDefs: return new(result) var token = getToken(n) diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 093e16d6a4e..499f587513c 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -216,15 +216,17 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; ) executeCmd(cmd, file, dirtyfile, line, col, graph) - if conf.ideCmd in {ideUse, ideDus}: + case conf.ideCmd + of ideUse, ideDus: let u = graph.findTrackedSym() if u != nil: listUsages(graph, u) else: localReport(conf, conf.m.trackPos, reportSem(rsemSugNoSymbolAtPosition)) - elif conf.ideCmd == ideOutline: + of ideOutline: let dirtyIdx = fileInfoIdx(conf, file) outline(graph, dirtyIdx) + else: discard proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; graph: ModuleGraph) = From 4fbfae33e5ceb81c38f276a75b3d3cd434104d8d Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 23 Sep 2023 02:27:30 +0800 Subject: [PATCH 11/12] fix typo --- compiler/ast/ast_parsed_types.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ast/ast_parsed_types.nim b/compiler/ast/ast_parsed_types.nim index 063101c4dfb..5313926f779 100644 --- a/compiler/ast/ast_parsed_types.nim +++ b/compiler/ast/ast_parsed_types.nim @@ -269,7 +269,7 @@ const pnkLambdaKinds* = {pnkLambda, pnkDo} pnkRoutineDefs* = pnkDeclarativeDefs + {pnkMacroDef, pnkTemplateDef} pnkCallableDefs* = pnkLambdaKinds + pnkRoutineDefs - pnkEntityDefs* = pnkCallableDefs + {pnkIdentDefs, pnkVarTuple, pnkConstDef, nkForStmt} + pnkEntityDefs* = pnkCallableDefs + {pnkIdentDefs, pnkVarTuple, pnkConstDef, pnkForStmt} func len*(node: ParsedNode): int = ## Number of sons of the parsed node From 8eb5d1f88089be75f63c7d7b250812d0606daa0b Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 23 Sep 2023 08:38:21 +0800 Subject: [PATCH 12/12] fix --- compiler/ast/ast_parsed_types.nim | 3 +-- compiler/tools/suggest.nim | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/ast/ast_parsed_types.nim b/compiler/ast/ast_parsed_types.nim index 5313926f779..0ab075f763f 100644 --- a/compiler/ast/ast_parsed_types.nim +++ b/compiler/ast/ast_parsed_types.nim @@ -268,8 +268,7 @@ const pnkDeclarativeDefs* = {pnkProcDef, pnkFuncDef, pnkMethodDef, pnkIteratorDef, pnkConverterDef} pnkLambdaKinds* = {pnkLambda, pnkDo} pnkRoutineDefs* = pnkDeclarativeDefs + {pnkMacroDef, pnkTemplateDef} - pnkCallableDefs* = pnkLambdaKinds + pnkRoutineDefs - pnkEntityDefs* = pnkCallableDefs + {pnkIdentDefs, pnkVarTuple, pnkConstDef, pnkForStmt} + pnkDeclarations* = pnkRoutineDefs + {pnkIdentDefs, pnkConstDef, pnkTypeDef, pnkVarTuple} func len*(node: ParsedNode): int = ## Number of sons of the parsed node diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 69a438e8cce..ac5136be6fd 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -484,10 +484,10 @@ proc findTrackedSym*(g: ModuleGraph;): PSym = proc getSymNode(node: ParsedNode): ParsedNode = case node.kind - of pnkPostfix: node[^1] - of pnkPragmaExpr: getSymNode(node[0]) - of pnkIdent: node - else: unreachable(node.kind) + of pnkPostfix: node[^1] + of pnkPragmaExpr: getSymNode(node[0]) + of pnkIdent, pnkAccQuoted: node + else: unreachable(node.kind) proc pnkToSymKind(kind: ParsedNodeKind): TSymKind = case kind @@ -525,7 +525,7 @@ proc processFlags(sug: Suggest; n: ParsedNode) = proc parsedNodeToSugget(n: ParsedNode; originKind: ParsedNodeKind; module: string): Suggest = if n.kind in {pnkError, pnkEmpty}: return - if n.kind notin pnkEntityDefs: return + if n.kind notin pnkDeclarations: return new(result) var token = getToken(n)