Skip to content

Commit c81106e

Browse files
committed
Prioritise table properties over other autocomplete entries
1 parent 853fb8d commit c81106e

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

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

1515
- Sync to upstream Luau 0.698
16+
- Table properties are now prioritised above other autocomplete entries (again, fixing a dormant bug)
1617

1718
### Fixed
1819

src/operations/Completion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,16 @@ static const char* sortText(const Luau::Frontend& frontend, const std::string& n
320320

321321
if (entry.wrongIndexType)
322322
return SortText::WrongIndexType;
323-
if (entry.typeCorrect == Luau::TypeCorrectKind::Correct)
324-
return SortText::CorrectTypeKind;
325-
else if (entry.typeCorrect == Luau::TypeCorrectKind::CorrectFunctionResult)
326-
return SortText::CorrectFunctionResult;
327323
else if (entry.kind == Luau::AutocompleteEntryKind::Property && types::isMetamethod(name))
328324
return SortText::MetatableIndex;
329325
else if (entry.kind == Luau::AutocompleteEntryKind::Property)
330326
return SortText::TableProperties;
331327
else if (entry.kind == Luau::AutocompleteEntryKind::Keyword)
332328
return SortText::Keywords;
329+
else if (entry.typeCorrect == Luau::TypeCorrectKind::Correct)
330+
return SortText::CorrectTypeKind;
331+
else if (entry.typeCorrect == Luau::TypeCorrectKind::CorrectFunctionResult)
332+
return SortText::CorrectFunctionResult;
333333

334334
return SortText::Default;
335335
}

tests/Autocomplete.test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ScopedFlags.h"
55
#include "Platform/RobloxPlatform.hpp"
66
#include "LSP/IostreamHelpers.hpp"
7+
#include "LSP/Completion.hpp"
78

89
std::optional<lsp::CompletionItem> getItem(const std::vector<lsp::CompletionItem>& items, const std::string& label)
910
{
@@ -1769,4 +1770,38 @@ TEST_CASE_FIXTURE(Fixture, "autocomplete_label_does_not_show_hidden_variadics")
17691770
CHECK_EQ(func->labelDetails->detail, "(path)");
17701771
}
17711772

1773+
TEST_CASE_FIXTURE(Fixture, "prioritise_properties_when_sorting_autocomplete_in_table")
1774+
{
1775+
ScopedFastFlag sff{FFlag::LuauSolverV2, true};
1776+
1777+
auto [source, marker] = sourceWithMarker(R"(
1778+
type Options = {
1779+
name: string,
1780+
description: string,
1781+
label: string
1782+
}
1783+
local function create(options: Options)
1784+
end
1785+
1786+
create({
1787+
|
1788+
})
1789+
)");
1790+
1791+
auto uri = newDocument("foo.luau", source);
1792+
1793+
lsp::CompletionParams params;
1794+
params.textDocument = lsp::TextDocumentIdentifier{uri};
1795+
params.position = marker;
1796+
1797+
auto result = workspace.completion(params, nullptr);
1798+
1799+
for (const auto property : {"name", "description", "label"})
1800+
{
1801+
auto entry = getItem(result, property);
1802+
REQUIRE(entry);
1803+
CHECK_EQ(entry->sortText, SortText::TableProperties);
1804+
}
1805+
}
1806+
17721807
TEST_SUITE_END();

0 commit comments

Comments
 (0)