diff --git a/BuildTasks.Tester/Program.cs b/BuildTasks.Tester/Program.cs index f0667465a..2df672900 100644 --- a/BuildTasks.Tester/Program.cs +++ b/BuildTasks.Tester/Program.cs @@ -1,11 +1,8 @@ using System; using System.Collections; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.Build.Framework; namespace WebEssentials.BuildTasks.Tester diff --git a/BuildTasks/NodeInstaller.cs b/BuildTasks/NodeInstaller.cs index fea5c2b04..30405d186 100644 --- a/BuildTasks/NodeInstaller.cs +++ b/BuildTasks/NodeInstaller.cs @@ -5,11 +5,7 @@ using System.IO.Compression; using System.Linq; using System.Net; -using System.Reflection; using System.Runtime.CompilerServices; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using Microsoft.Build.Framework; using Newtonsoft.Json; diff --git a/EditorExtensions/CSS/DragDrop/FontDrop.cs b/EditorExtensions/CSS/DragDrop/FontDrop.cs index f02f66e1a..696ab268d 100644 --- a/EditorExtensions/CSS/DragDrop/FontDrop.cs +++ b/EditorExtensions/CSS/DragDrop/FontDrop.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Globalization; using System.IO; using System.Linq; using System.Web; -using System.Windows.Forms; -using MadsKristensen.EditorExtensions.Images; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor.DragDrop; using Microsoft.VisualStudio.Utilities; diff --git a/EditorExtensions/CustomDictionary.xml b/EditorExtensions/CustomDictionary.xml index 382029fd8..bcf8a2718 100644 --- a/EditorExtensions/CustomDictionary.xml +++ b/EditorExtensions/CustomDictionary.xml @@ -90,10 +90,11 @@ - XHTML + BOM + CSS JSON JSONLD - BOM + XHTML diff --git a/EditorExtensions/HTML/DragDrop/HtmlImageDrop.cs b/EditorExtensions/HTML/DragDrop/HtmlImageDrop.cs index 65ee30698..b6180ddb7 100644 --- a/EditorExtensions/HTML/DragDrop/HtmlImageDrop.cs +++ b/EditorExtensions/HTML/DragDrop/HtmlImageDrop.cs @@ -1,13 +1,8 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.IO; -using System.Web; -using MadsKristensen.EditorExtensions.Css; using MadsKristensen.EditorExtensions.Images; -using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor.DragDrop; using Microsoft.VisualStudio.Utilities; @@ -32,7 +27,7 @@ namespace MadsKristensen.EditorExtensions.Html // but apparently visual studio get confused by content type inheritance or does not // handle it correcly. [Order(Before = "DefaultFileDropHandler")] - [Order(Before = "HtmlViewFileDropHandlerProvider")] + [Order(Before = "HtmlViewFileDropHandlerProvider")] public class MarkdownImageDropHandlerProvider : IDropHandlerProvider { public IDropHandler GetAssociatedDropHandler(IWpfTextView wpfTextView) diff --git a/EditorExtensions/Handlebars/Compilers/HandlebarsCompiler.cs b/EditorExtensions/Handlebars/Compilers/HandlebarsCompiler.cs index be36ef06e..6d5d5e87a 100644 --- a/EditorExtensions/Handlebars/Compilers/HandlebarsCompiler.cs +++ b/EditorExtensions/Handlebars/Compilers/HandlebarsCompiler.cs @@ -21,14 +21,9 @@ protected override string GetPath(string sourceFileName, string targetFileName) parameters.Add("service", ServiceName); parameters.Add("sourceFileName", sourceFileName); parameters.Add("targetFileName", targetFileName); - parameters.Add("compiledTemplateName", CleanTemplateNameForJs(Path.GetFileNameWithoutExtension(sourceFileName))); + parameters.Add("compiledTemplateName", Path.GetFileNameWithoutExtension(sourceFileName).Replace("-", "_")); return parameters.FlattenParameters(); } - - private string CleanTemplateNameForJs(string templateName) - { - return templateName.Replace("-", "_"); - } } } diff --git a/EditorExtensions/Images/Commands/PasteImageCommandTarget.cs b/EditorExtensions/Images/Commands/PasteImageCommandTarget.cs index 11f61df98..d39a34275 100644 --- a/EditorExtensions/Images/Commands/PasteImageCommandTarget.cs +++ b/EditorExtensions/Images/Commands/PasteImageCommandTarget.cs @@ -1,16 +1,10 @@ using System; using System.Drawing; using System.Drawing.Imaging; -using System.Globalization; using System.IO; using System.Linq; -using System.Web; using System.Windows.Forms; -using MadsKristensen.EditorExtensions.Markdown; -using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; -using Microsoft.VisualStudio.Text.Editor.DragDrop; -using Microsoft.VisualStudio.Text.Projection; using Microsoft.VisualStudio.TextManager.Interop; using Microsoft.Web.Editor; @@ -134,8 +128,6 @@ private static async void SaveClipboardImageToFile(IDataObject data, string file ProjectHelpers.AddFileToActiveProject(fileName); } - - protected override bool IsEnabled() { return true; diff --git a/EditorExtensions/Images/ImageExtensions.cs b/EditorExtensions/Images/ImageExtensions.cs index 4ea74e01c..74bfe3fa7 100644 --- a/EditorExtensions/Images/ImageExtensions.cs +++ b/EditorExtensions/Images/ImageExtensions.cs @@ -63,9 +63,9 @@ private static string GetFormat(IWpfTextView textView) foreach (ITextBuffer buffer in buffers) { var point = textView.BufferGraph.MapDownToBuffer( - snapshotPoint, - PointTrackingMode.Negative, - buffer, + snapshotPoint, + PointTrackingMode.Negative, + buffer, PositionAffinity.Predecessor ); @@ -86,8 +86,8 @@ private static string GetRelativeEncodedUrl(string fileName) if (activeDocument == null) return null; - var baseFolder = activeDocument.FullName; - + var baseFolder = activeDocument.FullName; + var result = FileHelpers.RelativePath(baseFolder, fileName); if (result.Contains("://")) @@ -149,7 +149,7 @@ public static bool InsertLinkToImageFile(this IWpfTextView textView, string abso string format = GetFormat(textView); int position = textView.Caret.Position.BufferPosition.Position; - + string text = string.Format(CultureInfo.InvariantCulture, format, relative, Path.GetFileName(absoluteImageFilePath)); using (WebEssentialsPackage.UndoContext("Insert Image")) diff --git a/EditorExtensions/Images/Sprite/SpriteGenerator.cs b/EditorExtensions/Images/Sprite/SpriteGenerator.cs index 9597b27b6..44bcf375f 100644 --- a/EditorExtensions/Images/Sprite/SpriteGenerator.cs +++ b/EditorExtensions/Images/Sprite/SpriteGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -89,7 +90,7 @@ private static Dictionary GetImages(SpriteDocument sprite) { if (!System.IO.File.Exists(file)) { - Logger.Log(string.Format("The image file {0} for sprite {1} was not found", file, sprite.FileName)); + Logger.Log(string.Format(CultureInfo.CurrentCulture, "The image file {0} for sprite {1} was not found", file, sprite.FileName)); return null; } diff --git a/EditorExtensions/JavaScript/Completion/GruntTaskCompletionSourceProvider.cs b/EditorExtensions/JavaScript/Completion/GruntTaskCompletionSourceProvider.cs index b5793434f..e4ec37486 100644 --- a/EditorExtensions/JavaScript/Completion/GruntTaskCompletionSourceProvider.cs +++ b/EditorExtensions/JavaScript/Completion/GruntTaskCompletionSourceProvider.cs @@ -1,8 +1,4 @@ -using Microsoft.VisualStudio.Language.Intellisense; -using Microsoft.VisualStudio.Text; -using Microsoft.VisualStudio.Utilities; -using Newtonsoft.Json.Linq; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; @@ -11,6 +7,10 @@ using System.Threading.Tasks; using System.Windows.Media; using System.Windows.Media.Imaging; +using Microsoft.VisualStudio.Language.Intellisense; +using Microsoft.VisualStudio.Text; +using Microsoft.VisualStudio.Utilities; +using Newtonsoft.Json.Linq; using Intel = Microsoft.VisualStudio.Language.Intellisense; namespace MadsKristensen.EditorExtensions.JavaScript diff --git a/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs b/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs index 1d1617914..f8aa264fd 100644 --- a/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs +++ b/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs @@ -38,10 +38,5 @@ protected override string GetPath(string sourceFileName, string targetFileName) return parameters.FlattenParameters(); } - - protected override string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - return result; - } } } diff --git a/EditorExtensions/Markdown/Margin/MarkdownMargin.cs b/EditorExtensions/Markdown/Margin/MarkdownMargin.cs index ae1c22c82..5f81acdb7 100644 --- a/EditorExtensions/Markdown/Margin/MarkdownMargin.cs +++ b/EditorExtensions/Markdown/Margin/MarkdownMargin.cs @@ -78,12 +78,12 @@ public static IEnumerable GetExistingFilesInFolders(string fileName, par /// private static string ConvertLocalDirectoryPathToUrl(string absoluteOrRelativePath, bool ensureTrailingSlash = true) { - if (ensureTrailingSlash && !absoluteOrRelativePath.EndsWith("\\")) + if (ensureTrailingSlash && !absoluteOrRelativePath.EndsWith("\\", StringComparison.Ordinal)) absoluteOrRelativePath = absoluteOrRelativePath + "\\"; - + return string.Format( CultureInfo.InvariantCulture, - "file:///{0}", + "file:///{0}", absoluteOrRelativePath.Replace("\\", "/") ); } @@ -298,7 +298,7 @@ protected override FrameworkElement CreatePreviewControl() _browser.HorizontalAlignment = HorizontalAlignment.Stretch; // This can be done only once - _browser.ObjectForScripting = new JavaScriptToManagedConnector((errorMsg, document, line) => + _browser.ObjectForScripting = new JavaScriptToManagedConnector((errorMsg, document, line) => { // Unfortunatly, when the error is in a file other than the main document the errorMsg // and line are not available. @@ -306,7 +306,7 @@ protected override FrameworkElement CreatePreviewControl() // This is another IE "feature" to "protect" you :). Log("Error in ({0}:{1}): {2}", document, line, errorMsg); }); - + _browser.Navigated += (sender, ev) => { if (!ShouldHandleNavigationEvent(ev)) @@ -315,16 +315,16 @@ protected override FrameworkElement CreatePreviewControl() var browser = sender as WebBrowser; InjectJavascriptErrorsRedirection(browser); }; - - _browser.LoadCompleted += (sender,ev) => + + _browser.LoadCompleted += (sender, ev) => { - if (!ShouldHandleNavigationEvent(ev)) + if (!ShouldHandleNavigationEvent(ev)) return; var browser = sender as WebBrowser; RestoreDocumentVerticalPosition(browser); }; - + return _browser; } @@ -376,7 +376,7 @@ private static bool ShouldHandleNavigationEvent(System.Windows.Navigation.Naviga // If the user click on a link in the preview window, @event.Uri is null. return @event.Uri == null; } - + /// /// Hook the the DOM onerror event and redirect it to the managed host that /// will then write it to the visual studio output pane. @@ -405,7 +405,7 @@ private static void InjectJavascriptErrorsRedirection(WebBrowser browser) } } } - + private static void Log(string format, params object[] args) { Logger.Log(string.Format(CultureInfo.InvariantCulture, "[markdown]: " + format, args)); @@ -428,17 +428,20 @@ public InternetExplorerFeatureControlSecurityException() { } - public InternetExplorerFeatureControlSecurityException(string message) : base(message) + public InternetExplorerFeatureControlSecurityException(string message) + : base(message) { } - public InternetExplorerFeatureControlSecurityException(string message, Exception inner) : base(message, inner) + public InternetExplorerFeatureControlSecurityException(string message, Exception inner) + : base(message, inner) { } protected InternetExplorerFeatureControlSecurityException( SerializationInfo info, - StreamingContext context) : base(info, context) + StreamingContext context) + : base(info, context) { } } @@ -449,7 +452,7 @@ protected InternetExplorerFeatureControlSecurityException( /// internal class InternetExplorerBrowserFeatureControl { - + private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer"; private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; private const string BlockCrossProtocolFileNavigation = InternetExplorerRootKey + @"\MAIN\FeatureControl\FEATURE_BLOCK_CROSS_PROTOCOL_FILE_NAVIGATION"; @@ -482,7 +485,7 @@ private enum BrowserEmulationVersion /// The RegistryKey instance that can be used to access /// the registry sub key /// - private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.RegistryKey key, + private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.RegistryKey key, string subkeyName, bool writable) { var subKey = key.OpenSubKey(subkeyName, writable); @@ -514,7 +517,7 @@ private static Microsoft.Win32.RegistryKey OpenOrCreateKey(Microsoft.Win32.Regis /// execute this operation. /// private static T UseRegistryKey( - Microsoft.Win32.RegistryKey key, string subkeyName, + Microsoft.Win32.RegistryKey key, string subkeyName, bool writable, Func useKey ) { @@ -530,11 +533,11 @@ private static T UseRegistryKey( // The user does not have the permissions required to read from the registry key. throw new InternetExplorerFeatureControlSecurityException( string.Format( - CultureInfo.CurrentCulture, + CultureInfo.CurrentCulture, "The current user does not have the rights to open the registry key: '{0}\\{1}'", key, subkeyName), se ); - + } catch (UnauthorizedAccessException uaEx) { @@ -562,7 +565,7 @@ private static int GetInternetExplorerMajorVersion() if (separator != -1) { if (!int.TryParse(version.Substring(0, separator), out result)) - { + { // Make CodeAnalisys happy :) result = 0; } @@ -696,7 +699,7 @@ public JavaScriptToManagedConnector() { } - public JavaScriptToManagedConnector(Action errorHandler) + public JavaScriptToManagedConnector(Action errorHandler) { _errorHandler = errorHandler; } diff --git a/EditorExtensions/Markdown/MenuItems/Markdown.cs b/EditorExtensions/Markdown/MenuItems/Markdown.cs index 2da60811b..76cd3c1ce 100644 --- a/EditorExtensions/Markdown/MenuItems/Markdown.cs +++ b/EditorExtensions/Markdown/MenuItems/Markdown.cs @@ -62,7 +62,7 @@ private void HasStylesheet(object sender, System.EventArgs e) menuCommand.Enabled = !File.Exists(MarkdownMargin.GetCustomSolutionStylesheetFilePath()); } - + private void HasHtmlTemplate(object sender, System.EventArgs e) { OleMenuCommand menuCommand = sender as OleMenuCommand; diff --git a/EditorExtensions/Misc/Bundles/BundleGenerator.cs b/EditorExtensions/Misc/Bundles/BundleGenerator.cs index 910f0d474..d6348a2b2 100644 --- a/EditorExtensions/Misc/Bundles/BundleGenerator.cs +++ b/EditorExtensions/Misc/Bundles/BundleGenerator.cs @@ -106,10 +106,9 @@ private async static Task CombineFiles(Dictionary files, source.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0 && bundle.AdjustRelativePaths) source = CssUrlNormalizer.NormalizeUrls( - tree: new CssParser().Parse(source, true), - targetFile: bundleFile, - oldBasePath: actualFile - ); + tree: new CssParser().Parse(source, true), + targetFile: bundleFile, + oldBasePath: actualFile); } else if (Path.GetExtension(file).Equals(".ts", StringComparison.OrdinalIgnoreCase)) { diff --git a/EditorExtensions/SCSS/Compilers/ScssCompiler.cs b/EditorExtensions/SCSS/Compilers/ScssCompiler.cs index fbff50010..4dd52f561 100644 --- a/EditorExtensions/SCSS/Compilers/ScssCompiler.cs +++ b/EditorExtensions/SCSS/Compilers/ScssCompiler.cs @@ -1,13 +1,10 @@ -using System; -using System.ComponentModel.Composition; +using System.ComponentModel.Composition; using System.Globalization; using System.IO; using System.Threading.Tasks; using System.Web; -using MadsKristensen.EditorExtensions.Helpers; using MadsKristensen.EditorExtensions.RtlCss; using MadsKristensen.EditorExtensions.Settings; -using Microsoft.CSS.Core; using Microsoft.VisualStudio.Utilities; using Microsoft.Web.Editor; @@ -84,34 +81,5 @@ protected override string GetPath(string sourceFileName, string targetFileName) return parameters.FlattenParameters(); } - - protected override string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - // If the caller wants us to renormalize URLs to a different filename, do so. - if (targetFileName != null && - WESettings.Instance.Scss.AdjustRelativePaths && - result.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0) - { - try - { - result = CssUrlNormalizer.NormalizeUrls( - tree: new CssParser().Parse(result, true), - targetFile: targetFileName, - oldBasePath: sourceFileName); - - Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - } - catch (Exception ex) - { - Logger.Log(ServiceName + ": An error occurred while normalizing generated paths in " + sourceFileName + "\r\n" + ex); - } - } - else - { - Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - } - - return result; - } } } diff --git a/EditorExtensions/Settings/WESettings.cs b/EditorExtensions/Settings/WESettings.cs index c35a75cef..06b94ecf2 100644 --- a/EditorExtensions/Settings/WESettings.cs +++ b/EditorExtensions/Settings/WESettings.cs @@ -604,25 +604,22 @@ void OnEnableChainCompilationChanged(EventArgs e) } } - public abstract class CssChainableCompilationSettings : ChainableCompilationSettings, ICssChainableCompilerSettings where T : CssChainableCompilationSettings - { - [Category("Compilation")] - [DisplayName("Adjust Relative Paths")] - [Description("Adjust relative paths in post-processing step. This option only works when \"Custom output directory\" is used.")] - [DefaultValue(true)] - public bool AdjustRelativePaths { get; set; } - } - - public sealed class LessSettings : CssChainableCompilationSettings + public sealed class LessSettings : ChainableCompilationSettings { [Category("Compilation")] [DisplayName("Strict Math")] [Description("With this option turned off, LESS will try and process all maths in your CSS.")] [DefaultValue(false)] public bool StrictMath { get; set; } + + [Category("Compilation")] + [DisplayName("Adjust Relative Paths")] + [Description("Adjust relative paths in post-processing step.")] + [DefaultValue(true)] + public bool AdjustRelativePaths { get; set; } } - public sealed class ScssSettings : CssChainableCompilationSettings + public sealed class ScssSettings : ChainableCompilationSettings { public enum OutputFormat { @@ -796,11 +793,6 @@ public interface IChainableCompilerSettings : ICompilerInvocationSettings event EventHandler EnableChainCompilationChanged; } - public interface ICssChainableCompilerSettings : IChainableCompilerSettings - { - bool AdjustRelativePaths { get; } - } - public interface IMinifierSettings { bool AutoMinify { get; set; } diff --git a/EditorExtensions/Shared/Compilers/CompilerRunner.cs b/EditorExtensions/Shared/Compilers/CompilerRunner.cs index 77a756bd6..b69a4f011 100644 --- a/EditorExtensions/Shared/Compilers/CompilerRunner.cs +++ b/EditorExtensions/Shared/Compilers/CompilerRunner.cs @@ -253,7 +253,8 @@ class MarkdownCompilerRunner : CompilerRunnerBase { private readonly ITextDocument _document; - public MarkdownCompilerRunner(IContentType contentType, ITextDocument document = null) : base(contentType) + public MarkdownCompilerRunner(IContentType contentType, ITextDocument document = null) + : base(contentType) { _document = document; } diff --git a/EditorExtensions/Shared/Compilers/CssCompilerBase.cs b/EditorExtensions/Shared/Compilers/CssCompilerBase.cs index be8979d6d..0062d7d60 100644 --- a/EditorExtensions/Shared/Compilers/CssCompilerBase.cs +++ b/EditorExtensions/Shared/Compilers/CssCompilerBase.cs @@ -6,12 +6,15 @@ namespace MadsKristensen.EditorExtensions { public abstract class CssCompilerBase : NodeExecutorBase { - protected async override Task RtlVariantHandler(CompilerResult result) + protected async override Task PostWritingResult(CompilerResult result) { - if (!WESettings.Instance.Css.RtlCss || result.RtlTargetFileName == null) - return; + if (WESettings.Instance.Css.RtlCss && result.RtlTargetFileName != null) + await HandleRtlCss(result); + } - string value = PostProcessResult(result.RtlResult, result.RtlTargetFileName, result.RtlSourceFileName); + private async Task HandleRtlCss(CompilerResult result) + { + string value = result.RtlResult; // Write output file if (result.RtlTargetFileName != null && (MinifyInPlace || !File.Exists(result.RtlTargetFileName) || diff --git a/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs b/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs index 5a7651c64..7f30e0c3a 100644 --- a/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs +++ b/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs @@ -59,19 +59,20 @@ private async Task ProcessResult(CompilerResult result, bool onl return result; } - string resultString = PostProcessResult(result.Result, result.TargetFileName, result.SourceFileName); + if (this is ILintCompiler) + return result; + + Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); if (!onlyPreview) { // Write output file if (result.TargetFileName != null && (MinifyInPlace || !File.Exists(result.TargetFileName) || - resultString != await FileHelpers.ReadAllTextRetry(result.TargetFileName))) + result.Result != await FileHelpers.ReadAllTextRetry(result.TargetFileName))) { ProjectHelpers.CheckOutFileFromSourceControl(result.TargetFileName); - await FileHelpers.WriteAllTextRetry(result.TargetFileName, resultString); - - if (!(this is ILintCompiler)) - ProjectHelpers.AddFileToProject(result.SourceFileName, result.TargetFileName); + await FileHelpers.WriteAllTextRetry(result.TargetFileName, result.Result); + ProjectHelpers.AddFileToProject(result.SourceFileName, result.TargetFileName); } // Write map file @@ -80,15 +81,13 @@ private async Task ProcessResult(CompilerResult result, bool onl { ProjectHelpers.CheckOutFileFromSourceControl(result.MapFileName); await FileHelpers.WriteAllTextRetry(result.MapFileName, result.ResultMap); - - if (!(this is ILintCompiler)) - ProjectHelpers.AddFileToProject(result.TargetFileName, result.MapFileName); + ProjectHelpers.AddFileToProject(result.TargetFileName, result.MapFileName); } - await RtlVariantHandler(result); + await PostWritingResult(result); } - return CompilerResult.UpdateResult(result, resultString); + return result; } public static string GetOrCreateGlobalSettings(string fileName) @@ -105,17 +104,11 @@ public static string GetOrCreateGlobalSettings(string fileName) return globalFile; } - protected virtual Task RtlVariantHandler(CompilerResult result) + protected virtual Task PostWritingResult(CompilerResult result) { return Task.Factory.StartNew(() => { }); } - protected virtual string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - return result; - } - protected abstract string GetPath(string sourceFileName, string targetFileName); } } diff --git a/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs b/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs index 3dadd54df..1e08094c3 100644 --- a/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs +++ b/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs @@ -47,11 +47,5 @@ public static CompilerResult GenerateResult(string sourceFileName, string target { return new CompilerResult(sourceFileName, targetFileName, mapFileName, isSuccess, result, resultMap, errors, hasSkipped); } - - internal static CompilerResult UpdateResult(CompilerResult result, string resultString) - { - result.Result = resultString; - return result; - } } } diff --git a/EditorExtensions/Shared/Compilers/ServerBase.cs b/EditorExtensions/Shared/Compilers/ServerBase.cs index b0e82ce9b..b61c1f71a 100644 --- a/EditorExtensions/Shared/Compilers/ServerBase.cs +++ b/EditorExtensions/Shared/Compilers/ServerBase.cs @@ -105,7 +105,7 @@ protected static async Task Up(T server) break; else { - if(server._process.HasExited) + if (server._process.HasExited) { Logger.Log("Unable to start resource, aborting"); server.Dispose(); diff --git a/EditorExtensions/Shared/ExtensionMethods/DragDropExtensions.cs b/EditorExtensions/Shared/ExtensionMethods/DragDropExtensions.cs index 6bb4556ee..873ad2861 100644 --- a/EditorExtensions/Shared/ExtensionMethods/DragDropExtensions.cs +++ b/EditorExtensions/Shared/ExtensionMethods/DragDropExtensions.cs @@ -1,8 +1,4 @@ -using System; -using System.Diagnostics; -using System.Threading.Tasks; -using System.Windows.Forms; -using MadsKristensen.EditorExtensions.Settings; +using System.Windows.Forms; using Microsoft.VisualStudio.Text.Editor.DragDrop; namespace MadsKristensen.EditorExtensions diff --git a/EditorExtensions/Shared/ExtensionMethods/Extensions.cs b/EditorExtensions/Shared/ExtensionMethods/Extensions.cs index 29cbff826..81fecd79c 100644 --- a/EditorExtensions/Shared/ExtensionMethods/Extensions.cs +++ b/EditorExtensions/Shared/ExtensionMethods/Extensions.cs @@ -22,6 +22,8 @@ static class Extensions /// public static T ForContentType(this WESettings settings, IContentType contentType) where T : class { + if (contentType == null) + return null; var name = contentType.TypeName; if (name.Equals("HTMLX", StringComparison.OrdinalIgnoreCase)) name = "Html"; var prop = TypeAccessor.Properties.FirstOrDefault(p => p.Property.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); diff --git a/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs b/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs index 812dacd0f..daead801c 100644 --- a/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs +++ b/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs @@ -12,10 +12,11 @@ class CssUrlNormalizer : ICssSimpleTreeVisitor { readonly string targetFile, oldBaseDirectory; readonly List> replacements = new List>(); + private CssUrlNormalizer(string targetFile, string oldBasePath) { - this.targetFile = Path.GetFullPath(targetFile); - this.oldBaseDirectory = Path.GetDirectoryName(oldBasePath); + targetFile = Path.GetFullPath(targetFile); + oldBaseDirectory = Path.GetDirectoryName(oldBasePath); } ///Normalizes all URLs in a CSS parse tree to be relative to the specified directory. @@ -34,6 +35,7 @@ private CssUrlNormalizer(string targetFile, string oldBasePath) public static string NormalizeUrls(BlockItem tree, string targetFile, string oldBasePath) { var normalizer = new CssUrlNormalizer(targetFile, oldBasePath); + tree.Accept(normalizer); var retVal = new StringBuilder(tree.Text); @@ -45,6 +47,7 @@ public static string NormalizeUrls(BlockItem tree, string targetFile, string old retVal.Remove(range.Start, range.Length); retVal.Insert(range.Start, HttpUtility.UrlPathEncode(url)); } + return retVal.ToString(); } @@ -55,6 +58,7 @@ public VisitItemResult Visit(ParseItem parseItem) return VisitItemResult.Continue; var newUrl = FixPath(DecodeStringLiteral(urlItem.UrlString.Text)); + if (newUrl == null) // No change return VisitItemResult.Continue; diff --git a/EditorExtensions/Shared/Helpers/CssSourceMap.cs b/EditorExtensions/Shared/Helpers/CssSourceMap.cs index 1d5995226..ec71d7305 100644 --- a/EditorExtensions/Shared/Helpers/CssSourceMap.cs +++ b/EditorExtensions/Shared/Helpers/CssSourceMap.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -8,7 +7,6 @@ using MadsKristensen.EditorExtensions.Settings; using Microsoft.CSS.Core; using Microsoft.CSS.Editor; -using Microsoft.Scss.Core; using Microsoft.VisualStudio.Utilities; using Newtonsoft.Json; diff --git a/EditorExtensions/Shared/Helpers/FileHelpers.cs b/EditorExtensions/Shared/Helpers/FileHelpers.cs index be85bf3d4..92db1266c 100644 --- a/EditorExtensions/Shared/Helpers/FileHelpers.cs +++ b/EditorExtensions/Shared/Helpers/FileHelpers.cs @@ -321,9 +321,9 @@ public async static Task ReadAllTextRetry(string fileName, Encoding enco // Keep the previous behavior if no encoding is provided. return await PolicyFactory.GetPolicy(new FileTransientErrorDetectionStrategy(), retryCount) .ExecuteAsync(() => - encoding == null ? + encoding == null ? Task.FromResult(File.ReadAllText(fileName)) : - Task.FromResult(File.ReadAllText(fileName, encoding)) + Task.FromResult(File.ReadAllText(fileName, encoding)) ); } catch (IOException) diff --git a/EditorExtensions/XML/DragDrop/BundleDrop.cs b/EditorExtensions/XML/DragDrop/BundleDrop.cs index 6437cda3d..56a5b138b 100644 --- a/EditorExtensions/XML/DragDrop/BundleDrop.cs +++ b/EditorExtensions/XML/DragDrop/BundleDrop.cs @@ -1,8 +1,6 @@ using System; using System.ComponentModel.Composition; using System.Globalization; -using MadsKristensen.EditorExtensions.Css; -using MadsKristensen.EditorExtensions.Images; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor.DragDrop; using Microsoft.VisualStudio.Utilities;