Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6e23a2e
snippets first loook
akhera99 Nov 11, 2021
a74697d
Merge branch 'main' into features/snippets_1
akhera99 Dec 9, 2021
6bda3a9
starting imp
akhera99 Dec 10, 2021
592e07f
still figuring things out
akhera99 Jan 6, 2022
cce51e9
temp
akhera99 Jan 13, 2022
f1bf487
console snippet
akhera99 Feb 1, 2022
e96dfd8
console snippet works
akhera99 Feb 3, 2022
fb20055
tests + correct formatting :)
akhera99 Feb 4, 2022
01b7fef
more tests
akhera99 Feb 4, 2022
e43efd1
more tests, removed old unusued code
akhera99 Feb 4, 2022
e3d9029
added a few comments
akhera99 Feb 7, 2022
3a1ab80
a lot of changes aha
akhera99 Feb 14, 2022
9e3b740
remove any use og a syntaxtoken in the completion provider
akhera99 Feb 15, 2022
555b72f
lots more tests/enumeration of cases
akhera99 Feb 16, 2022
22d3602
fix tests
akhera99 Feb 17, 2022
e66613e
removed unused usings
akhera99 Feb 17, 2022
e225c49
comments + moving to proper directories
akhera99 Feb 18, 2022
695ab2b
rename + more comments
akhera99 Feb 18, 2022
445f6ce
feedback
akhera99 Feb 19, 2022
28d938f
a lot of changes, still need to reformat the introduced usings
akhera99 Feb 25, 2022
95d5317
more changes aha
akhera99 Feb 26, 2022
7e5b410
removed commented out code
akhera99 Feb 26, 2022
a628f93
need to add more tests
akhera99 Feb 28, 2022
21a5e73
simplifier broke, need to add other tests
akhera99 Mar 1, 2022
225cd65
tests
akhera99 Mar 2, 2022
493ccf8
pr feedback
akhera99 Mar 2, 2022
8f40b9f
more comment fixes
akhera99 Mar 2, 2022
0bb9cd8
even more comment fixes
akhera99 Mar 2, 2022
aff0b27
didnt need to be public
akhera99 Mar 2, 2022
eff7227
more pr feedback
akhera99 Mar 2, 2022
6ffd036
more comments
akhera99 Mar 2, 2022
e3c8e8d
locks?
akhera99 Mar 3, 2022
ce0d96b
made rename virtual
akhera99 Mar 3, 2022
2fc54b0
Merge branch 'features/semantic-snippets' into features/snippets_1
akhera99 Mar 3, 2022
604c85d
removed unused method
akhera99 Mar 3, 2022
b558cea
Merge branch 'features/snippets_1' of https://github.com/akhera99/ros…
akhera99 Mar 3, 2022
88d968e
fix failing tests
akhera99 Mar 3, 2022
e2caf59
fix failing item
akhera99 Mar 3, 2022
465a8b5
Merge branch 'features/semantic-snippets' into features/snippets_1
akhera99 Mar 9, 2022
49ab16d
some formatting stuff
akhera99 Mar 9, 2022
5682a6d
more pr feedback
akhera99 Mar 9, 2022
c82acb9
more pr feedback
akhera99 Mar 9, 2022
7633033
fix comments
akhera99 Mar 9, 2022
e9f17f4
more pr feeedback
akhera99 Mar 9, 2022
a36edea
fix name
akhera99 Mar 9, 2022
1a908e0
removed unnecessary check
akhera99 Mar 9, 2022
3be711b
fixed naming
akhera99 Mar 9, 2022
0c98af8
fix completion provider ordering
akhera99 Mar 10, 2022
4a1e4d9
more feedback
akhera99 Mar 11, 2022
20ba1e4
rename file as well
akhera99 Mar 11, 2022
1d4fe39
stop using tryadd
akhera99 Mar 11, 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
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);
Copy link
Member

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.

}

[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");
}
}
}
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()
{

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

}

internal override string Language => LanguageNames.CSharp;
}
}
Loading