private static bool ShouldFormatScope(ITextView textView, ITextBuffer textBuffer, int lineOffset) { IREditorDocument document = REditorDocument.TryFromTextBuffer(textBuffer); if (document != null) { IEditorTree tree = document.EditorTree; tree.EnsureTreeReady(); SnapshotPoint?caret = MapCaretToBuffer(textView, textBuffer); if (caret.HasValue) { try { int lineNumber = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(caret.Value.Position); ITextSnapshotLine line = textBuffer.CurrentSnapshot.GetLineFromLineNumber(Math.Max(lineNumber - 1, 0)); string lineText = line.GetText(); if (lineText.IndexOfAny(new char[] { '{', '}' }) >= 0) { IKeywordScopeStatement scopeStatement = tree.AstRoot.GetNodeOfTypeFromPosition <IKeywordScopeStatement>(caret.Value); return(scopeStatement != null); } } catch (Exception) { } } } return(false); }
private static IKeywordScopeStatement GetFormatScope(ITextView textView, ITextBuffer textBuffer, AstRoot ast) { SnapshotPoint?caret = REditorDocument.MapCaretPositionFromView(textView); if (caret.HasValue) { try { int lineNumber = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(caret.Value.Position); ITextSnapshotLine line = textBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber); string lineText = line.GetText(); if (lineText.TrimEnd().EndsWith("}", StringComparison.Ordinal)) { IKeywordScopeStatement scopeStatement = ast.GetNodeOfTypeFromPosition <IKeywordScopeStatement>(caret.Value); return(scopeStatement); } } catch (Exception) { } } return(null); }