Skip to content

Commit

Permalink
Enhanced the text cursor (#363)
Browse files Browse the repository at this point in the history
* added factory

* added abstract node

* added more logic in abstract node

* updated the packages

* added syntax token

* added diagnostics

* added source text

* added docs

* enhanced text cursor

* improved test cursor

* fixed peek method

* enhanced text cursor

* fixed the lock files

* fixed sonar comments
  • Loading branch information
victor-pogor authored Nov 19, 2024
1 parent e0052d8 commit 3b8d882
Show file tree
Hide file tree
Showing 56 changed files with 5,078 additions and 271 deletions.
15 changes: 9 additions & 6 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.3.7",
"version": "5.3.11",
"commands": [
"reportgenerator"
]
],
"rollForward": false
},
"dotnet-config": {
"version": "1.0.6",
"version": "1.2.0",
"commands": [
"dotnet-config"
]
],
"rollForward": false
},
"dotnet-stryker": {
"version": "4.0.6",
"version": "4.3.0",
"commands": [
"dotnet-stryker"
]
],
"rollForward": false
}
}
}
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ dotnet_diagnostic.SA1308.severity = none
# SA1311: Static readonly fields should begin with upper-case letter
dotnet_diagnostic.SA1311.severity = none

# SA1503: Braces should not be omitted
dotnet_diagnostic.SA1503.severity = none

# CSharp code style settings:
[*.cs]
# Newline settings
Expand Down Expand Up @@ -253,8 +256,12 @@ csharp_preserve_single_line_statements = true
dotnet_diagnostic.IDE0060.severity = warning

# Nullable are treated as errors
dotnet_diagnostic.CS8618.severity = error
dotnet_diagnostic.CS8625.severity = error

# SA1500: Braces for multi-line statements should not share line
dotnet_diagnostic.SA1500.severity = none

[tests/**/*.{cs,vb}]

