Skip to content

Commit

Permalink
Snippet for resource/module conditions (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
majastrz authored Mar 13, 2021
1 parent 81c2e12 commit cf4e7ec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Bicep.Core.Samples/Files/Completions/object.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"newText": "[for (${2:item}, ${3:index}) in ${1:list}: {\n\t$0\n}]"
}
},
{
"label": "if",
"kind": "snippet",
"detail": "if",
"deprecated": false,
"preselect": false,
"sortText": "1_if",
"insertTextFormat": "snippet",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "if (${1:condition}) {\n\t$0\n}"
}
},
{
"label": "{}",
"kind": "value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"newText": "[for (${2:item}, ${3:index}) in ${1:list}: {\n\t$0\n}]"
}
},
{
"label": "if",
"kind": "snippet",
"detail": "if",
"deprecated": false,
"preselect": false,
"sortText": "1_if",
"insertTextFormat": "snippet",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "if (${1:condition}) {\n\t$0\n}"
}
},
{
"label": "{}",
"kind": "value",
Expand Down
12 changes: 12 additions & 0 deletions src/Bicep.LangServer/Completions/BicepCompletionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ private IEnumerable<CompletionItem> GetResourceOrModuleBodyCompletions(BicepComp
{
yield return CreateObjectBodyCompletion(context.ReplacementRange);

yield return CreateResourceOrModuleConditionCompletion(context.ReplacementRange);

// loops are always allowed in a resource/module
foreach (var completion in CreateLoopCompletions(context.ReplacementRange, LanguageConstants.Object))
{
Expand Down Expand Up @@ -676,6 +678,16 @@ private static CompletionItem CreateObjectBodyCompletion(Range replacementRange)
.WithSortText(GetSortText(objectLabel, CompletionPriority.High));
}

private static CompletionItem CreateResourceOrModuleConditionCompletion(Range replacementRange)
{
const string conditionLabel = "if";
return CompletionItemBuilder.Create(CompletionItemKind.Snippet)
.WithLabel(conditionLabel)
.WithSnippetEdit(replacementRange, "if (${1:condition}) {\n\t$0\n}", InsertTextMode.AdjustIndentation)
.WithDetail(conditionLabel)
.WithSortText(GetSortText(conditionLabel, CompletionPriority.High));
}

private static IEnumerable<CompletionItem> CreateLoopCompletions(Range replacementRange, TypeSymbol arrayItemType)
{
const string loopLabel = "for";
Expand Down

0 comments on commit cf4e7ec

Please sign in to comment.