Skip to content
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

Snippets: If snippet and use of LSP's SnippetExpander #60860

Merged
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
05edfc3
Merge remote-tracking branch 'upstream/features/semantic-snippets' in…
akhera99 Mar 16, 2022
4ee5f98
start work on if snippet
akhera99 Mar 16, 2022
f7ff1ad
wip
akhera99 Mar 16, 2022
bf3685c
wip
akhera99 Mar 17, 2022
74f5583
wip
akhera99 Mar 17, 2022
fa96642
wip
akhera99 Mar 22, 2022
3fbf4c7
wip
akhera99 Mar 23, 2022
977529d
tests
akhera99 Mar 28, 2022
14de21f
Merge remote-tracking branch 'upstream/features/semantic-snippets' in…
akhera99 Apr 5, 2022
2c1ed38
wip
akhera99 Apr 6, 2022
c705fd8
wip
akhera99 Apr 6, 2022
d84a6c5
Merge remote-tracking branch 'upstream/features/semantic-snippets' in…
akhera99 Apr 6, 2022
85c12cc
lsp service now works
akhera99 Apr 12, 2022
293e2b5
lots of changes
akhera99 Apr 14, 2022
b8593eb
wip
akhera99 Apr 19, 2022
105e658
Merge branch 'main' into features/snippets_2
akhera99 Apr 19, 2022
e137363
remove added changes
akhera99 Apr 19, 2022
e78d2d4
fixes
akhera99 Apr 19, 2022
9220332
cleanup
akhera99 Apr 19, 2022
5e4aefe
comments
akhera99 Apr 19, 2022
334331b
remove unused file
akhera99 Apr 19, 2022
ddd0aab
revert change made
akhera99 Apr 20, 2022
f4f0aea
update
akhera99 Apr 20, 2022
3230e0a
fix random file change
akhera99 Apr 20, 2022
ddfedf3
simplify
akhera99 Apr 20, 2022
29c41a6
cleanup/comments
akhera99 Apr 20, 2022
61ffd0e
remove unused attribute
akhera99 Apr 20, 2022
fae94b9
Merge remote-tracking branch 'upstream/features/semantic-snippets' in…
akhera99 Apr 20, 2022
35ba79b
pr feedback
akhera99 Apr 21, 2022
6588ac4
pr feedback, need to fix tests
akhera99 Apr 25, 2022
b09573d
fix tests
akhera99 Apr 26, 2022
76c70e1
fix/add comments
akhera99 Apr 26, 2022
29e3e17
more fixes
akhera99 Apr 26, 2022
51e7377
more pr feedback
akhera99 Apr 26, 2022
05e839f
lots of fixes
akhera99 Apr 26, 2022
631d80d
pr feedback
akhera99 Apr 26, 2022
f257f52
naming
akhera99 Apr 26, 2022
7f7c087
lots of changes + added new tests
akhera99 May 2, 2022
6ef9f5d
comments
akhera99 May 2, 2022
c281d2a
more fixes
akhera99 May 2, 2022
7002563
bug
akhera99 May 2, 2022
1940bb2
fix
akhera99 May 2, 2022
02a1a15
merge main
akhera99 May 2, 2022
e6254ed
options changed
akhera99 May 2, 2022
a4e669f
tests wrong and I did stupid stuff as a result
akhera99 May 2, 2022
93c8e9a
remove unnecessary code
akhera99 May 2, 2022
75970d1
comments
akhera99 May 2, 2022
d26a3a4
cleanup, need to add more tests
akhera99 May 2, 2022
fae4cff
tests
akhera99 May 2, 2022
08c22d6
every iteration
akhera99 May 2, 2022
973b95b
regions for easier viewing
akhera99 May 2, 2022
ed94922
no changes
akhera99 May 3, 2022
1a87816
feedback
akhera99 May 3, 2022
6baf3b3
pr feedback
akhera99 May 3, 2022
5021c4e
remove unused method
akhera99 May 4, 2022
2c2be6b
fix bug
akhera99 May 4, 2022
c244e00
feedback
akhera99 May 6, 2022
74111f9
way more tests
akhera99 May 6, 2022
af2aada
handle same positions better
akhera99 May 6, 2022
f36a262
comments
akhera99 May 6, 2022
c8f674f
tests
akhera99 May 9, 2022
6e33b9d
pr feedback
akhera99 May 9, 2022
2498eff
removed unnecessary check
akhera99 May 9, 2022
d02e1c2
fix
akhera99 May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Compilers/Test/Core/Traits/Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static class Features
public const string RemoveUnnecessaryLineContinuation = nameof(RemoveUnnecessaryLineContinuation);
public const string Rename = nameof(Rename);
public const string RenameTracking = nameof(RenameTracking);
public const string RoslynLSPSnippetConverter = nameof(RoslynLSPSnippetConverter);
public const string SignatureHelp = nameof(SignatureHelp);
public const string Simplification = nameof(Simplification);
public const string SmartIndent = nameof(SmartIndent);
Expand Down
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Completion.CompletionProviders.Snippets;
using Microsoft.CodeAnalysis.Snippets;
using Microsoft.CodeAnalysis.Test.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets
{
public abstract class AbstractCSharpSnippetCompletionProviderTests : AbstractCSharpCompletionProviderTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per before, i would not do this as a provider test. especially for something as complex as snippets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point, it's basically just testing that the data I retrieve for a snippet is correct. I can remove it the tests.

{
protected abstract string ItemToCommit { get; }

protected override TestComposition GetComposition()
=> base.GetComposition()
.AddExcludedPartTypes(typeof(IRoslynLSPSnippetExpander))
.AddParts(typeof(TestRoslynLanguageServerSnippetExpander));

internal override Type GetCompletionProviderType()
=> typeof(CSharpSnippetCompletionProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders.Snippets
{
public class CSharpConsoleSnippetCompletionProviderTests : AbstractCSharpCompletionProviderTests
public class CSharpConsoleSnippetCompletionProviderTests : AbstractCSharpSnippetCompletionProviderTests
{
private static readonly string s_itemToCommit = FeaturesResources.Write_to_the_console;

internal override Type GetCompletionProviderType()
=> typeof(CSharpSnippetCompletionProvider);
protected override string ItemToCommit => FeaturesResources.Write_to_the_console;

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task InsertConsoleSnippetInMethodTest()
Expand All @@ -40,7 +37,7 @@ public void Method()
Console.WriteLine($$);
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -65,7 +62,7 @@ public async Task MethodAsync()
await Console.Out.WriteLineAsync($$);
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -84,13 +81,14 @@ public async Task MethodAsync()
@"using System;

Console.WriteLine($$);

class Program
{
public async Task MethodAsync()
{
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -108,7 +106,7 @@ public async Task MethodAsync()
}
}
}";
await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -125,7 +123,7 @@ public async Task MethodAsync()
}
}
";
await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -152,7 +150,7 @@ public Program()
Console.WriteLine($$);
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

/// <summary>
Expand Down Expand Up @@ -189,7 +187,7 @@ void LocalMethod()
}
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

/// <summary>
Expand Down Expand Up @@ -222,7 +220,7 @@ static void Main(string[] args)
};

}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

