Exemplo n.º 1
0
        protected override async Task <(int ExitCode, string Value, int HasDefaultValue)> GetDefaultValueAsync(CancellationToken cancellationToken)
        {
            var value           = _fullyQualifiedName;
            var hasDefaultValue = 1;

            if (!TryGetDocument(out var document))
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            if (!TryGetFieldSpan(out var fieldSpan))
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            var simplifierOptions = await document.GetSimplifierOptionsAsync(snippetExpansionClient.GlobalOptions, cancellationToken).ConfigureAwait(false);

            var simplifiedTypeName = await SnippetFunctionService.GetSimplifiedTypeNameAsync(document, fieldSpan.Value, _fullyQualifiedName, simplifierOptions, cancellationToken).ConfigureAwait(false);

            if (string.IsNullOrEmpty(simplifiedTypeName))
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            return(VSConstants.S_OK, simplifiedTypeName !, hasDefaultValue);
        }
        private void ReadDeclarations(XElement?declarations)
        {
            if (declarations == null)
            {
                return;
            }

            foreach (var declarationElement in declarations.Elements())
            {
                var editableAttribute = declarationElement.Attribute("Editable");
                var functionElement   = CodeSnippet.GetElementWithoutNamespace(declarationElement, "Function");
                SnippetFunctionService.TryGetSnippetFunctionInfo(functionElement?.Value, out var functionName, out var functionParam);
                _tokens.Add(new ExpansionField(
                                CodeSnippet.GetElementInnerText(declarationElement, "ID"),
                                CodeSnippet.GetElementInnerText(declarationElement, "Default") ?? " ",
                                functionName,
                                functionParam,
                                editableAttribute == null || string.Equals(editableAttribute.Value, "true", StringComparison.Ordinal) || string.Equals(editableAttribute.Value, "1", StringComparison.Ordinal)));
            }
        }
Exemplo n.º 3
0
        public async Task <SnippetFunctionPart> WithSnippetFunctionResultAsync(Document documentWithSnippet, TextSpan fieldSpan, SimplifierOptions simplifierOptions, CancellationToken cancellationToken)
        {
            var snippetFunctionService = documentWithSnippet.Project.GetRequiredLanguageService <SnippetFunctionService>();

            switch (FunctionName)
            {
            case "SimpleTypeName":
                if (FunctionParam == null)
                {
                    return(this);
                }

                var simplifiedTypeName = await SnippetFunctionService.GetSimplifiedTypeNameAsync(documentWithSnippet, fieldSpan, FunctionParam, simplifierOptions, cancellationToken).ConfigureAwait(false);

                if (simplifiedTypeName == null)
                {
                    return(this);
                }

                return(this with {
                    DefaultText = simplifiedTypeName
                });