Beispiel #1
0
        internal static Snippet AddInitializer(ExecutionContext context, Snippet snippet, string initializer, string defaultValue)
        {
            string suffix = (snippet.Language == Language.Cpp) ? " (with initialization)" : " (with initializer)";

            snippet.SuffixTitle(suffix);
            snippet.SuffixShortcut(context.WithInitializerSuffix(snippet));
            snippet.SuffixDescription(suffix);

            snippet.ReplacePlaceholders(LiteralIdentifiers.Initializer, initializer);

            snippet.AddLiteral(LiteralIdentifiers.Value, null, defaultValue);

            snippet.RemoveLiteral(LiteralIdentifiers.Initializer);

            if (snippet.Language == Language.Cpp)
            {
                Literal typeLiteral = snippet.Literals.Find(LiteralIdentifiers.Type);
                typeLiteral.DefaultValue = "auto";

                LiteralRenamer.Rename(snippet, LiteralIdentifiers.Type, "type");
            }
            else
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.ArrayLength);
            }

            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.SuffixFileName((snippet.Language == Language.Cpp) ? "WithInitialization" : "WithInitializer");

            return(snippet);
        }
Beispiel #2
0
        private void PostProcess(Snippet snippet)
        {
            ReplacePlaceholders(snippet);

            if (snippet.Language == Language.VisualBasic)
            {
                snippet.ReplaceSubOrFunctionLiteral("Function");
            }

            Literal typeLiteral = snippet.Literals[LiteralIdentifiers.Type];

            if (typeLiteral != null)
            {
                typeLiteral.DefaultValue = "T";
            }

            RemoveUnusedLiterals(snippet);

            RemoveKeywords(snippet);

            snippet.AddTag(KnownTags.AutoGenerated);

            snippet.SortCollections();

            snippet.Author = "Josef Pihrt";

            if (snippet.SnippetTypes == SnippetTypes.None)
            {
                snippet.SnippetTypes = SnippetTypes.Expansion;
            }
        }
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            base.Execute(context, snippet);

            if (!Modifier.Tags.Contains(KnownTags.Default))
            {
                snippet.AddTag(KnownTags.ExcludeFromReadme);
            }
        }
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixTitle(" (with content)");
            snippet.SuffixDescription(" (with content)");
            snippet.SuffixShortcut(XmlSnippetGenerator.ContentShortcut);
            snippet.SuffixFileName("_with_content");

            snippet.AddTag(KnownTags.ExcludeFromReadme);
        }
Beispiel #5
0
        private static Snippet GetObsoleteSnippetOrDefault(Snippet snippet)
        {
            if (!snippet.TryGetTag(KnownTags.ObsoleteShortcut, out TagInfo info))
            {
                return(null);
            }

            snippet.Keywords.RemoveAt(info.KeywordIndex);

            snippet = (Snippet)snippet.Clone();

            string s = $"Shortcut '{info.Value}' is obsolete, use '{snippet.Shortcut}' instead.";

            if (snippet.Language == Language.CSharp)
            {
                s = $"/* {s} */";
            }
            else if (snippet.Language == Language.VisualBasic)
            {
                s = $"' {s}\r\n";
            }
            else
            {
                throw new NotSupportedException(snippet.Language.ToString());
            }

            snippet.Title += " [Obsolete]";

            snippet.Shortcut = info.Value;

            snippet.CodeText = s + $"${Placeholder.EndIdentifier}$";

            snippet.Literals.Clear();

            snippet.AddTag(KnownTags.ExcludeFromSnippetBrowser);
            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.SuffixFileName("_Obsolete");

            return(snippet);
        }
Beispiel #6
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixTitle(" (with arguments)");
            snippet.SuffixShortcut(ShortcutChars.WithArguments);
            snippet.SuffixDescription(" (with arguments)");

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.ArgumentList, "($arguments$)");

            snippet.AddLiteral("arguments", "Arguments", "arguments");

            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.SuffixFileName("WithArguments");
        }
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            snippet.SuffixTitle(" (with parameters)");
            snippet.SuffixShortcut(ShortcutChars.WithParameters);
            snippet.SuffixDescription(" (with parameters)");

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.ParameterList, "($parameters$)");

            snippet.AddLiteral("parameters", "Parameters", language.GetDefaultParameter());

            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.SuffixFileName("WithParameters");
        }
Beispiel #8
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.PrefixTitle($"{Modifier.Keyword} ");

            snippet.PrefixShortcut(Modifier.Shortcut);

            snippet.PrefixDescription($"{Modifier.Keyword} ");

            if (!Modifier.Tags.Contains(KnownTags.Default))
            {
                snippet.AddTag(KnownTags.ExcludeFromReadme);
            }

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.Modifiers, Modifier.Keyword);

            snippet.PrefixFileName(Modifier.Name);
        }