/// <summary>
Expand All @@ -249,7 +247,7 @@ public async Task InsertConsoleSnippetInParenthesizedLambdaExpressionTest()
global::System.Console.WriteLine($$);
return x == y;
};";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -272,7 +270,7 @@ public void Method()
};
}
}";
await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -286,7 +284,7 @@ public void Method()
Func<int, int> f = x => $$;
}
}";
await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -301,7 +299,7 @@ public void Method()
}
}";

await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -326,7 +324,7 @@ public Test(string val)
}
}";

await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -340,7 +338,7 @@ public void Method(int x, $$)
}
}";

await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -354,7 +352,7 @@ public async Task NoConsoleSnippetInRecordDeclarationTest()
public string LastName { get; init; } = default!;
};";

await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -369,7 +367,7 @@ public void Method()
}
}";

await VerifyItemIsAbsentAsync(markupBeforeCommit, s_itemToCommit);
await VerifyItemIsAbsentAsync(markupBeforeCommit, ItemToCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -394,7 +392,7 @@ public void Method()
Console.WriteLine($$);
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -419,7 +417,7 @@ public void Method()
Console.WriteLine($$);
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, s_itemToCommit, expectedCodeAfterCommit);
await VerifyCustomCommitProviderAsync(markupBeforeCommit, ItemToCommit, expectedCodeAfterCommit);
}
}
}
Loading