Skip to content

Commit fff127b

Browse files
authored
Skip trailing asterisk when placing inlay type hints. Fixes #23067 (backport of #23068) (#23070)
(cherry picked from commit a373975)
1 parent 7b5289a commit fff127b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

compiler/suggest.nim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ proc cmpSuggestions(a, b: Suggest): int =
8181
# independent of hashing order:
8282
result = cmp(a.name[], b.name[])
8383

84-
proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int =
84+
proc scanForTrailingAsterisk(line: string, start: int): int =
85+
result = 0
86+
while start+result < line.len and line[start+result] in {' ', '\t'}:
87+
inc result
88+
if start+result < line.len and line[start+result] == '*':
89+
inc result
90+
else:
91+
result = 0
92+
93+
proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo; skipTrailingAsterisk: bool = false): int =
8594
let
8695
line = sourceLine(conf, info)
8796
column = toColumn(info)
@@ -105,6 +114,8 @@ proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int
105114
result = identLen(line, column)
106115
if cmpIgnoreStyle(line[column..column + result - 1], ident[0..min(result-1,len(ident)-1)]) != 0:
107116
result = 0
117+
if skipTrailingAsterisk and result > 0:
118+
result += scanForTrailingAsterisk(line, column + result)
108119
else:
109120
var sourceIdent: string
110121
result = parseWhile(line, sourceIdent,
@@ -179,7 +190,7 @@ proc symToSuggest*(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info
179190
result.tokenLen = if section notin {ideHighlight, ideInlayHints}:
180191
s.name.s.len
181192
else:
182-
getTokenLenFromSource(g.config, s.name.s, infox)
193+
getTokenLenFromSource(g.config, s.name.s, infox, section == ideInlayHints)
183194
result.version = g.config.suggestVersion
184195
result.endLine = endLine
185196
result.endCol = endCol

0 commit comments

Comments
 (0)