From: George Karpenkov Date: Thu, 21 Dec 2017 22:57:51 +0000 (+0000) Subject: [analyzer] Add Javascript to analyzer HTML output to allow keyboard navigation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27adfcf7f3c21a6c654918f5d20858adec6f0dd5;p=clang [analyzer] Add Javascript to analyzer HTML output to allow keyboard navigation. Differential Revision: https://reviews.llvm.org/D41414 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321320 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 23d1895e31..618c0179f1 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -342,6 +342,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, " .CodeInsertionHint { font-weight: bold; background-color: #10dd10 }\n" " .CodeRemovalHint { background-color:#de1010 }\n" " .CodeRemovalHint { border-bottom:1px solid #6F9DBE }\n" + " .selected{ background-color:orange !important; }\n" " table.simpletable {\n" " padding: 5px;\n" " font-size:12pt;\n" diff --git a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp index 9b820e81e3..ebf1487d4b 100644 --- a/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -91,6 +91,9 @@ public: // Rewrite the file specified by FID with HTML formatting. void RewriteFile(Rewriter &R, const SourceManager& SMgr, const PathPieces& path, FileID FID); + + /// \return Javascript for navigating the HTML report using j/k keys. + std::string generateKeyboardNavigationJavascript(); }; } // end anonymous namespace @@ -337,6 +340,9 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, int LineNumber = path.back()->getLocation().asLocation().getExpansionLineNumber(); int ColumnNumber = path.back()->getLocation().asLocation().getExpansionColumnNumber(); + R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), + generateKeyboardNavigationJavascript()); + // Add the name of the file as an

tag. { std::string s; @@ -378,8 +384,14 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, os << "" << html::EscapeText(*I) << "\n"; } - os << "\n\n" - "

Annotated Source Code

\n"; + os << R"<<<( + + +

Annotated Source Code

+

[?] + Use j/k keys for keyboard navigation +

+)<<<"; R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str()); } @@ -777,3 +789,82 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID, html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd); } + +std::string HTMLDiagnostics::generateKeyboardNavigationJavascript() { + return R"<<<( + + )<<<"; +}