# SA1600: Elements should be documented
Expand Down
17 changes: 10 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="9.0.0" />
</ItemGroup>
<!-- Analyzers -->
<ItemGroup>
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.26.0.92422">
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.4">
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
Expand All @@ -23,17 +26,17 @@
</ItemGroup>
<!-- Test packages -->
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1">
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
</ItemGroup>
<!-- Benchmarking packages -->
<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions OffDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OffDotNet.CodeAnalysis", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OffDotNet.CodeAnalysis.Tests", "tests\OffDotNet.CodeAnalysis.Tests\OffDotNet.CodeAnalysis.Tests.csproj", "{0D625237-2FE0-48E1-B71E-85020A8F0153}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OffDotNet.CodeAnalysis.Pdf", "src\OffDotNet.CodeAnalysis.Pdf\OffDotNet.CodeAnalysis.Pdf.csproj", "{07CBC834-454F-4272-B55C-4E0529971EDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OffDotNet.CodeAnalysis.Pdf.Tests", "tests\OffDotNet.CodeAnalysis.Pdf.Tests\OffDotNet.CodeAnalysis.Pdf.Tests.csproj", "{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -76,6 +80,14 @@ Global
{0D625237-2FE0-48E1-B71E-85020A8F0153}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D625237-2FE0-48E1-B71E-85020A8F0153}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D625237-2FE0-48E1-B71E-85020A8F0153}.Release|Any CPU.Build.0 = Release|Any CPU
{07CBC834-454F-4272-B55C-4E0529971EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07CBC834-454F-4272-B55C-4E0529971EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07CBC834-454F-4272-B55C-4E0529971EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07CBC834-454F-4272-B55C-4E0529971EDC}.Release|Any CPU.Build.0 = Release|Any CPU
{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,6 +99,8 @@ Global
{293A6DEE-237E-45F8-B770-717F6846A913} = {D587B5E1-06B4-4CA7-8FE4-62B0DF71BAD6}
{7712F911-485F-4DEE-8B16-2E8DF1C4FA0F} = {6BFF3E0A-DE9E-4854-99CF-C8CB861B3FBE}
{0D625237-2FE0-48E1-B71E-85020A8F0153} = {9AD1AB50-CB0F-43D9-B721-DE1572FC6875}
{07CBC834-454F-4272-B55C-4E0529971EDC} = {6BFF3E0A-DE9E-4854-99CF-C8CB861B3FBE}
{8B36AFA6-CA16-49F7-8CAC-C37989EBD13F} = {9AD1AB50-CB0F-43D9-B721-DE1572FC6875}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1C5CCEAE-E0B4-4074-9291-2AAD38F9117F}
Expand Down
47 changes: 47 additions & 0 deletions OffDotNet.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path=".gitattributes" />
<File Path=".gitignore" />
<File Path=".netconfig" />
<File Path="README.md" />
<File Path="Directory.Build.targets" />
<File Path="stryker-config.json" />
<File Path="LICENSE" />
<File Path="Directory.Build.props" />
<File Path="stylecop.json" />
<File Path="Directory.Packages.props" />
<File Path=".deepsource.toml" />
</Folder>
<Folder Name="/Solution Items/.config/">
<File Path=".config\dotnet-tools.json" />
</Folder>
<Folder Name="/Solution Items/.github/">
<File Path=".github\CODEOWNERS" />
<File Path=".github\dependabot.yml" />
</Folder>
<Folder Name="/Solution Items/.github/workflows/">
<File Path=".github\workflows\dotnet.yml" />
<File Path=".github\workflows\codeql.yml" />
<File Path=".github\workflows\dependency-review.yml" />
<File Path=".github\workflows\scorecard.yml" />
</Folder>
<Folder Name="/Solution Items/tools/">
<File Path="tools\code-coverage.bat" />
<File Path="tools\code-coverage.ps1" />
<File Path="tools\mutation-testing.bat" />
<File Path="tools\mutation-testing.ps1" />
<File Path="tools\benchmarks.bat" />
<File Path="tools\benchmarks.ps1" />
</Folder>
<Folder Name="/src/">
<Project Path="src\OffDotNet.CodeAnalysis.Pdf\OffDotNet.CodeAnalysis.Pdf.csproj" Type="Classic C#" />
<Project Path="src\OffDotNet.CodeAnalysis\OffDotNet.CodeAnalysis.csproj" Type="Classic C#" />
<File Path="src\Directory.Build.props" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests\OffDotNet.CodeAnalysis.Pdf.Tests\OffDotNet.CodeAnalysis.Pdf.Tests.csproj" Type="Classic C#" />
<Project Path="tests\OffDotNet.CodeAnalysis.Tests\OffDotNet.CodeAnalysis.Tests.csproj" Type="Classic C#" />
<File Path="tests\Directory.Build.props" />
</Folder>
</Solution>
4 changes: 4 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsings.cs"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ObjectPool" />
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"/>
</Project>
3 changes: 3 additions & 0 deletions src/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#pragma warning disable SA1200
global using System.Buffers;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.Runtime.InteropServices;
global using System.Text;

#pragma warning restore SA1200
13 changes: 13 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Configs/DiagnosticOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="DiagnosticOptions.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Configs;

/// <summary>Represents the diagnostic options for the PDF analysis.</summary>
public sealed record DiagnosticOptions
{
/// <summary>Gets the help link associated with the diagnostic.</summary>
public required string HelpLink { get; init; }
}
21 changes: 21 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Configs/RootConfigurations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <copyright file="RootConfigurations.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Configs;

using OffDotNet.CodeAnalysis.Configs;

/// <summary>Represents the root configurations for the OffDotNet analysis.</summary>
public sealed record RootConfigurations
{
/// <summary>The section name for the OffDotNet configurations.</summary>
public const string SectionName = "OffDotNet";

/// <summary>Gets the diagnostic options for the PDF analysis.</summary>
public required DiagnosticOptions Diagnostic { get; init; }

/// <summary>Gets the text cursor options for the PDF analysis.</summary>
public required TextCursorOptions TextCursor { get; init; }
}
33 changes: 33 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Dependencies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="Dependencies.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf;

