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


C# ITextSnapshot.GetLineFromPosition方法代码示例

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


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

示例1: IsFirstTokenOnLine

        public static bool IsFirstTokenOnLine(this SyntaxToken token, ITextSnapshot snapshot)
        {
            Contract.ThrowIfNull(snapshot);

            var baseLine = snapshot.GetLineFromPosition(token.SpanStart);
            return baseLine.GetFirstNonWhitespacePosition() == token.SpanStart;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:WhitespaceExtensions.cs

示例2: NodeSnapshot

        public NodeSnapshot(ITextSnapshot snapshot, INode node)
        {
            int offset = 0;
            if (node.Values.GetEnumerator().MoveNext())
            {
                ITextSnapshotLine line = snapshot.GetLineFromPosition(node.Position);

                // if the Value list is not empty, expand the snapshotSpan
                // to include leading whitespaces, so that when a user
                // types smth in this space he will get the dropdown
                for (; node.Position - offset > line.Extent.Start.Position; offset++)
                {
                    if (snapshot[node.Position - offset] == ' ')
                        continue;
                    if (snapshot[node.Position - offset] == '\t')
                        continue;
                    if (
                        snapshot[node.Position - offset] == '%' ||
                        snapshot[node.Position - offset] == '{' ||
                        snapshot[node.Position - offset] == '|'
                        )
                        offset++;
                    break;
                }
            }

            this.snapshotSpan = new SnapshotSpan(snapshot, node.Position - offset, node.Length + offset);
            this.node = node;
            foreach (IEnumerable<INode> list in node.Nodes.Values)
                foreach (INode child in list)
                    children.Add(new NodeSnapshot(snapshot, child));
        }
开发者ID:IntranetFactory,项目名称:ndjango,代码行数:32,代码来源:NodeSnapshot.cs

示例3: LinePreservingCodeReplacer

 private LinePreservingCodeReplacer(ITextView view, string newCode, Span range) {
     _view = view;
     _snapshot = view.TextBuffer.CurrentSnapshot;
     _oldCode = _snapshot.GetText(range);
     _newCode = newCode;
     _newLines = newCode.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
     _startingReplacementLine = _snapshot.GetLineFromPosition(range.Start).LineNumber;
 }
开发者ID:omnimark,项目名称:PTVS,代码行数:8,代码来源:LinePreservingCodeReplacer.cs

示例4: IsInNamespace

 public static bool IsInNamespace(ITextSnapshot snapshot, int position) {
     if (position > 0) {
         ITextSnapshotLine line = snapshot.GetLineFromPosition(position);
         if (line.Length > 2 && position - line.Start > 2) {
             return snapshot[position - 1] == ':';
         }
     }
     return false;
 }
开发者ID:Microsoft,项目名称:RTVS,代码行数:9,代码来源:RCompletionContext.cs

示例5: ReverseExpressionParser

        public ReverseExpressionParser(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            _snapshot = snapshot;
            _buffer = buffer;
            _span = span;

            var loc = span.GetSpan(snapshot);
            var line = _curLine = snapshot.GetLineFromPosition(loc.Start);

            var targetSpan = new Span(line.Start.Position, span.GetEndPoint(snapshot).Position - line.Start.Position);
            _tokens = Classifier.GetClassificationSpans(new SnapshotSpan(snapshot, targetSpan));
        }
开发者ID:TerabyteX,项目名称:main,代码行数:12,代码来源:ReverseExpressionParser.cs

示例6: GetFormattingSpan

        public static TextSpan GetFormattingSpan(ITextSnapshot snapshot, SnapshotSpan selectedSpan)
        {
            var currentLine = snapshot.GetLineFromPosition(selectedSpan.Start);
            var endPosition = selectedSpan.IsEmpty ? currentLine.End : selectedSpan.End;
            var previousLine = GetNonEmptyPreviousLine(snapshot, currentLine);

            // first line on screen
            if (currentLine == previousLine)
            {
                return TextSpan.FromBounds(currentLine.Start, endPosition);
            }

            var lastNonNoisyCharPosition = previousLine.GetLastNonWhitespacePosition().Value;
            return TextSpan.FromBounds(lastNonNoisyCharPosition, endPosition);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:15,代码来源:CommonFormattingHelpers.cs

示例7: GetRoxygenBlockPosition

 private static Span? GetRoxygenBlockPosition(ITextSnapshot snapshot, int definitionStart) {
     var line = snapshot.GetLineFromPosition(definitionStart);
     for (int i = line.LineNumber - 1; i >= 0; i--) {
         var currentLine = snapshot.GetLineFromLineNumber(i);
         string lineText = currentLine.GetText().TrimStart();
         if (lineText.Length > 0) {
             if (lineText.EqualsOrdinal("##")) {
                 return new Span(currentLine.Start, currentLine.Length);
             } else if (lineText.EqualsOrdinal("#'")) {
                 return null;
             }
             break;
         }
     }
     return new Span(line.Start, 0);
 }
开发者ID:Microsoft,项目名称:RTVS,代码行数:16,代码来源:RoxygenBlock.cs

示例8: AddError

        public void AddError(ITextSnapshot snapshot, Diagnostic diagnostic, TextSpan span)
        {
            var line = snapshot.GetLineFromPosition(span.Start);

            var task = new ErrorTask
            {
                Text = diagnostic.Message,
                Line = line.LineNumber,
                Column = span.Start - line.Start.Position,
                Category = TaskCategory.CodeSense,
                ErrorCategory = TaskErrorCategory.Error,
                Priority = TaskPriority.Normal,
                Document = span.Filename
            };

            task.Navigate += OnTaskNavigate;

            _errorListProvider.Tasks.Add(task);
        }
开发者ID:davidlee80,项目名称:HlslTools,代码行数:19,代码来源:ErrorListHelper.cs

示例9: DesignerNode

        /// <summary>
        /// Creates the designer (proxy) node over the real syntax node passed in as a parameter
        /// Also recursively creates child nodes for all 'real' node children
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="snapshot"></param>
        /// <param name="node"></param>
        public DesignerNode(NodeProvider provider, DesignerNode parent, ITextSnapshot snapshot, INode node)
        {
            this.provider = provider;
            Parent = parent;
            this.node = node;
            if (node.NodeType == NodeType.ParsingContext)
            {
                snapshotSpan = new SnapshotSpan(snapshot, node.Position + node.Length, 0);
                extensionSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
            }
            else
            {
                snapshotSpan = new SnapshotSpan(snapshot, node.Position, node.Length);
                int offset = 0;
                if (node.Values.GetEnumerator().MoveNext())
                {
                    ITextSnapshotLine line = snapshot.GetLineFromPosition(node.Position);

                    // if the Value list is not empty, expand the snapshotSpan
                    // to include leading whitespaces, so that when a user
                    // types smth in this space he will get the dropdown
                    for (; node.Position - offset > line.Extent.Start.Position; offset++)
                    {
                        switch (snapshot[node.Position - offset - 1])
                        {
                            case ' ':
                            case '\t':
                                continue;
                            default:
                                break;
                        }
                        break;
                    }
                }
                extensionSpan = new SnapshotSpan(snapshot, node.Position - offset, offset);
            }
            foreach (IEnumerable<INode> list in node.Nodes.Values)
                foreach (INode child in list)
                    children.Add(new DesignerNode(provider, this, snapshot, child));
        }
开发者ID:IntranetFactory,项目名称:ndjango,代码行数:47,代码来源:DesignerNode.cs

示例10: GetLineTextFromPosition

 public static string GetLineTextFromPosition(int position, ITextSnapshot snapshot)
 {
     return snapshot.GetLineFromPosition(position - 1).GetText();
 }
开发者ID:mazong1123,项目名称:DocStubsJs,代码行数:4,代码来源:StubUtils.cs

示例11: TokenEndsAtEndOfLine

        protected virtual bool TokenEndsAtEndOfLine(ITextSnapshot snapshot, ITokenSource lexer, IToken token)
        {
            Lexer lexerLexer = lexer as Lexer;
            if (lexerLexer != null)
            {
                int c = lexerLexer.CharStream.LA(1);
                return c == '\r' || c == '\n';
            }

            ITextSnapshotLine line = snapshot.GetLineFromPosition(token.StopIndex + 1);
            return line.End <= token.StopIndex + 1 && line.EndIncludingLineBreak >= token.StopIndex + 1;
        }
开发者ID:chandramouleswaran,项目名称:LangSvcV2,代码行数:12,代码来源:AntlrClassifierBase.cs

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

示例13: GetFirstArgumentIndent

 private static int GetFirstArgumentIndent(ITextSnapshot snapshot, IFunction fc) {
     var line = snapshot.GetLineFromPosition(fc.OpenBrace.End);
     return fc.OpenBrace.End - line.Start;
 }
开发者ID:Microsoft,项目名称:RTVS,代码行数:4,代码来源:SmartIndenter.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: GetLineNumber

		static int GetLineNumber(ITextSnapshot snapshot, int position) {
			Debug.Assert((uint)position <= (uint)snapshot.Length);
			if ((uint)position > (uint)snapshot.Length)
				return int.MaxValue;
			return snapshot.GetLineFromPosition(position).LineNumber;
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:6,代码来源:AnalyzerService.cs


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