コード例 #1
0
 protected void BeforeQueryStatus(object sender, EventArgs e)
 {
     try
     {
         ((OleMenuCommand)sender).Visible = LintableFiles.AreAllSelectedItemsLintable();
     }
     catch (Exception ex)
     {
         Logger.LogAndWarn(ex);
     }
 }
コード例 #2
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); }
 }
コード例 #3
0
 private static bool AnyItemNotLintableSingleFile(UIHierarchyItem[] items)
 {
     foreach (UIHierarchyItem selItem in items)
     {
         if (!(selItem.Object is ProjectItem item &&
               item.GetFullPath() is string projectItemPath &&
               LintableFiles.IsLintableTsTsxJsJsxFile(projectItemPath)))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
 public static void OnFileOpened(IWpfTextView wpfTextView, ITextDocument textDocument)
 {
     try
     {
         // Called on UI thread
         if (wpfTextView == null || textDocument == null)
         {
             return;                                              // || !IsInSolution(textDocument.FilePath)) return;
         }
         // Legacy: Web Compiler and Bundler & Minifier added this property to generated files
         if (wpfTextView.Properties.TryGetProperty("generated", out bool generated) && generated)
         {
             return;
         }
         if (!LintableFiles.IsValidFile(textDocument.FilePath))
         {
             return;                                                     // Is the filepath valid and does the file exist
         }
         AddTextViewToBufferList(wpfTextView);
         wpfTextView.Properties.AddProperty("lint_document", textDocument);
         wpfTextView.Closed += TextviewClosed;
         // It's possible to open a second textview on the same underlying file/buffer
         if (wpfTextView.TextBuffer.Properties.TryGetProperty("lint_filename", out string fileName) && fileName != null)
         {
             return;
         }
         wpfTextView.TextBuffer.Properties.AddProperty("lint_filename", textDocument.FilePath);
         textDocument.FileActionOccurred += OnFileActionOccurred; // Hook the event whether lintable or not: it may become lintable
         if (!LintableFiles.IsLintableTsTsxJsJsxFile(textDocument.FilePath,
                                                     checkIgnoreOptions: !(WebLinterPackage.Settings?.UseTsConfig ?? false)))
         {
             return;
         }
         // Don't run linter again if error list already contains errors for the file.
         if (!ErrorListDataSource.Instance.HasErrors(textDocument.FilePath) &&
             WebLinterPackage.Settings != null && !WebLinterPackage.Settings.OnlyRunIfRequested)
         {
             Task.Run(async() =>
             {
                 await LintFile(textDocument.FilePath);
             });
         }
     }
     catch (Exception ex) { Logger.LogAndWarn(ex); }
 }
コード例 #5
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); }
        }
コード例 #6
0
 private async static void OnFileActionOccurred(object sender, TextDocumentFileActionEventArgs e)
 {
     try
     {
         // Called from UI thread: file save etc
         if (WebLinterPackage.Settings != null && !WebLinterPackage.Settings.OnlyRunIfRequested &&
             (e.FileActionType == FileActionTypes.ContentSavedToDisk || e.FileActionType == FileActionTypes.DocumentRenamed) &&
             LintableFiles.IsLintableTsTsxJsJsxFile(e.FilePath, checkIgnoreOptions: !WebLinterPackage.Settings.UseTsConfig))
         {
             await LintFile(e.FilePath);
         }
         // Not a lintable file, has been renamed or saved, may have existing errors (was lintable before a config change)
         else if (e.FileActionType == FileActionTypes.ContentSavedToDisk || e.FileActionType == FileActionTypes.DocumentRenamed)
         {
             ErrorListDataSource.Instance.CleanErrors(new[] { e.FilePath });
             WebLinterPackage.TaggerProvider?.RefreshTags();
         }
         if (e.FileActionType == FileActionTypes.DocumentRenamed)
         {
             CleanErrorsForOldFileName(sender, e);
         }
     }
     catch (Exception ex) { Logger.LogAndWarn(ex); }
 }