Skip to content

Commit

Permalink
Fix GetPropertyChangedSignal showing children in autocomplete
Browse files Browse the repository at this point in the history
We forgot to attach the @sourcemap-generated tag to children types
created in "getSourcemapType"

Fixes #699
  • Loading branch information
JohnnyMorganz committed Jul 20, 2024
1 parent d807235 commit 0cfed81
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fixed `:FindFirstChild()` not supporting a boolean "recursive" 2nd parameter on DataModel types ([#704](https://github.com/JohnnyMorganz/luau-lsp/issues/704))
- Fixed `:WaitForChild()` not supporting a number "timeout" 2nd parameter on DataModel types ([#704](https://github.com/JohnnyMorganz/luau-lsp/issues/704))
- Fixed inlay hint off-by-one on a function definition with an explicit self (i.e., `function Class.foo(self, param)`) ([#702](https://github.com/JohnnyMorganz/luau-lsp/issues/702))
- Fixed `:GetPropertyChangedSignal()` still showing children in autocomplete for DataModel types ([#699](https://github.com/JohnnyMorganz/luau-lsp/issues/699))

## [1.32.0] - 2024-07-14

Expand Down
9 changes: 8 additions & 1 deletion src/platform/roblox/RobloxSourcemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ static Luau::TypeId getSourcemapType(const Luau::GlobalTypes& globals, Luau::Typ

// Add children as properties
for (const auto& child : node->children)
ctv->props[child->name] = Luau::makeProperty(getSourcemapType(globals, arena, child));
ctv->props[child->name] = ctv->props[child->name] = Luau::Property{
getSourcemapType(globals, arena, child),
/* deprecated */ false,
/* deprecatedSuggestion */ {},
/* location */ std::nullopt,
/* tags */ {kSourcemapGeneratedTag},
/* documentationSymbol*/ std::nullopt,
};

// Add FindFirstAncestor and FindFirstChild
if (auto instanceType = getTypeIdForClass(globals.globalScope, "Instance"))
Expand Down
35 changes: 35 additions & 0 deletions tests/Autocomplete.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,41 @@ TEST_CASE_FIXTURE(Fixture, "get_property_changed_signal_does_not_include_childre
checkStringCompletionExists(result, "ClassName");
}

TEST_CASE_FIXTURE(Fixture, "get_property_changed_signal_does_not_include_children_from_sourcemap_second_level_getsourcemaptype_ty")
{
loadSourcemap(R"(
{
"name": "Game",
"className": "DataModel",
"children": [
{
"name": "ReplicatedStorage",
"className": "ReplicatedStorage",
"children": [{"name": "Part", "className": "Part"}]
}
]
})");

auto [source, marker] = sourceWithMarker(R"(
--!strict
game.ReplicatedStorage:GetPropertyChangedSignal("|")
)");

auto uri = newDocument("foo.luau", source);

lsp::CompletionParams params;
params.textDocument = lsp::TextDocumentIdentifier{uri};
params.position = marker;

auto result = workspace.completion(params);

CHECK_EQ(result.size(), 3);
CHECK_EQ(getItem(result, "Part"), std::nullopt);
checkStringCompletionExists(result, "Name");
checkStringCompletionExists(result, "Parent");
checkStringCompletionExists(result, "ClassName");
}

TEST_CASE_FIXTURE(Fixture, "find_first_child_on_datamodel_contains_children")
{
loadSourcemap(R"(
Expand Down

0 comments on commit 0cfed81

Please sign in to comment.