Skip to content

Commit

Permalink
Merge pull request #294 from AvaloniaUI/nullable
Browse files Browse the repository at this point in the history
Avalonia.Ide.CompletionEngine: nullable, trimming, STJ, code format
  • Loading branch information
maxkatz6 authored Feb 9, 2023
2 parents 392e639 + 9fb42cc commit fada721
Show file tree
Hide file tree
Showing 38 changed files with 2,542 additions and 2,453 deletions.
114 changes: 100 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ root = true
insert_final_newline = true
indent_style = space
indent_size = 4
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion

# C# files
[*.cs]
Expand All @@ -21,6 +39,7 @@ csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# trim_trailing_whitespace = true

# Indentation preferences
csharp_indent_block_contents = true
Expand All @@ -47,28 +66,29 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
# private static fields should have s_ prefix
dotnet_naming_rule.private_static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_have_prefix.style = private_static_prefix_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private

dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.capitalization = camel_case
dotnet_naming_style.private_static_prefix_style.required_prefix = s_
dotnet_naming_style.private_static_prefix_style.capitalization = camel_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
Expand Down Expand Up @@ -116,7 +136,7 @@ csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
Expand All @@ -131,10 +151,73 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
space_within_single_line_array_initializer_braces = true

#Net Analyzer
dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed.

# CS0649: Field 'field' is never assigned to, and will always have its default value 'value'
dotnet_diagnostic.CS0649.severity = error

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = suggestion

# CS0162: Remove unreachable code
dotnet_diagnostic.CS0162.severity = error
# CA1018: Mark attributes with AttributeUsageAttribute
dotnet_diagnostic.CA1018.severity = error
# CA1304: Specify CultureInfo
dotnet_diagnostic.CA1304.severity = warning
# CA1802: Use literals where appropriate
dotnet_diagnostic.CA1802.severity = warning
# CA1813: Avoid unsealed attributes
dotnet_diagnostic.CA1813.severity = error
# CA1815: Override equals and operator equals on value types
dotnet_diagnostic.CA1815.severity = warning
# CA1820: Test for empty strings using string length
dotnet_diagnostic.CA1820.severity = warning
# CA1821: Remove empty finalizers
dotnet_diagnostic.CA1821.severity = warning
# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = suggestion
# CA1823: Avoid unused private fields
dotnet_diagnostic.CA1823.severity = warning
dotnet_code_quality.CA1822.api_surface = private, internal
# CA1825: Avoid zero-length array allocations
dotnet_diagnostic.CA1825.severity = warning
# CA1826: Use property instead of Linq Enumerable method
dotnet_diagnostic.CA1826.severity = suggestion
# CA1827: Do not use Count/LongCount when Any can be used
dotnet_diagnostic.CA1827.severity = warning
# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used
dotnet_diagnostic.CA1828.severity = warning
# CA1829: Use Length/Count property instead of Enumerable.Count method
dotnet_diagnostic.CA1829.severity = warning
# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
dotnet_diagnostic.CA1847.severity = warning
# CA2211: Non-constant fields should not be visible
dotnet_diagnostic.CA2211.severity = error
# IDE0057: Use Range operator
dotnet_diagnostic.IDE0057.severity = silent
# Spelling
dotnet_diagnostic.SPELL.severity = silent

# Wrapping preferences
csharp_wrap_before_ternary_opsigns = false
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_null_check_over_type_check = true:suggestion


# Xaml files
[*.xaml]
indent_size = 4
[*.{xaml,axaml}]
indent_size = 2

# Xml project files
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
Expand All @@ -152,8 +235,11 @@ indent_size = 2
[*.{props,targets,config,nuspec}]
indent_size = 2

[*.json]
indent_size = 2

