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


C# IBraceCompletionSession类代码示例

本文整理汇总了C#中IBraceCompletionSession的典型用法代码示例。如果您正苦于以下问题:C# IBraceCompletionSession类的具体用法?C# IBraceCompletionSession怎么用?C# IBraceCompletionSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: OnReturn

        public void OnReturn(IBraceCompletionSession session) {
            if (NodejsPackage.Instance.FormattingGeneralOptionsPage.FormatOnEnter) {
                // reshape code from
                // {
                // |}
                // 
                // to
                // {
                //     |
                // }
                // where | indicates caret position.

                var closingPointPosition = session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot);

                Debug.Assert(
                    condition: closingPointPosition > 0,
                    message: "The closing point position should always be greater than zero",
                    detailMessage: "The closing point position should always be greater than zero, " +
                                   "since there is also an opening point for this brace completion session");

                // Insert an extra newline and indent the closing brace manually.           
                session.SubjectBuffer.Insert(
                    closingPointPosition - 1,
                    VsExtensions.GetNewLineText(session.TextView.TextSnapshot));

                // Format before setting the caret.
                Format(session);

                // After editing, set caret to the correct position.
                SetCaretPosition(session);
            }
        }
开发者ID:lioaphy,项目名称:nodejstools,代码行数:32,代码来源:BraceCompletionContext.cs

示例2: OnReturn

 /// <summary>
 /// Called by the editor when return is pressed while both 
 /// braces are on the same line and no typing has occurred 
 /// in the session.
 /// </summary>
 /// <remarks>
 /// Called after the newline has been inserted into the buffer.
 /// Formatting for scenarios where the closing brace needs to be 
 /// moved down an additional line past the caret should be done here.
 /// </remarks>
 /// <param name="session">Default brace completion session</param>
 public void OnReturn(IBraceCompletionSession session) {
     if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
         AutoFormat.IgnoreOnce = true;
         EnsureTreeReady(session.SubjectBuffer);
         FormatOperations.FormatCurrentScope(session.TextView, session.SubjectBuffer, indentCaret: true);
     }
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:18,代码来源:BraceCompletionContext.cs

