Skip to content

Commit 77a307e

Browse files
committed
Prioritise contextual keywords over other autocomplete entries
1 parent c81106e commit 77a307e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1414

1515
- Sync to upstream Luau 0.698
1616
- Table properties are now prioritised above other autocomplete entries (again, fixing a dormant bug)
17+
- Contextual keywords (`else` / `elseif` / `end`) are prioritised over other autocomplete entries when inside of the relevant statement
1718

1819
### Fixed
1920

src/operations/Completion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ static const char* sortText(const Luau::Frontend& frontend, const std::string& n
325325
else if (entry.kind == Luau::AutocompleteEntryKind::Property)
326326
return SortText::TableProperties;
327327
else if (entry.kind == Luau::AutocompleteEntryKind::Keyword)
328+
{
329+
// These keywords are contextual and only show up when relevant - they should be prioritised over other suggestions
330+
if (name == "else" || name == "elseif" || name == "until" || name == "end")
331+
return SortText::PrioritisedSuggestion;
328332
return SortText::Keywords;
333+
}
329334
else if (entry.typeCorrect == Luau::TypeCorrectKind::Correct)
330335
return SortText::CorrectTypeKind;
331336
else if (entry.typeCorrect == Luau::TypeCorrectKind::CorrectFunctionResult)

tests/Autocomplete.test.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,4 +1804,29 @@ TEST_CASE_FIXTURE(Fixture, "prioritise_properties_when_sorting_autocomplete_in_t
18041804
}
18051805
}
18061806

1807+
TEST_CASE_FIXTURE(Fixture, "prioritise_relevant_keywords_when_inside_of_if")
1808+
{
1809+
ScopedFastFlag sff{FFlag::LuauSolverV2, true};
1810+
1811+
auto [source, marker] = sourceWithMarker(R"(
1812+
if true then
1813+
|
1814+
)");
1815+
1816+
auto uri = newDocument("foo.luau", source);
1817+
1818+
lsp::CompletionParams params;
1819+
params.textDocument = lsp::TextDocumentIdentifier{uri};
1820+
params.position = marker;
1821+
1822+
auto result = workspace.completion(params, nullptr);
1823+
1824+
for (const auto property : {"else", "elseif", "end"})
1825+
{
1826+
auto entry = getItem(result, property);
1827+
REQUIRE(entry);
1828+
CHECK_EQ(entry->sortText, SortText::PrioritisedSuggestion);
1829+
}
1830+
}
1831+
18071832
TEST_SUITE_END();

0 commit comments

Comments
 (0)