Skip to content

Commit 9e8cf33

Browse files
committed
Show auto-imports in array-like tables
Closes #1062
1 parent 9c8d58e commit 9e8cf33

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

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

2323
- Fixed auto-indentation in VSCode when entering a block if there is a comment after the introduction token (e.g., `if true then -- comment`) ([#1222](https://github.com/JohnnyMorganz/luau-lsp/issues/1222))
24+
- Fixed auto-imports not showing up when autocompleting in array-like tables (i.e., before the `=` sign has been written for a property) ([#1062](https://github.com/JohnnyMorganz/luau-lsp/issues/1062))
2425

2526
## [1.55.0] - 2025-10-19
2627

src/operations/Completion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ std::vector<lsp::CompletionItem> WorkspaceFolder::completion(const lsp::Completi
761761

762762
if (config.completion.suggestImports || config.completion.imports.enabled)
763763
{
764-
if (result.context == Luau::AutocompleteContext::Expression || result.context == Luau::AutocompleteContext::Statement)
764+
if (result.context == Luau::AutocompleteContext::Expression || result.context == Luau::AutocompleteContext::Statement ||
765+
result.context == Luau::AutocompleteContext::Property)
765766
{
766767
suggestImports(moduleName, position, config, *textDocument, items, /* completingTypeReferencePrefix: */ false);
767768
}

tests/AutoImports.test.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,4 +1449,42 @@ TEST_CASE_FIXTURE(Fixture, "auto_import_empty_require_statement")
14491449
CHECK_EQ(item->additionalTextEdits[0].range.start.line, 1);
14501450
}
14511451

1452+
TEST_CASE_FIXTURE(Fixture, "auto_imports_shows_up_in_tables_before_equals_sign")
1453+
{
1454+
client->globalConfig.completion.imports.enabled = true;
1455+
auto [source, marker] = sourceWithMarker(R"(
1456+
create({
1457+
|
1458+
})
1459+
)");
1460+
1461+
auto uri = newDocument("foo.luau", source);
1462+
1463+
lsp::CompletionParams params;
1464+
params.textDocument = lsp::TextDocumentIdentifier{uri};
1465+
params.position = marker;
1466+
1467+
auto result = workspace.completion(params, nullptr);
1468+
CHECK(getItem(result, "ReplicatedStorage"));
1469+
}
1470+
1471+
TEST_CASE_FIXTURE(Fixture, "auto_imports_shows_up_in_tables_after_equals_sign")
1472+
{
1473+
client->globalConfig.completion.imports.enabled = true;
1474+
auto [source, marker] = sourceWithMarker(R"(
1475+
create({
1476+
Key = |
1477+
})
1478+
)");
1479+
1480+
auto uri = newDocument("foo.luau", source);
1481+
1482+
lsp::CompletionParams params;
1483+
params.textDocument = lsp::TextDocumentIdentifier{uri};
1484+
params.position = marker;
1485+
1486+
auto result = workspace.completion(params, nullptr);
1487+
CHECK(getItem(result, "ReplicatedStorage"));
1488+
}
1489+
14521490
TEST_SUITE_END();

0 commit comments

Comments
 (0)