コード例 #1
0
        public void DeclaringSymbolWithFunctionNameShouldHideTheFunctionCompletion()
        {
            var grouping = SyntaxTreeGroupingFactory.CreateFromText(@"
param concat string
var resourceGroup = true
resource base64 'Microsoft.Foo/foos@2020-09-01' = {
  name: 'foo'
}
output length int = 
");
            var offset   = grouping.EntryPoint.ProgramSyntax.Declarations.OfType <OutputDeclarationSyntax>().Single().Value.Span.Position;

            var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), grouping);
            var provider    = new BicepCompletionProvider(new FileResolver(), new SnippetsProvider(), new TelemetryProvider(Server));
            var context     = BicepCompletionContext.Create(compilation, offset);
            var completions = provider.GetFilteredCompletions(compilation, context).ToList();

            AssertExpectedFunctions(completions, expectParamDefaultFunctions: false, new[] { "sys.concat", "az.resourceGroup", "sys.base64" });

            // outputs can't be referenced so they should not show up in completions
            completions.Where(c => c.Kind == SymbolKind.Output.ToCompletionItemKind()).Should().BeEmpty();

            const string expectedVariable   = "resourceGroup";
            var          variableCompletion = completions.Single(c => c.Kind == SymbolKind.Variable.ToCompletionItemKind());

            variableCompletion.Label.Should().Be(expectedVariable);
            variableCompletion.Kind.Should().Be(CompletionItemKind.Variable);
            variableCompletion.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
            variableCompletion.TextEdit !.TextEdit !.NewText.Should().Be(expectedVariable);
            variableCompletion.CommitCharacters.Should().BeNull();
            variableCompletion.Detail.Should().Be(expectedVariable);

            const string expectedResource   = "base64";
            var          resourceCompletion = completions.Single(c => c.Kind == SymbolKind.Resource.ToCompletionItemKind());

            resourceCompletion.Label.Should().Be(expectedResource);
            resourceCompletion.Kind.Should().Be(CompletionItemKind.Interface);
            resourceCompletion.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
            resourceCompletion.TextEdit !.TextEdit !.NewText.Should().Be(expectedResource);
            resourceCompletion.CommitCharacters.Should().BeEquivalentTo(new [] { ":", });
            resourceCompletion.Detail.Should().Be(expectedResource);

            const string expectedParam   = "concat";
            var          paramCompletion = completions.Single(c => c.Kind == SymbolKind.Parameter.ToCompletionItemKind());

            paramCompletion.Label.Should().Be(expectedParam);
            paramCompletion.Kind.Should().Be(CompletionItemKind.Field);
            paramCompletion.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
            paramCompletion.TextEdit !.TextEdit !.NewText.Should().Be(expectedParam);
            paramCompletion.CommitCharacters.Should().BeNull();
            paramCompletion.Detail.Should().Be(expectedParam);
        }
コード例 #2
0
            static void AssertExistingKeywordCompletion(CompletionItem item)
            {
                item.Label.Should().Be("existing");
                item.Detail.Should().Be("existing");
                item.Documentation.Should().BeNull();
                item.Kind.Should().Be(CompletionItemKind.Keyword);
                item.Preselect.Should().BeFalse();
                item.TextEdit !.NewText.Should().Be("existing");

                // do not add = to the list of commit chars
                // it makes it difficult to type = without the "existing" keyword :)
                item.CommitCharacters.Should().BeNull();
            }
コード例 #3
0
 private static void AssertExpectedDeclarationTypeCompletions(List <CompletionItem> completions)
 {
     completions.Should().SatisfyRespectively(
         c =>
     {
         const string expected = "array";
         c.Label.Should().Be(expected);
         c.Kind.Should().Be(CompletionItemKind.Class);
         c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
         c.TextEdit !.TextEdit !.NewText.Should().Be(expected);
         c.Detail.Should().Be(expected);
     },
         c =>
     {
         const string expected = "bool";
         c.Label.Should().Be(expected);
         c.Kind.Should().Be(CompletionItemKind.Class);
         c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
         c.TextEdit !.TextEdit !.NewText.Should().Be(expected);
         c.Detail.Should().Be(expected);
     },
         c =>
     {
         const string expected = "int";
         c.Label.Should().Be(expected);
         c.Kind.Should().Be(CompletionItemKind.Class);
         c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
         c.TextEdit !.TextEdit !.NewText.Should().Be(expected);
         c.Detail.Should().Be(expected);
     },
         c =>
     {
         const string expected = "object";
         c.Label.Should().Be(expected);
         c.Kind.Should().Be(CompletionItemKind.Class);
         c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
         c.TextEdit !.TextEdit !.NewText.Should().Be(expected);
         c.Detail.Should().Be(expected);
     },
         c =>
     {
         const string expected = "string";
         c.Label.Should().Be(expected);
         c.Kind.Should().Be(CompletionItemKind.Class);
         c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
         c.TextEdit !.TextEdit !.NewText.Should().Be(expected);
         c.Detail.Should().Be(expected);
     });
 }
コード例 #4
0
        public void VerifyParameterTypeCompletionWithPrecedingComment()
        {
            var grouping    = SyntaxTreeGroupingFactory.CreateFromText("/*test*/param foo ");
            var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), grouping);
            var provider    = new BicepCompletionProvider(new FileResolver(), new SnippetsProvider(), new TelemetryProvider(Server));

            var offset = grouping.EntryPoint.ProgramSyntax.Declarations.OfType <ParameterDeclarationSyntax>().Single().Type.Span.Position;

            var completions = provider.GetFilteredCompletions(compilation, BicepCompletionContext.Create(compilation, offset));
            var declarationTypeCompletions = completions.Where(c => c.Kind == CompletionItemKind.Class).ToList();

            AssertExpectedDeclarationTypeCompletions(declarationTypeCompletions);

            completions.Where(c => c.Kind == CompletionItemKind.Snippet).Should().SatisfyRespectively(
                c =>
            {
                c.Label.Should().Be("secureObject");
                c.Kind.Should().Be(CompletionItemKind.Snippet);
                c.InsertTextFormat.Should().Be(InsertTextFormat.Snippet);
                c.TextEdit !.TextEdit !.NewText.Should().Be("object");
                c.TextEdit.TextEdit.Range.Start.Line.Should().Be(0);
                c.TextEdit.TextEdit.Range.Start.Character.Should().Be(18);
                c.Detail.Should().Be("Secure object");
                c.AdditionalTextEdits !.Count().Should().Be(1);
                c.AdditionalTextEdits !.ElementAt(0).NewText.Should().Be("@secure()\n");
                c.AdditionalTextEdits !.ElementAt(0).Range.Start.Line.Should().Be(0);
                c.AdditionalTextEdits !.ElementAt(0).Range.Start.Character.Should().Be(8);
                c.AdditionalTextEdits !.ElementAt(0).Range.End.Line.Should().Be(0);
                c.AdditionalTextEdits !.ElementAt(0).Range.End.Character.Should().Be(8);
            },
                c =>
            {
                c.Label.Should().Be("secureString");
                c.Kind.Should().Be(CompletionItemKind.Snippet);
                c.InsertTextFormat.Should().Be(InsertTextFormat.Snippet);
                c.TextEdit !.TextEdit !.NewText.Should().Be("string");
                c.TextEdit.TextEdit.Range.Start.Line.Should().Be(0);
                c.TextEdit.TextEdit.Range.Start.Character.Should().Be(18);
                c.Detail.Should().Be("Secure string");
                c.AdditionalTextEdits !.Count().Should().Be(1);
                c.AdditionalTextEdits !.ElementAt(0).NewText.Should().Be("@secure()\n");
                c.AdditionalTextEdits !.ElementAt(0).Range.Start.Line.Should().Be(0);
                c.AdditionalTextEdits !.ElementAt(0).Range.Start.Character.Should().Be(8);
                c.AdditionalTextEdits !.ElementAt(0).Range.End.Line.Should().Be(0);
                c.AdditionalTextEdits !.ElementAt(0).Range.End.Character.Should().Be(8);
            });
        }
