[clang-tools-extra] fa1f4cf - [clangd] Rename FormattedString -> Markup, move to support. NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Sat May 2 05:54:18 PDT 2020
Author: Sam McCall
Date: 2020-05-02T14:53:47+02:00
New Revision: fa1f4cf84326b59f917bccde784875c742e71740
URL: https://github.com/llvm/llvm-project/commit/fa1f4cf84326b59f917bccde784875c742e71740
DIFF: https://github.com/llvm/llvm-project/commit/fa1f4cf84326b59f917bccde784875c742e71740.diff
LOG: [clangd] Rename FormattedString -> Markup, move to support. NFC
Added:
clang-tools-extra/clangd/support/Markup.cpp
clang-tools-extra/clangd/support/Markup.h
clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
Modified:
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/unittests/CMakeLists.txt
Removed:
clang-tools-extra/clangd/FormattedString.cpp
clang-tools-extra/clangd/FormattedString.h
clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
################################################################################
diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt
index b8e179855b9d..dd3e02713559 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -44,7 +44,6 @@ add_clang_library(clangDaemon
FileDistance.cpp
Format.cpp
FS.cpp
- FormattedString.cpp
FuzzyMatch.cpp
GlobalCompilationDatabase.cpp
Headers.cpp
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 882df4abf1ce..b0fc35bb632b 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -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"
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 3dce7fec86c5..8cf0d863689f 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -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"
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index d36dfd1e9a88..76fa64b5a314 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -11,7 +11,6 @@
#include "../clang-tidy/ClangTidyOptions.h"
#include "CodeComplete.h"
-#include "FormattedString.h"
#include "GlobalCompilationDatabase.h"
#include "Hover.h"
#include "Protocol.h"
diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h
index 8c2908e445ae..7070aec79b79 100644
--- a/clang-tools-extra/clangd/CodeComplete.h
+++ b/clang-tools-extra/clangd/CodeComplete.h
@@ -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"
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index 5e92ee189035..799d37626489 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -11,12 +11,12 @@
#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"
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 73138c284b6c..931e1c2363a4 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -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 {
diff --git a/clang-tools-extra/clangd/XRefs.h b/clang-tools-extra/clangd/XRefs.h
index d1ba7bac6660..521c28f934be 100644
--- a/clang-tools-extra/clangd/XRefs.h
+++ b/clang-tools-extra/clangd/XRefs.h
@@ -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"
diff --git a/clang-tools-extra/clangd/support/CMakeLists.txt b/clang-tools-extra/clangd/support/CMakeLists.txt
index 719d7577576d..04a897e67037 100644
--- a/clang-tools-extra/clangd/support/CMakeLists.txt
+++ b/clang-tools-extra/clangd/support/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangdSupport
Context.cpp
FSProvider.cpp
Logger.cpp
+ Markup.cpp
Shutdown.cpp
Threading.cpp
Trace.cpp
diff --git a/clang-tools-extra/clangd/FormattedString.cpp b/clang-tools-extra/clangd/support/Markup.cpp
similarity index 96%
rename from clang-tools-extra/clangd/FormattedString.cpp
rename to clang-tools-extra/clangd/support/Markup.cpp
index ae6eb1e31354..94081b399a20 100644
--- a/clang-tools-extra/clangd/FormattedString.cpp
+++ b/clang-tools-extra/clangd/support/Markup.cpp
@@ -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"
@@ -25,9 +24,15 @@
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;
}
diff --git a/clang-tools-extra/clangd/FormattedString.h b/clang-tools-extra/clangd/support/Markup.h
similarity index 93%
rename from clang-tools-extra/clangd/FormattedString.h
rename to clang-tools-extra/clangd/support/Markup.h
index 06a8fd9052e6..560071031e66 100644
--- a/clang-tools-extra/clangd/FormattedString.h
+++ b/clang-tools-extra/clangd/support/Markup.h
@@ -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>
diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index 962a8785ce8d..017d7fbeb8e7 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -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
diff --git a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp b/clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
similarity index 99%
rename from clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
rename to clang-tools-extra/clangd/unittests/support/MarkupTests.cpp
index 87df6396becc..77160e1863a5 100644
--- a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ b/clang-tools-extra/clangd/unittests/support/MarkupTests.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"
More information about the cfe-commits
mailing list