Beispiel #1
0
        private async void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
        {
            if (e.FileActionType != FileActionTypes.ContentSavedToDisk || !_project.IsLessCompilationEnabled())
            {
                return;
            }

            if (NodeProcess.IsInstalling)
            {
                VsHelpers.WriteStatus("The LESS compiler is being installed. Please try again in a few seconds...");
            }
            else if (NodeProcess.IsReadyToExecute())
            {
                CompilerOptions options = await CompilerOptions.Parse(e.FilePath, _view.TextBuffer.CurrentSnapshot.GetText());

                if (_view.Properties.TryGetProperty(typeof(LessAdornment), out LessAdornment adornment))
                {
                    await adornment.Update(options);
                }

                if (options == null || !_project.SupportsCompilation() || !_project.IsLessCompilationEnabled())
                {
                    return;
                }

                await LessCatalog.UpdateFile(_project, options);

                if (await LessCatalog.EnsureCatalog(_project))
                {
                    await CompilerService.CompileAsync(options, _project);
                }
            }
        }
Beispiel #2
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            _view = view;

            if (!DocumentService.TryGetTextDocument(view.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            _project = VsHelpers.DTE.Solution.FindProjectItem(doc.FilePath)?.ContainingProject;

            if (!_project.SupportsCompilation())
            {
                return;
            }

            Settings.Changed += OnSettingsChanged;
            view.Closed      += OnViewClosed;

            Microsoft.VisualStudio.Shell.ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, async() =>
            {
                bool isEnabled = _project.IsLessCompilationEnabled();

                LessAdornment adornment = view.Properties.GetOrCreateSingletonProperty(() => new LessAdornment(view, _project));

                if (isEnabled && await LessCatalog.EnsureCatalog(_project))
                {
                    CompilerOptions options = LessCatalog.Catalog[_project.UniqueName].LessFiles.Keys.FirstOrDefault(l => l.InputFilePath == doc.FilePath);

                    if (options != null)
                    {
                        await adornment.Update(options);
                    }
                }
            });

            doc.FileActionOccurred += DocumentSaved;
        }
Beispiel #3
0
        private async Tasks.Task Execute()
        {
            if (!NodeProcess.IsReadyToExecute())
            {
                return;
            }

            var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution));
            IEnumerable <IVsHierarchy> hierarchies = GetProjectsInSolution(solution, __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION);

            foreach (IVsHierarchy hierarchy in hierarchies)
            {
                Project project = GetDTEProject(hierarchy);

                if (project.SupportsCompilation() && project.IsLessCompilationEnabled())
                {
                    if (await LessCatalog.EnsureCatalog(project))
                    {
                        await CompilerService.CompileProjectAsync(project);
                    }
                }
            }
        }
        private async Task <bool> IsOutput(string fileName)
        {
            EnvDTE.Project project = VsHelpers.DTE.Solution.FindProjectItem(fileName)?.ContainingProject;

            if (!project.SupportsCompilation() || !project.IsLessCompilationEnabled() || !await LessCatalog.EnsureCatalog(project))
            {
                return(false);
            }

            ProjectMap map = LessCatalog.Catalog[project.UniqueName];

            return(map.LessFiles.Keys.Any(l =>
                                          l.OutputFilePath.Equals(fileName, StringComparison.OrdinalIgnoreCase) ||
                                          (l.Minify && l.OutputFilePath.Equals(fileName.Replace(".min.css", ".css"), StringComparison.OrdinalIgnoreCase))));
        }