Skip to content

Commit

Permalink
10346 br/alias completions to top level (Azure#11381)
Browse files Browse the repository at this point in the history
Fixes Azure#10346
###### Microsoft Reviewers:
codeflow:open?pullrequest=https://github.com/Azure/bicep/pull/11381&drop=dogfoodAlpha

---------

Co-authored-by: Bicep Automation <[email protected]>
Co-authored-by: Stephen Weatherford <Stephen.Weatherford.com>
  • Loading branch information
StephenWeatherford and Bicep Automation committed Jul 31, 2023
1 parent 8d65280 commit 7c4bfda
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@
}
},
{
"label": "br/",
"label": "br/public:",
"kind": "reference",
"detail": "Bicep registry (alias)",
"detail": "Public Bicep registry",
"deprecated": false,
"preselect": false,
"sortText": "90_br/",
"filterText": "'br/$0'",
"sortText": "90_br/public:",
"filterText": "'br/public:$0'",
"insertTextFormat": "snippet",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "'br/$0'"
"newText": "'br/public:$0'"
}
},
{
Expand Down Expand Up @@ -293,6 +293,21 @@
"newText": "'subscription_empty.bicep'"
}
},
{
"label": "ts/",
"kind": "reference",
"detail": "Template spec (alias)",
"deprecated": false,
"preselect": false,
"sortText": "90_ts/",
"filterText": "'ts/$0'",
"insertTextFormat": "snippet",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "'ts/$0'"
}
},
{
"label": "ts:",
"kind": "reference",
Expand Down
2 changes: 2 additions & 0 deletions src/Bicep.Core/LanguageConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static class LanguageConstants
public const string JsoncFileExtension = ".jsonc";
public const string ArmTemplateFileExtension = ".arm";

public const string BicepPublicMcrRegistry = "mcr.microsoft.com";

public const int MaxParameterCount = 256;
public const int MaxIdentifierLength = 255;
public const int MaxLiteralCharacterLimit = 131072;
Expand Down
6 changes: 2 additions & 4 deletions src/Bicep.Core/Registry/OciModuleRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public sealed class OciModuleRegistry : ExternalModuleRegistry<OciArtifactModule

private readonly RootConfiguration configuration;

private readonly Uri parentModuleUri;

private const string BicepPublicMcrRegistry = "mcr.microsoft.com";
private readonly Uri parentModuleUri;

public OciModuleRegistry(IFileResolver FileResolver, IContainerRegistryClientFactory clientFactory, IFeatureProvider features, RootConfiguration configuration, Uri parentModuleUri)
: base(FileResolver)
Expand Down Expand Up @@ -130,7 +128,7 @@ public override bool TryGetLocalModuleEntryPointUri(OciArtifactModuleReference r
|| string.IsNullOrWhiteSpace(documentationUri))
{
// Automatically generate a help URI for public MCR modules
if (ociArtifactModuleReference.Registry == BicepPublicMcrRegistry && ociArtifactModuleReference.Repository.StartsWith(LanguageConstants.McrRepositoryPrefix, StringComparison.Ordinal))
if (ociArtifactModuleReference.Registry == LanguageConstants.BicepPublicMcrRegistry && ociArtifactModuleReference.Repository.StartsWith(LanguageConstants.McrRepositoryPrefix, StringComparison.Ordinal))
{
var moduleName = ociArtifactModuleReference.Repository.Substring(LanguageConstants.McrRepositoryPrefix.Length);
return ociArtifactModuleReference.Tag is null ? null : GetPublicBicepModuleDocumentationUri(moduleName, ociArtifactModuleReference.Tag);
Expand Down
3 changes: 2 additions & 1 deletion src/Bicep.LangServer.IntegrationTests/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,8 @@ public async Task ModuleCompletionsShouldNotBeUrlEscaped()
x => x.Label.Should().Be("percentage%file.bicep"),
x => x.Label.Should().Be("../"),
x => x.Label.Should().Be("folder with space/"),
x => x.Label.Should().Be("br/"),
x => x.Label.Should().Be("br/public:"),
x => x.Label.Should().Be("ts/"),
x => x.Label.Should().Be("br:"),
x => x.Label.Should().Be("ts:")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ModuleReferenceCompletionProviderTests
private static IPublicRegistryModuleMetadataProvider publicRegistryModuleMetadataProvider = StrictMock.Of<IPublicRegistryModuleMetadataProvider>().Object;
private ISettingsProvider settingsProvider = StrictMock.Of<ISettingsProvider>().Object;

// TODO: We need improved assertions for all the completion item tests

[DataTestMethod]
[DataRow("module test |''", 14)]
[DataRow("module test ''|", 14)]
Expand All @@ -54,7 +56,19 @@ public async Task GetFilteredCompletions_WithBicepRegistryAndTemplateSpecShemaCo
BicepTestConstants.CreateMockTelemetryProvider().Object);
var completions = await moduleReferenceCompletionProvider.GetFilteredCompletions(documentUri.ToUri(), completionContext, CancellationToken.None);

completions.Count().Should().Be(3);
completions.Count().Should().Be(4);

completions.Should().Contain(
c => c.Label == "br/public:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Public Bicep registry" &&
c.TextEdit!.TextEdit!.NewText == "'br/public:$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
c.TextEdit.TextEdit.Range.End.Character == expectedEnd);

completions.Should().Contain(
c => c.Label == "br:" &&
Expand All @@ -69,12 +83,12 @@ public async Task GetFilteredCompletions_WithBicepRegistryAndTemplateSpecShemaCo
c.TextEdit.TextEdit.Range.End.Character == expectedEnd);

completions.Should().Contain(
c => c.Label == "br/" &&
c => c.Label == "ts/" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Bicep registry (alias)" &&
c.TextEdit!.TextEdit!.NewText == "'br/$0'" &&
c.Detail == "Template spec (alias)" &&
c.TextEdit!.TextEdit!.NewText == "'ts/$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
Expand Down Expand Up @@ -121,55 +135,59 @@ public async Task GetFilteredCompletions_WithBicepRegistryAndTemplateSpecShemaCo
BicepTestConstants.CreateMockTelemetryProvider().Object);
var completions = await moduleReferenceCompletionProvider.GetFilteredCompletions(documentUri.ToUri(), completionContext, CancellationToken.None);

completions.Count().Should().Be(4);
completions.Count().Should().Be(5);

foreach ( var c in completions) {
c.Label.Should().MatchRegex("^(.*/)|(.*:)$");
c.Kind.Should().Be(CompletionItemKind.Reference);
c.InsertTextFormat.Should().Be(InsertTextFormat.Snippet);
c.InsertText.Should().BeNull();
c.TextEdit!.TextEdit!.NewText.Should().MatchRegex("^'.*\\$0'$");
c.TextEdit.TextEdit.Range.Start.Line.Should().Be(0);
c.TextEdit.TextEdit.Range.Start.Character.Should().Be(12);
c.TextEdit.TextEdit.Range.End.Line.Should().Be(0);
c.TextEdit.TextEdit.Range.End.Character.Should().Be(14);
}

completions.Should().Contain(
c => c.Label == "br:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Bicep registry" &&
c.TextEdit!.TextEdit!.NewText == "'br:$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
c.TextEdit.TextEdit.Range.End.Character == 14);
c.TextEdit!.TextEdit!.NewText == "'br:$0'");

completions.Should().Contain(
c => c.Label == "br/" &&
c => c.Label == "br/test:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Bicep registry (alias)" &&
c.TextEdit!.TextEdit!.NewText == "'br/$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
c.TextEdit.TextEdit.Range.End.Character == 14);
c.Detail == "Alias for br:testacr.azurecr.io/bicep/modules/" &&
c.TextEdit!.TextEdit!.NewText == "'br/test:$0'");

