Exemple #1
0
        public void CreateSquiggleSpan(SimpleTagger <ErrorTag> tagger)
        {
            if (_rawSpan.Start >= _rawSpan.End || _spanTranslator == null)
            {
                return;
            }

            // TODO: Map between versions rather than using the current snapshot
            var snapshot = _spanTranslator.TextBuffer.CurrentSnapshot;
            var target   = _rawSpan.ToSnapshotSpan(snapshot);

            //SnapshotSpan target = _spanTranslator.TranslateForward(
            //    new Span(_rawSpan.Start.Index, _rawSpan.Length)
            //);

            if (target.Length <= 0)
            {
                return;
            }

            var tagSpan = snapshot.CreateTrackingSpan(
                target.Start,
                target.Length,
                SpanTrackingMode.EdgeInclusive
                );

            tagger.CreateTagSpan(tagSpan, new ErrorTag(ErrorType, _message));
        }
        private void CreateTracking(IWpfTextView textView, ITextSnapshot textSnapshot, Span span)
        {
            if (_trackingSpan != null)
            {
                return;
            }

            _textView = textView;

            if (_tagger == null)
            {
                IComponentModel componentModel = (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel));
                ISarifLocationProviderFactory sarifLocationProviderFactory = componentModel.GetService <ISarifLocationProviderFactory>();

                // Get a SimpleTagger over the buffer to color
                _tagger = sarifLocationProviderFactory.GetTextMarkerTagger(_textView.TextBuffer);
            }

            // Add the marker
            if (_tagger != null)
            {
                // The list of colors for TextMarkerTag are defined in Platform\Text\Impl\TextMarkerAdornment\TextMarkerProviderFactory.cs
                _trackingSpan = textSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
            }
        }
        private void ParseSnapshot(ISnapshotTextContentProvider snapshotContent)
        {
            // queue analysis of the parsed tree at High Pri so the active buffer is quickly re-analyzed
            var snapshot = snapshotContent.Snapshot;

            if (snapshot.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType))
            {
                PythonAst           ast;
                CollectingErrorSink errorSink;
                ParsePythonCode((TextContentProvider)snapshotContent, out ast, out errorSink);
                if (ast != null)
                {
                    IPythonProjectEntry analysis;
                    if (snapshot.TextBuffer.TryGetPythonAnalysis(out analysis))
                    {
                        // only update the AST when we're error free, this way we don't remove
                        // a useful analysis with an incomplete and useless analysis.
                        if (errorSink.Errors.Count == 0)
                        {
                            analysis.UpdateTree(ast, new SnapshotCookie(snapshot));
                            _analysisQueue.Enqueue(analysis, AnalysisPriority.High);
                        }

                        SimpleTagger <ErrorTag> squiggles = _squiggleProvider.GetErrorTagger(snapshot.TextBuffer);
                        squiggles.RemoveTagSpans(x => true);

                        // update squiggles for the live buffer
                        foreach (ErrorResult warning in errorSink.Warnings)
                        {
                            var span  = warning.Span;
                            var tspan = CreateSpan(snapshot, span);
                            squiggles.CreateTagSpan(tspan, new ErrorTag("Warning", warning.Message));
                        }

                        foreach (ErrorResult error in errorSink.Errors)
                        {
                            var span  = error.Span;
                            var tspan = CreateSpan(snapshot, span);
                            squiggles.CreateTagSpan(tspan, new ErrorTag("Error", error.Message));
                        }
                    }
                }
            }
            else if (snapshot.TextBuffer.ContentType.IsOfType("xaml"))
            {
                string path = snapshot.TextBuffer.GetFilePath();
                if (path != null)
                {
                    IProjectEntry    analysis;
                    XamlProjectEntry xamlProject;
                    if (_projectFiles.TryGetValue(path, out analysis) &&
                        (xamlProject = analysis as XamlProjectEntry) != null)
                    {
                        xamlProject.UpdateContent(((TextContentProvider)snapshotContent).GetReader(), new SnapshotCookie(snapshotContent.Snapshot));
                        _analysisQueue.Enqueue(analysis, AnalysisPriority.High);
                    }
                }
            }
        }
        public VersionTrackingTagger(ITextBuffer buffer)
        {
            m_buffer  = buffer ?? throw new ArgumentNullException(nameof(buffer));
            m_storage = new SimpleTagger <T>(buffer);

            m_buffer.Changed      += Buffer_Changed;
            m_storage.TagsChanged += Storage_TagsChanged;
        }
        internal static SimpleTagger <TextMarkerTag> CreateSarifLocationTaggerInternal(ITextBuffer textBuffer)
        {
            SimpleTagger <TextMarkerTag> sarifLocationTagger = textBuffer.Properties.GetOrCreateSingletonProperty <SimpleTagger <TextMarkerTag> >(delegate
            {
                return(new SimpleTagger <TextMarkerTag>(textBuffer));
            });

            return(sarifLocationTagger);
        }
 public SimpleTagger<TextMarkerTag> GetTextMarkerTagger(ITextBuffer textBuffer) {
     SimpleTagger<TextMarkerTag> tagger;
     if (textBuffer.Properties.TryGetProperty(typeof(SimpleTagger<TextMarkerTag>), out tagger)) {
         return tagger;
     }
     tagger = new SimpleTagger<TextMarkerTag>(textBuffer);
     textBuffer.Properties.AddProperty(typeof(SimpleTagger<TextMarkerTag>), tagger);
     return tagger;
 }
 public SimpleTagger <TextMarkerTag> GetTextMarkerTagger(ITextBuffer textBuffer)
 {
     if (textBuffer.Properties.TryGetProperty(typeof(SimpleTagger <TextMarkerTag>), out SimpleTagger <TextMarkerTag> tagger))
     {
         return(tagger);
     }
     tagger = new SimpleTagger <TextMarkerTag>(textBuffer);
     textBuffer.Properties.AddProperty(typeof(SimpleTagger <TextMarkerTag>), tagger);
     return(tagger);
 }
