mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Fix nimsuggest highlight for import statements (#23263)
Currently, I don't have syntax highlighting (+ no/wrong
jump-to-definition) for some import statement forms, namely:
- `import module/name/with/(slashes)`
- `import (mod) as alias`
- `import basemod/[ (sub1), (sub2) ]`
With this patch, highlight/def will work for the regions indicated by
parentheses.
(cherry picked from commit 15577043e8)
This commit is contained in:
@@ -304,7 +304,15 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym =
|
||||
var prefix = ""
|
||||
if realModule.constraint != nil: prefix = realModule.constraint.strVal & "; "
|
||||
message(c.config, n.info, warnDeprecated, prefix & realModule.name.s & " is deprecated")
|
||||
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)
|
||||
|
||||
|
||||
12
nimsuggest/tests/timport_highlight.nim
Normal file
12
nimsuggest/tests/timport_highlight.nim
Normal file
@@ -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
|
||||
"""
|
||||
Reference in New Issue
Block a user