-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the properties for the source generator
They were not building correctly in gitlab.
- Loading branch information
1 parent
d7cd221
commit 0890c8f
Showing
11 changed files
with
185 additions
and
84 deletions.
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
85 changes: 51 additions & 34 deletions
85
src/SourceGenerator.Foundations.Contracts/Diagnostics/LoggerExtensions.cs
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,44 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using SGF.Diagnostics; | ||
using System; | ||
|
||
namespace SGF.Diagnostics | ||
/// <summary> | ||
/// Contains extension methods for working with logging in Source Generator Foundations | ||
/// </summary> | ||
public static class LoggerExtensions | ||
{ | ||
public static class LoggerExtensions | ||
public static void AddSink<T>(this ILogger logger) where T : ILogSink, new() | ||
{ | ||
public static void AddSink<T>(this ILogger logger) where T: ILogSink, new() | ||
{ | ||
logger.AddSink(new T()); | ||
} | ||
logger.AddSink(new T()); | ||
} | ||
|
||
public static void Information(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Information, null, message); | ||
} | ||
/// <summary> | ||
/// Adds a new info log entry | ||
/// </summary> | ||
public static void Information(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Information, null, message); | ||
} | ||
|
||
public static void Information(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Information, exception, message); | ||
} | ||
/// <summary> | ||
/// Adds a new info log entry with an exception | ||
/// </summary> | ||
public static void Information(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Information, exception, message); | ||
} | ||
|
||
public static void Warning(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Warning, null, message); | ||
} | ||
/// <summary> | ||
/// Adds a new warning log entry | ||
/// </summary> | ||
public static void Warning(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Warning, null, message); | ||
} | ||
|
||
public static void Warning(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Warning, exception, message); | ||
} | ||
/// <summary> | ||
/// Adds a new warning entry with an exception | ||
/// </summary> | ||
public static void Warning(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Warning, exception, message); | ||
} | ||
|
||
public static void Error(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Error, null, message); | ||
} | ||
/// <summary> | ||
/// Adds a new warning entry | ||
/// </summary> | ||
public static void Error(this ILogger logger, string message) | ||
{ | ||
logger.Log(LogLevel.Error, null, message); | ||
} | ||
|
||
public static void Error(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Error, exception, message); | ||
} | ||
/// <summary> | ||
/// Adds a new error entry with an exception | ||
/// </summary> | ||
public static void Error(this ILogger logger, Exception exception, string message) | ||
{ | ||
logger.Log(LogLevel.Error, exception, message); | ||
} | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
src/SourceGenerator.Foundations.MSBuild/SourceGenerator.Foundations.MSBuild.targets
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
src/SourceGenerator.Foundations.Shared/SgfSourceProductionContext.cs
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,56 @@ | ||
using Microsoft.CodeAnalysis.Text; | ||
using Microsoft.CodeAnalysis; | ||
using SGF.Diagnostics; | ||
using System.Text; | ||
using System.Threading; | ||
/// <summary> | ||
/// Wrapper around a <see cref="SourceProductionContext"/> used to help capture errors and report logs | ||
/// </summary> | ||
internal struct SgfSourceProductionContext | ||
{ | ||
private int m_sourceCount; | ||
private readonly ILogger m_logger; | ||
private readonly SourceProductionContext m_context; | ||
|
||
/// <summary> | ||
/// A token that will be cancelled when generation should stop | ||
/// </summary> | ||
public CancellationToken CancellationToken => m_context.CancellationToken; | ||
|
||
internal SgfSourceProductionContext(SourceProductionContext context, ILogger logger) | ||
{ | ||
m_sourceCount = 0; | ||
m_logger = logger; | ||
m_context = context; | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// Adds source code in the form of a <see cref="string"/> to the compilation. | ||
/// </summary> | ||
/// <param name="hintName">An identifier that can be used to reference this source text, must be unique within this generator</param> | ||
/// <param name="source">The source code to add to the compilation</param> | ||
public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8)); | ||
|
||
/// <summary> | ||
/// Adds a <see cref="SourceText"/> to the compilation | ||
/// </summary> | ||
/// <param name="hintName">An identifier that can be used to reference this source text, must be unique within this generator</param> | ||
/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param> | ||
public void AddSource(string hintName, SourceText sourceText) | ||
{ | ||
m_sourceCount++; | ||
m_logger.Information($" [AddedSource:{m_sourceCount:00}]: {hintName}"); | ||
m_context.AddSource(hintName, sourceText); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a <see cref="Diagnostic"/> to the users compilation | ||
/// </summary> | ||
/// <param name="diagnostic">The diagnostic that should be added to the compilation</param> | ||
/// <remarks> | ||
/// The severity of the diagnostic may cause the compilation to fail, depending on the <see cref="Compilation"/> settings. | ||
/// </remarks> | ||
public void ReportDiagnostic(Diagnostic diagnostic) => m_context.ReportDiagnostic(diagnostic); | ||
} |
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.