diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpConditionalBlockSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpConditionalBlockSnippetCompletionProviderTests.cs index 485546c5a1d1e..12f8aaf435f11 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpConditionalBlockSnippetCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/AbstractCSharpConditionalBlockSnippetCompletionProviderTests.cs @@ -126,7 +126,7 @@ public Program() } [WpfFact] - public async Task InsertSnippettInLocalFunctionTest() + public async Task InsertSnippetInLocalFunctionTest() { var markupBeforeCommit = """ class Program diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs new file mode 100644 index 0000000000000..e1ae704c239b1 --- /dev/null +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/Snippets/CSharpDoSnippetCompletionProviderTests.cs @@ -0,0 +1,709 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Test.Utilities; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets; + +[Trait(Traits.Feature, Traits.Features.Completion)] +public class CSharpDoSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests +{ + protected override string ItemToCommit => "do"; + + [WpfFact] + public async Task InsertSnippetInMethodTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + $$ + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + public void Method() + { + do + { + $$ + } + while (true); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertSnippetInGlobalContextTest() + { + var markupBeforeCommit = """ + Ins$$ + """; + + var expectedCodeAfterCommit = """ + do + { + $$ + } + while (true); + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task NoSnippetInBlockNamespaceTest() + { + var markupBeforeCommit = """ + namespace Namespace + { + $$ + class Program + { + public async Task MethodAsync() + { + } + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInFileScopedNamespaceTest() + { + var markupBeforeCommit = """ + namespace Namespace; + $$ + class Program + { + public async Task MethodAsync() + { + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task InsertSnippetInConstructorTest() + { + var markupBeforeCommit = """ + class Program + { + public Program() + { + var x = 5; + $$ + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + public Program() + { + var x = 5; + do + { + $$ + } + while (true); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertSnippetInLocalFunctionTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + $$ + } + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + public void Method() + { + var x = 5; + void LocalMethod() + { + do + { + $$ + } + while (true); + } + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertSnippetInAnonymousFunctionTest() + { + var markupBeforeCommit = """ + public delegate void Print(int value); + + static void Main(string[] args) + { + Print print = delegate(int val) { + $$ + }; + + } + """; + + var expectedCodeAfterCommit = """ + public delegate void Print(int value); + + static void Main(string[] args) + { + Print print = delegate(int val) { + do + { + $$ + } + while (true); + }; + + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertSnippetInParenthesizedLambdaExpressionTest() + { + var markupBeforeCommit = """ + Func testForEquality = (x, y) => + { + $$ + return x == y; + }; + """; + + var expectedCodeAfterCommit = """ + Func testForEquality = (x, y) => + { + do + { + $$ + } + while (true); + return x == y; + }; + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task NoSnippetInSwitchExpression() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + var operation = 2; + + var result = operation switch + { + $$ + 1 => "Case 1", + 2 => "Case 2", + 3 => "Case 3", + 4 => "Case 4", + }; + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInSingleLambdaExpression() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + Func f = x => $$; + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInStringTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + var str = "$$"; + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInObjectInitializerTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + var str = new Test($$); + } + } + + class Test + { + private string val; + + public Test(string val) + { + this.val = val; + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInParameterListTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method(int x, $$) + { + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInRecordDeclarationTest() + { + var markupBeforeCommit = """ + public record Person + { + $$ + public string FirstName { get; init; } = default!; + public string LastName { get; init; } = default!; + }; + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoSnippetInVariableDeclarationTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + var x = $$ + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task InsertSnippetWithInvocationBeforeAndAfterCursorTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + Wr$$Blah + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + public void Method() + { + do + { + $$ + } + while (true); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertSnippetWithInvocationUnderscoreBeforeAndAfterCursorTest() + { + var markupBeforeCommit = """ + class Program + { + public void Method() + { + _Wr$$Blah_ + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + public void Method() + { + do + { + $$ + } + while (true); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task InsertInlineSnippetForCorrectTypeTest() + { + var markupBeforeCommit = """ + class Program + { + void M(bool arg) + { + arg.$$ + } + } + """; + + var expectedCodeAfterCommit = """ + class Program + { + void M(bool arg) + { + do + { + $$ + } + while (arg); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact] + public async Task NoInlineSnippetForIncorrectTypeTest() + { + var markupBeforeCommit = """ + class Program + { + void M(int arg) + { + arg.$$ + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfFact] + public async Task NoInlineSnippetWhenNotDirectlyExpressionStatementTest() + { + var markupBeforeCommit = """ + class Program + { + void M(bool arg) + { + System.Console.WriteLine(arg.$$); + } + } + """; + + await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit); + } + + [WpfTheory] + [InlineData("// comment")] + [InlineData("/* comment */")] + [InlineData("#region test")] + public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest1(string trivia) + { + var markupBeforeCommit = $$""" + class Program + { + void M(bool arg) + { + {{trivia}} + arg.$$ + } + } + """; + + var expectedCodeAfterCommit = $$""" + class Program + { + void M(bool arg) + { + {{trivia}} + do + { + $$ + } + while (arg); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfTheory] + [InlineData("#if true")] + [InlineData("#pragma warning disable CS0108")] + [InlineData("#nullable enable")] + public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInMethodTest2(string trivia) + { + var markupBeforeCommit = $$""" + class Program + { + void M(bool arg) + { + {{trivia}} + arg.$$ + } + } + """; + + var expectedCodeAfterCommit = $$""" + class Program + { + void M(bool arg) + { + {{trivia}} + do + { + $$ + } + while (arg); + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfTheory] + [InlineData("// comment")] + [InlineData("/* comment */")] + public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest1(string trivia) + { + var markupBeforeCommit = $$""" + {{trivia}} + true.$$ + """; + + var expectedCodeAfterCommit = $$""" + {{trivia}} + do + { + $$ + } + while (true); + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfTheory] + [InlineData("#region test")] + [InlineData("#if true")] + [InlineData("#pragma warning disable CS0108")] + [InlineData("#nullable enable")] + public async Task CorrectlyDealWithLeadingTriviaInInlineSnippetInGlobalStatementTest2(string trivia) + { + var markupBeforeCommit = $$""" + {{trivia}} + true.$$ + """; + + var expectedCodeAfterCommit = $$""" + + {{trivia}} + do + { + $$ + } + while (true); + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69598")] + public async Task InsertInlineSnippetWhenDottingBeforeContextualKeywordTest1() + { + var markupBeforeCommit = """ + using System.Collections.Generic; + + class C + { + void M(bool flag) + { + flag.$$ + var a = 0; + } + } + """; + + var expectedCodeAfterCommit = """ + using System.Collections.Generic; + + class C + { + void M(bool flag) + { + do + { + $$ + } + while (flag); + var a = 0; + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/69598")] + public async Task InsertInlineSnippetWhenDottingBeforeContextualKeywordTest2() + { + var markupBeforeCommit = """ + using System.Collections.Generic; + + class C + { + void M(bool flag, Task t) + { + flag.$$ + await t; + } + } + """; + + var expectedCodeAfterCommit = $$""" + using System.Collections.Generic; + + class C + { + void M(bool flag, Task t) + { + do + { + $$ + } + while (flag); + await t; + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } + + [WpfTheory, WorkItem("https://github.com/dotnet/roslyn/issues/69598")] + [InlineData("Task")] + [InlineData("Task")] + [InlineData("System.Threading.Tasks.Task")] + public async Task InsertInlineSnippetWhenDottingBeforeNameSyntaxTest(string nameSyntax) + { + var markupBeforeCommit = $$""" + using System.Collections.Generic; + + class C + { + void M(bool flag) + { + flag.$$ + {{nameSyntax}} t = null; + } + } + """; + + var expectedCodeAfterCommit = $$""" + using System.Collections.Generic; + + class C + { + void M(bool flag) + { + do + { + $$ + } + while (flag); + {{nameSyntax}} t = null; + } + } + """; + + await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit); + } +} diff --git a/src/Features/CSharp/Portable/CSharpFeaturesResources.resx b/src/Features/CSharp/Portable/CSharpFeaturesResources.resx index 42585a2a7411a..13d4e8e6195ea 100644 --- a/src/Features/CSharp/Portable/CSharpFeaturesResources.resx +++ b/src/Features/CSharp/Portable/CSharpFeaturesResources.resx @@ -621,4 +621,8 @@ Warning: AI suggestions might be inaccurate. + + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + \ No newline at end of file diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/SnippetCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/SnippetCompletionProvider.cs index d4528663391b0..6df55c5e6ee55 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/SnippetCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/SnippetCompletionProvider.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Completion.Providers; using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; +using Microsoft.CodeAnalysis.CSharp.Snippets; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host; @@ -33,23 +34,24 @@ internal sealed class SnippetCompletionProvider : LSPCompletionProvider { private static readonly HashSet s_snippetsWithReplacements = [ - "class", - "cw", - "ctor", - "else", - "enum", - "for", - "forr", - "foreach", - "if", - "interface", - "lock", - "prop", - "propg", - "sim", - "struct", - "svm", - "while" + CSharpSnippetIdentifiers.Class, + CommonSnippetIdentifiers.ConsoleWriteLine, + CommonSnippetIdentifiers.Constructor, + CSharpSnippetIdentifiers.Do, + CSharpSnippetIdentifiers.Else, + CSharpSnippetIdentifiers.Enum, + CSharpSnippetIdentifiers.For, + CSharpSnippetIdentifiers.ReversedFor, + CSharpSnippetIdentifiers.ForEach, + CSharpSnippetIdentifiers.If, + CSharpSnippetIdentifiers.Interface, + CSharpSnippetIdentifiers.Lock, + CommonSnippetIdentifiers.Property, + CommonSnippetIdentifiers.GetOnlyProperty, + CSharpSnippetIdentifiers.StaticIntMain, + CSharpSnippetIdentifiers.Struct, + CSharpSnippetIdentifiers.StaticVoidMain, + CSharpSnippetIdentifiers.While ]; internal override bool IsSnippetProvider => true; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpClassSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpClassSnippetProvider.cs index 60f1e7e449909..fdff09116cb05 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpClassSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpClassSnippetProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpClassSnippetProvider : AbstractCSharpTypeSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpClassSnippetProvider() : AbstractCSharpTypeSnippetProvider { private static readonly ISet s_validModifiers = new HashSet(SyntaxFacts.EqualityComparer) { @@ -34,13 +36,7 @@ internal sealed class CSharpClassSnippetProvider : AbstractCSharpTypeSnippetProv SyntaxKind.FileKeyword, }; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpClassSnippetProvider() - { - } - - public override string Identifier => "class"; + public override string Identifier => CSharpSnippetIdentifiers.Class; public override string Description => FeaturesResources.class_; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpConstructorSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpConstructorSnippetProvider.cs index 986e051f00d80..1842fd505243f 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpConstructorSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpConstructorSnippetProvider.cs @@ -24,7 +24,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpConstructorSnippetProvider : AbstractConstructorSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpConstructorSnippetProvider() : AbstractConstructorSnippetProvider { private static readonly ISet s_validModifiers = new HashSet(SyntaxFacts.EqualityComparer) { @@ -35,12 +37,6 @@ internal sealed class CSharpConstructorSnippetProvider : AbstractConstructorSnip SyntaxKind.StaticKeyword, }; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpConstructorSnippetProvider() - { - } - protected override bool IsValidSnippetLocation(in SnippetContext context, CancellationToken cancellationToken) { var syntaxContext = (CSharpSyntaxContext)context.SyntaxContext; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpDoWhileLoopStatementProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpDoWhileLoopStatementProvider.cs new file mode 100644 index 0000000000000..eecd8f6549786 --- /dev/null +++ b/src/Features/CSharp/Portable/Snippets/CSharpDoWhileLoopStatementProvider.cs @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Editing; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.Shared.Extensions.ContextQuery; +using Microsoft.CodeAnalysis.Snippets; +using Microsoft.CodeAnalysis.Snippets.SnippetProviders; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis.CSharp.Snippets; + +[ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpDoWhileLoopStatementProvider() : AbstractConditionalBlockSnippetProvider +{ + public override string Identifier => CSharpSnippetIdentifiers.Do; + + public override string Description => CSharpFeaturesResources.do_while_loop; + + protected override SyntaxNode GenerateStatement(SyntaxGenerator generator, SyntaxContext syntaxContext, InlineExpressionInfo? inlineExpressionInfo) + { + return SyntaxFactory.DoStatement( + SyntaxFactory.Block(), + (ExpressionSyntax)(inlineExpressionInfo?.Node.WithoutLeadingTrivia() ?? generator.TrueLiteralExpression())); + } + + protected override SyntaxNode GetCondition(SyntaxNode node) + { + var doStatement = (DoStatementSyntax)node; + return doStatement.Condition; + } + + protected override Func GetSnippetContainerFunction(ISyntaxFacts syntaxFacts) + => static node => node is DoStatementSyntax; + + protected override int GetTargetCaretPosition(ISyntaxFactsService syntaxFacts, SyntaxNode caretTarget, SourceText sourceText) + { + return CSharpSnippetHelpers.GetTargetCaretPositionInBlock( + caretTarget, + static s => (BlockSyntax)s.Statement, + sourceText); + } + + protected override Task AddIndentationToDocumentAsync(Document document, CancellationToken cancellationToken) + { + return CSharpSnippetHelpers.AddBlockIndentationToDocumentAsync( + document, + FindSnippetAnnotation, + static s => (BlockSyntax)s.Statement, + cancellationToken); + } +} diff --git a/src/Features/CSharp/Portable/Snippets/CSharpElseSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpElseSnippetProvider.cs index f7edde19d6865..e877cfabf694b 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpElseSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpElseSnippetProvider.cs @@ -17,13 +17,13 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal class CSharpElseSnippetProvider : AbstractElseSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpElseSnippetProvider() : AbstractElseSnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpElseSnippetProvider() - { - } + public override string Identifier => CSharpSnippetIdentifiers.Else; + + public override string Description => FeaturesResources.else_statement; protected override bool IsValidSnippetLocation(in SnippetContext context, CancellationToken cancellationToken) { diff --git a/src/Features/CSharp/Portable/Snippets/CSharpEnumSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpEnumSnippetProvider.cs index 31509a7bf38db..894887883ad18 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpEnumSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpEnumSnippetProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpEnumSnippetProvider : AbstractCSharpTypeSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpEnumSnippetProvider() : AbstractCSharpTypeSnippetProvider { private static readonly ISet s_validModifiers = new HashSet(SyntaxFacts.EqualityComparer) { @@ -29,13 +31,8 @@ internal sealed class CSharpEnumSnippetProvider : AbstractCSharpTypeSnippetProvi SyntaxKind.FileKeyword, }; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpEnumSnippetProvider() - { - } + public override string Identifier => CSharpSnippetIdentifiers.Enum; - public override string Identifier => "enum"; public override string Description => FeaturesResources.enum_; protected override ISet ValidModifiers => s_validModifiers; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs index 67eeec1f62388..412feb6e47945 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpForEachLoopSnippetProvider.cs @@ -23,13 +23,13 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpForEachLoopSnippetProvider : AbstractForEachLoopSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpForEachLoopSnippetProvider() : AbstractForEachLoopSnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpForEachLoopSnippetProvider() - { - } + public override string Identifier => CSharpSnippetIdentifiers.ForEach; + + public override string Description => FeaturesResources.foreach_loop; protected override bool IsValidSnippetLocation(in SnippetContext context, CancellationToken cancellationToken) { diff --git a/src/Features/CSharp/Portable/Snippets/CSharpForLoopSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpForLoopSnippetProvider.cs index f29cb1373e30c..7ea6feaf03f60 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpForLoopSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpForLoopSnippetProvider.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class CSharpForLoopSnippetProvider() : AbstractCSharpForLoopSnippetProvider { - public override string Identifier => "for"; + public override string Identifier => CSharpSnippetIdentifiers.For; public override string Description => CSharpFeaturesResources.for_loop; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpIfSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpIfSnippetProvider.cs index d826b1ee686fc..f62e112de2e69 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpIfSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpIfSnippetProvider.cs @@ -16,13 +16,13 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpIfSnippetProvider : AbstractIfSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpIfSnippetProvider() : AbstractIfSnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpIfSnippetProvider() - { - } + public override string Identifier => CSharpSnippetIdentifiers.If; + + public override string Description => FeaturesResources.if_statement; protected override SyntaxNode GetCondition(SyntaxNode node) { diff --git a/src/Features/CSharp/Portable/Snippets/CSharpIntMainSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpIntMainSnippetProvider.cs index 5d69ace161a82..addce88a21a00 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpIntMainSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpIntMainSnippetProvider.cs @@ -22,18 +22,14 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpIntMainSnippetProvider : AbstractCSharpMainMethodSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpIntMainSnippetProvider() : AbstractCSharpMainMethodSnippetProvider { - public override string Identifier => "sim"; + public override string Identifier => CSharpSnippetIdentifiers.StaticIntMain; public override string Description => CSharpFeaturesResources.static_int_Main; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpIntMainSnippetProvider() - { - } - protected override SyntaxNode GenerateReturnType(SyntaxGenerator generator) => generator.TypeExpression(SpecialType.System_Int32); diff --git a/src/Features/CSharp/Portable/Snippets/CSharpInterfaceSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpInterfaceSnippetProvider.cs index 6774f33d9a7e7..471f4b953238b 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpInterfaceSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpInterfaceSnippetProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpInterfaceSnippetProvider : AbstractCSharpTypeSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpInterfaceSnippetProvider() : AbstractCSharpTypeSnippetProvider { private static readonly ISet s_validModifiers = new HashSet(SyntaxFacts.EqualityComparer) { @@ -30,13 +32,7 @@ internal sealed class CSharpInterfaceSnippetProvider : AbstractCSharpTypeSnippet SyntaxKind.FileKeyword, }; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpInterfaceSnippetProvider() - { - } - - public override string Identifier => "interface"; + public override string Identifier => CSharpSnippetIdentifiers.Interface; public override string Description => FeaturesResources.interface_; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpLockSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpLockSnippetProvider.cs index 0ef47e1701195..496a578f23d82 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpLockSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpLockSnippetProvider.cs @@ -17,15 +17,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpLockSnippetProvider : AbstractLockSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpLockSnippetProvider() : AbstractLockSnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpLockSnippetProvider() - { - } - - public override string Identifier => "lock"; + public override string Identifier => CSharpSnippetIdentifiers.Lock; public override string Description => CSharpFeaturesResources.lock_statement; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpPropSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpPropSnippetProvider.cs index 786e6d5be97a5..64d2ab7a1a40e 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpPropSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpPropSnippetProvider.cs @@ -14,15 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpPropSnippetProvider : AbstractCSharpAutoPropertySnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpPropSnippetProvider() : AbstractCSharpAutoPropertySnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpPropSnippetProvider() - { - } - - public override string Identifier => "prop"; + public override string Identifier => CommonSnippetIdentifiers.Property; public override string Description => FeaturesResources.property_; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpPropgSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpPropgSnippetProvider.cs index 8a96f8423b0ad..5bc0832910a7b 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpPropgSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpPropgSnippetProvider.cs @@ -14,15 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal class CSharpPropgSnippetProvider : AbstractCSharpAutoPropertySnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpPropgSnippetProvider() : AbstractCSharpAutoPropertySnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpPropgSnippetProvider() - { - } - - public override string Identifier => "propg"; + public override string Identifier => CommonSnippetIdentifiers.GetOnlyProperty; public override string Description => FeaturesResources.get_only_property; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpPropiSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpPropiSnippetProvider.cs index 7e2f6a5523769..c73393afc4d11 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpPropiSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpPropiSnippetProvider.cs @@ -14,15 +14,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal class CSharpPropiSnippetProvider : AbstractCSharpAutoPropertySnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpPropiSnippetProvider() : AbstractCSharpAutoPropertySnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpPropiSnippetProvider() - { - } - - public override string Identifier => "propi"; + public override string Identifier => CSharpSnippetIdentifiers.InitOnlyProperty; public override string Description => CSharpFeaturesResources.init_only_property; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpReversedForLoopSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpReversedForLoopSnippetProvider.cs index 0eb42d90c84f0..1c05b3df2ac6b 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpReversedForLoopSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpReversedForLoopSnippetProvider.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class CSharpReversedForLoopSnippetProvider() : AbstractCSharpForLoopSnippetProvider { - public override string Identifier => "forr"; + public override string Identifier => CSharpSnippetIdentifiers.ReversedFor; public override string Description => CSharpFeaturesResources.reversed_for_loop; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpSnippetFunctionService.cs b/src/Features/CSharp/Portable/Snippets/CSharpSnippetFunctionService.cs index 2e152fd85737a..b29c82ef669b7 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpSnippetFunctionService.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpSnippetFunctionService.cs @@ -14,14 +14,10 @@ namespace Microsoft.CodeAnalysis.CSharp; [ExportLanguageService(typeof(SnippetFunctionService), LanguageNames.CSharp), Shared] -internal class CSharpSnippetFunctionService : SnippetFunctionService +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpSnippetFunctionService() : SnippetFunctionService { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpSnippetFunctionService() - { - } - public override async Task GetContainingClassNameAsync(Document document, int position, CancellationToken cancellationToken) { // Find the nearest enclosing type declaration and use its name diff --git a/src/Features/CSharp/Portable/Snippets/CSharpSnippetIdentifiers.cs b/src/Features/CSharp/Portable/Snippets/CSharpSnippetIdentifiers.cs new file mode 100644 index 0000000000000..f2c39f292e8d3 --- /dev/null +++ b/src/Features/CSharp/Portable/Snippets/CSharpSnippetIdentifiers.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.CodeAnalysis.CSharp.Snippets; + +/// +/// Contains C#-specific snippet identifiers. +/// These either are C# keywords, contain C# keywords or represent C#-only language constructs +/// +internal static class CSharpSnippetIdentifiers +{ + public const string Class = "class"; + public const string Do = "do"; + public const string Else = "else"; + public const string Enum = "enum"; + public const string For = "for"; + public const string ReversedFor = "forr"; + public const string ForEach = "foreach"; + public const string InitOnlyProperty = "propi"; + public const string If = "if"; + public const string Interface = "interface"; + public const string Lock = "lock"; + public const string StaticIntMain = "sim"; + public const string Struct = "struct"; + public const string StaticVoidMain = "svm"; + public const string While = "while"; +} diff --git a/src/Features/CSharp/Portable/Snippets/CSharpSnippetService.cs b/src/Features/CSharp/Portable/Snippets/CSharpSnippetService.cs index 16590ff577a6c..462f2a8e921d9 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpSnippetService.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpSnippetService.cs @@ -14,6 +14,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportLanguageService(typeof(ISnippetService), LanguageNames.CSharp), Shared] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal class CSharpSnippetService([ImportMany] IEnumerable> snippetProviders) : AbstractSnippetService(snippetProviders) +internal sealed class CSharpSnippetService([ImportMany] IEnumerable> snippetProviders) : AbstractSnippetService(snippetProviders) { } diff --git a/src/Features/CSharp/Portable/Snippets/CSharpStructSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpStructSnippetProvider.cs index 6a208cd578d57..90a4f1355a6de 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpStructSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpStructSnippetProvider.cs @@ -18,7 +18,9 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpStructSnippetProvider : AbstractCSharpTypeSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpStructSnippetProvider() : AbstractCSharpTypeSnippetProvider { private static readonly ISet s_validModifiers = new HashSet(SyntaxFacts.EqualityComparer) { @@ -32,13 +34,7 @@ internal sealed class CSharpStructSnippetProvider : AbstractCSharpTypeSnippetPro SyntaxKind.FileKeyword, }; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpStructSnippetProvider() - { - } - - public override string Identifier => "struct"; + public override string Identifier => CSharpSnippetIdentifiers.Struct; public override string Description => FeaturesResources.struct_; diff --git a/src/Features/CSharp/Portable/Snippets/CSharpVoidMainSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpVoidMainSnippetProvider.cs index 036c046cd3230..416b2850a83a0 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpVoidMainSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpVoidMainSnippetProvider.cs @@ -19,18 +19,14 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpVoidMainSnippetProvider : AbstractCSharpMainMethodSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpVoidMainSnippetProvider() : AbstractCSharpMainMethodSnippetProvider { - public override string Identifier => "svm"; + public override string Identifier => CSharpSnippetIdentifiers.StaticVoidMain; public override string Description => CSharpFeaturesResources.static_void_Main; - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpVoidMainSnippetProvider() - { - } - protected override SyntaxNode GenerateReturnType(SyntaxGenerator generator) => SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)); diff --git a/src/Features/CSharp/Portable/Snippets/CSharpWhileLoopSnippetProvider.cs b/src/Features/CSharp/Portable/Snippets/CSharpWhileLoopSnippetProvider.cs index 6f5928a0d38b8..8288d49ba8d57 100644 --- a/src/Features/CSharp/Portable/Snippets/CSharpWhileLoopSnippetProvider.cs +++ b/src/Features/CSharp/Portable/Snippets/CSharpWhileLoopSnippetProvider.cs @@ -16,13 +16,13 @@ namespace Microsoft.CodeAnalysis.CSharp.Snippets; [ExportSnippetProvider(nameof(ISnippetProvider), LanguageNames.CSharp), Shared] -internal sealed class CSharpWhileLoopSnippetProvider : AbstractWhileLoopSnippetProvider +[method: ImportingConstructor] +[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] +internal sealed class CSharpWhileLoopSnippetProvider() : AbstractWhileLoopSnippetProvider { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpWhileLoopSnippetProvider() - { - } + public override string Identifier => CSharpSnippetIdentifiers.While; + + public override string Description => FeaturesResources.while_loop; protected override SyntaxNode GetCondition(SyntaxNode node) { diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf index b17a7ac3590d4..895bf6cf3c3b2 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.cs.xlf @@ -267,6 +267,11 @@ asynchronní deklarace using {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias externí alias diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf index 02660912cf6ee..0ff37d89a6748 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.de.xlf @@ -267,6 +267,11 @@ asynchrone using-Deklaration {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias externer Alias diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf index f2814210ca73a..271ad0c92d304 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.es.xlf @@ -267,6 +267,11 @@ declaración using asincrónica {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias alias externo diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf index 29e448463f800..5357e21703139 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.fr.xlf @@ -267,6 +267,11 @@ déclaration using asynchrone {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias alias externe diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf index b41883686cb23..6a1440d66d551 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.it.xlf @@ -267,6 +267,11 @@ dichiarazione using asincrona {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias alias extern diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf index bd88b4053d763..11dd8ccbb2e28 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ja.xlf @@ -267,6 +267,11 @@ 非同期の using 宣言 {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias extern エイリアス diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf index bd4db9829f81a..b73f52d47bf3b 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ko.xlf @@ -267,6 +267,11 @@ 비동기 using 선언 {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias extern 별칭 diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf index 386a40445065f..52f640354543d 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pl.xlf @@ -267,6 +267,11 @@ asynchroniczna deklaracja using {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias alias zewnętrzny diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf index f04c9b23cad52..7ab6a42188b13 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.pt-BR.xlf @@ -267,6 +267,11 @@ declaração using assíncrona {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias alias externo diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf index 6b1f679835cbd..28e83bb4a9a22 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.ru.xlf @@ -267,6 +267,11 @@ асинхронное объявление using {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias внешний псевдоним diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf index 88c82b816a35b..25484efa105e1 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.tr.xlf @@ -267,6 +267,11 @@ zaman uyumsuz using bildirimi {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias dış diğer ad diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf index f44e0e84dbeff..bef0d35b51ee5 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hans.xlf @@ -267,6 +267,11 @@ 异步 using 声明 {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias 外部别名 diff --git a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf index 8296579c41354..18a89560a0a31 100644 --- a/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf +++ b/src/Features/CSharp/Portable/xlf/CSharpFeaturesResources.zh-Hant.xlf @@ -267,6 +267,11 @@ 非同步 using 宣告 {Locked="using"} "using" is a C# keyword and should not be localized. + + do-while loop + do-while loop + {Locked="do"}{Locked="while"} "do" and "while" are C# keywords and should not be localized. + extern alias 外部別名 diff --git a/src/Features/Core/Portable/Snippets/CommonSnippetIdentifiers.cs b/src/Features/Core/Portable/Snippets/CommonSnippetIdentifiers.cs new file mode 100644 index 0000000000000..1167581c3f826 --- /dev/null +++ b/src/Features/Core/Portable/Snippets/CommonSnippetIdentifiers.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.CodeAnalysis.Snippets; + +/// +/// Contains language-neutral snippet identifiers, +/// which can theoretically be used in a snippet provider regardless its target language +/// +internal static class CommonSnippetIdentifiers +{ + public const string ConsoleWriteLine = "cw"; + public const string Constructor = "ctor"; + public const string Property = "prop"; + public const string GetOnlyProperty = "propg"; +} diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConsoleSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConsoleSnippetProvider.cs index 57d80f27cd2f2..75cd79d46d593 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConsoleSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConsoleSnippetProvider.cs @@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.Snippets; internal abstract class AbstractConsoleSnippetProvider : AbstractStatementSnippetProvider { - public override string Identifier => "cw"; + public override string Identifier => CommonSnippetIdentifiers.ConsoleWriteLine; public override string Description => FeaturesResources.console_writeline; diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConstructorSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConstructorSnippetProvider.cs index 50792aaefb98d..6758953a6981c 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConstructorSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractConstructorSnippetProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Snippets.SnippetProviders; internal abstract class AbstractConstructorSnippetProvider : AbstractSingleChangeSnippetProvider { - public override string Identifier => "ctor"; + public override string Identifier => CommonSnippetIdentifiers.Constructor; public override string Description => FeaturesResources.constructor; diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractElseSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractElseSnippetProvider.cs index 89b5fe97b53d6..011cd47ec0bc6 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractElseSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractElseSnippetProvider.cs @@ -11,10 +11,6 @@ namespace Microsoft.CodeAnalysis.Snippets.SnippetProviders; internal abstract class AbstractElseSnippetProvider : AbstractStatementSnippetProvider { - public override string Identifier => "else"; - - public override string Description => FeaturesResources.else_statement; - protected override Func GetSnippetContainerFunction(ISyntaxFacts syntaxFacts) => syntaxFacts.IsElseClause; protected override ImmutableArray GetPlaceHolderLocationsList(SyntaxNode node, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractForEachLoopSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractForEachLoopSnippetProvider.cs index c71af5d49c209..a8543986818f7 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractForEachLoopSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractForEachLoopSnippetProvider.cs @@ -11,10 +11,6 @@ namespace Microsoft.CodeAnalysis.Snippets; internal abstract class AbstractForEachLoopSnippetProvider : AbstractInlineStatementSnippetProvider { - public override string Identifier => "foreach"; - - public override string Description => FeaturesResources.foreach_loop; - protected override bool IsValidAccessingType(ITypeSymbol type, Compilation compilation) => type.CanBeEnumerated() || type.CanBeAsynchronouslyEnumerated(compilation); diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractIfSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractIfSnippetProvider.cs index 4cd9cf954b66a..8e4fe49334e36 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractIfSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractIfSnippetProvider.cs @@ -13,10 +13,6 @@ namespace Microsoft.CodeAnalysis.Snippets; internal abstract class AbstractIfSnippetProvider : AbstractConditionalBlockSnippetProvider { - public override string Identifier => "if"; - - public override string Description => FeaturesResources.if_statement; - public override ImmutableArray AdditionalFilterTexts { get; } = ["statement"]; protected override Func GetSnippetContainerFunction(ISyntaxFacts syntaxFacts) => syntaxFacts.IsIfStatement; diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractWhileLoopSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractWhileLoopSnippetProvider.cs index a118a52e99764..1683ec4ca7db2 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractWhileLoopSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractWhileLoopSnippetProvider.cs @@ -11,10 +11,6 @@ namespace Microsoft.CodeAnalysis.Snippets.SnippetProviders; internal abstract class AbstractWhileLoopSnippetProvider : AbstractConditionalBlockSnippetProvider { - public override string Identifier => "while"; - - public override string Description => FeaturesResources.while_loop; - protected override Func GetSnippetContainerFunction(ISyntaxFacts syntaxFacts) => syntaxFacts.IsWhileStatement; protected override SyntaxNode GenerateStatement(SyntaxGenerator generator, SyntaxContext syntaxContext, InlineExpressionInfo? inlineExpressionInfo)