Exemple #8
0
        public ErrorListPresenter(ITextBuffer textBuffer, IErrorProviderFactory squiggleProviderFactory, IServiceProvider serviceProvider)
        {
            _textBuffer          = textBuffer;
            _textBuffer.Changed += OnTextBufferChanged;

            _serviceProvider   = serviceProvider;
            _squiggleTagger    = squiggleProviderFactory.GetErrorTagger(_textBuffer);
            _errorListProvider = new Microsoft.VisualStudio.Shell.ErrorListProvider(serviceProvider);
            _previousErrors    = new List <ErrorTask>();
            _previousSquiggles = new List <TrackingTagSpan <IErrorTag> >();
        }
    public ErrorListPresenter(ITextBuffer textBuffer, IErrorProviderFactory squiggleProviderFactory, IServiceProvider serviceProvider)
    {
      _textBuffer = textBuffer;
      _textBuffer.Changed += OnTextBufferChanged;

      _serviceProvider = serviceProvider;
      _squiggleTagger = squiggleProviderFactory.GetErrorTagger(_textBuffer);
      _errorListProvider = new Microsoft.VisualStudio.Shell.ErrorListProvider(serviceProvider);
      _previousErrors = new List<ErrorTask>();
      _previousSquiggles = new List<TrackingTagSpan<IErrorTag>>();
    }
 private void RemoveTracking()
 {
     if (_trackingSpan != null)
     {
         // TODO: Find a way to delete TrackingSpan
         _marker = _tagger.CreateTagSpan(_trackingSpan, new TextMarkerTag(Color));
         RemoveHighlightMarker();
         _trackingSpan = null;
         _tagger       = null;
         _docCookie    = null;
     }
 }
Exemple #11
0
 private void RemoveTracking()
 {
     if (m_trackingSpan != null)
     {
         // TODO: Find a way to delete TrackingSpan
         m_marker = m_tagger.CreateTagSpan(m_trackingSpan, new TextMarkerTag(Color));
         RemoveMarker();
         m_trackingSpan = null;
         m_tagger       = null;
         m_docCookie    = null;
     }
 }
Exemple #12
0
        public void Parse(TextContentProvider /*!*/ content)
        {
            var            errorSink = new CollectingErrorSink();
            SourceUnitTree ast       = MakeParseTree(content, errorSink);

            ISnapshotTextContentProvider snapshotContent = content as ISnapshotTextContentProvider;

            if (snapshotContent != null)
            {
                // queue analysis of the parsed tree at High Pri so the active buffer is quickly re-analyzed
                var snapshot = snapshotContent.Snapshot;

                var analysis = AnalysisItem.GetAnalysis(snapshot.TextBuffer);

                // only update the AST when we're error free, this way we don't remove
                // a useful analysis with an incomplete and useless analysis.
                if (errorSink.Errors.Count == 0)
                {
                    analysis.UpdateTree(ast, new SnapshotCookie(snapshot));
                    _analysisQueue.Enqueue(analysis, AnalysisPriority.High);
                }

                SimpleTagger <ErrorTag> squiggles = _squiggleProvider.GetErrorTagger(snapshot.TextBuffer);
                squiggles.RemoveTagSpans(x => true);

                // update squiggles for the live buffer
                foreach (ErrorResult warning in errorSink.Warnings)
                {
                    var span  = warning.Span;
                    var tspan = CreateSpan(snapshot, span);
                    squiggles.CreateTagSpan(tspan, new ErrorTag("Warning", warning.Message));
                }

                foreach (ErrorResult error in errorSink.Errors)
                {
                    var span  = error.Span;
                    var tspan = CreateSpan(snapshot, span);
                    squiggles.CreateTagSpan(tspan, new ErrorTag("Error", error.Message));
                }
            }
            else
            {
                FileTextContentProvider fileContent = content as FileTextContentProvider;
                AnalysisItem            analysis;
                if (fileContent != null && _projectFiles.TryGetValue(fileContent.Path, out analysis))
                {
                    analysis.UpdateTree(ast, new FileCookie(fileContent.Path));
                    _analysisQueue.Enqueue(analysis, AnalysisPriority.Normal);
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Clear all markers and tracking classes
        /// </summary>
        public void Clear()
        {
            if (m_marker != null)
            {
                RemoveMarker();
            }

            if (IsTracking())
            {
                RemoveTracking();
            }

            m_tagger = null;
        }
Exemple #14
0
        public void CreateSquiggleSpan(SimpleTagger <ErrorTag> tagger)
        {
            SnapshotSpan target = _spanTranslator.TranslateForward(
                new Span(_rawSpan.Start.Index, _rawSpan.Length)
                );

            var tagSpan = _spanTranslator.TextBuffer.CurrentSnapshot.CreateTrackingSpan(
                target.Start,
                target.Length,
                SpanTrackingMode.EdgeInclusive
                );

            tagger.CreateTagSpan(tagSpan, new ErrorTag(ErrorType, _message));
        }
Exemple #15
0
        public SquiggleErrorPresenter(IWpfTextView textView, IErrorProviderFactory squiggleProviderFactory, IServiceProvider serviceProvider)
        {
            this.textView = textView;
            this.textView.TextBuffer.Changed += OnTextBufferChanged;
            //this.textView.Closed += new EventHandler(OnTextViewClosed);
            textView.GotAggregateFocus += new EventHandler(OnTextViewGotFocus);


            this.errorListProvider = new StaDynErrorListProvider();
            this.squiggleTagger    = squiggleProviderFactory.GetErrorTagger(textView.TextBuffer);
            previousSquiggles      = new List <TrackingTagSpan <IErrorTag> >();

            //CreateErrors();
        }
        /// <summary>
        /// Clear all markers and tracking classes
        /// </summary>
        public void Clear()
        {
            if (_marker != null)
            {
                RemoveHighlightMarker();
            }

            if (IsTracking())
            {
                RemoveTracking();
            }

            _tagger = null;
        }
        public ErrorListPresenter(IWpfTextView textView, IErrorProviderFactory squiggleProviderFactory, IServiceProvider serviceProvider)
        {
            this.textView = textView;
            this.textView.TextBuffer.Changed += OnTextBufferChanged;
            this.textView.Closed             += new EventHandler(OnTextViewClosed);

            this.errorListProvider = new PyErrorListProvider();
            this.squiggleTagger    = squiggleProviderFactory.GetErrorTagger(textView.TextBuffer);

            errorList = new Microsoft.VisualStudio.Shell.ErrorListProvider(serviceProvider);

            previousErrors    = new List <ErrorTask>();
            previousSquiggles = new List <TrackingTagSpan <IErrorTag> >();

            CreateErrors();
        }
        public ErrorListPresenter(IWpfTextView textView, IErrorProviderFactory squiggleProviderFactory, IServiceProvider serviceProvider)
        {
            this.textView = textView;
            this.textView.TextBuffer.Changed += OnTextBufferChanged;
            this.textView.Closed += new EventHandler(OnTextViewClosed);

            this.errorListProvider = new PyErrorListProvider();
            this.squiggleTagger = squiggleProviderFactory.GetErrorTagger(textView.TextBuffer);

            errorList = new Microsoft.VisualStudio.Shell.ErrorListProvider(serviceProvider);

            previousErrors = new List<ErrorTask>();
            previousSquiggles = new List<TrackingTagSpan<IErrorTag>>();

            CreateErrors();
        }
Exemple #19
0
        public void CreateSquiggleSpan(SimpleTagger <ErrorTag> tagger)
        {
            if (_rawSpan.Start >= _rawSpan.End || _spanTranslator == null)
            {
                return;
            }

            var snapshot = _spanTranslator.TextBuffer.CurrentSnapshot;
            var target   = _spanTranslator.Translate(_rawSpan, _fromVersion, snapshot);

            if (target.Length <= 0)
            {
                return;
            }

            var tagSpan = snapshot.CreateTrackingSpan(
                target.Start,
                target.Length,
                SpanTrackingMode.EdgeInclusive
                );

            tagger.CreateTagSpan(tagSpan, new ErrorTagWithMoniker(ErrorType, _message, _moniker));
        }
        // Re-collapse the spans
        public void CollapseRegions()
        {
            if (_outliningManager == null || _textView == null || _collapsedSpans == null)
            {
                return;
            }

            ITextSnapshot snapshot = _textView.TextBuffer.CurrentSnapshot;

            // Get a span that includes all collapsed regions
            int min = Int32.MinValue;
            int max = Int32.MinValue;

            foreach (Tuple <Span, IOutliningRegionTag> span in _collapsedSpans)
            {
                if (min == Int32.MinValue || span.Item1.Start < min)
                {
                    min = span.Item1.Start;
                }

                if (max == Int32.MinValue || span.Item1.End > max)
                {
                    max = span.Item1.End;
                }
            }

            // avoid running if there were no spans
            if (min == Int32.MinValue)
            {
                Debug.Fail("No spans");
                return;
            }

            // span containing all collapsed regions
            SnapshotSpan entireSpan = new SnapshotSpan(snapshot, min, max - min);

            // regions have not yet been tagged by the language service during the undo/redo and
            // so we need to tag them again in order to do the collapse
            SimpleTagger <IOutliningRegionTag> simpleTagger =
                _textView.TextBuffer.Properties.GetOrCreateSingletonProperty <SimpleTagger <IOutliningRegionTag> >(() => new SimpleTagger <IOutliningRegionTag>(_textView.TextBuffer));

            Debug.Assert(!simpleTagger.GetTaggedSpans(entireSpan).GetEnumerator().MoveNext(),
                         "The code is not expecting the regions to be tagged already. Verify that redundant tagging is not occurring.");

            List <Span> toCollapse = new List <Span>();

            // tag the regions and add them to the list to be bulk collapsed
            foreach (Tuple <Span, IOutliningRegionTag> span in _collapsedSpans)
            {
                ITrackingSpan tspan = snapshot.CreateTrackingSpan(span.Item1, SpanTrackingMode.EdgeExclusive);
                simpleTagger.CreateTagSpan(tspan, span.Item2);

                toCollapse.Add(span.Item1);
            }

            // Disable the OutliningUndoManager to avoid it adding our collapse to the undo stack as an expand
            bool disableOutliningUndo = _textView.Options.IsOutliningUndoEnabled();

            try
            {
                if (disableOutliningUndo)
                {
                    _textView.Options.SetOptionValue(DefaultTextViewOptions.OutliningUndoOptionId, false);
                }

                // Do the collapse
                _outliningManager.CollapseAll(entireSpan, colSpan => (!colSpan.IsCollapsed && toCollapse.Contains(colSpan.Extent.GetSpan(snapshot))));
            }
            finally
            {
                if (disableOutliningUndo)
                {
                    _textView.Options.SetOptionValue(DefaultTextViewOptions.OutliningUndoOptionId, true);
                }
            }
        }
 private void RemoveTracking()
 {
     if (m_trackingSpan != null)
     {
         // TODO: Find a way to delete TrackingSpan
         m_marker = m_tagger.CreateTagSpan(m_trackingSpan, new TextMarkerTag(Color));
         RemoveHighlightMarker();
         m_trackingSpan = null;
         m_tagger = null;
         m_docCookie = null;
     }
 }
Exemple #22
0
        public void ParseBuffers(BufferParser bufferParser, Severity indentationSeverity, params ITextSnapshot[] snapshots)
        {
            IProjectEntry analysis;

            lock (_openFiles) {
                if (!_openFiles.TryGetValue(bufferParser, out analysis))
                {
                    return;
                }
            }

            IPythonProjectEntry pyProjEntry = analysis as IPythonProjectEntry;
            List <PythonAst>    asts        = new List <PythonAst>();
            bool hasErrors = false;

            foreach (var snapshot in snapshots)
            {
                var snapshotContent = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));

                if (pyProjEntry != null && snapshot.TextBuffer.ContentType.IsOfType(PythonCoreConstants.ContentType))
                {
                    if (!snapshot.IsReplBufferWithCommand())
                    {
                        PythonAst           ast;
                        CollectingErrorSink errorSink;

                        ParsePythonCode(snapshotContent, indentationSeverity, out ast, out errorSink);
                        if (ast != null)
                        {
                            asts.Add(ast);

                            if (errorSink.Errors.Count != 0)
                            {
                                hasErrors = true;
                            }

                            // update squiggles for the buffer
                            var buffer = snapshot.TextBuffer;
                            SimpleTagger <ErrorTag> squiggles = _errorProvider.GetErrorTagger(snapshot.TextBuffer);
                            squiggles.RemoveTagSpans(x => true);

                            TaskProvider provider = GetTaskListProviderForProject(bufferParser._currentProjEntry);

                            AddWarnings(snapshot, errorSink, squiggles, provider);

                            AddErrors(snapshot, errorSink, squiggles, provider);

                            UpdateErrorList(errorSink, buffer.GetFilePath(), provider);
                        }
                    }
                }
                else
                {
                    // other file such as XAML
                    IExternalProjectEntry externalEntry;
                    if ((externalEntry = (analysis as IExternalProjectEntry)) != null)
                    {
                        externalEntry.ParseContent(snapshotContent, new SnapshotCookie(snapshotContent.Snapshot));
                        _analysisQueue.Enqueue(analysis, AnalysisPriority.High);
                    }
                }
            }

            if ((!hasErrors && asts.Count > 0) || asts.Count > 1)
            {
                // only update the AST when we're error free, this way we don't remove
                // a useful analysis with an incomplete and useless analysis.
                // If we have more than one AST we're in the REPL - we'll update the
                // AST in that case as errors won't go away.

                PythonAst finalAst;
                if (asts.Count == 1)
                {
                    finalAst = asts[0];
                }
                else
                {
                    // multiple ASTs, merge them together
                    List <Statement> bodies = new List <Statement>();
                    foreach (var ast in asts)
                    {
                        bodies.Add(ast.Body);
                    }
                    finalAst = new PythonAst(new SuiteStatement(bodies.ToArray()), new int[0]);
                }

                pyProjEntry.UpdateTree(finalAst, new SnapshotCookie(snapshots[0])); // SnapshotCookie is ot entirely right, we should merge the snapshots
                _analysisQueue.Enqueue(analysis, AnalysisPriority.High);
            }
        }
Exemple #23
0
 private static void AddErrors(ITextSnapshot snapshot, CollectingErrorSink errorSink, SimpleTagger <ErrorTag> squiggles, TaskProvider provider)
 {
     foreach (ErrorResult error in errorSink.Errors)
     {
         var span  = error.Span;
         var tspan = CreateSpan(snapshot, span);
         squiggles.CreateTagSpan(tspan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, error.Message));
         if (provider != null)
         {
             provider.AddError(error);
         }
     }
 }
