Ejemplo n.º 1
0
        /// <summary>
        /// Create a tagger that will track SonarLint issues on the view/buffer combination.
        /// </summary>
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only attempt to track the view's edit buffer.
            if (buffer != textView.TextBuffer ||
                typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            ITextDocument textDocument;

            if (!textDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out textDocument))
            {
                return(null);
            }

            var detectedLanguages = languageRecognizer.Detect(textDocument, buffer);

            if (detectedLanguages.Any() && analyzerController.IsAnalysisSupported(detectedLanguages))
            {
                // Multiple views could have that buffer open simultaneously, so only create one instance of the tracker.
                var issueTracker = buffer.Properties.GetOrCreateSingletonProperty(typeof(IIssueTracker),
                                                                                  () => new TextBufferIssueTracker(dte, this, textDocument, detectedLanguages, logger, issuesFilter));

                // Always create a new tagger for each request
                return(new IssueTagger(issueTracker) as ITagger <T>);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a tagger that will track SonarLint issues on the view/buffer combination.
        /// </summary>
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            // Only attempt to track the view's edit buffer.
            if (typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            if (!textDocumentFactoryService.TryGetTextDocument(buffer, out var textDocument))
            {
                return(null);
            }

            var detectedLanguages = languageRecognizer.Detect(textDocument.FilePath, buffer.ContentType);

            if (detectedLanguages.Any() && analyzerController.IsAnalysisSupported(detectedLanguages))
            {
                // We only want one TBIT per buffer and we don't want it be disposed until
                // it is not being used by any tag aggregators, so we're wrapping it in a SingletonDisposableTaggerManager
                var singletonTaggerManager = buffer.Properties.GetOrCreateSingletonProperty(SingletonManagerPropertyCollectionKey,
                                                                                            () => new SingletonDisposableTaggerManager <IErrorTag>(_ => InternalCreateTextBufferIssueTracker(textDocument, detectedLanguages)));

                var tagger = singletonTaggerManager.CreateTagger(buffer);
                return(tagger as ITagger <T>);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void OnActiveDocumentFocused(object sender, ActiveDocumentChangedEventArgs e)
        {
            if (e.ActiveTextDocument == null)
            {
                return;
            }

            var detectedLanguages = sonarLanguageRecognizer.Detect(e.ActiveTextDocument.FilePath, e.ActiveTextDocument.TextBuffer.ContentType);

            if (!detectedLanguages.Any() || !cFamilyAnalyzer.IsAnalysisSupported(detectedLanguages))
            {
                return;
            }

            var cFamilyAnalyzerOptions = new CFamilyAnalyzerOptions
            {
                CreatePreCompiledHeaders = true
            };

            scheduler.Schedule(PchJobId, token =>
            {
                cFamilyAnalyzer.ExecuteAnalysis(e.ActiveTextDocument.FilePath,
                                                detectedLanguages,
                                                null,
                                                cFamilyAnalyzerOptions,
                                                null,
                                                token);
            }, pchJobTimeoutInMilliseconds);
        }
Ejemplo n.º 4
0
        public bool IsTaggable(ITextBuffer buffer)
        {
            var filePath = buffer.GetFilePath();

            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            var analysisLanguages = languageRecognizer.Detect(filePath, buffer.ContentType);

            return(analysisLanguages.Any());
        }
        private bool HasActiveCFamilyDoc()
        {
            var activeDoc = activeDocumentLocator.FindActiveDocument();

            if (activeDoc == null)
            {
                logger.WriteLine(CFamilyStrings.ReproCmd_NoActiveDocument);
                return(false);
            }

            var languages = sonarLanguageRecognizer.Detect(activeDoc.FilePath, activeDoc.TextBuffer.ContentType);

            if (languages.Contains(AnalysisLanguage.CFamily))
            {
                logger.WriteLine(CFamilyStrings.ReproCmd_DocumentIsAnalyzable, activeDoc.FilePath);
                return(true);
            }

            logger.WriteLine(CFamilyStrings.ReproCmd_DocumentIsNotAnalyzable, activeDoc.FilePath);
            return(false);
        }
        /// <summary>
        /// Create a tagger that will track SonarLint issues on the view/buffer combination.
        /// </summary>
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            if (!settings.IsActivateMoreEnabled)
            {
                return(null);
            }

            // Only attempt to track the view's edit buffer.
            // Multiple views could have that buffer open simultaneously, so only create one instance of the tracker.
            if (buffer != textView.TextBuffer ||
                typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            ITextDocument textDocument;

            if (!textDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out textDocument))
            {
                return(null);
            }

            var detectedLanguages = languageRecognizer.Detect(textDocument, buffer);

            if (detectedLanguages.Any())
            {
                lock (taggers)
                {
                    if (!taggers.ExistsForFile(textDocument.FilePath))
                    {
                        return(new IssueTagger(dte, this, buffer, textDocument, detectedLanguages)
                               as ITagger <T>);
                    }
                }
            }

            return(null);
        }