Skip to content

Commit afdbdc8

Browse files
committed
Fix inlay hints for real
1 parent 69e2423 commit afdbdc8

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/operations/InlayHints.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,20 @@ struct InlayHintVisitor : public Luau::AstVisitor
9393
// Parameter types hint
9494
if (config.inlayHints.parameterTypes)
9595
{
96-
size_t idx = 0;
97-
for (auto argType : ftv->argTypes)
96+
auto it = Luau::begin(ftv->argTypes);
97+
if (it == Luau::end(ftv->argTypes))
98+
return true;
99+
100+
// Skip first item if it is self
101+
if (ftv->hasSelf)
102+
it++;
103+
104+
for (auto param : func->args)
98105
{
99-
if (func->args.size <= idx)
106+
if (it == Luau::end(ftv->argTypes))
100107
break;
101108

102-
auto param = func->args.data[idx];
109+
auto argType = *it;
103110
if (!param->annotation)
104111
{
105112
lsp::InlayHint hint;
@@ -109,7 +116,8 @@ struct InlayHintVisitor : public Luau::AstVisitor
109116
makeInsertable(hint, argType);
110117
hints.emplace_back(hint);
111118
}
112-
idx++;
119+
120+
it++;
113121
}
114122
}
115123

@@ -143,37 +151,49 @@ struct InlayHintVisitor : public Luau::AstVisitor
143151
auto followedTy = Luau::follow(*ty);
144152
if (auto ftv = Luau::get<Luau::FunctionTypeVar>(followedTy))
145153
{
154+
if (ftv->argNames.size() == 0)
155+
return true;
156+
146157
auto namesIt = ftv->argNames.begin();
147158
auto idx = 0;
148159
for (auto param : call->args)
149160
{
150161
// Skip first item if it is self
151162
if (idx == 0 && ftv->hasSelf && call->self)
152-
continue;
163+
namesIt++;
153164

154165
if (namesIt == ftv->argNames.end())
155166
break;
167+
156168
if (!namesIt->has_value())
169+
{
170+
namesIt++;
171+
idx++;
157172
continue;
173+
}
158174

175+
auto createHint = true;
159176
auto paramName = (*namesIt)->name;
160177
if (!isLiteral(param))
161178
{
162179
if (config.inlayHints.parameterNames == InlayHintsParameterNamesConfig::Literals)
163-
continue;
180+
createHint = false;
164181

165182
// If the name somewhat matches the arg name, we can skip the inlay hint
166183
if (Luau::equalsLower(Luau::toString(param), paramName))
167-
continue;
184+
createHint = false;
168185
}
169186

170187
// TODO: only apply in specific situations
171-
lsp::InlayHint hint;
172-
hint.kind = lsp::InlayHintKind::Parameter;
173-
hint.label = paramName + ":";
174-
hint.position = convertPosition(param->location.begin);
175-
hint.paddingRight = true;
176-
hints.emplace_back(hint);
188+
if (createHint)
189+
{
190+
lsp::InlayHint hint;
191+
hint.kind = lsp::InlayHintKind::Parameter;
192+
hint.label = paramName + ":";
193+
hint.position = convertPosition(param->location.begin);
194+
hint.paddingRight = true;
195+
hints.emplace_back(hint);
196+
}
177197

178198
namesIt++;
179199
idx++;

0 commit comments

Comments
 (0)