示例#1
0
 private async void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
 {
     try
     {
         if (WebLinterPackage.Settings != null && !WebLinterPackage.Settings.OnlyRunIfRequested &&
             e.FileActionType == FileActionTypes.ContentSavedToDisk &&
             LintableFiles.IsLintableTsOrTsxFile(e.FilePath)) // We may have changed settings since the event was hooked
         {
             await CallLinterService(e.FilePath);
         }
     }
     catch (Exception ex) { Logger.LogAndWarn(ex); }
 }
示例#2
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            try
            {
                // If we open a folder then our package isn't initialized but this class does get created
                // We get failures in the events because Settings is null, so don't do anything if that's the case
                if (WebLinterPackage.Settings == null)
                {
                    return;
                }
                var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
                textView.Closed += TextviewClosed;

                // Both "Web Compiler" and "Bundler & Minifier" extensions add this property on their
                // generated output files. Generated output should be ignored from linting
                if (textView.Properties.TryGetProperty("generated", out bool generated) && generated)
                {
                    return;
                }

                if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out ITextDocument _document))
                {
                    if (!LintableFiles.IsLintableTsOrTsxFile(_document.FilePath))
                    {
                        return;
                    }
                    _document.FileActionOccurred += DocumentSaved;
                    textView.Properties.AddProperty("lint_filename", _document.FilePath);
                    // Don't run linter again if error list already contains errors for the file.
                    if (!TableDataSource.Instance.HasErrors(_document.FilePath) &&
                        WebLinterPackage.Settings != null && !WebLinterPackage.Settings.OnlyRunIfRequested)
                    {
                        Task.Run(async() =>
                        {
                            await CallLinterService(_document.FilePath);
                        });
                    }
                }
            }
            catch (Exception ex) { Logger.LogAndWarn(ex); }
        }