diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index b8e179855b9df1..dd3e0271355902 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 882df4abf1ced0..b0fc35bb632b4f 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 3dce7fec86c5a8..8cf0d863689f47 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 d36dfd1e9a887d..76fa64b5a31429 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 8c2908e445ae4b..7070aec79b7997 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 5e92ee1890357e..799d3762648962 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 73138c284b6c58..931e1c2363a45b 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 d1ba7bac66600c..521c28f934bef4 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 719d7577576d33..04a897e6703726 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 ae6eb1e3135410..94081b399a2012 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.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 06a8fd9052e663..560071031e66a5 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 diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt b/clang-tools-extra/clangd/unittests/CMakeLists.txt index 962a8785ce8dd4..017d7fbeb8e7fa 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 87df6396becc6d..77160e1863a5bd 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"