diff options
author | Nikolay Nikolov <nickysn@gmail.com> | 2023-12-13 22:13:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 21:13:36 +0100 |
commit | a3739751a8439908624815b02d8242515cb5e178 (patch) | |
tree | f6838bdecab307e9963e25d86df8e584dabc4033 /compiler/suggest.nim | |
parent | cd4ecddb30a64f5d2c3c6fdde955366c7976577f (diff) | |
download | Nim-a3739751a8439908624815b02d8242515cb5e178.tar.gz |
Skip trailing asterisk when placing inlay type hints. Fixes #23067 (#23068)
Diffstat (limited to 'compiler/suggest.nim')
-rw-r--r-- | compiler/suggest.nim | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 4f90fe00b..9e0fc13e4 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -85,7 +85,16 @@ proc cmpSuggestions(a, b: Suggest): int = # independent of hashing order: result = cmp(a.name[], b.name[]) -proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int = +proc scanForTrailingAsterisk(line: string, start: int): int = + result = 0 + while start+result < line.len and line[start+result] in {' ', '\t'}: + inc result + if start+result < line.len and line[start+result] == '*': + inc result + else: + result = 0 + +proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo; skipTrailingAsterisk: bool = false): int = let line = sourceLine(conf, info) column = toColumn(info) @@ -109,6 +118,8 @@ proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int result = identLen(line, column) if cmpIgnoreStyle(line[column..column + result - 1], ident[0..min(result-1,len(ident)-1)]) != 0: result = 0 + if skipTrailingAsterisk and result > 0: + result += scanForTrailingAsterisk(line, column + result) else: var sourceIdent: string = "" result = parseWhile(line, sourceIdent, @@ -184,7 +195,7 @@ proc symToSuggest*(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info result.tokenLen = if section notin {ideHighlight, ideInlayHints}: s.name.s.len else: - getTokenLenFromSource(g.config, s.name.s, infox) + getTokenLenFromSource(g.config, s.name.s, infox, section == ideInlayHints) result.version = g.config.suggestVersion result.endLine = endLine result.endCol = endCol |