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

Implement simple LSP run tests #68889

Merged
merged 9 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<SourceGeneratorMicrosoftCodeAnalysisVersion>4.1.0</SourceGeneratorMicrosoftCodeAnalysisVersion>
<MicrosoftILVerificationVersion>7.0.0-alpha.1.22060.1</MicrosoftILVerificationVersion>
<MicrosoftVisualStudioThreadingPackagesVersion>17.7.1-preview</MicrosoftVisualStudioThreadingPackagesVersion>
<MicrosoftTestPlatformVersion>17.4.0-preview-20220707-01</MicrosoftTestPlatformVersion>
<MicrosoftTestPlatformVersion>17.4.1</MicrosoftTestPlatformVersion>
</PropertyGroup>
<!--
Dependency versions
Expand Down
51 changes: 51 additions & 0 deletions src/Features/CSharp/Portable/Testing/CSharpTestMethodFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Features.Testing;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.CSharp.Testing;

[ExportLanguageService(typeof(ITestMethodFinder), LanguageNames.CSharp), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class CSharpTestMethodFinder([ImportMany] IEnumerable<ITestFrameworkMetadata> testFrameworks) : AbstractTestMethodFinder<MethodDeclarationSyntax>(testFrameworks)
Copy link
Member Author

Choose a reason for hiding this comment

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

abstracted out because we have language specific details here.

dibarbet marked this conversation as resolved.
Show resolved Hide resolved
{
protected override bool DescendIntoChildren(SyntaxNode node)
{
// We only need to look in type declarations for test methods (and therefore namespaces to find types).
return node is BaseNamespaceDeclarationSyntax or TypeDeclarationSyntax;
}

protected override bool IsTestMethod(MethodDeclarationSyntax method)
{
foreach (var attributeList in method.AttributeLists)
{
foreach (var attribute in attributeList.Attributes)
{
var isTestAttribute = IsTestAttribute(attribute);
if (isTestAttribute)
{
return true;
}
}
}

return false;
}

private bool IsTestAttribute(AttributeSyntax attribute)
{
var attributeName = attribute.Name.GetNameToken().Text;

var matches = TestFrameworkMetadata.Any(metadata => metadata.MatchesAttributeSyntacticName(attributeName));
dibarbet marked this conversation as resolved.
Show resolved Hide resolved
dibarbet marked this conversation as resolved.
Show resolved Hide resolved
return matches;
}
}
Loading