Skip to content

Commit

Permalink
Merge pull request #69608 from sharwell/codelens-vscode-fields
Browse files Browse the repository at this point in the history
Include CodeLens on remaining types and members
  • Loading branch information
sharwell authored Aug 18, 2023
2 parents b4a9c62 + 29cece3 commit 6652c33
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
{
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
base.VisitEnumDeclaration(node);
}

public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
Expand Down Expand Up @@ -83,5 +84,41 @@ public override void VisitRecordDeclaration(RecordDeclarationSyntax node)
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
base.VisitRecordDeclaration(node);
}

public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node)
{
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
}

public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
{
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
}

public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
foreach (var variable in node.Declaration.Variables)
{
_memberBuilder.Add(new CodeLensMember(variable, variable.Identifier.Span));
}
}

public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node)
{
foreach (var variable in node.Declaration.Variables)
{
_memberBuilder.Add(new CodeLensMember(variable, variable.Identifier.Span));
}
}

public override void VisitEventDeclaration(EventDeclarationSyntax node)
{
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
}

public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node)
{
_memberBuilder.Add(new CodeLensMember(node, node.Identifier.Span));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.CodeAnalysis.LanguageServer.Handler.CodeLens;
using Newtonsoft.Json;
using Roslyn.Test.Utilities;
using StreamJsonRpc;
using Xunit;
using Xunit.Abstractions;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
Expand Down Expand Up @@ -134,6 +133,19 @@ public async Task TestEnumDeclarationAsync(bool lspMutatingWorkspace)
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestEnumMemberDeclarationAsync(bool lspMutatingWorkspace)
{
var markup =
@"enum A
{
{|codeLens:One|}
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
public async Task TestPropertyDeclarationAsync(bool lspMutatingWorkspace)
{
Expand All @@ -146,6 +158,136 @@ public async Task TestPropertyDeclarationAsync(bool lspMutatingWorkspace)
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestEventDeclarationAsync(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public event System.EventHandler {|codeLens:I|} { add { } remove { } }
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestEventFieldDeclaration1Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public event System.EventHandler {|codeLens:I|};
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestEventFieldDeclaration2Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public event System.EventHandler {|codeLens:I|}, I2;
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestEventFieldDeclaration3Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public event System.EventHandler I, {|codeLens:I2|};
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestFieldDeclaration1Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public int {|codeLens:I|};
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestFieldDeclaration2Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public int {|codeLens:I|}, I2;
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestFieldDeclaration3Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public int I, {|codeLens:I2|};
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestConstantDeclaration1Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public const int {|codeLens:I|} = 0;
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestConstantDeclaration2Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public const int {|codeLens:I|} = 0, I2 = 0;
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestConstantDeclaration3Async(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
public const int I = 0, {|codeLens:I2|} = 0;
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
public async Task TestMethodDeclarationAsync(bool lspMutatingWorkspace)
{
Expand All @@ -171,6 +313,16 @@ public async Task TestStructDeclarationAsync(bool lspMutatingWorkspace)
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestDelegateDeclarationAsync(bool lspMutatingWorkspace)
{
var markup =
@"delegate void {|codeLens:A|}();";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
public async Task TestConstructorDeclarationAsync(bool lspMutatingWorkspace)
{
Expand All @@ -185,6 +337,21 @@ public async Task TestConstructorDeclarationAsync(bool lspMutatingWorkspace)
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
[WorkItem("https://github.com/dotnet/roslyn/issues/69583")]
public async Task TestDestructorDeclarationAsync(bool lspMutatingWorkspace)
{
var markup =
@"class A
{
~{|codeLens:A|}()
{
}
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, lspMutatingWorkspace, CapabilitiesWithVSExtensions);
await VerifyCodeLensAsync(testLspServer, expectedNumberOfReferences: 0);
}

[Theory, CombinatorialData]
public async Task TestRecordDeclarationAsync(bool lspMutatingWorkspace)
{
Expand Down
Loading

0 comments on commit 6652c33

Please sign in to comment.