示例3: TryCreateSession

        public bool TryCreateSession(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionSession session)
        {
            this.AssertIsForeground();

            var textSnapshot = openingPoint.Snapshot;
            var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
            if (document != null)
            {
                var editorSessionFactory = document.GetLanguageService<IEditorBraceCompletionSessionFactory>();
                if (editorSessionFactory != null)
                {
                    // Brace completion is (currently) not cancellable.
                    var cancellationToken = CancellationToken.None;

                    var editorSession = editorSessionFactory.TryCreateSession(document, openingPoint, openingBrace, cancellationToken);
                    if (editorSession != null)
                    {
                        var undoHistory = _undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory;
                        session = new BraceCompletionSession(
                            textView, openingPoint.Snapshot.TextBuffer, openingPoint, openingBrace, closingBrace,
                            undoHistory, _editorOperationsFactoryService,
                            editorSession);
                        return true;
                    }
                }
            }

            session = null;
            return false;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:BraceCompletionSessionProvider.cs

示例4: AfterReturn

        public override void AfterReturn(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            // check whether shape of the braces are what we support
            // shape must be either "{|}" or "{ }". | is where caret is. otherwise, we don't do any special behavior
            if (!ContainsOnlyWhitespace(session))
            {
                return;
            }

            // alright, it is in right shape.
            var undoHistory = GetUndoHistory(session.TextView);
            using (var transaction = undoHistory.CreateTransaction(EditorFeaturesResources.Brace_Completion))
            {
                var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
                if (document != null)
                {
                    document.InsertText(session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot) - 1, Environment.NewLine, cancellationToken);
                    FormatTrackingSpan(session, shouldHonorAutoFormattingOnCloseBraceOption: false, rules: GetFormattingRules(document));

                    // put caret at right indentation
                    PutCaretOnLine(session, session.OpeningPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot).GetContainingLineNumber() + 1);

                    transaction.Complete();
                }
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:26,代码来源:CurlyBraceCompletionSession.cs

示例5: Finish

 /// <summary>
 /// Called after the session has been removed from the stack.
 /// </summary>
 /// <param name="session">Default brace completion session</param>
 public void Finish(IBraceCompletionSession session) {
     //if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
     //    AutoFormat.IgnoreOnce = false;
     //    EnsureTreeReady(session.SubjectBuffer);
     //    FormatOperations.FormatCurrentScope(session.TextView, session.SubjectBuffer, indentCaret: false);
     //}
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:11,代码来源:BraceCompletionContext.cs

示例6: Start

 /// <summary>
 /// Called before the session is added to the stack.
 /// </summary>
 /// <remarks>
 /// If additional formatting is required for the opening or 
 /// closing brace it should be done here.
 /// </remarks>
 /// <param name="session">Default brace completion session</param>
 public void Start(IBraceCompletionSession session) {
     if (session.OpeningBrace == '{' && REditorSettings.AutoFormat) {
         AutoFormat.IgnoreOnce = false;
         EnsureTreeReady(session.SubjectBuffer);
         FormatOperations.FormatCurrentNode<IStatement>(session.TextView, session.SubjectBuffer);
     }
 }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:15,代码来源:BraceCompletionContext.cs

示例7: ContainsOnlyWhitespace

        private static bool ContainsOnlyWhitespace(IBraceCompletionSession session)
        {
            var span = session.GetSessionSpan();

            var snapshot = span.Snapshot;

            var start = span.Start.Position;
            start = snapshot[start] == session.OpeningBrace ? start + 1 : start;

            var end = span.End.Position - 1;
            end = snapshot[end] == session.ClosingBrace ? end - 1 : end;

            if (!start.PositionInSnapshot(snapshot) ||
                !end.PositionInSnapshot(snapshot))
            {
                return false;
            }

            for (int i = start; i <= end; i++)
            {
                if (!char.IsWhiteSpace(snapshot[i]))
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:28,代码来源:CurlyBraceCompletionSession.cs

示例8: SetCaretPosition

        private static void SetCaretPosition(IBraceCompletionSession session) {
            // Find next line from brace.
            var snapshot = session.SubjectBuffer.CurrentSnapshot;
            var openCurlyLine = session.OpeningPoint.GetPoint(snapshot).GetContainingLine();
            var nextLineNumber = openCurlyLine.LineNumber + 1;

            bool nextLineExists = nextLineNumber < snapshot.LineCount;
            Debug.Assert(nextLineExists, "There are no lines after this brace completion's opening brace, no place to seek caret to.");
            if (!nextLineExists) {
                // Don't move the caret as we have somehow ended up without a line following our opening brace.
                return;
            }

            // Get indent for this line.
            ITextSnapshotLine nextLine = snapshot.GetLineFromLineNumber(nextLineNumber);
            var indentation = GetIndentationLevelForLine(session, nextLine);
            if (indentation > 0) {
                // before deleting, make sure this line is only whitespace.
                bool lineIsWhitepace = string.IsNullOrWhiteSpace(nextLine.GetText());
                Debug.Assert(lineIsWhitepace, "The line after the brace should be empty.");
                if (lineIsWhitepace) {
                    session.SubjectBuffer.Delete(nextLine.Extent);
                    MoveCaretTo(session.TextView, nextLine.End, indentation);
                }
            } else {
                MoveCaretTo(session.TextView, nextLine.End);
            }
        }
开发者ID:lioaphy,项目名称:nodejstools,代码行数:28,代码来源:BraceCompletionContext.cs

示例9: CheckOpeningPoint

        public override bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            var snapshot = session.SubjectBuffer.CurrentSnapshot;
            var position = session.OpeningPoint.GetPosition(snapshot);
            var token = snapshot.FindToken(position, cancellationToken);

            // check token at the opening point first
            if (!IsValidToken(token) ||
                token.RawKind != OpeningTokenKind ||
                token.SpanStart != position || token.Parent == null)
            {
                return false;
            }

            // now check whether parser think whether there is already counterpart closing parenthesis
            var pair = token.Parent.GetParentheses();

            // if pair is on the same line, then the closing parenthesis must belong to other tracker.
            // let it through
            if (snapshot.GetLineNumberFromPosition(pair.Item1.SpanStart) == snapshot.GetLineNumberFromPosition(pair.Item2.Span.End))
            {
                return true;
            }

            return (int)pair.Item2.Kind() != ClosingTokenKind || pair.Item2.Span.Length == 0;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:ParenthesisCompletionSession.cs

示例10: CheckOpeningPoint

        public bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            var snapshot = session.SubjectBuffer.CurrentSnapshot;
            var position = session.OpeningPoint.GetPosition(snapshot);
            var token = snapshot.FindToken(position, cancellationToken);

            return token.IsKind(SyntaxKind.InterpolatedStringStartToken, SyntaxKind.InterpolatedVerbatimStringStartToken)
                && token.Span.End - 1 == position;
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:9,代码来源:InterpolatedStringCompletionSession.cs

示例11: Format

 private void Format(IBraceCompletionSession session) {
     var buffer = session.SubjectBuffer;
     EditFilter.ApplyEdits(
         buffer,
         Formatter.GetEditsAfterEnter(
             buffer.CurrentSnapshot.GetText(),
             session.OpeningPoint.GetPosition(buffer.CurrentSnapshot),
             session.ClosingPoint.GetPosition(buffer.CurrentSnapshot),
             EditFilter.CreateFormattingOptions(session.TextView.Options, session.TextView.TextSnapshot)
         )
     );
 }
开发者ID:lioaphy,项目名称:nodejstools,代码行数:12,代码来源:BraceCompletionContext.cs

示例12: CheckBackspace

        internal void CheckBackspace(IBraceCompletionSession session)
        {
            session.TextView.TryMoveCaretToAndEnsureVisible(session.OpeningPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot).Add(1));
            session.PreBackspace(out var handled);
            if (!handled)
            {
                session.PostBackspace();
            }

            Assert.Null(session.OpeningPoint);
            Assert.Null(session.ClosingPoint);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:AbstractAutomaticBraceCompletionTests.cs

示例13: CheckCurrentPosition

        protected bool CheckCurrentPosition(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
            if (document != null)
            {
                // make sure auto closing is called from a valid position
                var tree = document.GetSyntaxRootSynchronously(cancellationToken).SyntaxTree;

                return !_syntaxFactsService.IsInNonUserCode(tree, session.GetCaretPosition().Value, cancellationToken);
            }

            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs

示例14: CheckOpeningPoint

        public virtual bool CheckOpeningPoint(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            var snapshot = session.SubjectBuffer.CurrentSnapshot;
            var position = session.OpeningPoint.GetPosition(snapshot);
            var token = snapshot.FindToken(position, cancellationToken);

            if (!IsValidToken(token))
            {
                return false;
            }

            return token.RawKind == OpeningTokenKind && token.SpanStart == position;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs

示例15: CheckClosingTokenKind

        protected bool CheckClosingTokenKind(IBraceCompletionSession session, CancellationToken cancellationToken)
        {
            var document = session.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
            if (document != null)
            {
                var root = document.GetSyntaxRootSynchronously(cancellationToken);
                var position = session.ClosingPoint.GetPosition(session.SubjectBuffer.CurrentSnapshot);

                return root.FindTokenFromEnd(position, includeZeroWidth: false, findInsideTrivia: true).RawKind == this.ClosingTokenKind;
            }

            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:AbstractTokenBraceCompletionSession.cs


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