Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support object property name completions in lambda body syntax #16055

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Bicep.Core/TypeSystem/DeclaredTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,14 @@ AccessExpressionSyntax access when access.BaseExpression is ForSyntax
var type = TypeHelper.MakeRequiredPropertiesOptional(enclosingObjectType);

return TryCreateAssignment(type, syntax);

case TypedLambdaSyntax lambda when binder.IsEqualOrDescendent(syntax, lambda.Body):
if (GetTypedLambdaType(lambda).Reference is not LambdaType lambdaType)
{
return null;
}

return TryCreateAssignment(lambdaType.ReturnType, syntax);
}

return null;
Expand Down
30 changes: 30 additions & 0 deletions src/Bicep.LangServer.IntegrationTests/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5204,5 +5204,35 @@ public async Task String_literal_union_with_object_value_should_not_cause_stack_
var completions = await mainFile.RequestCompletion(cursor);
completions.Should().BeEmpty();
}

[TestMethod]
// https://github.com/azure/bicep/issues/14429
public async Task Lambda_output_type_completions_are_offered()
{
var serverHelper = new ServerRequestHelper(TestContext, DefaultServer);

var (text, cursor) = ParserHelper.GetFileWithSingleCursor("""
type fooType = {
bar: 'bar'
}

func fooFunc() fooType => {
|
}
""");
var mainFile = await serverHelper.OpenFile(text);

var newFile = await mainFile.RequestAndApplyCompletion(cursor, "bar");

newFile.Should().HaveSourceText("""
type fooType = {
bar: 'bar'
}

func fooFunc() fooType => {
bar:|
}
""");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public BicepFile ApplyCompletion(CompletionItem completion, params string[] tabS
return SourceFileFactory.CreateBicepFile(bicepFile.Uri, replaced);
}

public async Task<BicepFile> RequestAndApplyCompletion(int cursor, string label)
{
var completionList = await RequestCompletion(cursor);
var completion = completionList.Should().ContainSingle(x => x.Label == label).Subject;

return ApplyCompletion(completion);
}

public BicepFile ApplyWorkspaceEdit(WorkspaceEdit? edit)
{
// not yet supported by this logic
Expand Down
Loading