public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context) {
     if (IsValidBraceCompletionContext(openingPoint)) {
         context = new BraceCompletionContext();
         return true;
     } else {
         context = null;
         return false;
     }
 }
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context) {
     // if we are in a comment or string literal we cannot begin a completion session.
     if (IsValidBraceCompletionContext(openingPoint)) {
         context = new BraceCompletionContext();
         return true;
     } else {
         context = null;
         return false;
     }
 }
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
 {
     // if we are in a comment or string literal we cannot begin a completion session.
     if (IsValidBraceCompletionContext(openingPoint))
     {
         context = new BraceCompletionContext(SmartIndentationService, TextBufferUndoManagerProvider, ClassificationService, OptionsService);
         return true;
     }
     else
     {
         context = null;
         return false;
     }
 }
예제 #4
0
 /// <summary>
 /// Default session with a language specific context
 /// </summary>
 public BraceCompletionDefaultSession(ITextView textView, ITextBuffer subjectBuffer,
                                      SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextBufferUndoManagerProvider undoManager,
                                      IEditorOperationsFactoryService editorOperationsFactoryService, IBraceCompletionContext context)
 {
     _textView         = textView;
     _subjectBuffer    = subjectBuffer;
     _openingBrace     = openingBrace;
     _closingBrace     = closingBrace;
     _closingPoint     = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _context          = context;
     _undoManager      = undoManager;
     _undoHistory      = undoManager.GetTextBufferUndoManager(_textView.TextBuffer).TextBufferUndoHistory;
     _editorOperations = editorOperationsFactoryService.GetEditorOperations(_textView);
 }
        /// <summary>
        /// Creates an <see cref="IBraceCompletionContext"/> to handle 
        /// language-specific actions such as parsing and formatting.
        /// </summary>
        /// <remarks>
        /// Opening points within strings and comments are usually invalid points to start 
        /// an <see cref="IBraceCompletionSession"/> and will return false.
        /// </remarks>
        /// <param name="textView">View containing the <paramref name="openingPoint"/>.</param>
        /// <param name="openingPoint">Insertion point of the <paramref name="openingBrace"/>.</param>
        /// <param name="openingBrace">Opening brace that has been typed by the user.</param>
        /// <param name="closingBrace">Closing brace character</param>
        /// <param name="context">Brace completion context if created.</param>
        /// <returns>Returns true if the <paramref name="openingPoint"/> 
        /// was a valid point in the buffer to start a <see cref="IBraceCompletionSession"/>.
        /// </returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context) {
            IREditorDocument document = REditorDocument.TryFromTextBuffer(openingPoint.Snapshot.TextBuffer);
            if (document != null) {
                var ast = document.EditorTree.AstRoot;

                // We don't want to complete inside strings
                if (ast.IsPositionInsideString(openingPoint.Position)) {
                    context = null;
                    return false;
                }

                // We don't want to complete inside comments
                if (document.IsPositionInComment(openingPoint.Position)) {
                    context = null;
                    return false;
                }
            }
            context = new BraceCompletionContext(_shell);
            return true;
        }
        /// <summary>
        /// Creates an <see cref="IBraceCompletionContext"/> to handle 
        /// language-specific actions such as parsing and formatting.
        /// </summary>
        /// <remarks>
        /// Opening points within strings and comments are usually invalid points to start 
        /// an <see cref="IBraceCompletionSession"/> and will return false.
        /// </remarks>
        /// <param name="textView">View containing the <paramref name="openingPoint"/>.</param>
        /// <param name="openingPoint">Insertion point of the <paramref name="openingBrace"/>.</param>
        /// <param name="openingBrace">Opening brace that has been typed by the user.</param>
        /// <param name="closingBrace">Closing brace character</param>
        /// <param name="context">Brace completion context if created.</param>
        /// <returns>Returns true if the <paramref name="openingPoint"/> 
        /// was a valid point in the buffer to start a <see cref="IBraceCompletionSession"/>.
        /// </returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context) {
            IREditorDocument document = REditorDocument.TryFromTextBuffer(openingPoint.Snapshot.TextBuffer);
            if (document != null) {
                IEditorTree tree = document.EditorTree;
                tree.EnsureTreeReady();

                // We don't want to complete inside strings
                if (tree.AstRoot.IsPositionInsideString(openingPoint.Position)) {
                    context = null;
                    return false;
                }

                // We don't want to complete inside comments
                int index = tree.AstRoot.Comments.GetItemContaining(openingPoint.Position);
                if (index >= 0) {
                    context = null;
                    return false;
                }
            }
            context = new BraceCompletionContext();
            return true;
        }
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
 {
     // if we are in a comment or string literal we cannot begin a completion session.
     if (IsValidBraceCompletionContext(openingPoint))
     {
         context = new BraceCompletionContext(SmartIndentationService, TextBufferUndoManagerProvider, ClassificationService, OptionsService);
         return(true);
     }
     else
     {
         context = null;
         return(false);
     }
 }
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            context = null;
            //if (!this.roslynInstalled.HasValue)
            //{
            //    this.roslynInstalled = new bool?(this.CheckRoslyn());
            //}
            //if (!this.roslynInstalled.Value)
            //{
            ITextDocument document = null;

            if (/*!this.ServiceRunning() ||*/ !this.TryGetTextDocument(textView, out document))
            {
                return(false);
            }
            Genero4glLanguageInfo languageInfo = new Genero4glLanguageInfo(/*this.CompilationHost,*/ this.completionBroker, openingPoint.Snapshot.TextBuffer, document.FilePath);

            if (!languageInfo.IsValidContext(openingPoint))
            {
                return(false);
            }
            switch (openingBrace)
            {
            //case '<':
            //    if (!languageInfo.IsPossibleTypeVariableDecl(openingPoint))
            //    {
            //        return false;
            //    }
            //    context = new NormalCompletionContext(languageInfo);
            //    return true;

            case '[':
            case '(':
                context = new NormalCompletionContext(languageInfo);
                return(true);

            case '{':
                context = new CurlyBraceContext(languageInfo);
                return(true);

            case '\'':
            case '"':
                context = new LiteralCompletionContext(languageInfo);
                return(true);
            }
            //}
            return(false);
        }
        /// <summary>
        /// Creates an <see cref="IBraceCompletionContext"/> to handle
        /// language-specific actions such as parsing and formatting.
        /// </summary>
        /// <remarks>
        /// Opening points within strings and comments are usually invalid points to start
        /// an <see cref="IBraceCompletionSession"/> and will return false.
        /// </remarks>
        /// <param name="textView">View containing the <paramref name="openingPoint"/>.</param>
        /// <param name="openingPoint">Insertion point of the <paramref name="openingBrace"/>.</param>
        /// <param name="openingBrace">Opening brace that has been typed by the user.</param>
        /// <param name="closingBrace">Closing brace character</param>
        /// <param name="context">Brace completion context if created.</param>
        /// <returns>Returns true if the <paramref name="openingPoint"/>
        /// was a valid point in the buffer to start a <see cref="IBraceCompletionSession"/>.
        /// </returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            IREditorDocument document = REditorDocument.TryFromTextBuffer(openingPoint.Snapshot.TextBuffer);

            if (document != null)
            {
                var ast = document.EditorTree.AstRoot;

                // We don't want to complete inside strings
                if (ast.IsPositionInsideString(openingPoint.Position))
                {
                    context = null;
                    return(false);
                }

                // We don't want to complete inside comments
                int index = ast.Comments.GetItemContaining(openingPoint.Position);
                if (index >= 0)
                {
                    context = null;
                    return(false);
                }
            }
            context = new BraceCompletionContext();
            return(true);
        }
