コード例 #1
0
        private static void AssertExpectedFunctions(List <CompletionItem> completions, bool expectParamDefaultFunctions, IEnumerable <string>?fullyQualifiedFunctionNames = null)
        {
            fullyQualifiedFunctionNames ??= Enumerable.Empty <string>();

            var fullyQualifiedFunctionParts = fullyQualifiedFunctionNames.Select(fqfn =>
            {
                var parts = fqfn.Split('.', StringSplitOptions.None);
                return(@namespace: parts[0], function: parts[1]);
            });

            var functionCompletions = completions.Where(c => c.Kind == CompletionItemKind.Function).OrderBy(c => c.Label).ToList();

            var availableFunctionNames = new NamespaceSymbol[] { new AzNamespaceSymbol(ResourceScope.ResourceGroup), new SystemNamespaceSymbol() }
            .SelectMany(ns => ns.Type.MethodResolver.GetKnownFunctions().Values)
            .Where(symbol => expectParamDefaultFunctions || !symbol.FunctionFlags.HasFlag(FunctionFlags.ParamDefaultsOnly))
            .Select(func => func.Name)
            .Except(fullyQualifiedFunctionParts.Select(p => p.function), LanguageConstants.IdentifierComparer)
            .Concat(fullyQualifiedFunctionNames)
            .OrderBy(s => s);

            functionCompletions.Select(c => c.Label).Should().BeEquivalentTo(availableFunctionNames);
            functionCompletions.Should().OnlyContain(c => c.TextEdit !.TextEdit !.NewText.StartsWith(c.Label + '(', StringComparison.Ordinal));
            functionCompletions.Should().OnlyContain(c => string.Equals(c.Label + "()", c.Detail));
            functionCompletions.Should().OnlyContain(c => c.InsertTextFormat == InsertTextFormat.Snippet);
        }
コード例 #2
0
 /// <summary>
 /// Removes a common prefix from the edit to turn IntelliSense replacements into insertions where possible
 /// </summary>
 /// <returns>A normalized text change</returns>
 public TextChange Normalize()
 {
     if (OldBuffer != null && IsReplace && NewLength > OldLength && NewText.StartsWith(OldText, StringComparison.Ordinal) && NewPosition == OldPosition)
     {
         // Normalize the change into an insertion of the uncommon suffix (i.e. strip out the common prefix)
         return(new TextChange(oldPosition: OldPosition + OldLength,
                               oldLength: 0,
                               oldBuffer: OldBuffer,
                               newPosition: OldPosition + OldLength,
                               newLength: NewLength - OldLength,
                               newBuffer: NewBuffer));
     }
     return(this);
 }