当前位置: 首页>>代码示例>>C#>>正文


C# ITextSnapshot.CreateTrackingSpan方法代码示例

本文整理汇总了C#中ITextSnapshot.CreateTrackingSpan方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshot.CreateTrackingSpan方法的具体用法?C# ITextSnapshot.CreateTrackingSpan怎么用?C# ITextSnapshot.CreateTrackingSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextSnapshot的用法示例。


在下文中一共展示了ITextSnapshot.CreateTrackingSpan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConstructAsync

        /// <summary>
        /// Asynchronously constructs a line map from a <paramref name="snapshot"/> and <paramref name="code"/>.
        /// </summary>
        /// <param name="snapshot">The current text snapshot.</param>
        /// <param name="code">The code to derive a line map from.</param>
        /// <param name="cancelToken">Cancellation token.</param>
        /// <returns>
        /// A <see cref="LineMap"/> if <paramref name="code"/> was parsed correctly,
        /// <c>null</c> if there was invalid code or it was canceled.
        /// </returns>
        internal static Task<LineMap> ConstructAsync(ITextSnapshot snapshot, string code, CancellationToken cancelToken)
        {
            if (snapshot == null)
                throw new ArgumentNullException ("snapshot");
            if (code == null)
                throw new ArgumentNullException ("code");

            return Task<LineMap>.Factory.StartNew (() =>
            {
                try
                {
                    var tree = SyntaxTree.Parse (code, cancellationToken: cancelToken);
                    if (tree.Errors.Any (p => p.ErrorType == ErrorType.Error))
                        return null;

                    var identifier = new IdentifyingVisitor();
                    tree.AcceptVisitor (identifier);

                    var spans = new Dictionary<int, ITrackingSpan> (identifier.LineMap.Count);
                    foreach (var kvp in identifier.LineMap)
                    {
                        ITextSnapshotLine line = snapshot.GetLineFromLineNumber (kvp.Value - 1);
                        ITrackingSpan span = snapshot.CreateTrackingSpan (line.Extent, SpanTrackingMode.EdgeExclusive);
                        spans.Add (kvp.Key, span);
                    }

                    return (cancelToken.IsCancellationRequested) ? null : new LineMap (spans);
                }
                catch (OperationCanceledException)
                {
                    return null;
                }
            }, cancelToken);
        }
开发者ID:ermau,项目名称:Instant,代码行数:44,代码来源:LineMap.cs

示例2: InitializeTrackingSpans

        internal void InitializeTrackingSpans(ITextSnapshot textSnapshot)
        {
            this.TrackingSpans = this.Spans.Select(s => textSnapshot.CreateTrackingSpan(s.ToSpan(), SpanTrackingMode.EdgeExclusive)).ToList();

            if (this.ChildItems != null)
            {
                this.ChildItems.Do(i => i.InitializeTrackingSpans(textSnapshot));
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:9,代码来源:NavigationBarItem.cs

示例3: ComputeReplacementSpan

        private Span ComputeReplacementSpan(ITextBuffer subjectBuffer, ITextSnapshot snapshot)
        {
            var trackingSpan = snapshot.CreateTrackingSpan(FilterSpan.ToSpan(), SpanTrackingMode.EdgeInclusive);
            var currentSpan = trackingSpan.GetSpan(subjectBuffer.CurrentSnapshot);

            return Span.FromBounds(subjectBuffer.CurrentSnapshot[currentSpan.Start - 1] == '<' && _beforeCaretText[0] == '<'
                            ? currentSpan.Start - 1
                            : currentSpan.Start,
                            currentSpan.End);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:10,代码来源:XmlDocCommentCompletionItem.cs

示例4: GetApplicableToSpan

        private ITrackingSpan GetApplicableToSpan(ITextSnapshot snapshot, SnapshotPoint triggerPoint)
        {
            var line = triggerPoint.GetContainingLine();

            SnapshotPoint start = triggerPoint;
            while (start > line.Start && !char.IsWhiteSpace((start - 1).GetChar()))
            {
                start -= 1;
            }

            return snapshot.CreateTrackingSpan(new SnapshotSpan(start, line.End), SpanTrackingMode.EdgeInclusive);
        }
开发者ID:heinrichbreedt,项目名称:SpecFlow,代码行数:12,代码来源:CompletionSource.cs

示例5: RoslynOutliningRegionTag

        public RoslynOutliningRegionTag(
            ITextEditorFactoryService textEditorFactoryService,
            IProjectionBufferFactoryService projectionBufferFactoryService,
            IEditorOptionsFactoryService editorOptionsFactoryService,
            ITextSnapshot snapshot,
            BlockSpan outliningSpan)
        {
            _textEditorFactoryService = textEditorFactoryService;
            _projectionBufferFactoryService = projectionBufferFactoryService;
            _editorOptionsFactoryService = editorOptionsFactoryService;
            _subjectBuffer = snapshot.TextBuffer;
            BlockSpan = outliningSpan;

            _hintSpan = snapshot.CreateTrackingSpan(BlockSpan.HintSpan.ToSpan(), SpanTrackingMode.EdgeExclusive);
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:15,代码来源:RoslynOutliningRegionTag.cs

示例6: GetApplicableToForStep

        private ITrackingSpan GetApplicableToForStep(ITextSnapshot snapshot, SnapshotPoint triggerPoint)
        {
            var line = triggerPoint.GetContainingLine();

            SnapshotPoint start = line.Start;
            ForwardWhile(ref start, triggerPoint, p => char.IsWhiteSpace(p.GetChar()));
            ForwardWhile(ref start, triggerPoint, p => !char.IsWhiteSpace(p.GetChar()));
            if (start < triggerPoint)
                ForwardWhile(ref start, start + 1, p => char.IsWhiteSpace(p.GetChar()));

            return snapshot.CreateTrackingSpan(new SnapshotSpan(start, line.End), SpanTrackingMode.EdgeInclusive);
        }
开发者ID:roffster,项目名称:SpecFlow,代码行数:12,代码来源:GherkinStepCompletionSource.cs

示例7: CreateTrackingSpan

 private static ITrackingSpan CreateTrackingSpan(ITextSnapshot snapshot, Span span)
 {
     return snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:4,代码来源:ActiveStatementTrackingService.cs

示例8: GetApplicableSpan

        /// <summary>
        /// Returns the applicable span at the provided position.
        /// </summary>
        /// <returns>A tracking span, or null if there is no token at the
        /// provided position.</returns>
        internal static ITrackingSpan GetApplicableSpan(ITextSnapshot snapshot, int position) {
            var classifier = snapshot.TextBuffer.GetNodejsClassifier();
            var line = snapshot.GetLineFromPosition(position);
            if (classifier == null || line == null) {
                return null;
            }

            var spanLength = position - line.Start.Position;
            // Increase position by one to include 'fob' in: "abc.|fob"
            if (spanLength < line.Length) {
                spanLength += 1;
            }

            var classifications = classifier.GetClassificationSpans(new SnapshotSpan(line.Start, spanLength));
            // Handle "|"
            if (classifications == null || classifications.Count == 0) {
                return null;
            }

            var lastToken = classifications[classifications.Count - 1];
            // Handle "fob |"
            if (lastToken == null || position > lastToken.Span.End) {
                return null;
            }

            if (position > lastToken.Span.Start) {
                if (lastToken.CanComplete()) {
                    // Handle "fo|o"
                    return snapshot.CreateTrackingSpan(lastToken.Span, SpanTrackingMode.EdgeInclusive);
                } else {
                    // Handle "<|="
                    return null;
                }
            }

            var secondLastToken = classifications.Count >= 2 ? classifications[classifications.Count - 2] : null;
            if (lastToken.Span.Start == position && lastToken.CanComplete() &&
                (secondLastToken == null ||             // Handle "|fob"
                 position > secondLastToken.Span.End || // Handle "if |fob"
                 !secondLastToken.CanComplete())) {     // Handle "abc.|fob"
                return snapshot.CreateTrackingSpan(lastToken.Span, SpanTrackingMode.EdgeInclusive);
            }

            // Handle "abc|."
            // ("ab|c." would have been treated as "ab|c")
            if (secondLastToken != null && secondLastToken.Span.End == position && secondLastToken.CanComplete()) {
                return snapshot.CreateTrackingSpan(secondLastToken.Span, SpanTrackingMode.EdgeInclusive);
            }

            return null;
        }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:56,代码来源:CompletionSource.cs

示例9: GetReplacementSpanFromCompletions

 private static ITrackingSpan GetReplacementSpanFromCompletions(ITextSnapshot snapshot, Protocol.Response.AutocompleteResponse.Completion c)
 {
     int start = c.replaceStart;
     int length = c.replaceEnd - start;
     return snapshot.CreateTrackingSpan(start, length, SpanTrackingMode.EdgeInclusive);
 }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:6,代码来源:JavaCompletion.cs

示例10: ReportParseErrors

    public void ReportParseErrors(IParseResult parseResult, ITextSnapshot snapshot)
    {
      _errorListProvider.SuspendRefresh();
      try
      {
        // remove any previously created errors to get a clean start
        ClearErrors();

        var messages = (CompilerMessageList)parseResult.CompilerMessages;

        foreach (var error in messages.GetMessages())
        {
          // creates the instance that will be added to the Error List
          var nSpan = error.Location.Span;
          var span = new Span(nSpan.StartPos, nSpan.Length);
          if (span.Start >= snapshot.Length)
            continue;
          ErrorTask task = new ErrorTask();
          task.Category = TaskCategory.All;
          task.Priority = TaskPriority.Normal;
          task.Document = _textBuffer.Properties.GetProperty<ITextDocument>(typeof(ITextDocument)).FilePath;
          task.ErrorCategory = TranslateErrorCategory(error);
          task.Text = error.Text;
          task.Line = snapshot.GetLineNumberFromPosition(span.Start);
          task.Column = span.Start - snapshot.GetLineFromLineNumber(task.Line).Start;
          task.Navigate += OnTaskNavigate;
          _errorListProvider.Tasks.Add(task);
          _previousErrors.Add(task);

          var trackingSpan = snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeNegative);
          _squiggleTagger.CreateTagSpan(trackingSpan, new ErrorTag("syntax error", error.Text));
          _previousSquiggles.Add(new TrackingTagSpan<IErrorTag>(trackingSpan, new ErrorTag("syntax error", error.Text)));
        }
      }
      finally { _errorListProvider.ResumeRefresh(); }
    }
开发者ID:derigel23,项目名称:Nitra,代码行数:36,代码来源:ErrorListPresenter.cs

示例11: AddTokensFromText

 private void AddTokensFromText(ITextSnapshot snapshot, IList<LanguageToken> tokens, int startIndex,
                                string spanText)
 {
     Match match = _resourcesRegex.Match(spanText);
     while (match.Success)
     {
         Group keyGroup = match.Groups["key"];
         string key = keyGroup.Value;
         List<TranslationKeyInfo> translations = _translationKeys.GetTranslationsForKey(key).ToList();
         if (translations.Any())
         {
             var languageToken = new LanguageToken();
             languageToken.TranslationKeys = translations;
             languageToken.Span = snapshot.CreateTrackingSpan(startIndex + keyGroup.Index, keyGroup.Length,
                                                              SpanTrackingMode.EdgeExclusive);
             languageToken.TarnslationsString = translations
                 .Aggregate("\n", (curr, tr) => string.Format("{0}{1}: {2}\n", curr, tr.Language, tr.Value));
             tokens.Add(languageToken);
         }
         match = match.NextMatch();
     }
 }
开发者ID:pettersorby,项目名称:EPiServer-Language-VSX,代码行数:22,代码来源:CodeParser.cs

示例12: GetApplicableToForStep

        private ITrackingSpan GetApplicableToForStep(ITextSnapshot snapshot, SnapshotPoint triggerPoint, string parsedKeyword)
        {
            var line = triggerPoint.GetContainingLine();

            SnapshotPoint keywordEnd = line.Start;
            ForwardWhile(ref keywordEnd, triggerPoint, p => char.IsWhiteSpace(p.GetChar()));
            if (parsedKeyword != null)
                keywordEnd += parsedKeyword.Length;
            else
                ForwardWhile(ref keywordEnd, triggerPoint, p => !char.IsWhiteSpace(p.GetChar()));

            var start = keywordEnd;
            if (start < triggerPoint)
                ForwardWhile(ref start, start + 1, p => char.IsWhiteSpace(p.GetChar()));

            return snapshot.CreateTrackingSpan(new SnapshotSpan(start, line.End), SpanTrackingMode.EdgeInclusive);
        }
开发者ID:rdhatt,项目名称:SpecFlow,代码行数:17,代码来源:GherkinStepCompletionSource.cs

示例13: ValidateDirectiveSyntax

        ///////////////////////////////////////////////////////////////////////////////////
        //
        // 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;
            }
        }
开发者ID:JunyiYi,项目名称:MarkdownMode,代码行数:92,代码来源:MarkdownParser.cs

示例14: GetTrackingSpan

 private void GetTrackingSpan(ITextSnapshot snapshot, int triggerPoint)
 {
     ITextSnapshotLine line = snapshot.GetLineFromPosition(triggerPoint);
     string lineString = line.GetText();
     var stopChars = new char[] {' ', '\t', '{', '}', '.', '"', ':'};
     int start = lineString.Substring(0, triggerPoint - line.Start.Position).LastIndexOfAny(stopChars) + line.Start.Position + 1;
     int length = lineString.Substring(triggerPoint - line.Start.Position).IndexOfAny(stopChars) + triggerPoint - start;
     _trackingSpan = snapshot.CreateTrackingSpan(start, length < 0 ? 0 : length, SpanTrackingMode.EdgeInclusive);
 }
开发者ID:ketiko,项目名称:SparkSense,代码行数:9,代码来源:CompletionSessionManager.cs

示例15: CreateTracking

        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);
            }
        }
开发者ID:Microsoft,项目名称:sarif-sdk,代码行数:23,代码来源:ResultTextMarker.cs


注:本文中的ITextSnapshot.CreateTrackingSpan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。