Skip to content

Commit

Permalink
CSS: Avoid chained compilation on open. (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Apr 16, 2014
1 parent 46d8d8a commit 7feac7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions EditorExtensions/Shared/Compilers/CompilationChainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace MadsKristensen.EditorExtensions.Compilers
[TextViewRole(PredefinedTextViewRoles.Document)]
[ContentType("LESS")]
[ContentType("SCSS")]

class CompilationChainer : IVsTextViewCreationListener
{
[Import]
Expand Down Expand Up @@ -43,7 +42,7 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
var graph = GetGraph(contentType);
notifier.CompilationReady += async (s, e) =>
{
if (!settings.CompileOnSave || !settings.EnableChainCompilation)
if (!settings.CompileOnSave || !settings.EnableChainCompilation || (bool)s)
return;

var count = 0;
Expand Down
22 changes: 16 additions & 6 deletions EditorExtensions/Shared/Compilers/EditorCompilerInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ private void Document_FileActionOccurred(object sender, TextDocumentFileActionEv

///<summary>Raises the CompilationReady event.</summary>
///<param name="e">A CompilerResultEventArgs object that provides the event data.</param>
protected virtual void OnCompilationReady(CompilerResultEventArgs e)
protected virtual void OnCompilationReady(CompilerResultEventArgs e) { }

///<summary>
/// Raises the CompilationReady event.
/// In case of cached results, it will propogate a flag to event handler
/// to avoid chained compilation for CSS preprocessors.
/// (see https://github.com/madskristensen/WebEssentials2013/issues/916).
///</summary>
///<param name="e">A CompilerResultEventArgs object that provides the event data.</param>
///<param name="cached">A flag to indicate if event is raised for cached results.</param>
private void OnCompilationReady(CompilerResultEventArgs e, bool cached = false)
{
if (CompilationReady != null)
CompilationReady(this, e);
CompilationReady(cached, e);
}

protected virtual Task CompileAsync(string sourcePath)
Expand All @@ -71,19 +81,19 @@ public async void RequestCompilationResult(bool cached)

if (File.Exists(targetPath))
{
OnCompilationReady(new CompilerResultEventArgs(await CompilerResultFactory.GenerateResult(Document.FilePath, targetPath)));
OnCompilationReady(new CompilerResultEventArgs(await CompilerResultFactory.GenerateResult(Document.FilePath, targetPath)), true);

return;
}
}

InitiateCompilationAsync(Document.FilePath, save: false).DontWait("compiling " + Document.FilePath);
InitiateCompilationAsync(Document.FilePath, false, cached).DontWait("compiling " + Document.FilePath);
}

async Task InitiateCompilationAsync(string sourcePath, bool save)
async Task InitiateCompilationAsync(string sourcePath, bool save, bool cached = false)
{
var result = await CompilerRunner.CompileAsync(sourcePath, save);
OnCompilationReady(new CompilerResultEventArgs(result));
OnCompilationReady(new CompilerResultEventArgs(result), cached);
}
}

Expand Down

0 comments on commit 7feac7c

Please sign in to comment.