-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add FLLUseDependencyInjection property group & Move all constants to Shared project #18
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Flow.Launcher.Localization.Shared; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
@@ -7,7 +8,7 @@ | |
|
||
namespace Flow.Launcher.Localization.Analyzers.Localize | ||
{ | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
Check warning on line 11 in Flow.Launcher.Localization.Analyzers/Localize/ContextAvailabilityAnalyzer.cs
|
||
public class ContextAvailabilityAnalyzer : DiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create( | ||
|
@@ -17,10 +18,6 @@ | |
AnalyzerDiagnostics.ContextIsNotDeclared | ||
); | ||
|
||
private const string PluginContextTypeName = "PluginInitContext"; | ||
|
||
private const string PluginInterfaceName = "IPluginI18n"; | ||
|
||
public override void Initialize(AnalysisContext context) | ||
{ | ||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); | ||
|
@@ -30,6 +27,12 @@ | |
|
||
private static void AnalyzeNode(SyntaxNodeAnalysisContext context) | ||
{ | ||
var configOptions = context.Options.AnalyzerConfigOptionsProvider; | ||
var useDI = configOptions.GetFLLUseDependencyInjection(); | ||
|
||
// If we use dependency injection, we don't need to check for this context property | ||
if (useDI) return; | ||
|
||
var classDeclaration = (ClassDeclarationSyntax)context.Node; | ||
var semanticModel = context.SemanticModel; | ||
var classSymbol = semanticModel.GetDeclaredSymbol(classDeclaration); | ||
|
@@ -38,7 +41,7 @@ | |
|
||
var contextProperty = classDeclaration.Members.OfType<PropertyDeclarationSyntax>() | ||
.Select(p => semanticModel.GetDeclaredSymbol(p)) | ||
.FirstOrDefault(p => p?.Type.Name is PluginContextTypeName); | ||
.FirstOrDefault(p => p?.Type.Name is Constants.PluginContextTypeName); | ||
|
||
if (contextProperty != null) | ||
{ | ||
|
@@ -67,7 +70,7 @@ | |
.OfType<FieldDeclarationSyntax>() | ||
.SelectMany(f => f.Declaration.Variables) | ||
.Select(f => semanticModel.GetDeclaredSymbol(f)) | ||
.FirstOrDefault(f => f is IFieldSymbol fs && fs.Type.Name is PluginContextTypeName); | ||
.FirstOrDefault(f => f is IFieldSymbol fs && fs.Type.Name is Constants.PluginContextTypeName); | ||
var parentSyntax = fieldDeclaration | ||
?.DeclaringSyntaxReferences[0] | ||
.GetSyntax() | ||
|
@@ -89,6 +92,6 @@ | |
} | ||
|
||
private static bool IsPluginEntryClass(INamedTypeSymbol namedTypeSymbol) => | ||
namedTypeSymbol?.Interfaces.Any(i => i.Name == PluginInterfaceName) ?? false; | ||
namedTypeSymbol?.Interfaces.Any(i => i.Name == Constants.PluginInterfaceName) ?? false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Flow.Launcher.Localization.Shared | ||
{ | ||
public static class Constants | ||
{ | ||
public const string DefaultNamespace = "Flow.Launcher"; | ||
public const string ClassName = "Localize"; | ||
public const string PluginInterfaceName = "IPluginI18n"; | ||
public const string PluginContextTypeName = "PluginInitContext"; | ||
public const string SystemPrefixUri = "clr-namespace:System;assembly=mscorlib"; | ||
public const string XamlPrefixUri = "http://schemas.microsoft.com/winfx/2006/xaml"; | ||
public const string XamlTag = "String"; | ||
public const string KeyAttribute = "Key"; | ||
|
||
public static readonly Regex LanguagesXamlRegex = new Regex(@"\\Languages\\[^\\]+\.xaml$", RegexOptions.IgnoreCase); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Flow.Launcher.Localization.Shared/Flow.Launcher.Localization.Shared.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Version>0.0.1</Version> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<RootNamespace>Flow.Launcher.Localization.Shared</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
||
namespace Flow.Launcher.Localization.Shared | ||
{ | ||
public static class Helper | ||
{ | ||
public static bool GetFLLUseDependencyInjection(this AnalyzerConfigOptionsProvider configOptions) | ||
{ | ||
if (!configOptions.GlobalOptions.TryGetValue("build_property.FLLUseDependencyInjection", out var result) || | ||
!bool.TryParse(result, out var useDI)) | ||
{ | ||
return false; // Default to false | ||
} | ||
return useDI; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those
Item1
are getting out of hand. Isn't there a way to access them by their actual names?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really do not know how to name those things, like
((((ImmutableArray<LocalizableString> LocalizableStrings, ImmutableHashSet<string> InvocationKeys), ImmutableArray<PluginClassInfo> PluginClassInfos), AnalyzerConfigOptionsProvider ConfigOptionsProvider), Compilation Compilation)
such type.Use
Others
orLeft
? I have no idea. If you have any good name for me, please let me know.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just curious if it's possible to avoid using tuples altogether and just use a record:
I don't have in-depth knowledge about source generators, so I don't know if it's possible or not. Let's leave it as is for now, and just remember that this is something that should probably change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that .NetCore2.0 cannot support
record
....