[clangd] Rename FormattedString -> Markup, move to support. NFC
authorSam McCall <sam.mccall@gmail.com>
Sat, 2 May 2020 12:53:47 +0000 (14:53 +0200)
committerSam McCall <sam.mccall@gmail.com>
Sat, 2 May 2020 12:53:47 +0000 (14:53 +0200)
13 files changed:
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/Hover.h
clang-tools-extra/clangd/XRefs.h
clang-tools-extra/clangd/support/CMakeLists.txt
clang-tools-extra/clangd/support/Markup.cpp [moved from clang-tools-extra/clangd/FormattedString.cpp with 96% similarity]
clang-tools-extra/clangd/support/Markup.h [moved from clang-tools-extra/clangd/FormattedString.h with 93% similarity]
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/support/MarkupTests.cpp [moved from clang-tools-extra/clangd/unittests/FormattedStringTests.cpp with 99% similarity]

index b8e1798..dd3e027 100644 (file)
@@ -44,7 +44,6 @@ add_clang_library(clangDaemon
   FileDistance.cpp
   Format.cpp
   FS.cpp
-  FormattedString.cpp
   FuzzyMatch.cpp
   GlobalCompilationDatabase.cpp
   Headers.cpp
index 882df4a..b0fc35b 100644 (file)
@@ -9,7 +9,6 @@
 #include "ClangdLSPServer.h"
 #include "Diagnostics.h"
 #include "DraftStore.h"
-#include "FormattedString.h"
 #include "GlobalCompilationDatabase.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
index 3dce7fe..8cf0d86 100644 (file)
@@ -10,7 +10,6 @@
 #include "CodeComplete.h"
 #include "FindSymbols.h"
 #include "Format.h"
-#include "FormattedString.h"
 #include "HeaderSourceSwitch.h"
 #include "Headers.h"
 #include "ParsedAST.h"
@@ -27,6 +26,7 @@
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
+#include "support/Markup.h"
 #include "support/Trace.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
index d36dfd1..76fa64b 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "../clang-tidy/ClangTidyOptions.h"
 #include "CodeComplete.h"
-#include "FormattedString.h"
 #include "GlobalCompilationDatabase.h"
 #include "Hover.h"
 #include "Protocol.h"
index 8c2908e..7070aec 100644 (file)
@@ -15,7 +15,6 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
 
-#include "FormattedString.h"
 #include "Headers.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -23,6 +22,7 @@
 #include "index/Symbol.h"
 #include "index/SymbolOrigin.h"
 #include "support/Logger.h"
+#include "support/Markup.h"
 #include "support/Path.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"
index 5e92ee1..799d376 100644 (file)
 #include "AST.h"
 #include "CodeCompletionStrings.h"
 #include "FindTarget.h"
-#include "FormattedString.h"
 #include "ParsedAST.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "index/SymbolCollector.h"
 #include "support/Logger.h"
+#include "support/Markup.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
index 73138c2..931e1c2 100644 (file)
@@ -9,9 +9,9 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HOVER_H
 
-#include "FormattedString.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
+#include "support/Markup.h"
 #include "clang/Index/IndexSymbol.h"
 
 namespace clang {
index d1ba7ba..521c28f 100644 (file)
@@ -13,7 +13,6 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
 
-#include "FormattedString.h"
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/Index.h"
index 719d757..04a897e 100644 (file)
@@ -21,6 +21,7 @@ add_clang_library(clangdSupport
   Context.cpp
   FSProvider.cpp
   Logger.cpp
+  Markup.cpp
   Shutdown.cpp
   Threading.cpp
   Trace.cpp
similarity index 96%
rename from clang-tools-extra/clangd/FormattedString.cpp
rename to clang-tools-extra/clangd/support/Markup.cpp
index ae6eb1e..94081b3 100644 (file)
@@ -1,12 +1,11 @@
-//===--- FormattedString.cpp --------------------------------*- C++-*------===//
+//===--- Markup.cpp -----------------------------------------*- C++-*------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-#include "FormattedString.h"
-#include "clang/Basic/CharInfo.h"
+#include "support/Markup.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 namespace clang {
 namespace clangd {
 namespace markup {
-
 namespace {
 
+/// Like std::isspace but for "C" locale.
+/// FIXME: move to StringExtras?
+bool isSpace(char C) {
+  return C == ' ' || C == '\f' || C == '\n' || C == '\r' || C == '\t' ||
+         C == '\v';
+}
+
 // Is <contents a plausible start to an HTML tag?
 // Contents may not be the rest of the line, but it's the rest of the plain
 // text, so we expect to see at least the tag name.
@@ -45,11 +50,11 @@ bool looksLikeTag(llvm::StringRef Contents) {
                  .drop_while([](char C) {
                    return llvm::isAlnum(C) || C == '-' || C == '_' || C == ':';
                  })
-                 .drop_while(isWhitespace);
+                 .drop_while(isSpace);
   // The rest of the tag consists of attributes, which have restrictive names.
   // If we hit '=', all bets are off (attribute values can contain anything).
   for (; !Contents.empty(); Contents = Contents.drop_front()) {
-    if (llvm::isAlnum(Contents.front()) || isWhitespace(Contents.front()))
+    if (llvm::isAlnum(Contents.front()) || isSpace(Contents.front()))
       continue;
     if (Contents.front() == '>' || Contents.startswith("/>"))
       return true; // May close the tag.
@@ -70,7 +75,7 @@ bool looksLikeTag(llvm::StringRef Contents) {
 // a markdown grammar construct.
 bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
                         bool StartsLine) {
-  assert(Before.take_while(isWhitespace).empty());
+  assert(Before.take_while(isSpace).empty());
   auto RulerLength = [&]() -> /*Length*/ unsigned {
     if (!StartsLine || !Before.empty())
       return false;
@@ -82,8 +87,8 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
            (After.empty() || After.startswith(" "));
   };
   auto SpaceSurrounds = [&]() {
-    return (After.empty() || isWhitespace(After.front())) &&
-           (Before.empty() || isWhitespace(Before.back()));
+    return (After.empty() || isSpace(After.front())) &&
+           (Before.empty() || isSpace(Before.back()));
   };
   auto WordSurrounds = [&]() {
     return (!After.empty() && llvm::isAlnum(After.front())) &&
@@ -429,8 +434,8 @@ Paragraph &Paragraph::appendText(llvm::StringRef Text) {
   Chunk &C = Chunks.back();
   C.Contents = std::move(Norm);
   C.Kind = Chunk::PlainText;
-  C.SpaceBefore = isWhitespace(Text.front());
-  C.SpaceAfter = isWhitespace(Text.back());
+  C.SpaceBefore = isSpace(Text.front());
+  C.SpaceAfter = isSpace(Text.back());
   return *this;
 }
 
similarity index 93%
rename from clang-tools-extra/clangd/FormattedString.h
rename to clang-tools-extra/clangd/support/Markup.h
index 06a8fd9..5600710 100644 (file)
@@ -1,4 +1,4 @@
-//===--- FormattedString.h ----------------------------------*- C++-*------===//
+//===--- Markup.h -------------------------------------------*- C++-*------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// A simple intermediate representation of formatted text that could be
-// converted to plaintext or markdown.
+// A model of formatted text that can be rendered to plaintext or markdown.
 //
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMATTEDSTRING_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMATTEDSTRING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MARKUP_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_MARKUP_H
 
 #include "llvm/Support/raw_ostream.h"
 #include <cstddef>
index 962a878..017d7fb 100644 (file)
@@ -42,7 +42,6 @@ add_unittest(ClangdUnitTests ClangdTests
   FileIndexTests.cpp
   FindSymbolsTests.cpp
   FindTargetTests.cpp
-  FormattedStringTests.cpp
   FormatTests.cpp
   FSTests.cpp
   FuzzyMatchTests.cpp
@@ -82,6 +81,7 @@ add_unittest(ClangdUnitTests ClangdTests
   support/CancellationTests.cpp
   support/ContextTests.cpp
   support/FunctionTests.cpp
+  support/MarkupTests.cpp
   support/ThreadingTests.cpp
   support/TraceTests.cpp
 
@@ -1,11 +1,11 @@
-//===-- FormattedStringTests.cpp ------------------------------------------===//
+//===-- MarkupTests.cpp ---------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-#include "FormattedString.h"
+#include "support/Markup.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"