/// <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); }
/// <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; }