コード例 #5
0
        public void NonDeclarationContextShouldIncludeDeclaredSymbols()
        {
            var grouping    = SyntaxTreeGroupingFactory.CreateFromText(@"
param p string
var v = 
resource r 'Microsoft.Foo/foos@2020-09-01' = {
  name: 'foo'
}
output o int = 42
");
            var offset      = grouping.EntryPoint.ProgramSyntax.Declarations.OfType <VariableDeclarationSyntax>().Single().Value.Span.Position;
            var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), grouping);

            var provider    = new BicepCompletionProvider(new FileResolver(), new SnippetsProvider(), new TelemetryProvider(Server));
            var context     = BicepCompletionContext.Create(compilation, offset);
            var completions = provider.GetFilteredCompletions(compilation, context).ToList();

            AssertExpectedFunctions(completions, expectParamDefaultFunctions: false);

            // outputs can't be referenced so they should not show up in completions
            completions.Where(c => c.Kind == SymbolKind.Output.ToCompletionItemKind()).Should().BeEmpty();

            // the variable won't appear in completions because we are not suggesting cycles
            completions.Where(c => c.Kind == SymbolKind.Variable.ToCompletionItemKind()).Should().BeEmpty();

            const string expectedResource   = "r";
            var          resourceCompletion = completions.Single(c => c.Kind == SymbolKind.Resource.ToCompletionItemKind());

            resourceCompletion.Label.Should().Be(expectedResource);
            resourceCompletion.Kind.Should().Be(CompletionItemKind.Interface);
            resourceCompletion.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
            resourceCompletion.TextEdit !.TextEdit !.NewText.Should().Be(expectedResource);
            resourceCompletion.CommitCharacters.Should().BeEquivalentTo(new[] { ":", });
            resourceCompletion.Detail.Should().Be(expectedResource);

            const string expectedParam   = "p";
            var          paramCompletion = completions.Single(c => c.Kind == SymbolKind.Parameter.ToCompletionItemKind());

            paramCompletion.Label.Should().Be(expectedParam);
            paramCompletion.Kind.Should().Be(CompletionItemKind.Field);
            paramCompletion.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
            paramCompletion.TextEdit !.TextEdit !.NewText.Should().Be(expectedParam);
            paramCompletion.CommitCharacters.Should().BeNull();
            paramCompletion.Detail.Should().Be(expectedParam);
        }
コード例 #6
0
        public void DeclarationContextShouldReturnKeywordCompletions()
        {
            var grouping    = SyntaxTreeGroupingFactory.CreateFromText(string.Empty);
            var compilation = new Compilation(TestTypeHelper.CreateEmptyProvider(), grouping);

            compilation.GetEntrypointSemanticModel().GetAllDiagnostics().Should().BeEmpty();

            var provider = new BicepCompletionProvider(new FileResolver(), new SnippetsProvider(), new TelemetryProvider(Server));

            var completions = provider.GetFilteredCompletions(compilation, BicepCompletionContext.Create(compilation, 0));

            var keywordCompletions = completions
                                     .Where(c => c.Kind == CompletionItemKind.Keyword)
                                     .OrderBy(c => c.Label)
                                     .ToList();

            keywordCompletions.Should().SatisfyRespectively(
                c =>
            {
                c.Label.Should().Be("module");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Module keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("module");
            },
                c =>
            {
                c.Label.Should().Be("output");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Output keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("output");
            },
                c =>
            {
                c.Label.Should().Be("param");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Parameter keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("param");
            },
                c =>
            {
                c.Label.Should().Be("resource");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Resource keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("resource");
            },
                c =>
            {
                c.Label.Should().Be("targetScope");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Target Scope keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("targetScope");
            },
                c =>
            {
                c.Label.Should().Be("var");
                c.Kind.Should().Be(CompletionItemKind.Keyword);
                c.InsertTextFormat.Should().Be(InsertTextFormat.PlainText);
                c.InsertText.Should().BeNull();
                c.Detail.Should().Be("Variable keyword");
                c.TextEdit !.TextEdit !.NewText.Should().Be("var");
            });
        }