@@ -27,15 +27,17 @@ LUAU_FASTFLAG(LuauSolverV2)
2727LUAU_FASTINT (LuauTypeInferIterationLimit)
2828LUAU_FASTINT (LuauTypeInferRecursionLimit)
2929LUAU_FASTFLAGVARIABLE (DebugLuauMagicVariableNames)
30- LUAU_FASTFLAG (LuauImplicitTableIndexerKeys3)
3130LUAU_FASTFLAGVARIABLE (LuauIncludeBreakContinueStatements)
3231LUAU_FASTFLAGVARIABLE (LuauSuggestHotComments)
32+ LUAU_FASTFLAG (LuauAutocompleteAttributes)
3333
3434static constexpr std::array<std::string_view, 12 > kStatementStartingKeywords =
3535 {" while" , " if" , " local" , " repeat" , " function" , " do" , " for" , " return" , " break" , " continue" , " type" , " export" };
3636
3737static constexpr std::array<std::string_view, 6 > kHotComments = {" nolint" , " nocheck" , " nonstrict" , " strict" , " optimize" , " native" };
3838
39+ static const std::string kKnownAttributes [] = {" checked" , " deprecated" , " native" };
40+
3941namespace Luau
4042{
4143
@@ -582,39 +584,21 @@ static void autocompleteStringSingleton(TypeId ty, bool addQuotes, AstNode* node
582584
583585 ty = follow (ty);
584586
585- if (FFlag::LuauImplicitTableIndexerKeys3 )
587+ if (auto ss = get<StringSingleton>(get<SingletonType>(ty)) )
586588 {
587- if (auto ss = get<StringSingleton>(get<SingletonType>(ty)))
588- {
589- // This is purposefully `try_emplace` as we don't want to override any existing entries.
590- result.try_emplace (formatKey (ss->value ), AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct});
591- }
592- else if (auto uty = get<UnionType>(ty))
593- {
594- for (auto el : uty)
595- {
596- if (auto ss = get<StringSingleton>(get<SingletonType>(el)))
597- {
598- // This is purposefully `try_emplace` as we don't want to override any existing entries.
599- result.try_emplace (
600- formatKey (ss->value ), AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct}
601- );
602- }
603- }
604- }
589+ // This is purposefully `try_emplace` as we don't want to override any existing entries.
590+ result.try_emplace (formatKey (ss->value ), AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct});
605591 }
606- else
592+ else if ( auto uty = get<UnionType>(ty))
607593 {
608- if (auto ss = get<StringSingleton>(get<SingletonType>(ty)) )
594+ for (auto el : uty )
609595 {
610- result[formatKey (ss->value )] = AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct};
611- }
612- else if (auto uty = get<UnionType>(ty))
613- {
614- for (auto el : uty)
596+ if (auto ss = get<StringSingleton>(get<SingletonType>(el)))
615597 {
616- if (auto ss = get<StringSingleton>(get<SingletonType>(el)))
617- result[formatKey (ss->value )] = AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct};
598+ // This is purposefully `try_emplace` as we don't want to override any existing entries.
599+ result.try_emplace (
600+ formatKey (ss->value ), AutocompleteEntry{AutocompleteEntryKind::String, ty, false , false , TypeCorrectKind::Correct}
601+ );
618602 }
619603 }
620604 }
@@ -2105,12 +2089,6 @@ AutocompleteResult autocomplete_(
21052089 {
21062090 AutocompleteEntryMap result;
21072091
2108- if (!FFlag::LuauImplicitTableIndexerKeys3)
2109- {
2110- if (auto it = module ->astExpectedTypes .find (node->asExpr ()))
2111- autocompleteStringSingleton (*it, false , node, position, result);
2112- }
2113-
21142092 if (ancestry.size () >= 2 )
21152093 {
21162094 if (auto idxExpr = ancestry.at (ancestry.size () - 2 )->as <AstExprIndexExpr>())
@@ -2128,11 +2106,8 @@ AutocompleteResult autocomplete_(
21282106 }
21292107 }
21302108
2131- if (FFlag::LuauImplicitTableIndexerKeys3)
2132- {
2133- if (auto it = module ->astExpectedTypes .find (node->asExpr ()))
2134- autocompleteStringSingleton (*it, false , node, position, result);
2135- }
2109+ if (auto it = module ->astExpectedTypes .find (node->asExpr ()))
2110+ autocompleteStringSingleton (*it, false , node, position, result);
21362111
21372112 return {std::move (result), ancestry, AutocompleteContext::String};
21382113 }
@@ -2143,6 +2118,22 @@ AutocompleteResult autocomplete_(
21432118 AutocompleteEntryMap map;
21442119 return {std::move (map), ancestry, AutocompleteContext::String};
21452120 }
2121+ else if (AstExprFunction* func = node->as <AstExprFunction>())
2122+ {
2123+ if (FFlag::LuauAutocompleteAttributes)
2124+ {
2125+ for (AstAttr* attr : func->attributes )
2126+ {
2127+ if (attr->location .begin <= position && position <= attr->location .end && attr->type == AstAttr::Type::Unknown)
2128+ {
2129+ AutocompleteEntryMap ret;
2130+ for (const auto & attr : kKnownAttributes )
2131+ ret[attr.c_str ()] = {AutocompleteEntryKind::Keyword};
2132+ return {std::move (ret), std::move (ancestry), AutocompleteContext::Keyword};
2133+ }
2134+ }
2135+ }
2136+ }
21462137
21472138 if (node->is <AstExprConstantNumber>())
21482139 return {};
0 commit comments