From aa3f0c16d3dc8636e6c15ca822397310f1e9a06e Mon Sep 17 00:00:00 2001 From: Simon Werbeck Date: Sun, 28 Jan 2024 21:54:00 +0100 Subject: [PATCH] Fix nimsuggest highlight for import statements This fixes there being no syntax highlighting for the following import forms (highlighted region indicated by parentheses): - import module/name/with/(slashes) - import (mod) as alias - import basemod/[ (sub1), (sub2) ] --- compiler/importer.nim | 10 +++++++++- nimsuggest/tests/timport_highlight.nim | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 nimsuggest/tests/timport_highlight.nim diff --git a/compiler/importer.nim b/compiler/importer.nim index 57cbbb8475830..6d3cd6f93405f 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -307,7 +307,15 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym = if belongsToStdlib(c.graph, result) and not startsWith(moduleName, stdPrefix) and not startsWith(moduleName, "system/") and not startsWith(moduleName, "packages/"): message(c.config, n.info, warnStdPrefix, realModule.name.s) - suggestSym(c.graph, n.info, result, c.graph.usageSym, false) + + proc suggestMod(n: PNode; s: PSym) = + if n.kind == nkImportAs: + suggestMod(n[0], realModule) + elif n.kind == nkInfix: + suggestMod(n[2], s) + else: + suggestSym(c.graph, n.info, s, c.graph.usageSym, false) + suggestMod(n, result) importStmtResult.add newSymNode(result, n.info) #newStrNode(toFullPath(c.config, f), n.info) else: diff --git a/nimsuggest/tests/timport_highlight.nim b/nimsuggest/tests/timport_highlight.nim new file mode 100644 index 0000000000000..043f87d98fb6b --- /dev/null +++ b/nimsuggest/tests/timport_highlight.nim @@ -0,0 +1,12 @@ +import std/paths +import json as J +import std/[os,streams]#[!]# + +discard """ +$nimsuggest --tester $file +>highlight $1 +highlight;;skModule;;1;;11;;5 +highlight;;skModule;;2;;7;;4 +highlight;;skModule;;3;;12;;2 +highlight;;skModule;;3;;15;;7 +"""