compiler/suggest: highlight squashed operators (#11796)

The operator fetching proc is greedy, so operators such as `%*` in
expression `%*{}` can't be highlighted.

This commit fixes that.
This commit is contained in:
alaviss 2020-04-20 09:54:53 +00:00 • committed by GitHub
commit 77834f0fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View file

@ -106,11 +106,15 @@ proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int
if cmpIgnoreStyle(line[column..column + result - 1], ident) != 0: if cmpIgnoreStyle(line[column..column + result - 1], ident) != 0:
result = 0 result = 0
else: else:
result = skipWhile(line, OpChars + {'[', '(', '{', ']', ')', '}'}, column) var sourceIdent: string
result = parseWhile(line, sourceIdent,
OpChars + {'[', '(', '{', ']', ')', '}'}, column)
if ident[^1] == '=' and ident[0] in linter.Letters: if ident[^1] == '=' and ident[0] in linter.Letters:
if line[column..column + result - 1] != "=": if sourceIdent != "=":
result = 0 result = 0
elif line[column..column + result - 1] != ident: elif sourceIdent.len > ident.len and sourceIdent[..ident.high] == ident:
result = ident.len
elif sourceIdent != ident:
result = 0 result = 0
proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info: TLineInfo; proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info: TLineInfo;

View file

@ -0,0 +1,11 @@
import json
%*{}#[!]#
discard """
$nimsuggest --tester $file
>highlight $1
highlight;;skModule;;1;;7;;4
highlight;;skMacro;;3;;0;;2
highlight;;skMacro;;3;;0;;2
"""