예제 #10
0
        /// <summary>
        /// Creates an <see cref="IBraceCompletionContext"/> to handle
        /// language-specific actions such as parsing and formatting.
        /// </summary>
        /// <remarks>
        /// Opening points within strings and comments are usually invalid points to start
        /// an <see cref="IBraceCompletionSession"/> and will return false.
        /// </remarks>
        /// <param name="textView">View containing the <paramref name="openingPoint"/>.</param>
        /// <param name="openingPoint">Insertion point of the <paramref name="openingBrace"/>.</param>
        /// <param name="openingBrace">Opening brace that has been typed by the user.</param>
        /// <param name="closingBrace">Closing brace character</param>
        /// <param name="context">Brace completion context if created.</param>
        /// <returns>Returns true if the <paramref name="openingPoint"/>
        /// was a valid point in the buffer to start a <see cref="IBraceCompletionSession"/>.
        /// </returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            context = null;

            var document = openingPoint.Snapshot.TextBuffer.GetService <IREditorDocument>();

            if (document != null)
            {
                var ast = document.EditorTree.AstRoot;

                // We don't want to complete inside strings
                if (ast.IsPositionInsideString(openingPoint.Position))
                {
                    return(false);
                }

                // We don't want to complete inside comments
                if (document.IsPositionInComment(openingPoint.Position))
                {
                    return(false);
                }
            }

            context = new BraceCompletionContext(_shell);
            return(true);
        }
