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


C# SnapshotPoint.GetContainingLine方法代码示例

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


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

示例1: CommentRegion

        private static void CommentRegion(ITextView view, SnapshotPoint start, SnapshotPoint end)
        {
            using (var edit = view.TextBuffer.CreateEdit()) {
                int minColumn = Int32.MaxValue;
                // first pass, determine the position to place the comment
                for (int i = start.GetContainingLine().LineNumber; i <= end.GetContainingLine().LineNumber; i++) {
                    var curLine = view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(i);
                    var text = curLine.GetText();

                    minColumn = Math.Min(GetMinimumColumn(text), minColumn);
                }

                // second pass, place the comment
                for (int i = start.GetContainingLine().LineNumber; i <= end.GetContainingLine().LineNumber; i++) {
                    var curLine = view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(i);
                    if (curLine.Length < minColumn) {
                        // need extra white space
                        edit.Insert(curLine.Start.Position + curLine.Length, new String(' ', minColumn - curLine.Length) + "#");
                    } else {
                        edit.Insert(curLine.Start.Position + minColumn, "#");
                    }
                }

                edit.Apply();
            }

            // select the full region we just commented
            UpdateSelection(view, start, end);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:29,代码来源:EditorExtensions.cs

示例2: GetIndentationPrependText

		private static string GetIndentationPrependText(SnapshotPoint startPoint)
		{
			if (startPoint.Position <= startPoint.GetContainingLine().Start.Position)
			{
				return string.Empty;
			}
			int num = startPoint.Position - startPoint.GetContainingLine().Start.Position;
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < num; i++)
			{
				stringBuilder.Append(' ');
			}
			return stringBuilder.ToString();
		}
开发者ID:vairam-svs,项目名称:poshtools,代码行数:14,代码来源:ISESnippetSessionManager.cs

示例3: GetWordSpan

		static SnapshotSpan GetWordSpan(SnapshotPoint currentPosition, WordKind kind) {
			Debug.Assert(GetWordKind(currentPosition) == kind);
			var line = currentPosition.GetContainingLine();
			int column = currentPosition.Position - line.Start.Position;
			var start = GetStartSpanBefore(line, column, kind);
			var end = GetEndSpanAfter(line, column, kind);
			return new SnapshotSpan(start, end);
		}
开发者ID:0xd4d,项目名称:dnSpy,代码行数:8,代码来源:WordParser.cs

示例4: GetExtentOfWord

        private static SnapshotSpan? GetExtentOfWord(SnapshotPoint point)
        {
            var line = point.GetContainingLine();

            if (line == null) return null;

            var text = line.GetText();
            var index = point - line.Start;

            var start = index;
            var length = 0;

            if (index > 0 && index < line.Length)
            {
                for (var i = index; i >= 0; i--)
                {
                    var current = text[i];
                    if (current == '$')
                    {
                        start = i;
                        length++;
                        break;
                    }

                    if (current != '_' && char.IsLetterOrDigit(current) == false) break;

                    start = i;
                    length++;
                }
            }

            if (length > 0)
            {
                index++;

                if (index < line.Length)
                {
                    for (var i = index; i < line.Length; i++)
                    {
                        var current = text[i];
                        if (current != '_' && char.IsLetterOrDigit(current) == false) break;

                        length++;
                    }
                }

                var span = new SnapshotSpan(point.Snapshot, start + line.Start, length);

                //Log.Debug("[" + span.GetText() + "]");

                return span;
            }

            return null;
        }
开发者ID:ChinaJason,项目名称:Typewriter,代码行数:55,代码来源:QuickInfoController.cs

示例5: 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

示例6: GetLineBreak

		public static string GetLineBreak(this IEditorOptions editorOptions, SnapshotPoint pos) {
			if (editorOptions.GetReplicateNewLineCharacter()) {
				var line = pos.GetContainingLine();
				if (line.LineBreakLength != 0)
					return pos.Snapshot.GetText(line.Extent.End.Position, line.LineBreakLength);
				if (line.LineNumber != 0) {
					line = pos.Snapshot.GetLineFromLineNumber(line.LineNumber - 1);
					return pos.Snapshot.GetText(line.Extent.End.Position, line.LineBreakLength);
				}
			}
			var linebreak = editorOptions.GetNewLineCharacter();
			return linebreak.Length != 0 ? linebreak : Environment.NewLine;
		}
开发者ID:0xd4d,项目名称:dnSpy,代码行数:13,代码来源:EditorOptionsExtensions.cs

