protected override IEditorBraceCompletionSession CreateEditorSession(Document document, int openingPosition, char openingBrace, CancellationToken cancellationToken)
        {
            var syntaxFactsService = document.GetLanguageService <ISyntaxFactsService>();

            switch (openingBrace)
            {
            case BraceCompletionSessionProvider.CurlyBrace.OpenCharacter:
                return(InterpolationCompletionSession.IsContext(document, openingPosition, cancellationToken)
                        ? new InterpolationCompletionSession()
                        : (IEditorBraceCompletionSession) new CurlyBraceCompletionSession(syntaxFactsService, _smartIndentationService, _undoManager));

            case BraceCompletionSessionProvider.DoubleQuote.OpenCharacter:
                return(InterpolatedStringCompletionSession.IsContext(document, openingPosition, cancellationToken)
                        ? new InterpolatedStringCompletionSession()
                        : (IEditorBraceCompletionSession) new StringLiteralCompletionSession(syntaxFactsService));

            case BraceCompletionSessionProvider.Bracket.OpenCharacter: return(new BracketCompletionSession(syntaxFactsService));

            case BraceCompletionSessionProvider.Parenthesis.OpenCharacter: return(new ParenthesisCompletionSession(syntaxFactsService));

            case BraceCompletionSessionProvider.SingleQuote.OpenCharacter: return(new CharLiteralCompletionSession(syntaxFactsService));

            case BraceCompletionSessionProvider.LessAndGreaterThan.OpenCharacter: return(new LessAndGreaterThanCompletionSession(syntaxFactsService));

            default:
                throw ExceptionUtilities.UnexpectedValue(openingBrace);
            }
        }
예제 #2
0
        protected override bool CheckCodeContext(Document document, int position, char openingBrace, CancellationToken cancellationToken)
        {
            // SPECIAL CASE: Allow in curly braces in string literals to support interpolated strings.
            if (openingBrace == BraceCompletionSessionProvider.CurlyBrace.OpenCharacter &&
                InterpolationCompletionSession.IsContext(document, position, cancellationToken))
            {
                return(true);
            }

            if (openingBrace == BraceCompletionSessionProvider.DoubleQuote.OpenCharacter &&
                InterpolatedStringCompletionSession.IsContext(document, position, cancellationToken))
            {
                return(true);
            }

            // Otherwise, defer to the base implementation.
            return(base.CheckCodeContext(document, position, openingBrace, cancellationToken));
        }