Index: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs =================================================================== --- tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs +++ tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs @@ -84,8 +84,13 @@ // We're not in a text view. return; string text = view.TextBuffer.CurrentSnapshot.GetText(); - int start = view.Selection.Start.Position.GetContainingLine().Start.Position; - int end = view.Selection.End.Position.GetContainingLine().End.Position; + int start = 0; + int end = text.Length; + if (!view.Selection.IsEmpty) + { + start = view.Selection.Start.Position.GetContainingLine().Start.Position; + end = view.Selection.End.Position.GetContainingLine().End.Position; + } int length = end - start; // clang-format doesn't support formatting a range that starts at the end // of the file.