示例7: GetIndentation

        public static int GetIndentation(this IndentationResult result, ITextView textView, ITextSnapshotLine lineToBeIndented)
        {
            var position = new SnapshotPoint(lineToBeIndented.Snapshot, result.BasePosition);
            var pointInSurfaceSnapshot = textView.BufferGraph.MapUpToSnapshot(position, PointTrackingMode.Positive, PositionAffinity.Successor, textView.TextSnapshot);
            if (!pointInSurfaceSnapshot.HasValue)
            {
                return position.GetContainingLine().GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(textView.Options);
            }

            var lineInSurfaceSnapshot = pointInSurfaceSnapshot.Value.Snapshot.GetLineFromPosition(pointInSurfaceSnapshot.Value.Position);
            var offsetInLine = pointInSurfaceSnapshot.Value.Position - lineInSurfaceSnapshot.Start.Position;
            return lineInSurfaceSnapshot.GetColumnFromLineOffset(offsetInLine, textView.Options) + result.Offset;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:SmartIndentExtensions.cs

示例8: GetCodeElement

        private CodeElement GetCodeElement(DTE dte, SnapshotPoint  point, CodeElements codeElements, vsCMElement elementType)
        {
            foreach (CodeElement ce in codeElements)
            {
                if (ce.Kind.ToString() == "vsCMElementImportStmt")
                {
                    continue;
                }
                try
                {
                    _log.Debug("Searching " + ce.Name);
                    Debug.WriteLine(string.Format("Searching {0}:{1}", ce.Kind.ToString(), ce.Name));
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Exception getting object name: " + e.Message );
                }

                var sp = getStartPoint(ce);
                var pointLine = point.GetContainingLine().LineNumber;

                if (sp != null)
                {
                    if (sp.Line > pointLine )
                    {
                        // code element starts after the droplocation, ignore it
                    }
                    else if (ce.EndPoint.Line  < pointLine )
                    {
                        // code element finishes before the droplocation, ignore it
                    }
                    else
                    {

                        if (elementType == ce.Kind)
                        {

                            return ce;
                        }

                        var childElements = getCodeElements(ce);
                        if (childElements != null)
                        {
                            var ret = GetCodeElement(dte, point, childElements, elementType);
                            if (ret != null) return ret;
                        }
                    }
                }
            }
            return null;
        }
开发者ID:stickleprojects,项目名称:VSDropAssist,代码行数:51,代码来源:CodeElementHelper.cs

示例9: ShouldCompletionBeDiplayed

        /// <summary>
        /// Displays completion after typing a space after a step keyword
        /// </summary>
        protected override bool ShouldCompletionBeDiplayed(SnapshotPoint caret)
        {
            var lineStart = caret.GetContainingLine().Start.Position;
            var lineBeforeCaret = caret.Snapshot.GetText(lineStart, caret.Position - lineStart);

            if (lineBeforeCaret.Length > 0 &&
                char.IsWhiteSpace(lineBeforeCaret[lineBeforeCaret.Length - 1]))
            {
                string keyword = lineBeforeCaret.Substring(0, lineBeforeCaret.Length - 1).TrimStart();
                var languageService = GherkinProcessorServices.GetLanguageService(caret.Snapshot.TextBuffer);
                return languageService.IsStepKeyword(keyword);
            }

            return false;
        }
开发者ID:heinrichbreedt,项目名称:SpecFlow,代码行数:18,代码来源:GherkinCompletionCommandFilter.cs

示例10: ShouldCompletionBeDiplayed

        /// <summary>
        /// Displays completion after typing a space after a step keyword
        /// </summary>
        protected override bool ShouldCompletionBeDiplayed(SnapshotPoint caret)
        {
            var lineStart = caret.GetContainingLine().Start.Position;
            var lineBeforeCaret = caret.Snapshot.GetText(lineStart, caret.Position - lineStart);

            if (lineBeforeCaret.Length > 0 &&
                char.IsWhiteSpace(lineBeforeCaret[lineBeforeCaret.Length - 1]))
            {
                string keyword = lineBeforeCaret.Substring(0, lineBeforeCaret.Length - 1).TrimStart();

                var fileScope = languageService.GetFileScope(waitForParsingSnapshot: caret.Snapshot);
                if (fileScope != null && fileScope.GherkinDialect != null)
                    return fileScope.GherkinDialect.IsStepKeyword(keyword);
            }

            return false;
        }
开发者ID:eddpeterson,项目名称:SpecFlow,代码行数:20,代码来源:GherkinCompletionCommandFilter.cs

示例11: IsReplCommandLocation

        private bool IsReplCommandLocation(SnapshotPoint characterPoint)
        {
            // TODO(cyrusn): We don't need to do this textually.  We could just defer this to
            // IsTriggerCharacter and just check the syntax tree.
            var line = characterPoint.GetContainingLine();
            var text = characterPoint.Snapshot.GetText(line.Start.Position, characterPoint.Position - line.Start.Position);

            // TODO (tomat): REPL commands should have their own handlers:
            if (characterPoint.Snapshot.ContentType.IsOfType(ContentTypeNames.CSharpContentType))
            {
                if (s_referenceRegex.IsMatch(text))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:18,代码来源:ReplCommandCompletionProvider.cs

示例12: EnumeratePrecedingLineTokens

        // Inspired by NodejsTools
        /// <summary>
        /// Enumerates the classifications in the first code line preceding a point.
        /// Skips blank lines or comment-only lines.
        /// </summary>
        private static IEnumerable<ClassificationSpan> EnumeratePrecedingLineTokens(SnapshotPoint start)
        {
            var tagger = start.Snapshot.TextBuffer.Properties.GetProperty<ITagger<ClassificationTag>>(jsTaggerType);

            var curLine = start.GetContainingLine();
            if (curLine.LineNumber == 0)
                yield break;

            bool foundCode = false;
            do
            {
                curLine = start.Snapshot.GetLineFromLineNumber(curLine.LineNumber - 1);
                var classifications = tagger.GetTags(new NormalizedSnapshotSpanCollection(curLine.Extent));
                foreach (var tag in classifications.Where(c => !c.Tag.ClassificationType.IsOfType("comment")))
                {
                    foundCode = true;
                    yield return new ClassificationSpan(tag.Span, tag.Tag.ClassificationType);
                }
            }
            while (!foundCode && curLine.LineNumber > 0);
        }
开发者ID:NickCraver,项目名称:WebEssentials2013,代码行数:26,代码来源:UseDirectiveCompletionSource.cs

示例13: GetVariableNameAndSpan

        private static string GetVariableNameAndSpan(SnapshotPoint point, out SnapshotSpan span)
        {
            var line = point.GetContainingLine();
            var hoveredIndex = point.Position - line.Start.Position;

            var c = point.GetChar();
            if (!Char.IsDigit(c) && !Char.IsLetter(c) && (c != '_'))
            {
                span = new SnapshotSpan();
                return null;
            }

            // Find the name of the variable under the mouse pointer (ex: 'gesture.Pose.Name' when the mouse is hovering over the 'o' of pose)
            var match = m_variableExtractor.Matches(line.GetText()).OfType<Match>().SingleOrDefault(x => x.Index <= hoveredIndex && (x.Index + x.Length) >= hoveredIndex);
            if ((match == null) || (match.Value.Length == 0))
            {
                span = new SnapshotSpan();
                return null;
            }
            var name = match.Value;

            // Find the first '.' after the hoveredIndex and cut it off
            int relativeIndex = hoveredIndex - match.Index;
            var lastIndex = name.IndexOf('.', relativeIndex);
            if (lastIndex >= 0)
            {
                name = name.Substring(0, lastIndex);
            }
            else
            {
                lastIndex = name.Length;
            }

            var matchStartIndex = name.LastIndexOf('.', relativeIndex) + 1;
            span = new SnapshotSpan(line.Start.Add(match.Index + matchStartIndex), lastIndex - matchStartIndex);

            return name;
        }
开发者ID:wtf42,项目名称:VSGraphVis,代码行数:38,代码来源:DebuggerHandler.cs

示例14: HandlePreprocessor

        private void HandlePreprocessor(IQuickInfoSession session, SnapshotPoint point, Selector item, IList<object> qiContent)
        {
            if (item == null || !session.TextView.Properties.ContainsProperty("CssSourceMap"))
                return;

            CssSourceMap sourceMap;

            if (!session.TextView.Properties.TryGetProperty<CssSourceMap>("CssSourceMap", out sourceMap))
                return;

            var line = point.GetContainingLine().LineNumber;
            var column = item.Start - point.Snapshot.GetLineFromPosition(item.Start).Start;

            var node = sourceMap.MapNodes.FirstOrDefault(s =>
                           s.SourceFilePath == _buffer.GetFileName() &&
                           s.OriginalLine == line &&
                           s.OriginalColumn == column);

            if (node == null)
                return;

            qiContent.Add(GenerateContent(node.GeneratedSelector));
        }
开发者ID:venux,项目名称:WebEssentials2015,代码行数:23,代码来源:SelectorQuickInfo.cs

示例15: GetFirstWord

        static private string GetFirstWord(SnapshotPoint triggerPoint)
        {
            var line = triggerPoint.GetContainingLine();
            SnapshotPoint start = line.Start;
            ForwardWhile(ref start, triggerPoint, p => char.IsWhiteSpace(p.GetChar()));
            SnapshotPoint end = start;
            ForwardWhile(ref end, triggerPoint, p => !char.IsWhiteSpace(p.GetChar()));
            if (start >= end)
                return null;

            return triggerPoint.Snapshot.GetText(start, end.Position - start);
        }
开发者ID:roffster,项目名称:SpecFlow,代码行数:12,代码来源:GherkinStepCompletionSource.cs


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