From af1265072ed5f9693e2f32e18876b1aea20b2000 Mon Sep 17 00:00:00 2001 From: bung87 Date: Sat, 16 Sep 2023 16:40:20 +0800 Subject: [PATCH 1/3] refactor symToSuggest,restrict conditions to IdeCmd --- compiler/tools/suggest.nim | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/tools/suggest.nim b/compiler/tools/suggest.nim index 17536c68ed9..9cc660ce131 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -162,15 +162,17 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info: result.quality = quality result.isGlobal = sfGlobal in s.flags result.prefix = prefix - result.contextFits = inTypeContext == (s.kind in {skType, skGenericParam}) + if section in {ideSug, ideCon}: + result.contextFits = inTypeContext == (s.kind in {skType, skGenericParam}) result.scope = scope result.name = addr s.name.s when defined(nimsuggest): - result.globalUsages = s.allUsages.len - var c = 0 - for u in s.allUsages: - if u.fileIndex == info.fileIndex: inc c - result.localUsages = c + if section in {ideSug, ideCon}: + result.globalUsages = s.allUsages.len + var c = 0 + for u in s.allUsages: + if u.fileIndex == info.fileIndex: inc c + result.localUsages = c result.symkind = byte s.kind if optIdeTerse notin g.config.globalOptions: result.qualifiedPath = @[] @@ -192,7 +194,8 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info: else: result.forth = "" when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler): - result.doc = extractDocComment(g, s) + if section in {ideSug, ideCon, ideDef, ideChk}: + result.doc = extractDocComment(g, s) let infox = if useSuppliedInfo or section in {ideUse, ideHighlight, ideOutline}: info @@ -201,10 +204,10 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info: result.filePath = toFullPath(g.config, infox) result.line = toLinenumber(infox) result.column = toColumn(infox) - result.tokenLen = if section != ideHighlight: - s.name.s.len - else: - getTokenLenFromSource(g.config, s.name.s, infox) + if section in {ideHighlight}: + result.tokenLen = getTokenLenFromSource(g.config, s.name.s, infox) + else: + result.tokenLen = s.name.s.len proc `$`*(suggest: Suggest): string = result = $suggest.section From 8ea9851976e17d609944ab242677ff43e1eea966 Mon Sep 17 00:00:00 2001 From: Bung Date: Thu, 21 Sep 2023 02:42:11 +0800 Subject: [PATCH 2/3] Update compiler/tools/suggest.nim Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com> --- 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 16e5e3ea135..660e6b0419a 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -203,10 +203,10 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info: result.filePath = toFullPath(g.config, infox) result.line = toLinenumber(infox) result.column = toColumn(infox) - if section in {ideHighlight}: - result.tokenLen = getTokenLenFromSource(g.config, s.name.s, infox) - else: - result.tokenLen = s.name.s.len + result.tokenLen = if section != ideHighlight: + s.name.s.len + else: + getTokenLenFromSource(g.config, s.name.s, infox) proc `$`*(suggest: Suggest): string = result = $suggest.section From 5c05240016c93c0f3a9e59d8e84a3d2640ea3412 Mon Sep 17 00:00:00 2001 From: Bung Date: Thu, 21 Sep 2023 07:59:17 +0800 Subject: [PATCH 3/3] 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 660e6b0419a..0a0e8e2ebb5 100644 --- a/compiler/tools/suggest.nim +++ b/compiler/tools/suggest.nim @@ -193,7 +193,7 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info: else: result.forth = "" when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler): - if section in {ideSug, ideCon, ideDef, ideChk}: + if section != ideHighlight: result.doc = extractDocComment(g, s) let infox = if useSuppliedInfo or section in {ideUse, ideHighlight, ideOutline}: