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


C# SnapshotSpan.Intersection方法代码示例

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


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

示例1: ClassifyToken

        private ClassificationSpan ClassifyToken(SnapshotSpan span, TokenInfo token, int lineNumber)
        {
            IClassificationType classification = null;

            if (token.Category == TokenCategory.Operator) {
                if (token.Trigger == TokenTriggers.MemberSelect) {
                    classification = _provider.DotClassification;
                }
            } else if (token.Category == TokenCategory.Grouping) {
                if ((token.Trigger & TokenTriggers.MatchBraces) != 0) {
                    classification = _provider.GroupingClassification;
                }
            } else if (token.Category == TokenCategory.Delimiter) {
                if (token.Trigger == TokenTriggers.ParameterNext) {
                    classification = _provider.CommaClassification;
                }
            }

            if (classification == null) {
                CategoryMap.TryGetValue(token.Category, out classification);
            }

            if (classification != null) {
                var tokenSpan = SnapshotSpanToSpan(span.Snapshot, token, lineNumber);
                var intersection = span.Intersection(tokenSpan);

                if (intersection != null && intersection.Value.Length > 0 ||
                    (span.Length == 0 && tokenSpan.Contains(span.Start))) { // handle zero-length spans which Intersect and Overlap won't return true on ever.
                    return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
                }
            }

            return null;
        }
开发者ID:borota,项目名称:JTVS,代码行数:34,代码来源:JClassifier.cs

示例2: GetClassificationSpans

        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            var results = new List<ClassificationSpan>();

            var artifacts = artifactsGetter();

            // In case the span starts in the middle
            // of an HTML code block, we must always
            // start from the previous artifact.
            int thisArtifact = artifacts.GetLastItemBeforeOrAtPosition(span.Start);

            // For each artifact, classify the artifact and
            // the plain text after it.  If the span starts
            // before the first artifact, the 1st iteration
            // will classify the leading text only.
            while (thisArtifact < artifacts.Count)
            {
                // If the span starts before the first artifact, thisArtifact will be negative.
                if (thisArtifact >= 0)
                    results.AddRange(ClassifyArtifacts(span.Snapshot, artifacts, ref thisArtifact));

                int plainStart = thisArtifact < 0 ? 0 : artifacts[thisArtifact].End;
                thisArtifact++;
                int plainEnd = thisArtifact == artifacts.Count ? span.Snapshot.Length : artifacts[thisArtifact].Start;

                // If artifacts become inconsistent, don't choke
                if (plainEnd <= plainStart)
                    continue;

                // Chop off any part before or after the span being classified
                var plainSpan = span.Intersection(Span.FromBounds(plainStart, plainEnd));

                // If there was no intersection, we've passed the target span and can stop.
                if (plainSpan == null) break;

                results.AddRange(ClassifyPlainSpan(plainSpan.Value));
            }

            return results;
        }
开发者ID:dennis7742,项目名称:WebEssentials2015,代码行数:40,代码来源:MarkdownClassifier.cs

示例3: ClassifyToken

        private ClassificationSpan ClassifyToken(SnapshotSpan span, TokenInfo token, int lineNumber)
        {
            IClassificationType classification = null;

            if (token.Category == TokenCategory.Operator) {
                if (token.Trigger == TokenTriggers.MemberSelect) {
                    classification = _provider.DotClassification;
                }
            } else if (token.Category == TokenCategory.Grouping) {
                if (token.Trigger == (TokenTriggers.MatchBraces | TokenTriggers.ParameterStart)) {
                    classification = _provider.OpenGroupingClassification;
                } else if (token.Trigger == (TokenTriggers.MatchBraces | TokenTriggers.ParameterEnd)) {
                    classification = _provider.CloseGroupingClassification;
                }
            } else if (token.Category == TokenCategory.Delimiter) {
                if (token.Trigger == TokenTriggers.ParameterNext) {
                    classification = _provider.CommaClassification;
                }
            }

            if (classification == null) {
                CategoryMap.TryGetValue(token.Category, out classification);
            }

            if (classification != null) {
                var line = span.Snapshot.GetLineFromLineNumber(lineNumber);
                var index = line.Start.Position + token.SourceSpan.Start.Column - 1;
                var tokenSpan = new Span(index, token.SourceSpan.Length);
                var intersection = span.Intersection(tokenSpan);
                if (intersection != null && intersection.Value.Length > 0) {
                    return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
                }
            }

            return null;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:36,代码来源:DlrClassifier.cs

示例4: Intersects

		bool Intersects(SnapshotSpan fullSpan, ITextViewLine line, Rect rect) {
			var span = fullSpan.Intersection(line.ExtentIncludingLineBreak);
			if (span == null || span.Value.Length == 0)
				return false;
			var start = line.GetExtendedCharacterBounds(span.Value.Start);
			var end = line.GetExtendedCharacterBounds(span.Value.End - 1);
			double left = Math.Min(start.Left, end.Left) - wpfTextView.ViewportLeft;
			double top = Math.Min(start.Top, end.Top) - wpfTextView.ViewportTop;
			double right = Math.Max(start.Right, end.Right) - wpfTextView.ViewportLeft;
			double bottom = Math.Max(start.Bottom, end.Bottom) - wpfTextView.ViewportTop;
			bool b = left <= right && top <= bottom;
			Debug.Assert(b);
			if (!b)
				return false;
			var r = new Rect(left, top, right - left, bottom - top);
			return r.IntersectsWith(rect);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:17,代码来源:SearchService.cs

示例5: GetClassificationSpan

        private static ClassificationSpan GetClassificationSpan(SnapshotSpan span, TokenInfo token, int lineNumber, IClassificationType classification) {
            var tokenSpan = SnapshotSpanToSpan(span.Snapshot, token, lineNumber);
            var intersection = span.Intersection(tokenSpan);

            if (intersection != null && intersection.Value.Length > 0 ||
                (span.Length == 0 && tokenSpan.Contains(span.Start))) { // handle zero-length spans which Intersect and Overlap won't return true on ever.
                return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
            }
            return null;
        }
开发者ID:lioaphy,项目名称:nodejstools,代码行数:10,代码来源:NodejsClassifier.cs

示例6: AddClassifications

        /// <summary>
        /// Adds classification spans to the given collection.
        /// Scans a contiguous sub-<paramref name="span"/> of a larger code span which starts at <paramref name="codeStartLine"/>.
        /// </summary>
        private void AddClassifications(JSScanner JSScanner, List<ClassificationSpan> classifications, SnapshotSpan span) {
            Debug.Assert(span.Length > 0);

            var snapshot = span.Snapshot;
            int firstLine = snapshot.GetLineNumberFromPosition(span.Start);
            int lastLine = snapshot.GetLineNumberFromPosition(span.End - 1);

            Contract.Assert(firstLine >= 0);

            _tokenCache.EnsureCapacity(snapshot.LineCount);

            // find the closest line preceding firstLine for which we know categorizer state, stop at the codeStartLine:
            LineTokenization lineTokenization;
            int currentLine = _tokenCache.IndexOfPreviousTokenization(firstLine, 0, out lineTokenization) + 1;
            object state = lineTokenization.State;

            // track the previous 2 tokens to adjust our classifications of keywords
            // when they shouldn't be displayed as keywords...
            TokenInfoWithLine? prevToken = null, prevPrevToken = null;

            // initialize the previous tokens so we can handle things like:
            //      foo.
            //          get()
            // even if we're called on the line for get()
            int prevLine = currentLine - 1;
            while (prevLine >= 0 && prevToken == null) {
                LineTokenization prevLineTokenization = GetPreviousTokenization(JSScanner, snapshot, firstLine, prevLine);
                for (int i = prevLineTokenization.Tokens.Length - 1; i >= 0 && prevToken == null; i--) {
                    var tempToken = prevLineTokenization.Tokens[i];
                    if (IsValidPreviousToken(ref tempToken)) {
                        prevToken = prevPrevToken;
                        prevPrevToken = new TokenInfoWithLine() { TokenInfo = tempToken, Line = prevLine };
                    }
                }
                prevLine--;
            }

            while (currentLine <= lastLine) {
                if (!_tokenCache.TryGetTokenization(currentLine, out lineTokenization)) {
                    lineTokenization = TokenizeLine(JSScanner, snapshot, state, currentLine);
                    _tokenCache[currentLine] = lineTokenization;
                }

                state = lineTokenization.State;

                for (int i = 0; i < lineTokenization.Tokens.Length; i++) {
                    var token = lineTokenization.Tokens[i];

                    if (token.Category == TokenCategory.IncompleteMultiLineStringLiteral || token.Category == TokenCategory.Comment) {
                        IClassificationType type;
                        switch (token.Category) {
                            case TokenCategory.IncompleteMultiLineStringLiteral:
                                type = _provider.StringLiteral;
                                break;
                            case TokenCategory.Comment:
                                type = _provider.Comment;
                                break;
                            default:
                                type = null;
                                break;
                        }

                        Debug.Assert(type != null, "We should have a defined ClassificationType for every token.");

                        // we need to walk backwards to find the start of this multi-line string...
                        TokenInfo startToken = token;
                        int validPrevLine;
                        int length = startToken.SourceSpan.Length;
                        if (i == 0) {
                            length += GetLeadingMultiLineTokens(JSScanner, snapshot, token.Category, firstLine, currentLine, out validPrevLine, ref startToken);
                        } else {
                            validPrevLine = currentLine;
                        }

                        if (i == lineTokenization.Tokens.Length - 1) {
                            length += GetTrailingMultiLineTokens(JSScanner, snapshot, token.Category, currentLine, state);
                        }

                        var tokenSpan = new Span(SnapshotSpanToSpan(snapshot, startToken, validPrevLine).Start, length);
                        var intersection = span.Intersection(tokenSpan);

                        if ((intersection != null && intersection.Value.Length > 0) ||
                            (span.Length == 0 && tokenSpan.Contains(span.Start)) // handle zero-length spans
                        ) {
                            classifications.Add(new ClassificationSpan(new SnapshotSpan(snapshot, tokenSpan), type));
                        }
                    } else {
                        ClassificationSpan classification = null;
                        if (token.Category == TokenCategory.Keyword) {
                            // check and see if we're not really a keyword...
                            if (IsKeywordInIdentifierContext(snapshot, prevToken, prevPrevToken, new TokenInfoWithLine() { TokenInfo = token, Line = currentLine })) {
                                classification = GetClassificationSpan(
                                    span,
                                    token,
                                    currentLine,
                                    CategoryMap[TokenCategory.Identifier]
//.........这里部分代码省略.........
开发者ID:lioaphy,项目名称:nodejstools,代码行数:101,代码来源:NodejsClassifier.cs

示例7: Update

		void Update(SnapshotSpan span, ref HashSet<ITextViewLine> checkedLines) {
			Debug.Assert(span.Snapshot == wpfTextViewHost.TextView.TextSnapshot);
			var intersection = span.Intersection(wpfTextViewHost.TextView.TextViewLines.FormattedSpan);
			if (intersection == null)
				return;
			var point = intersection.Value.Start;
			while (point <= intersection.Value.End) {
				var line = wpfTextViewHost.TextView.TextViewLines.GetTextViewLineContainingBufferPosition(point);
				if (line == null)
					break;
				if (checkedLines == null)
					checkedLines = new HashSet<ITextViewLine>();
				if (!checkedLines.Contains(line)) {
					checkedLines.Add(line);
					Update(line);
				}
				if (line.IsLastDocumentLine())
					break;
				point = line.GetPointAfterLineBreak();
			}
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:21,代码来源:GlyphMargin.cs

示例8: FindAllSingleLineReverse

		IEnumerable<FindResult> FindAllSingleLineReverse(ITextSnapshotLine startLine, ITextSnapshotLine endLine, SnapshotSpan searchRange, string searchPattern, FindOptions options, StringComparison stringComparison, string replacePattern) {
			Debug.Assert((options & FindOptions.SearchReverse) != 0);
			int startLineNumber = startLine.LineNumber;
			var snapshot = searchRange.Snapshot;
			bool onlyWords = (options & FindOptions.WholeWord) != 0;
			var regex = (options & FindOptions.UseRegularExpressions) != 0 ? GetRegex(searchPattern, options) : null;
			for (int lineNumber = endLine.LineNumber; lineNumber >= startLineNumber; lineNumber--) {
				var line = snapshot.GetLineFromLineNumber(lineNumber);
				var range = searchRange.Intersection(line.ExtentIncludingLineBreak);
				if (range == null || range.Value.Length == 0)
					continue;
				var text = range.Value.GetText();
				int index = text.Length;
				if (regex != null) {
					foreach (var res in GetRegexResults(regex, range.Value.Start, text, index, searchPattern, options, replacePattern))
						yield return res;
				}
				else {
					while (index > 0) {
						index = text.LastIndexOf(searchPattern, index - 1, index, stringComparison);
						if (index < 0)
							break;
						if (!onlyWords || UnicodeUtilities.IsWord(line, range.Value.Start.Position - line.Start.Position + index, searchPattern.Length))
							yield return new FindResult(range.Value.Start.Position + index, searchPattern.Length, replacePattern);
						index += searchPattern.Length - 1;
					}
				}
			}
		}
开发者ID:0xd4d,项目名称:dnSpy,代码行数:29,代码来源:TextSearchService.cs


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