예제 #11
0
        /// <summary>
        /// Interface method implementation.
        /// </summary>
        /// <param name="textView">Current text view.</param>
        /// <param name="openingPoint">Snapshot point for the opening brace.</param>
        /// <param name="openingBrace">The opening brace char.</param>
        /// <param name="closingBrace">The closing brace char.</param>
        /// <param name="context">The instance of brace completion context.</param>
        /// <returns></returns>
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            if (!_validator.Validate())
            {
                context = null;
                return(false);
            }

            var editorOperations = this.EditOperationsFactory.GetEditorOperations(textView);
            var undoHistory      = this.UndoHistoryRegistry.GetHistory(textView.TextBuffer);

            if (IsValidBraceCompletionContext(textView, openingPoint))
            {
                context = new BraceCompletionContext(editorOperations, undoHistory);
                return(true);
            }
            else
            {
                context = null;
                return(false);
            }
        }
예제 #12
0
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            this.AssertIsForeground();

            if (IsValidBraceCompletionContext(openingPoint))
            {
                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 undoManager = _textBufferUndoManagerProvider.GetTextBufferUndoManager(textView.TextBuffer);
                            context = new BraceCompletionContext(_smartIndentationService, undoManager, editorSession);
                            return(true);
                        }
                    }
                }
            }

            context = null;
            return(false);
        }
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
 {
     // if we are in a comment or string literal we cannot begin a completion session.
     if (IsValidBraceCompletionContext(openingPoint))
     {
         context = new BraceCompletionContext();
         return(true);
     }
     else
     {
         context = null;
         return(false);
     }
 }
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
 {
     if (IsValidBraceCompletionContext(EditorServices.GetBufferInfo(openingPoint.Snapshot.TextBuffer), openingPoint))
     {
         context = new BraceCompletionContext();
         return(true);
     }
     else
     {
         context = null;
         return(false);
     }
 }
예제 #15
0
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            VSSource source   = VSSource.GetOrCreate(textView.TextBuffer);
            Snapshot snapshot = source.CurrentSnapshot;

            for (int i = 0; i < source.CommentSpans.Count; i++)
            {
                if (source.CommentSpans[i].GetSpan(snapshot).Contains(openingPoint.Position))
                {
                    context = null;
                    return(false);
                }
            }

            context = new GLSLBraceCompletionContext();
            return(true);
        }
            // Create the session
            public bool TryCreate(BraceCompletionAggregatorFactory factory, ITextView textView, SnapshotPoint openingPoint, char openingBrace, out IBraceCompletionSession session)
            {
                char closingBrace = GetClosingBrace(Metadata, openingBrace);

                if (IsSession)
                {
                    bool created = false;
                    IBraceCompletionSession currentSession = null;

                    factory.GuardedOperations.CallExtensionPoint(() =>
                    {
                        created = _sessionPair.Value.TryCreateSession(textView, openingPoint, openingBrace, closingBrace, out currentSession);
                    });

                    if (created)
                    {
                        session = currentSession;
                        return(true);
                    }

                    session = null;
                    return(false);
                }
                else if (IsContext)
                {
                    // Get a language specific context and add it to a default session.
                    IBraceCompletionContext context = null;

                    // check AllowDefaultSession to avoid starting a new "" session next to a "
                    if (AllowDefaultSession(openingPoint, openingBrace, closingBrace))
                    {
                        bool created = false;

                        factory.GuardedOperations.CallExtensionPoint(() =>
                        {
                            created = _contextPair.Value.TryCreateContext(textView, openingPoint, openingBrace, closingBrace, out context);
                        });

                        if (created)
                        {
                            session = new BraceCompletionDefaultSession(textView, openingPoint.Snapshot.TextBuffer, openingPoint, openingBrace,
                                                                        closingBrace, factory.UndoManager, factory.EditorOperationsFactoryService, context);

                            return(true);
                        }
                    }

                    session = null;
                    return(false);
                }
                else if (IsDefault)
                {
                    // perform some basic checks on the buffer before going in
                    if (AllowDefaultSession(openingPoint, openingBrace, closingBrace))
                    {
                        session = new BraceCompletionDefaultSession(textView, openingPoint.Snapshot.TextBuffer, openingPoint, openingBrace,
                                                                    closingBrace, factory.UndoManager, factory.EditorOperationsFactoryService);

                        return(true);
                    }
                }

                session = null;
                return(false);
            }
예제 #17
0
 /// <inheritdoc/>
 public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
 {
     if (IsValidBraceCompletionContext(openingPoint))
     {
         context = GetCompletionContext();
         return(true);
     }
     else
     {
         context = null !;
         return(false);
     }
 }
예제 #18
0
        public bool TryCreateContext(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionContext context)
        {
            var bi = PythonTextBufferInfo.ForBuffer(Site, openingPoint.Snapshot.TextBuffer);

            if (IsValidBraceCompletionContext(bi, openingPoint, openingBrace))
            {
                context = new BraceCompletionContext();
                return(true);
            }
            else
            {
                context = null;
                return(false);
            }
        }