-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Semantic Snippets: Console snippet first look #59303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akhera99
merged 51 commits into
dotnet:features/semantic-snippets
from
akhera99:features/snippets_1
Mar 12, 2022
Merged
Changes from 18 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
6e23a2e
snippets first loook
akhera99 a74697d
Merge branch 'main' into features/snippets_1
akhera99 6bda3a9
starting imp
akhera99 592e07f
still figuring things out
akhera99 cce51e9
temp
akhera99 f1bf487
console snippet
akhera99 e96dfd8
console snippet works
akhera99 fb20055
tests + correct formatting :)
akhera99 01b7fef
more tests
akhera99 e43efd1
more tests, removed old unusued code
akhera99 e3d9029
added a few comments
akhera99 3a1ab80
a lot of changes aha
akhera99 9e3b740
remove any use og a syntaxtoken in the completion provider
akhera99 555b72f
lots more tests/enumeration of cases
akhera99 22d3602
fix tests
akhera99 e66613e
removed unused usings
akhera99 e225c49
comments + moving to proper directories
akhera99 695ab2b
rename + more comments
akhera99 445f6ce
feedback
akhera99 28d938f
a lot of changes, still need to reformat the introduced usings
akhera99 95d5317
more changes aha
akhera99 7e5b410
removed commented out code
akhera99 a628f93
need to add more tests
akhera99 21a5e73
simplifier broke, need to add other tests
akhera99 225cd65
tests
akhera99 493ccf8
pr feedback
akhera99 8f40b9f
more comment fixes
akhera99 0bb9cd8
even more comment fixes
akhera99 aff0b27
didnt need to be public
akhera99 eff7227
more pr feedback
akhera99 6ffd036
more comments
akhera99 e3c8e8d
locks?
akhera99 ce0d96b
made rename virtual
akhera99 2fc54b0
Merge branch 'features/semantic-snippets' into features/snippets_1
akhera99 604c85d
removed unused method
akhera99 b558cea
Merge branch 'features/snippets_1' of https://github.com/akhera99/ros…
akhera99 88d968e
fix failing tests
akhera99 e2caf59
fix failing item
akhera99 465a8b5
Merge branch 'features/semantic-snippets' into features/snippets_1
akhera99 49ab16d
some formatting stuff
akhera99 5682a6d
more pr feedback
akhera99 c82acb9
more pr feedback
akhera99 7633033
fix comments
akhera99 e9f17f4
more pr feeedback
akhera99 a36edea
fix name
akhera99 1a908e0
removed unnecessary check
akhera99 3be711b
fixed naming
akhera99 0c98af8
fix completion provider ordering
akhera99 4a1e4d9
more feedback
akhera99 20ba1e4
rename file as well
akhera99 1d4fe39
stop using tryadd
akhera99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
351 changes: 351 additions & 0 deletions
351
...st/Completion/CompletionProviders/Snippets/CSharpConsoleSnippetCompletionProviderTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,351 @@ | ||
| // 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.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.CSharp.Completion.CompletionProviders.Snippets; | ||
| using Microsoft.CodeAnalysis.Test.Utilities; | ||
| using Roslyn.Test.Utilities; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets | ||
| { | ||
| public class CSharpConsoleSnippetCompletionProviderTests : AbstractCSharpCompletionProviderTests | ||
| { | ||
| internal override Type GetCompletionProviderType() | ||
| => typeof(CSharpSnippetCompletionProvider); | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetInMethodTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| Wr$$ | ||
| } | ||
| }"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| Console.WriteLine($$); | ||
| } | ||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertAsyncConsoleSnippetTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| Wr$$ | ||
| } | ||
| }"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @"class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| await Console.Out.WriteLineAsync($$); | ||
| } | ||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetGlobalTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @" | ||
| $$ | ||
| class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| } | ||
| }"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @" | ||
| Console.WriteLine($$); | ||
| class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| } | ||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInBlockNamespaceTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @" | ||
| namespace Namespace | ||
| { | ||
| $$ | ||
| class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| } | ||
| } | ||
| }"; | ||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInFileScopedNamespaceTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @" | ||
| namespace Namespace; | ||
| $$ | ||
| class Program | ||
| { | ||
| public async Task MethodAsync() | ||
| { | ||
| } | ||
| } | ||
| "; | ||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetInConstructorTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public Program() | ||
| { | ||
| var x = 5; | ||
| $$ | ||
| } | ||
| }"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @"class Program | ||
| { | ||
| public Program() | ||
| { | ||
| var x = 5; | ||
| Console.WriteLine($$); | ||
| } | ||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetInLocalFunctionTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| var x = 5; | ||
| void LocalMethod() | ||
| { | ||
| $$ | ||
| } | ||
| } | ||
| }"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| var x = 5; | ||
| void LocalMethod() | ||
| { | ||
| Console.WriteLine($$); | ||
| } | ||
| } | ||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetInAnonymousFunctionTest() | ||
| { | ||
| 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) { | ||
| Console.WriteLine($$); | ||
| }; | ||
|
|
||
| }"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task InsertConsoleSnippetInParenthesizedLambdaExpressionTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @" | ||
| Func<int, int, bool> testForEquality = (x, y) => | ||
| { | ||
| $$ | ||
| return x == y; | ||
| };"; | ||
|
|
||
| var expectedCodeAfterCommit = | ||
| @" | ||
| Func<int, int, bool> testForEquality = (x, y) => | ||
| { | ||
| Console.WriteLine($$); | ||
| return x == y; | ||
| };"; | ||
| await VerifyCustomCommitProviderAsync(markupBeforeCommit, "Write to the Console", expectedCodeAfterCommit); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInSwitchExpression() | ||
| { | ||
| 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, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInSingleLambdaExpression() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| Func<int, int> f = x => $$; | ||
| } | ||
| }"; | ||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInStringTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| var str = ""$$""; | ||
| } | ||
| }"; | ||
|
|
||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInObjectInitializerTest() | ||
| { | ||
| 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, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInParameterListTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method(int x, $$) | ||
| { | ||
| } | ||
| }"; | ||
|
|
||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInRecordDeclarationTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"public record Person | ||
| { | ||
| $$ | ||
| public string FirstName { get; init; } = default!; | ||
| public string LastName { get; init; } = default!; | ||
| };"; | ||
|
|
||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
|
|
||
| [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] | ||
| public async Task NoConsoleSnippetInVariableDeclarationTest() | ||
| { | ||
| var markupBeforeCommit = | ||
| @"class Program | ||
| { | ||
| public void Method() | ||
| { | ||
| var x = $$ | ||
| } | ||
| }"; | ||
|
|
||
| await VerifyItemIsAbsentAsync(markupBeforeCommit, "Write to the Console"); | ||
| } | ||
akhera99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...Sharp/Portable/Completion/CompletionProviders/Snippets/CSharpSnippetCompletionProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -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. | ||||
|
|
||||
| using System; | ||||
| using System.Composition; | ||||
| using Microsoft.CodeAnalysis.Completion; | ||||
| using Microsoft.CodeAnalysis.Completion.Providers.Snippets; | ||||
| using Microsoft.CodeAnalysis.CSharp.Completion.Providers; | ||||
| using Microsoft.CodeAnalysis.Host.Mef; | ||||
|
|
||||
| namespace Microsoft.CodeAnalysis.CSharp.Completion.CompletionProviders.Snippets | ||||
| { | ||||
| [ExportCompletionProvider(nameof(CSharpSnippetCompletionProvider), LanguageNames.CSharp)] | ||||
| [ExtensionOrder(After = nameof(FirstBuiltInCompletionProvider))] | ||||
| [Shared] | ||||
| internal class CSharpSnippetCompletionProvider : AbstractSnippetCompletionProvider | ||||
| { | ||||
| [ImportingConstructor] | ||||
| [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||||
| public CSharpSnippetCompletionProvider() | ||||
| { | ||||
|
|
||||
|
||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Write to the Console"here, and the rest of the file, needs to use the resource or the spanish tests will fail once the translation team have done their bit.