diff --git a/Analyzer/Analyzer.Vsix/source.extension.vsixmanifest b/Analyzer/Analyzer.Vsix/source.extension.vsixmanifest
index 0385d1d03..6eae5250e 100644
--- a/Analyzer/Analyzer.Vsix/source.extension.vsixmanifest
+++ b/Analyzer/Analyzer.Vsix/source.extension.vsixmanifest
@@ -1,27 +1,27 @@
-
+
DisCatSharp Analyzer
This is an diagnostic extension for DisCatSharp.
-
+
diff --git a/Analyzer/Analyzer/AnalyzerAnalyzer.cs b/Analyzer/Analyzer/AnalyzerAnalyzer.cs
index 5ce250904..1a75b2675 100644
--- a/Analyzer/Analyzer/AnalyzerAnalyzer.cs
+++ b/Analyzer/Analyzer/AnalyzerAnalyzer.cs
@@ -1,119 +1,119 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 2021-2022 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using DisCatSharp.Experimental;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Analyzer
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AnalyzerAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "DcsExp";
// You can change these strings in the Resources.resx file. If you do not want your analyzer to be localize-able, you can use regular strings for Title and MessageFormat.
// See https://github.com/dotnet/roslyn/blob/main/docs/analyzers/Localizing%20Analyzers.md for more on localization
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.AnalyzerTitle), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(Resources.AnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(Resources.AnalyzerDescription), Resources.ResourceManager, typeof(Resources));
private const string Category = "Informations";
private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);
public override ImmutableArray SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } }
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
// See https://github.com/dotnet/roslyn/blob/main/docs/analyzers/Analyzer%20Actions%20Semantics.md for more information
context.RegisterSyntaxNodeAction(AnalyzerInvocation, SyntaxKind.InvocationExpression);
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var namedTypeSymbol = (INamedTypeSymbol)context.Symbol;
// Find just those named type symbols with names containing lowercase letters.
if (namedTypeSymbol.Name.ToCharArray().Any(char.IsLower))
{
// For all such symbols, produce a diagnostic.
var diagnostic = Diagnostic.Create(Rule, namedTypeSymbol.Locations[0], namedTypeSymbol.Name);
context.ReportDiagnostic(diagnostic);
}
}
private static void AnalyzerInvocation(SyntaxNodeAnalysisContext context)
{
var invocation = (InvocationExpressionSyntax)context.Node;
var methodDeclaration = (context.SemanticModel.GetSymbolInfo(invocation, context.CancellationToken).Symbol as IMethodSymbol);
//There are several reason why this may be null e.g invoking a delegate
if (null == methodDeclaration)
{
return;
}
var methodAttributes = methodDeclaration.GetAttributes();
var attributeData = methodAttributes.FirstOrDefault(attr => IsExperimentalAttribute(context.SemanticModel, attr, typeof(ExperimentalAttribute)));
if (null == attributeData)
{
return;
}
var message = GetMessage(attributeData);
var diagnostic = Diagnostic.Create(Rule, invocation.GetLocation(), methodDeclaration.Name, message);
context.ReportDiagnostic(diagnostic);
}
static bool IsExperimentalAttribute(SemanticModel semanticModel, AttributeData attribute, Type desiredAttributeType)
{
var desiredTypeNamedSymbol = semanticModel.Compilation.GetTypeByMetadataName(desiredAttributeType.FullName);
var result = attribute.AttributeClass.Equals(desiredTypeNamedSymbol);
return result;
}
static string GetMessage(AttributeData attribute)
{
if (attribute.ConstructorArguments.Length < 1)
{
- return "This method is obsolete";
+ return "Do not use in production";
}
return (attribute.ConstructorArguments[0].Value as string);
}
}
}
diff --git a/Analyzer/Analyzer/Resources.Designer.cs b/Analyzer/Analyzer/Resources.Designer.cs
index 153684e34..537beac5b 100644
--- a/Analyzer/Analyzer/Resources.Designer.cs
+++ b/Analyzer/Analyzer/Resources.Designer.cs
@@ -1,90 +1,90 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace Analyzer {
using System;
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Analyzer.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
///
- /// Looks up a localized string similar to Don't use in production.
+ /// Looks up a localized string similar to {1}.
///
internal static string AnalyzerDescription {
get {
return ResourceManager.GetString("AnalyzerDescription", resourceCulture);
}
}
///
/// Looks up a localized string similar to Function '{0}' is experimental.
///
internal static string AnalyzerMessageFormat {
get {
return ResourceManager.GetString("AnalyzerMessageFormat", resourceCulture);
}
}
///
/// Looks up a localized string similar to Function is experimental.
///
internal static string AnalyzerTitle {
get {
return ResourceManager.GetString("AnalyzerTitle", resourceCulture);
}
}
}
}
diff --git a/Analyzer/Analyzer/Resources.resx b/Analyzer/Analyzer/Resources.resx
index 4e30f26f9..50b3af851 100644
--- a/Analyzer/Analyzer/Resources.resx
+++ b/Analyzer/Analyzer/Resources.resx
@@ -1,132 +1,132 @@
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Don't use in production
+ {1}
An optional longer localizable description of the diagnostic.
Function '{0}' is experimental
The format-able message the diagnostic displays.
Function is experimental
The title of the diagnostic.
\ No newline at end of file
diff --git a/DisCatSharp.Experimental/Program.cs b/DisCatSharp.Experimental/Program.cs
index 3bb49839c..14cfefe7b 100644
--- a/DisCatSharp.Experimental/Program.cs
+++ b/DisCatSharp.Experimental/Program.cs
@@ -1,18 +1,18 @@
using System;
namespace DisCatSharp.Experimental;
public class Program
{
public static void Main(string[] args = null)
{
- Test();
+ Test2();
}
- [Experimental("Test")]
- public static void Test()
+ [Experimental("Test2")]
+ public static void Test2()
{
- Console.WriteLine("Test");
+ Console.WriteLine("Test2");
}
}