From 1d76c6e10c706fd28625807d0aa8b0e69f28e306 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 8 Dec 2023 03:41:12 +0100 Subject: [PATCH 1/4] Fix snippet for abstract method --- .../KnownTags.cs | 1 + .../AutoGeneration/Abstract/Method.snippet | 44 +++++++++++++++ .../AutoGeneration/Method.snippet | 1 - .../AutoGeneration/Abstract/Method.snippet | 55 +++++++++++++++++++ .../AutoGeneration/Method.snippet | 1 - .../Commands/MultiCommandCollection.cs | 9 +++ .../LanguageSnippetGenerator.cs | 10 +++- .../Snippetica.CSharp/package/README.md | 2 +- .../Snippetica.Cpp/package/README.md | 2 +- .../Snippetica.VisualBasic/package/README.md | 4 +- 10 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet create mode 100644 src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet diff --git a/src/Snippetica.CodeGeneration.Common/KnownTags.cs b/src/Snippetica.CodeGeneration.Common/KnownTags.cs index 913aa45a..29cefc21 100644 --- a/src/Snippetica.CodeGeneration.Common/KnownTags.cs +++ b/src/Snippetica.CodeGeneration.Common/KnownTags.cs @@ -44,6 +44,7 @@ public static class KnownTags public const string GenerateStaticModifier = GeneratePrefix + "StaticModifier"; public const string GenerateVirtualModifier = GeneratePrefix + "VirtualModifier"; public const string GenerateAbstractModifier = GeneratePrefix + "AbstractModifier"; + public const string GenerateAbstractModifierRequired = "AbstractModifierRequired"; public const string GenerateInlineModifier = GeneratePrefix + "InlineModifier"; public const string GenerateConstModifier = GeneratePrefix + "ConstModifier"; public const string GenerateConstExprModifier = GeneratePrefix + "ConstExprModifier"; diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet new file mode 100644 index 00000000..bbda905c --- /dev/null +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet @@ -0,0 +1,44 @@ + + +
+ @type@ method + m + @type@ method declaration + Josef Pihrt + + Expansion + + + Meta-AbstractModifierRequired + Meta-FileName-Method + Meta-GenerateAbstractModifier + Meta-GenerateAccessModifier + Meta-GenerateProtectedModifier + +
+ + + + _modifiers + Modifier(s) + public + + + _parameters + List of parameters + T parameter + + + name + Method name + MethodName + + + type + Return type + void + + + + +
\ No newline at end of file diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Method.snippet index 01eeb8b5..15329625 100644 --- a/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Method.snippet +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Method.snippet @@ -9,7 +9,6 @@ Expansion - Meta-GenerateAbstractModifier Meta-GenerateAccessModifier Meta-GenerateProtectedModifier Meta-GenerateStaticModifier diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet new file mode 100644 index 00000000..b836a9c5 --- /dev/null +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet @@ -0,0 +1,55 @@ + + +
+ @type@ method + m + @type@ method declaration + Josef Pihrt + + Expansion + + + Meta-AbstractModifierRequired + Meta-GenerateAbstractModifier + Meta-GenerateAccessModifier + Meta-GenerateProtectedModifier + Meta-GenerateVoidType + Meta-NonUniqueShortcut + +
+ + + + _as + As keyword + As + + + _modifiers + Modifier(s) + Public + + + _parameters + List of parameters + parameter As T + + + _subOrFunction + Sub or Function + Function + + + name + Method name + MethodName + + + type + Return type + Object + + + + +
\ No newline at end of file diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Method.snippet index 6a6d6bad..5512adb9 100644 --- a/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Method.snippet +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Method.snippet @@ -9,7 +9,6 @@ Expansion - Meta-GenerateAbstractModifier Meta-GenerateAccessModifier Meta-GenerateProtectedModifier Meta-GenerateStaticModifier diff --git a/src/Snippetica.CodeGeneration/Commands/MultiCommandCollection.cs b/src/Snippetica.CodeGeneration/Commands/MultiCommandCollection.cs index 714cb02f..d8a68e69 100644 --- a/src/Snippetica.CodeGeneration/Commands/MultiCommandCollection.cs +++ b/src/Snippetica.CodeGeneration/Commands/MultiCommandCollection.cs @@ -7,6 +7,15 @@ namespace Snippetica.CodeGeneration.Commands; public class MultiCommandCollection : Collection { + public MultiCommandCollection() + { + } + + public MultiCommandCollection(IEnumerable commands) + { + AddRange(commands); + } + public void AddRange(IEnumerable commands) { foreach (MultiCommand command in commands) diff --git a/src/Snippetica.CodeGeneration/LanguageSnippetGenerator.cs b/src/Snippetica.CodeGeneration/LanguageSnippetGenerator.cs index 7ff67ee1..d0bb5cc5 100644 --- a/src/Snippetica.CodeGeneration/LanguageSnippetGenerator.cs +++ b/src/Snippetica.CodeGeneration/LanguageSnippetGenerator.cs @@ -41,6 +41,8 @@ protected override MultiCommandCollection CreateCommands(Snippet snippet) commands.AddMultiCommands(GetAccessModifierCommands(snippet)); + var abstractModifierRequired = false; + if (snippet.HasTag(KnownTags.GenerateStaticModifier)) commands.AddMultiCommand(CommandUtility.StaticCommand, duplicateWhenEmpty: true); @@ -48,7 +50,10 @@ protected override MultiCommandCollection CreateCommands(Snippet snippet) commands.AddMultiCommand(CommandUtility.VirtualCommand, duplicateWhenEmpty: true); if (snippet.HasTag(KnownTags.GenerateAbstractModifier)) - commands.AddMultiCommand(CommandUtility.AbstractCommand, duplicateWhenEmpty: true); + { + commands.AddMultiCommand(CommandUtility.AbstractCommand, duplicateWhenEmpty: false); + abstractModifierRequired = snippet.HasTag(KnownTags.GenerateAbstractModifierRequired); + } if (snippet.HasTag(KnownTags.GenerateConstModifier)) commands.AddMultiCommand(CommandUtility.ConstCommand, duplicateWhenEmpty: true); @@ -62,6 +67,9 @@ protected override MultiCommandCollection CreateCommands(Snippet snippet) if (snippet.HasTag(KnownTags.GenerateInitializer)) commands.AddMultiCommand(CommandUtility.InitializerCommand, duplicateWhenEmpty: true); + if (abstractModifierRequired) + commands = new MultiCommandCollection(commands.Where(mc => mc.Commands.Any(c => c.Kind == CommandKind.AbstractModifier))); + return commands; } diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md index 7f33dfee..641c6707 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md @@ -1,3 +1,3 @@ # C\# Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/csharp) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md index cd2b8b86..4cc44f42 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md @@ -1,3 +1,3 @@ # C\+\+ Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/cpp) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md index 5c0c68b4..61c52e96 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md @@ -1,3 +1,3 @@ -# Visual Basic Snippets +# VB Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/vb) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file From c0e5ed3b5f0fc8bbf0b044f48a09ebafa1f59361 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 8 Dec 2023 03:44:46 +0100 Subject: [PATCH 2/4] update --- ChangeLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 7ff3039d..abbd0f2f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed + +- Fix snippets for abstract method ([PR](https://github.com/josefpihrt/snippetica/pull/82)) + ## [2.0.2] - 2023-11-05 ## [2.0.1] - 2023-11-05 From 696d0a3bb35d1dd4aae1d13c9a81575ac2822571 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 8 Dec 2023 03:50:25 +0100 Subject: [PATCH 3/4] update --- .../Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet | 3 +-- .../AutoGeneration/Abstract/Method.snippet | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet index bbda905c..647f7b03 100644 --- a/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.CSharp/AutoGeneration/Abstract/Method.snippet @@ -10,7 +10,6 @@ Meta-AbstractModifierRequired - Meta-FileName-Method Meta-GenerateAbstractModifier Meta-GenerateAccessModifier Meta-GenerateProtectedModifier @@ -33,7 +32,7 @@ Method name MethodName - + type Return type void diff --git a/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet index b836a9c5..f920f818 100644 --- a/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet +++ b/src/Snippetica.CodeGeneration.Metadata/Snippetica.VisualBasic/AutoGeneration/Abstract/Method.snippet @@ -44,7 +44,7 @@ Method name MethodName - + type Return type Object From 1b8720a45fd27e4ee6ba6a44ca0b99a0e52ecf01 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 8 Dec 2023 03:55:43 +0100 Subject: [PATCH 4/4] update --- .../VisualStudioCode/VisualStudioCodeEnvironment.cs | 2 +- .../Snippetica.CSharp.Dev/package/README.md | 2 +- .../Snippetica.Cpp.Dev/package/README.md | 2 +- .../Snippetica.VisualBasic.Dev/package/README.md | 2 +- .../Snippetica.CSharp/package/README.md | 2 +- .../Snippetica.Cpp/package/README.md | 2 +- .../Snippetica.VisualBasic/package/README.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Snippetica.CodeGeneration/VisualStudioCode/VisualStudioCodeEnvironment.cs b/src/Snippetica.CodeGeneration/VisualStudioCode/VisualStudioCodeEnvironment.cs index fc760303..11c9748a 100644 --- a/src/Snippetica.CodeGeneration/VisualStudioCode/VisualStudioCodeEnvironment.cs +++ b/src/Snippetica.CodeGeneration/VisualStudioCode/VisualStudioCodeEnvironment.cs @@ -164,7 +164,7 @@ protected override void SaveSnippets(SnippetGeneratorResult result) MDocument document = Document( Heading1(result.Language.GetTitle() + " Snippets"), - Inline("Please see ", Link("documentation", "https://josefpihrt.github.io/docs/snippetica/vscode"), " for further information.")); + Inline("Please see ", Link("documentation", "https://josefpihrt.github.io/docs/snippetica/snippets/vscode/" + languageId), " for further information.")); IOUtility.WriteAllText(Path.Combine(packageDirectoryPath, "README.md"), document.ToString()); } diff --git a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.CSharp.Dev/package/README.md b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.CSharp.Dev/package/README.md index 641c6707..7f33dfee 100644 --- a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.CSharp.Dev/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.CSharp.Dev/package/README.md @@ -1,3 +1,3 @@ # C\# Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/csharp) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.Cpp.Dev/package/README.md b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.Cpp.Dev/package/README.md index 4cc44f42..cd2b8b86 100644 --- a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.Cpp.Dev/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.Cpp.Dev/package/README.md @@ -1,3 +1,3 @@ # C\+\+ Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/cpp) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.VisualBasic.Dev/package/README.md b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.VisualBasic.Dev/package/README.md index 61c52e96..1bb2a2e2 100644 --- a/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.VisualBasic.Dev/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix.Dev/Snippetica.VisualBasic.Dev/package/README.md @@ -1,3 +1,3 @@ # VB Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/vb) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md index 641c6707..7f33dfee 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.CSharp/package/README.md @@ -1,3 +1,3 @@ # C\# Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/csharp) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md index 4cc44f42..cd2b8b86 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.Cpp/package/README.md @@ -1,3 +1,3 @@ # C\+\+ Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/cpp) for further information\. \ No newline at end of file diff --git a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md index 61c52e96..1bb2a2e2 100644 --- a/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md +++ b/src/Snippetica.VisualStudioCode.Vsix/Snippetica.VisualBasic/package/README.md @@ -1,3 +1,3 @@ # VB Snippets -Please see [documentation](https://josefpihrt.github.io/docs/snippetica/vscode) for further information\. \ No newline at end of file +Please see [documentation](https://josefpihrt.github.io/docs/snippetica/snippets/vscode/vb) for further information\. \ No newline at end of file