Exemple #24
0
 private static void AddWarnings(ITextSnapshot snapshot, CollectingErrorSink errorSink, SimpleTagger <ErrorTag> squiggles, TaskProvider provider)
 {
     foreach (ErrorResult warning in errorSink.Warnings)
     {
         var span  = warning.Span;
         var tspan = CreateSpan(snapshot, span);
         squiggles.CreateTagSpan(tspan, new ErrorTag(PredefinedErrorTypeNames.Warning, warning.Message));
         if (provider != null)
         {
             provider.AddWarning(warning);
         }
     }
 }
 public AgentTagger(ITextBuffer buffer)
 {
     _buffer             = buffer;
     tagger              = new SimpleTagger <RemoteAgentTag>(buffer);
     tagger.TagsChanged += (sender, args) => TagsChanged(this, args);
 }
        private void CreateTracking(IWpfTextView textView, ITextSnapshot textSnapshot, Span span)
        {
            if (m_trackingSpan != null)
                return;

            m_textView = textView;

            if (m_tagger == null)
            {
                IComponentModel componentModel = (IComponentModel)m_serviceProvider.GetService(typeof(SComponentModel));
                ISarifLocationProviderFactory sarifLocationProviderFactory = componentModel.GetService<ISarifLocationProviderFactory>();

                // Get a SimpleTagger over the buffer to color
                m_tagger = sarifLocationProviderFactory.GetTextMarkerTagger(m_textView.TextBuffer);
            }

            // Add the marker
            if (m_tagger != null)
            {
                // The list of colors for TextMarkerTag are defined in Platform\Text\Impl\TextMarkerAdornment\TextMarkerProviderFactory.cs
                m_trackingSpan = textSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////
        //
        // Validate the mardown directive syntax according to the ruleset definitions
        //
        // Copyright (c) 2014 Microsoft Corporation.
        // Author: Junyi Yi ([email protected]) - Initial version
        //
        ///////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Validate the whole document according to the specified ruleset.
        /// </summary>
        /// <param name="snapshot">The whole document snapshot.</param>
        /// <param name="errorTagger">The tagger used to generate error squiggles.</param>
        /// <param name="ruleset">The specified ruleset.</param>
        public static void ValidateDirectiveSyntax(ITextSnapshot snapshot, DirectiveRuleset ruleset, SimpleTagger<ErrorTag> errorTagger)
        {
            // Remove all current error squiggles
            errorTagger.RemoveTagSpans(errorTagSpan => true);

            // Get the full document text and clear all HTML tags
            string text = snapshot.GetText();
            text = MarkdownParser.DestroyHtmlTags(text);

            // Three cases:
            // 0123456789              01234567 8              01234567  8
            // [  WA ab ]              [  WA ab \n             [  WA ab EOT
            // |        |-endIndex=9   |        |-endIndex=8   |         |-endIndex=8
            // |-startIndex=0          |-startIndex=0          |-startIndex=0

            // Greedily search for the pair of '[...]' (supports nested pair '[... [...] ...]')
            // Here 'Greedily' means if we have a string '[...[...]', it would also treat the latter '[...]' as the pair
            for (int startIndex = text.IndexOf('['); startIndex >= 0; startIndex = text.IndexOf('[', startIndex))
            {
                int endIndex = MarkdownParser.FindCorrespondingEndBracket(text, startIndex + 1);

                // Get the directive content string
                ITrackingSpan overallDirective = snapshot.CreateTrackingSpan(startIndex + 1, endIndex - startIndex - 1, SpanTrackingMode.EdgeInclusive);
                string directive = overallDirective.GetText(snapshot);
                var directiveMatches = Regex.Matches(directive, string.Concat(@"^\s*(", ValidationUtilities.DirectiveNameRegularPattern, @")(.*)$"));
                if (directiveMatches.Count != 1 || !directiveMatches[0].Success || directiveMatches[0].Groups.Count != 3 || directiveMatches[0].Value != directive)
                {
                    startIndex++;
                    continue;
                }
                string directiveName = directiveMatches[0].Groups[1].Value;
                string directiveContent = directiveMatches[0].Groups[2].Value;

                var rule = ruleset.TryGetDirectiveRule(directiveName);
                if (rule != null)
                {
                    // Get the preceding and following directive string of the same line
                    ITextSnapshotLine line = snapshot.GetLineFromPosition(startIndex);
                    string precedingText = snapshot.GetText(line.Start, startIndex - line.Start);
                    string followingText = endIndex < line.End ? snapshot.GetText(endIndex + 1, line.End - endIndex - 1) : string.Empty;

                    // If we found a exactly-matched rule, just validate it
                    string message = rule.Validate(directiveContent, precedingText, followingText);
                    if (message != null)
                    {
                        ITrackingSpan squiggleSpan = overallDirective;
                        if (rule.SquiggleWholeLine)
                        {
                            squiggleSpan = snapshot.CreateTrackingSpan(line.Start, line.Length, SpanTrackingMode.EdgeInclusive);
                        }
                        errorTagger.CreateTagSpan(squiggleSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, message));
                    }

                    // If we miss the closing bracket, give out the prompt message
                    if (endIndex >= text.Length || text[endIndex] != ']')
                    {
                        errorTagger.CreateTagSpan(snapshot.CreateTrackingSpan(line.End, 0, SpanTrackingMode.EdgePositive), new ErrorTag(PredefinedErrorTypeNames.CompilerError, "Missing the closing bracket"));
                    }
                }
                else
                {
                    // Otherwise we may take a look at the suspects
                    var suspects = ruleset.GetSuspects(directive);
                    if (suspects.Count() > 0)
                    {
                        StringBuilder suspectPrompt = new StringBuilder();
                        suspectPrompt.AppendLine("Are you trying to enter one of the following directives?");
                        foreach (var suspect in suspects)
                        {
                            suspectPrompt.AppendLine(string.Format("    \u2022 {0} - {1}", suspect.ParentRule.DirectiveName, suspect.SuggestionMessage));
                        }
                        errorTagger.CreateTagSpan(overallDirective, new ErrorTag(PredefinedErrorTypeNames.Warning, suspectPrompt.ToString().TrimEnd()));
                    }
                }

                startIndex = endIndex;
            }
        }
 public SimpleTagger <ErrorTag> GetErrorTagger(Microsoft.VisualStudio.Text.ITextBuffer textBuffer)
 {
     return(_instance = _instance ?? new SimpleTagger <ErrorTag>(textBuffer));
 }
Exemple #29
0
 public void SetBuffer(ITextBuffer buffer) {
   if(buffer == null)
     throw new ArgumentNullException("buffer");
   _Buffer = buffer;
   _Tagger = null;
 }
 public SimpleTagger<ErrorTag> GetErrorTagger(Microsoft.VisualStudio.Text.ITextBuffer textBuffer) {
     return _instance = _instance ?? new SimpleTagger<ErrorTag>(textBuffer);
 }
Exemple #31
0
 public void CreateSquiggleSpan(SimpleTagger <ErrorTag> tagger)
 {
     tagger.CreateTagSpan(_span, new ErrorTag(ErrorType, _message));
 }
        /// <summary>
        /// Clear all markers and tracking classes
        /// </summary>
        public void Clear()
        {
            if (m_marker != null)
            {
                RemoveHighlightMarker();
            }

            if (IsTracking())
            {
                RemoveTracking();
            }

            m_tagger = null;
        }