diff --git a/src/Compiler/CompilerService.cs b/src/Compiler/CompilerService.cs index 1f86c8d..b0a071b 100644 --- a/src/Compiler/CompilerService.cs +++ b/src/Compiler/CompilerService.cs @@ -9,6 +9,7 @@ using System.Text; using Tasks = System.Threading.Tasks; using EnvDTE80; +using Microsoft.VisualStudio.Threading; namespace LessCompiler { @@ -16,6 +17,8 @@ internal static class CompilerService { public static async Tasks.Task CompileProjectAsync(Project project) { + var tf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext); + await tf.SwitchToMainThreadAsync(); if (project == null || !LessCatalog.Catalog.TryGetValue(project.UniqueName, out ProjectMap map)) return; @@ -24,7 +27,7 @@ public static async Tasks.Task CompileProjectAsync(Project project) foreach (CompilerOptions option in map.LessFiles.Keys) { if (option.Compile) - compileTasks.Add(CompileSingleFile(option)); + compileTasks.Add(CompileSingleFileAsync(option)); } await Tasks.Task.WhenAll(compileTasks); @@ -34,6 +37,8 @@ public static async Tasks.Task CompileProjectAsync(Project project) public static async Tasks.Task CompileAsync(CompilerOptions options, Project project) { + var tf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext); + await tf.SwitchToMainThreadAsync(); if (options == null || project == null || !LessCatalog.Catalog.TryGetValue(project.UniqueName, out ProjectMap map)) return; @@ -50,7 +55,7 @@ public static async Tasks.Task CompileAsync(CompilerOptions options, Project pro foreach (CompilerOptions parentOptions in parents.Where(p => p.Compile)) { - compilerTaks.Add(CompileSingleFile(parentOptions)); + compilerTaks.Add(CompileSingleFileAsync(parentOptions)); } await Tasks.Task.WhenAll(compilerTaks); @@ -60,7 +65,7 @@ public static async Tasks.Task CompileAsync(CompilerOptions options, Project pro VsHelpers.WriteStatus($"LESS file compiled in {Math.Round(sw.Elapsed.TotalSeconds, 2)} seconds"); } - private static async Tasks.Task CompileSingleFile(CompilerOptions options) + private static async Tasks.Task CompileSingleFileAsync(CompilerOptions options) { try { @@ -104,6 +109,8 @@ public static bool SupportsCompilation(this Project project) private static void AddFilesToProject(CompilerOptions options) { + Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); + ProjectItem item = VsHelpers.DTE.Solution.FindProjectItem(options.InputFilePath); if (item?.ContainingProject != null) @@ -139,7 +146,7 @@ public static void Minify(CompilerOptions options) CommentMode = CssComment.Important }; - UgliflyResult result = Uglify.Css(cssContent, settings); + NUglify.UglifyResult result = Uglify.Css(cssContent, settings); if (result.HasErrors) return; diff --git a/src/Compiler/ProjectMap.cs b/src/Compiler/ProjectMap.cs index e470f6d..4e51ce2 100644 --- a/src/Compiler/ProjectMap.cs +++ b/src/Compiler/ProjectMap.cs @@ -1,5 +1,6 @@ using EnvDTE; using EnvDTE80; +using Microsoft.VisualStudio.Threading; using System; using System.Collections.Generic; using System.Diagnostics; @@ -36,14 +37,20 @@ public async Task BuildMap(Project project) var sw = new Stopwatch(); sw.Start(); + var tf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext); + await tf.SwitchToMainThreadAsync(); IEnumerable lessFiles = FindLessFiles(project.ProjectItems); + var tasklist = new List(); foreach (string file in lessFiles) { - await AddFile(file); + tasklist.Add(AddFile(file)); } + await Task.WhenAll(tasklist); + sw.Stop(); + await tf.SwitchToMainThreadAsync(); Logger.Log($"LESS file catalog for {project.Name} built in {Math.Round(sw.Elapsed.TotalSeconds, 2)} seconds"); } @@ -78,7 +85,7 @@ private async Task AddFile(string lessFilePath) if (LessFiles.Keys.Any(c => c.InputFilePath == lessFilePath)) return; - string lessContent = File.ReadAllText(lessFilePath); + string lessContent = await VsHelpers.ReadFileAsync(lessFilePath); CompilerOptions options = await CompilerOptions.Parse(lessFilePath, lessContent); LessFiles.Add(options, new List()); @@ -93,10 +100,19 @@ private async Task AddOption(CompilerOptions options, string lessContent = null) foreach (Match match in _import.Matches(lessContent)) { - string childFilePath = new FileInfo(Path.Combine(lessDir, match.Groups["url"].Value)).FullName; - + string childFileName =Path.Combine(lessDir, match.Groups["url"].Value); + if (!File.Exists(childFileName)) + { + Logger.Log($"{childFileName} is inaccessible"); + continue; + } + + string childFilePath = new FileInfo(childFileName).FullName; if (!File.Exists(childFilePath)) + { + Logger.Log($"{childFilePath} is inaccessible"); continue; + } CompilerOptions import = LessFiles.Keys.FirstOrDefault(c => c.InputFilePath == childFilePath); @@ -114,6 +130,7 @@ private async Task AddOption(CompilerOptions options, string lessContent = null) private static IEnumerable FindLessFiles(ProjectItems items, List files = null) { + Dispatcher.CurrentDispatcher.VerifyAccess(); if (files == null) files = new List(); @@ -143,11 +160,13 @@ private void OnProjectItemRenamed(ProjectItem item, string OldName) ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () => { + Dispatcher.CurrentDispatcher.VerifyAccess(); LessFiles.Clear(); + Project itemContainingProject = item.ContainingProject; Task.Run(async () => { - await BuildMap(item.ContainingProject); + await BuildMap(itemContainingProject); }); }); } diff --git a/src/LessCompiler.csproj b/src/LessCompiler.csproj index 853d78f..43db413 100644 --- a/src/LessCompiler.csproj +++ b/src/LessCompiler.csproj @@ -10,6 +10,7 @@ /rootsuffix Exp + @@ -22,7 +23,7 @@ Properties LessCompiler LessCompiler - v4.5.2 + v4.6.2 true true true @@ -88,6 +89,7 @@ VsctGenerator VSCommandTable.cs + Designer @@ -118,107 +120,96 @@ False False - - ..\packages\Microsoft.VisualStudio.CoreUtility.14.3.25407\lib\net45\Microsoft.VisualStudio.CoreUtility.dll - False + + ..\packages\Microsoft.VisualStudio.CoreUtility.15.8.525\lib\net46\Microsoft.VisualStudio.CoreUtility.dll - - ..\packages\Microsoft.VisualStudio.Editor.14.3.25407\lib\net45\Microsoft.VisualStudio.Editor.dll - False + + ..\packages\Microsoft.VisualStudio.Editor.15.8.525\lib\net46\Microsoft.VisualStudio.Editor.dll - - ..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll - False + + ..\packages\Microsoft.VisualStudio.ImageCatalog.15.7.27703\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll + + + ..\packages\Microsoft.VisualStudio.Imaging.15.7.27703\lib\net45\Microsoft.VisualStudio.Imaging.dll + + + ..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.14.3.25408\lib\net20\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll + True - ..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6070\lib\Microsoft.VisualStudio.OLE.Interop.dll - False + ..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6071\lib\Microsoft.VisualStudio.OLE.Interop.dll ..\packages\Microsoft.VisualStudio.Shell.14.0.14.3.25407\lib\Microsoft.VisualStudio.Shell.14.0.dll - False - - ..\packages\Microsoft.VisualStudio.Shell.Immutable.10.0.10.0.30319\lib\net40\Microsoft.VisualStudio.Shell.Immutable.10.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Framework.15.0.26201\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll - - ..\packages\Microsoft.VisualStudio.Shell.Immutable.11.0.11.0.50727\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Immutable.10.0.15.0.25415\lib\net45\Microsoft.VisualStudio.Shell.Immutable.10.0.dll - - ..\packages\Microsoft.VisualStudio.Shell.Immutable.12.0.12.0.21003\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Immutable.11.0.15.0.25415\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll - - ..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.14.3.25407\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll - False + + ..\packages\Microsoft.VisualStudio.Shell.Immutable.12.0.15.0.25415\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll + + + ..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.15.0.25405\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll - ..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll - False + ..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6072\lib\net11\Microsoft.VisualStudio.Shell.Interop.dll + ..\packages\Microsoft.VisualStudio.Shell.Interop.10.0.10.0.30320\lib\net20\Microsoft.VisualStudio.Shell.Interop.10.0.dll True - ..\packages\Microsoft.VisualStudio.Shell.Interop.10.0.10.0.30319\lib\Microsoft.VisualStudio.Shell.Interop.10.0.dll - True + ..\packages\Microsoft.VisualStudio.Shell.Interop.11.0.11.0.61031\lib\net20\Microsoft.VisualStudio.Shell.Interop.11.0.dll True - ..\packages\Microsoft.VisualStudio.Shell.Interop.11.0.11.0.61030\lib\Microsoft.VisualStudio.Shell.Interop.11.0.dll - True + ..\packages\Microsoft.VisualStudio.Shell.Interop.12.0.12.0.30111\lib\net20\Microsoft.VisualStudio.Shell.Interop.12.0.dll True - ..\packages\Microsoft.VisualStudio.Shell.Interop.12.0.12.0.30110\lib\Microsoft.VisualStudio.Shell.Interop.12.0.dll - True - ..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.Shell.Interop.8.0.dll - False + ..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50728\lib\net11\Microsoft.VisualStudio.Shell.Interop.8.0.dll - ..\packages\Microsoft.VisualStudio.Shell.Interop.9.0.9.0.30729\lib\Microsoft.VisualStudio.Shell.Interop.9.0.dll - False + ..\packages\Microsoft.VisualStudio.Shell.Interop.9.0.9.0.30730\lib\net11\Microsoft.VisualStudio.Shell.Interop.9.0.dll - - ..\packages\Microsoft.VisualStudio.Text.Data.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Data.dll - False + + ..\packages\Microsoft.VisualStudio.Text.Data.15.8.525\lib\net46\Microsoft.VisualStudio.Text.Data.dll - - ..\packages\Microsoft.VisualStudio.Text.Logic.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Logic.dll - False + + ..\packages\Microsoft.VisualStudio.Text.Logic.15.8.525\lib\net46\Microsoft.VisualStudio.Text.Logic.dll - - ..\packages\Microsoft.VisualStudio.Text.UI.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.UI.dll - False + + ..\packages\Microsoft.VisualStudio.Text.UI.15.8.525\lib\net46\Microsoft.VisualStudio.Text.UI.dll - - ..\packages\Microsoft.VisualStudio.Text.UI.Wpf.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.UI.Wpf.dll - False + + ..\packages\Microsoft.VisualStudio.Text.UI.Wpf.15.8.525\lib\net46\Microsoft.VisualStudio.Text.UI.Wpf.dll - ..\packages\Microsoft.VisualStudio.TextManager.Interop.7.10.6070\lib\Microsoft.VisualStudio.TextManager.Interop.dll - False + ..\packages\Microsoft.VisualStudio.TextManager.Interop.7.10.6071\lib\net11\Microsoft.VisualStudio.TextManager.Interop.dll - ..\packages\Microsoft.VisualStudio.TextManager.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.TextManager.Interop.8.0.dll - False + ..\packages\Microsoft.VisualStudio.TextManager.Interop.8.0.8.0.50728\lib\net11\Microsoft.VisualStudio.TextManager.Interop.8.0.dll - - ..\packages\Microsoft.VisualStudio.Threading.14.1.111\lib\net45\Microsoft.VisualStudio.Threading.dll - False + + ..\packages\Microsoft.VisualStudio.Threading.15.8.145\lib\net46\Microsoft.VisualStudio.Threading.dll - - ..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll - False + + ..\packages\Microsoft.VisualStudio.Utilities.15.7.27703\lib\net46\Microsoft.VisualStudio.Utilities.dll - - ..\packages\Microsoft.VisualStudio.Validation.14.1.111\lib\net45\Microsoft.VisualStudio.Validation.dll - False + + ..\packages\Microsoft.VisualStudio.Validation.15.3.58\lib\net45\Microsoft.VisualStudio.Validation.dll + + + ..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll - - ..\packages\NUglify.1.5.5\lib\net40\NUglify.dll + + ..\packages\NUglify.1.5.12\lib\net40\NUglify.dll @@ -226,11 +217,21 @@ False False + + ..\packages\StreamJsonRpc.1.3.23\lib\net45\StreamJsonRpc.dll + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -252,14 +253,21 @@ VSPackage - + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + +