Skip to content

Commit

Permalink
Support object property name completions in lambda body syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Jan 10, 2025
1 parent 74c4ce3 commit 2d74969
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
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("/main.bicep", 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

0 comments on commit 2d74969

Please sign in to comment.