using Configs;
using Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using OffDotNet.CodeAnalysis.Diagnostics;
using OffDotNet.CodeAnalysis.Lexer;

/// <summary>
/// Provides extension methods for registering code analysis services.
/// </summary>
public static class Dependencies
{
/// <summary>
/// Adds the code analysis services to the specified <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services">The service collection to which the services will be added.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddPdfCodeAnalysis(this IServiceCollection services)
{
services.AddOptions<RootConfigurations>(RootConfigurations.SectionName).ValidateOnStart();

services.AddCoreCodeAnalysis();
services.AddSingleton<ILexer, Lexer.Lexer>();
services.AddSingleton<IMessageProvider, MessageProvider>();
return services;
}
}
17 changes: 17 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Diagnostics/DiagnosticCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// <copyright file="DiagnosticCode.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Diagnostics;

/// <summary>
/// Represents the diagnostic codes for the PDF analysis.
/// </summary>
public enum DiagnosticCode
{
/// <summary>
/// Represents an unknown diagnostic code.
/// </summary>
Unknown = 0,
}
74 changes: 74 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Diagnostics/MessageProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// <copyright file="MessageProvider.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Diagnostics;

using Configs;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OffDotNet.CodeAnalysis.Diagnostics;

/// <summary>
/// Provides localized messages for diagnostics in PDF analysis.
/// </summary>
internal sealed class MessageProvider : AbstractMessageProvider
{
private const string TitleSuffix = "_Title";
private const string DescriptionSuffix = "_Description";

private readonly IStringLocalizer<MessageProvider> _localizer;
private readonly DiagnosticOptions _options;

/// <summary>
/// Initializes a new instance of the <see cref="MessageProvider"/> class.
/// </summary>
/// <param name="localizer">The localizer for retrieving localized strings.</param>
/// <param name="options">The diagnostic options.</param>
public MessageProvider(IStringLocalizer<MessageProvider> localizer, IOptions<DiagnosticOptions> options)
{
_localizer = localizer;
_options = options.Value ?? throw new ArgumentNullException(nameof(options));
}

/// <summary>
/// Gets the language prefix for the diagnostics.
/// </summary>
public override string LanguagePrefix => "PDF";

/// <summary>
/// Gets the localized title for the specified diagnostic code.
/// </summary>
/// <param name="code">The diagnostic code.</param>
/// <returns>The localized title.</returns>
public override LocalizedString GetTitle(ushort code) => _localizer[$"{(DiagnosticCode)code}{TitleSuffix}"];

/// <summary>
/// Gets the localized description for the specified diagnostic code.
/// </summary>
/// <param name="code">The diagnostic code.</param>
/// <returns>The localized description.</returns>
public override LocalizedString GetDescription(ushort code) => _localizer[$"{(DiagnosticCode)code}{DescriptionSuffix}"];

/// <summary>
/// Gets the help link for the specified diagnostic code.
/// </summary>
/// <param name="code">The diagnostic code.</param>
/// <returns>The help link.</returns>
public override string GetHelpLink(ushort code) => string.Format(_options.HelpLink, GetIdForDiagnosticCode(code));

/// <summary>
/// Gets the severity for the specified diagnostic code.
/// </summary>
/// <param name="code">The diagnostic code.</param>
/// <returns>The severity as a byte value.</returns>
public override byte GetSeverity(ushort code)
{
switch (code)
{
default:
return (byte)DiagnosticSeverity.Hidden;
}
}
}
13 changes: 13 additions & 0 deletions src/OffDotNet.CodeAnalysis.Pdf/Lexer/Lexer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="Lexer.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Lexer;

using OffDotNet.CodeAnalysis.Lexer;

/// <summary>
/// Represents the lexer for PDF code analysis.
/// </summary>
public class Lexer : ILexer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<ProjectReference Include="..\OffDotNet.CodeAnalysis\OffDotNet.CodeAnalysis.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit 3b8d882

Please sign in to comment.