# Shell scripts
[*.sh]
end_of_line = lf
[*.{cmd, bat}]
[*.{cmd,bat}]
end_of_line = crlf
7 changes: 5 additions & 2 deletions AvaloniaVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaResourceDictionaryT
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaStylesTemplate", "templates\AvaloniaStylesTemplate\AvaloniaStylesTemplate.csproj", "{9FEF480A-5A56-489D-AD89-53970FD2B2A1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaVS.VS2019AndEarlier", "AvaloniaVS.VS2019AndEarlier\AvaloniaVS.VS2019AndEarlier.csproj", "{79A4832C-9D3E-42D9-9215-D786565269B5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaVS.VS2019AndEarlier", "AvaloniaVS.VS2019AndEarlier\AvaloniaVS.VS2019AndEarlier.csproj", "{79A4832C-9D3E-42D9-9215-D786565269B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaVS.VS2022", "AvaloniaVS.VS2022\AvaloniaVS.VS2022.csproj", "{1029EC08-7B2E-4018-B20D-E85CA58DEB59}"
EndProject
Expand All @@ -30,6 +30,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
azure-pipelines.yml = azure-pipelines.yml
Directory.Build.props = Directory.Build.props
Props\NetAnalyzers.props = Props\NetAnalyzers.props
Props\NullableEnable.props = Props\NullableEnable.props
Props\TrimmingEnable.props = Props\TrimmingEnable.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Ide.CompletionEngine", "CompletionEngine\Avalonia.Ide.CompletionEngine\Avalonia.Ide.CompletionEngine.csproj", "{CD7DB042-4282-4DFB-9910-958036DD621D}"
Expand Down Expand Up @@ -212,6 +215,6 @@ Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
AvaloniaVS.Shared\AvaloniaVS.Shared.projitems*{1029ec08-7b2e-4018-b20d-e85ca58deb59}*SharedItemsImports = 4
AvaloniaVS.Shared\AvaloniaVS.Shared.projitems*{40d9809e-d179-44b2-bf42-61d781fb74f6}*SharedItemsImports = 13
AvaloniaVS.Shared\AvaloniaVS.Shared.projitems*{79a4832c-9d3e-42d9-9215-d786565269b5}*SharedItemsImports = 4
AvaloniaVS.Shared\AvaloniaVS.Shared.projitems*{79a4832c-9d3e-42d9-9215-d786565269b5}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="Exists('$(SolutionDir)Key.snk')">
<SignAssembly>true</SignAssembly>
Expand All @@ -15,4 +14,7 @@
<ProjectReference Include="..\Avalonia.Ide.CompletionEngine\Avalonia.Ide.CompletionEngine.csproj" />
</ItemGroup>

<Import Project="../../Props/NullableEnable.props" />
<Import Project="../../Props/TrimmingEnable.props" />
<Import Project="../../Props/NetAnalyzers.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public static bool IsPublic(this MethodDef methodDef)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsPublicOrInternal(this MethodDef methodDef)
=> methodDef?.IsPublic == true || methodDef.Access == MethodAttributes.Assembly;
=> methodDef?.IsPublic == true || methodDef?.Access == MethodAttributes.Assembly;

public static IEnumerable<string> GetVisibleTo(this AssemblyDef assemblyDef)
{
var result = assemblyDef.CustomAttributes
.Where(att => att.TypeFullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute")
.Select(att => att.ConstructorArguments[0].Value.ToString())
.Where(val => val is not null)
.ToArray();
return result;
return result!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@
using Avalonia.Ide.CompletionEngine.AssemblyMetadata;
using dnlib.DotNet;

namespace Avalonia.Ide.CompletionEngine.DnlibMetadataProvider
namespace Avalonia.Ide.CompletionEngine.DnlibMetadataProvider;

public class DnlibMetadataProvider : IMetadataProvider
{
public class DnlibMetadataProvider : IMetadataProvider
{

public IMetadataReaderSession GetMetadata(IEnumerable<string> paths)
{
return new DnlibMetadataProviderSession(paths.ToArray());
}
public IMetadataReaderSession GetMetadata(IEnumerable<string> paths)
{
return new DnlibMetadataProviderSession(paths.ToArray());
}
}

class DnlibMetadataProviderSession : IMetadataReaderSession
internal class DnlibMetadataProviderSession : IMetadataReaderSession
{
public string TargetAssemblyName { get; private set; }
public IEnumerable<IAssemblyInformation> Assemblies { get; }
public DnlibMetadataProviderSession(string[] directoryPath)
{
public string TargetAssemblyName { get; private set; }
public IEnumerable<IAssemblyInformation> Assemblies { get; }
public DnlibMetadataProviderSession(string[] directoryPath)
{
TargetAssemblyName = System.Reflection.AssemblyName.GetAssemblyName(directoryPath[0]).ToString();
Assemblies = LoadAssemblies(directoryPath).Select(a => new AssemblyWrapper(a)).ToList();
}
TargetAssemblyName = System.Reflection.AssemblyName.GetAssemblyName(directoryPath[0]).ToString();
Assemblies = LoadAssemblies(directoryPath).Select(a => new AssemblyWrapper(a)).ToList();
}

static List<AssemblyDef> LoadAssemblies(string[] lst)
{
AssemblyResolver asmResolver = new AssemblyResolver();
ModuleContext modCtx = new ModuleContext(asmResolver);
asmResolver.DefaultModuleContext = modCtx;
asmResolver.EnableTypeDefCache = true;
private static List<AssemblyDef> LoadAssemblies(string[] lst)
{
AssemblyResolver asmResolver = new AssemblyResolver();
ModuleContext modCtx = new ModuleContext(asmResolver);
asmResolver.DefaultModuleContext = modCtx;
asmResolver.EnableTypeDefCache = true;

foreach (var path in lst)
asmResolver.PreSearchPaths.Add(path);
foreach (var path in lst)
asmResolver.PreSearchPaths.Add(path);

List<AssemblyDef> assemblies = new List<AssemblyDef>();
List<AssemblyDef> assemblies = new List<AssemblyDef>();

foreach (var asm in lst)
foreach (var asm in lst)
{
try
{
try
{
var def = AssemblyDef.Load(File.ReadAllBytes(asm));
def.Modules[0].Context = modCtx;
asmResolver.AddToCache(def);
assemblies.Add(def);
}
catch
{
//Ignore
}
var def = AssemblyDef.Load(File.ReadAllBytes(asm));
def.Modules[0].Context = modCtx;
asmResolver.AddToCache(def);
assemblies.Add(def);
}
catch
{
//Ignore
}

return assemblies;
}

public void Dispose()
{
//no-op
}
return assemblies;
}

public void Dispose()
{
//no-op
}
}
Loading

0 comments on commit fada721

Please sign in to comment.