Skip to content
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

Improve handling with Cake Script Service. #2013

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/OmniSharp.Cake/Services/CakeScriptService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class CakeScriptService : ICakeScriptService, IDisposable
private readonly ILoggerFactory _loggerFactory;
private readonly IDictionary<string, ISet<string>> _cachedReferences;
private readonly IDictionary<string, ISet<string>> _cachedUsings;
private readonly ILogger<CakeScriptService> _logger;
private ScriptGenerationClient _generationService;

[ImportingConstructor]
Expand All @@ -32,6 +33,7 @@ public CakeScriptService(IOmniSharpEnvironment environment, ICakeConfiguration c
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
_cachedReferences = new Dictionary<string, ISet<string>>();
_cachedUsings = new Dictionary<string, ISet<string>>();
_logger = _loggerFactory.CreateLogger<CakeScriptService>();
}

public bool Initialize(CakeOptions options)
Expand All @@ -40,10 +42,16 @@ public bool Initialize(CakeOptions options)

if (File.Exists(serverExecutablePath))
{
_logger.LogInformation($"Using Cake.Bakery at {serverExecutablePath}");

_generationService = PlatformHelper.IsMono ?
new ScriptGenerationClient(new MonoScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory) :
new ScriptGenerationClient(serverExecutablePath, _environment.TargetDirectory, _loggerFactory);
}
else if (!string.IsNullOrEmpty(serverExecutablePath))
{
_logger.LogWarning($"Cake.Bakery not found at path {serverExecutablePath}");
}

return _generationService != null;
}
Expand All @@ -52,7 +60,7 @@ public CakeScript Generate(FileChange fileChange)
{
if (_generationService == null)
{
throw new InvalidOperationException("Service not initialized.");
throw new InvalidOperationException("Cake.Bakery not initialized.");
}

if (!fileChange.FromDisk && fileChange.Buffer is null && fileChange.LineChanges.Count == 0)
Expand All @@ -65,6 +73,14 @@ public CakeScript Generate(FileChange fileChange)

var cakeScript = _generationService.Generate(fileChange);

if (string.IsNullOrEmpty(cakeScript?.Source))
{
return new CakeScript
{
Source = null
};
}

// Set line processor for generated aliases. TODO: Move to Cake.Bakery
cakeScript.Source = cakeScript.Source.Insert(0, $"{Constants.Directive.Generated}\n");

Expand Down