Beispiel #9
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixShortcut("x");
            snippet.SuffixTitle(" definition");
            snippet.SuffixDescription(" definition");
            snippet.SnippetTypes |= SnippetTypes.SurroundsWith;
            snippet.SuffixFileName("Definition");
            snippet.AddTag(KnownTags.ExcludeFromReadme);

            PlaceholderCollection placeholders = snippet.Code.Placeholders;

            if (placeholders.Contains("_definition"))
            {
                snippet.CodeText = snippet.Code.ReplacePlaceholders("_definition", @" {
	$selected$$end$
}");
            }
        }
Beispiel #10
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.SuffixTitle(" property");
            snippet.SuffixShortcut("py");
            snippet.SuffixDescription(" property");
            snippet.RemoveTag(KnownTags.GenerateXamlProperty);
            snippet.RemoveTag(KnownTags.NonUniqueShortcut);
            snippet.AddTag(KnownTags.AutoGenerated);

            snippet.Literals.Clear();
            snippet.AddLiteral("property", "Property name", ".");

            string name = Path.GetFileNameWithoutExtension(snippet.FilePath);

            snippet.CodeText = $"<{name}$property$>$end$</{name}$property$>";

            snippet.SuffixFileName("Property");
        }
Beispiel #11
0
        internal static Snippet AddInitializer(Snippet snippet, string initializer, string defaultValue)
        {
            snippet.SuffixTitle(" (with initializer)");
            snippet.SuffixShortcut(ShortcutChars.WithInitializer);
            snippet.SuffixDescription(" (with initializer)");

            snippet.ReplacePlaceholders(LiteralIdentifiers.Initializer, initializer);

            snippet.AddLiteral(LiteralIdentifiers.Value, null, defaultValue);

            snippet.RemoveLiteral(LiteralIdentifiers.Initializer);

            snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.ArrayLength);

            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.SuffixFileName("WithInitializer");

            return(snippet);
        }
Beispiel #12
0
        protected virtual Snippet PostProcess(Snippet snippet)
        {
            snippet.AddTag(KnownTags.AutoGenerated);

            return(snippet);
        }
 protected override void Execute(ExecutionContext context, Snippet snippet)
 {
     snippet.PrefixTitle($"{Type.Shortcut} ");
     snippet.AddTag(KnownTags.TitleStartsWithShortcut);
 }
Beispiel #14
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            snippet.AddTag(KnownTags.NonUniqueShortcut);
            snippet.AddTag(KnownTags.TitleStartsWithShortcut);

            if (Type == null)
            {
                return;
            }

            if (snippet.HasTag(KnownTags.TryParse) && !Tags.Contains(KnownTags.TryParse))
            {
                context.IsCanceled = true;
                return;
            }

            if (Type.Name == "Void" && snippet.Language == Language.VisualBasic)
            {
                snippet.ReplaceSubOrFunctionLiteral("Sub");

                snippet.RemoveLiteral(LiteralIdentifiers.As);
                snippet.ReplacePlaceholders(LiteralIdentifiers.Type, "");

                snippet.CodeText = Regex.Replace(snippet.CodeText, $@"[\s-[\r\n]]*\${LiteralIdentifiers.As}\$[\s-[\r\n]]*", "");
            }
            else
            {
                snippet.ReplaceSubOrFunctionLiteral("Function");
            }

            snippet.Title = snippet.Title
                            .ReplacePlaceholder(Placeholders.Type, Type.Title)
                            .ReplacePlaceholder(Placeholders.OfType, $"of {Type.Title}")
                            .ReplacePlaceholder(Placeholders.GenericType, language.GetTypeParameterList(Type.Keyword));

            snippet.Description = snippet.Description
                                  .ReplacePlaceholder(Placeholders.Type, Type.Title)
                                  .ReplacePlaceholder(Placeholders.OfType, $"of {Type.Title}")
                                  .ReplacePlaceholder(Placeholders.GenericType, language.GetTypeParameterList(Type.Keyword));

            snippet.AddNamespace(Type.Namespace);

            snippet.AddTag(KnownTags.ExcludeFromReadme);

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.Type, Type.Keyword);

            Literal valueLiteral = snippet.Literals.Find(LiteralIdentifiers.Value);

            if (valueLiteral != null)
            {
                valueLiteral.DefaultValue = Type.DefaultValue;
            }

            if (Type.DefaultIdentifier != null)
            {
                Literal identifierLiteral = snippet.Literals.Find(LiteralIdentifiers.Identifier);

                if (identifierLiteral != null)
                {
                    identifierLiteral.DefaultValue = Type.DefaultIdentifier;
                }
            }

            string fileName = Path.GetFileName(snippet.FilePath);

            if (fileName.IndexOf("OfT", StringComparison.Ordinal) != -1)
            {
                fileName = fileName.Replace("OfT", $"Of{Type.Name}");
            }
            else if (snippet.HasTag(KnownTags.TryParse))
            {
                fileName = Path.GetFileNameWithoutExtension(fileName) + Type.Name + Path.GetExtension(fileName);
            }
            else
            {
                fileName = Type.Name + fileName;
            }

            snippet.SetFileName(fileName);
        }
Beispiel #15
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            snippet.Shortcut = CreateAlternativeShortcut(snippet);

            snippet.AddTag(KnownTags.NonUniqueTitle);
        }