completions.Should().Contain(
c => c.Label == "br/public:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Public Bicep registry" &&
c.TextEdit!.TextEdit!.NewText == "'br/public:$0'");

completions.Should().Contain(
c => c.Label == "ts:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Template spec" &&
c.TextEdit!.TextEdit!.NewText == "'ts:$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
c.TextEdit.TextEdit.Range.End.Character == 14);
c.TextEdit!.TextEdit!.NewText == "'ts:$0'");

completions.Should().Contain(
c => c.Label == "ts/" &&
c => c.Label == "ts/mySpecRG:" &&
c.Kind == CompletionItemKind.Reference &&
c.InsertTextFormat == InsertTextFormat.Snippet &&
c.InsertText == null &&
c.Detail == "Template spec (alias)" &&
c.TextEdit!.TextEdit!.NewText == "'ts/$0'" &&
c.TextEdit.TextEdit.Range.Start.Line == 0 &&
c.TextEdit.TextEdit.Range.Start.Character == 12 &&
c.TextEdit.TextEdit.Range.End.Line == 0 &&
c.TextEdit.TextEdit.Range.End.Character == 14);
c.Detail == "Template spec" &&
c.TextEdit!.TextEdit!.NewText == "'ts/mySpecRG:$0'");
}

[TestMethod]
Expand Down Expand Up @@ -541,7 +559,7 @@ public async Task GetFilteredCompletions_WithPathCompletionContext_ReturnsComple

completions.Should().Contain(
x => x.Label == expectedLabel &&
x.Kind == CompletionItemKind.Snippet &&
x.Kind == CompletionItemKind.Reference &&
x.InsertText == null &&
x.TextEdit!.TextEdit!.NewText == expectedCompletionText &&
x.TextEdit!.TextEdit!.Range.Start.Line == startLine &&
Expand Down Expand Up @@ -673,7 +691,7 @@ public async Task GetFilteredCompletions_WithPublicAliasOverriddenInBicepConfigA

completions.Should().Contain(
x => x.Label == expectedLabel &&
x.Kind == CompletionItemKind.Snippet &&
x.Kind == CompletionItemKind.Reference &&
x.InsertText == null &&
x.TextEdit!.TextEdit!.NewText == expectedCompletionText &&
x.TextEdit!.TextEdit!.Range.Start.Line == startLine &&
Expand Down
Loading

0 comments on commit 7c4bfda

Please sign in to comment.