/// <summary>
        /// If there was no $end$ token, place it at the end of the snippet code. Otherwise, it
        /// defaults to the beginning of the snippet code.
        /// </summary>
        private static bool SetEndPositionIfNoneSpecified(IExpansionSession pSession)
        {
            if (pSession.GetSnippetNode() is not XElement snippetNode)
            {
                return(false);
            }

            var ns       = snippetNode.Name.NamespaceName;
            var codeNode = snippetNode.Element(XName.Get("Code", ns));

            if (codeNode == null)
            {
                return(false);
            }

            var delimiterAttribute = codeNode.Attribute("Delimiter");
            var delimiter          = delimiterAttribute != null ? delimiterAttribute.Value : "$";

            if (codeNode.Value.IndexOf(string.Format("{0}end{0}", delimiter), StringComparison.OrdinalIgnoreCase) != -1)
            {
                return(false);
            }

            var snippetSpan = pSession.GetSnippetSpan();

            var newEndSpan = new SnapshotSpan(snippetSpan.End, 0);

            pSession.EndSpan = newEndSpan;
            return(true);
        }
Exemplo n.º 2
0
        private void AddReferencesAndImports(
            IExpansionSession pSession,
            int position,
            CancellationToken cancellationToken)
        {
            if (!(pSession.GetSnippetNode() is XElement snippetNode))
            {
                return;
            }

            var documentWithImports = this.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (documentWithImports == null)
            {
                return;
            }

            var documentOptions           = documentWithImports.GetOptionsAsync(cancellationToken).WaitAndGetResult(cancellationToken);
            var placeSystemNamespaceFirst = documentOptions.GetOption(GenerationOptions.PlaceSystemNamespaceFirst);

            documentWithImports = AddImports(documentWithImports, position, snippetNode, placeSystemNamespaceFirst, cancellationToken);
            AddReferences(documentWithImports.Project, snippetNode);
        }