Skip to content

Commit 3423e0b

Browse files
committed
Merge from 'master' to 'sycl-web' (#37)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticIDs.h
2 parents 7d0ceb8 + 8fa322d commit 3423e0b

File tree

158 files changed

+4286
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+4286
-585
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
485485
}
486486
}
487487

488-
ClangdServerOpts.SemanticHighlighting =
489-
Params.capabilities.SemanticHighlighting;
488+
ClangdServerOpts.TheiaSemanticHighlighting =
489+
Params.capabilities.TheiaSemanticHighlighting;
490490
if (Params.rootUri && *Params.rootUri)
491491
ClangdServerOpts.WorkspaceRoot = std::string(Params.rootUri->file());
492492
else if (Params.rootPath && !Params.rootPath->empty())
@@ -611,7 +611,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
611611
}}}};
612612
if (NegotiatedOffsetEncoding)
613613
Result["offsetEncoding"] = *NegotiatedOffsetEncoding;
614-
if (Params.capabilities.SemanticHighlighting)
614+
if (Params.capabilities.TheiaSemanticHighlighting)
615615
Result.getObject("capabilities")
616616
->insert(
617617
{"semanticHighlighting",
@@ -1169,8 +1169,8 @@ void ClangdLSPServer::applyConfiguration(
11691169
reparseOpenedFiles(ModifiedFiles);
11701170
}
11711171

1172-
void ClangdLSPServer::publishSemanticHighlighting(
1173-
const SemanticHighlightingParams &Params) {
1172+
void ClangdLSPServer::publishTheiaSemanticHighlighting(
1173+
const TheiaSemanticHighlightingParams &Params) {
11741174
notify("textDocument/semanticHighlighting", Params);
11751175
}
11761176

@@ -1376,12 +1376,12 @@ void ClangdLSPServer::onHighlightingsReady(
13761376
// LSP allows us to send incremental edits of highlightings. Also need to diff
13771377
// to remove highlightings from tokens that should no longer have them.
13781378
std::vector<LineHighlightings> Diffed = diffHighlightings(Highlightings, Old);
1379-
SemanticHighlightingParams Notification;
1379+
TheiaSemanticHighlightingParams Notification;
13801380
Notification.TextDocument.uri =
13811381
URIForFile::canonicalize(File, /*TUPath=*/File);
13821382
Notification.TextDocument.version = decodeVersion(Version);
1383-
Notification.Lines = toSemanticHighlightingInformation(Diffed);
1384-
publishSemanticHighlighting(Notification);
1383+
Notification.Lines = toTheiaSemanticHighlightingInformation(Diffed);
1384+
publishTheiaSemanticHighlighting(Notification);
13851385
}
13861386

13871387
void ClangdLSPServer::onDiagnosticsReady(PathRef File, llvm::StringRef Version,

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
135135
void applyConfiguration(const ConfigurationSettings &Settings);
136136

137137
/// Sends a "publishSemanticHighlighting" notification to the LSP client.
138-
void publishSemanticHighlighting(const SemanticHighlightingParams &);
138+
void
139+
publishTheiaSemanticHighlighting(const TheiaSemanticHighlightingParams &);
139140

140141
/// Sends a "publishDiagnostics" notification to the LSP client.
141142
void publishDiagnostics(const PublishDiagnosticsParams &);

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ namespace {
5858
struct UpdateIndexCallbacks : public ParsingCallbacks {
5959
UpdateIndexCallbacks(FileIndex *FIndex,
6060
ClangdServer::Callbacks *ServerCallbacks,
61-
bool SemanticHighlighting)
61+
bool TheiaSemanticHighlighting)
6262
: FIndex(FIndex), ServerCallbacks(ServerCallbacks),
63-
SemanticHighlighting(SemanticHighlighting) {}
63+
TheiaSemanticHighlighting(TheiaSemanticHighlighting) {}
6464

6565
void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
6666
std::shared_ptr<clang::Preprocessor> PP,
@@ -75,14 +75,14 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
7575

7676
std::vector<Diag> Diagnostics = AST.getDiagnostics();
7777
std::vector<HighlightingToken> Highlightings;
78-
if (SemanticHighlighting)
78+
if (TheiaSemanticHighlighting)
7979
Highlightings = getSemanticHighlightings(AST);
8080

8181
if (ServerCallbacks)
8282
Publish([&]() {
8383
ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
8484
std::move(Diagnostics));
85-
if (SemanticHighlighting)
85+
if (TheiaSemanticHighlighting)
8686
ServerCallbacks->onHighlightingsReady(Path, AST.version(),
8787
std::move(Highlightings));
8888
});
@@ -103,7 +103,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
103103
private:
104104
FileIndex *FIndex;
105105
ClangdServer::Callbacks *ServerCallbacks;
106-
bool SemanticHighlighting;
106+
bool TheiaSemanticHighlighting;
107107
};
108108
} // namespace
109109

@@ -112,7 +112,7 @@ ClangdServer::Options ClangdServer::optsForTest() {
112112
Opts.UpdateDebounce = DebouncePolicy::fixed(/*zero*/ {});
113113
Opts.StorePreamblesInMemory = true;
114114
Opts.AsyncThreadsCount = 4; // Consistent!
115-
Opts.SemanticHighlighting = true;
115+
Opts.TheiaSemanticHighlighting = true;
116116
return Opts;
117117
}
118118

@@ -142,8 +142,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
142142
// critical paths.
143143
WorkScheduler(
144144
CDB, TUScheduler::Options(Opts),
145-
std::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), Callbacks,
146-
Opts.SemanticHighlighting)) {
145+
std::make_unique<UpdateIndexCallbacks>(
146+
DynamicIdx.get(), Callbacks, Opts.TheiaSemanticHighlighting)) {
147147
// Adds an index to the stack, at higher priority than existing indexes.
148148
auto AddIndex = [&](SymbolIndex *Idx) {
149149
if (this->Index != nullptr) {

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class ClangdServer {
143143
std::vector<std::string> QueryDriverGlobs;
144144

145145
/// Enable semantic highlighting features.
146-
bool SemanticHighlighting = false;
146+
bool TheiaSemanticHighlighting = false;
147147

148148
/// Returns true if the tweak should be enabled.
149149
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {

clang-tools-extra/clangd/Hover.cpp

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,49 @@ llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST) {
520520
}
521521
return llvm::None;
522522
}
523+
524+
bool isParagraphLineBreak(llvm::StringRef Str, size_t LineBreakIndex) {
525+
return Str.substr(LineBreakIndex + 1)
526+
.drop_while([](auto C) { return C == ' ' || C == '\t'; })
527+
.startswith("\n");
528+
};
529+
530+
bool isPunctuationLineBreak(llvm::StringRef Str, size_t LineBreakIndex) {
531+
constexpr llvm::StringLiteral Punctuation = R"txt(.:,;!?)txt";
532+
533+
return LineBreakIndex > 0 && Punctuation.contains(Str[LineBreakIndex - 1]);
534+
};
535+
536+
bool isFollowedByHardLineBreakIndicator(llvm::StringRef Str,
537+
size_t LineBreakIndex) {
538+
// '-'/'*' md list, '@'/'\' documentation command, '>' md blockquote,
539+
// '#' headings, '`' code blocks
540+
constexpr llvm::StringLiteral LinbreakIdenticators = R"txt(-*@\>#`)txt";
541+
542+
auto NextNonSpaceCharIndex = Str.find_first_not_of(' ', LineBreakIndex + 1);
543+
544+
if (NextNonSpaceCharIndex == llvm::StringRef::npos) {
545+
return false;
546+
}
547+
548+
auto FollowedBySingleCharIndicator =
549+
LinbreakIdenticators.find(Str[NextNonSpaceCharIndex]) !=
550+
llvm::StringRef::npos;
551+
552+
auto FollowedByNumberedListIndicator =
553+
llvm::isDigit(Str[NextNonSpaceCharIndex]) &&
554+
NextNonSpaceCharIndex + 1 < Str.size() &&
555+
(Str[NextNonSpaceCharIndex + 1] == '.' ||
556+
Str[NextNonSpaceCharIndex + 1] == ')');
557+
558+
return FollowedBySingleCharIndicator || FollowedByNumberedListIndicator;
559+
};
560+
561+
bool isHardLineBreak(llvm::StringRef Str, size_t LineBreakIndex) {
562+
return isPunctuationLineBreak(Str, LineBreakIndex) ||
563+
isFollowedByHardLineBreakIndicator(Str, LineBreakIndex);
564+
}
565+
523566
} // namespace
524567

525568
llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
@@ -652,7 +695,7 @@ markup::Document HoverInfo::present() const {
652695
}
653696

654697
if (!Documentation.empty())
655-
Output.addParagraph().appendText(Documentation);
698+
parseDocumentation(Documentation, Output);
656699

657700
if (!Definition.empty()) {
658701
Output.addRuler();
@@ -675,6 +718,45 @@ markup::Document HoverInfo::present() const {
675718
return Output;
676719
}
677720

721+
void parseDocumentation(llvm::StringRef Input, markup::Document &Output) {
722+
723+
constexpr auto WhiteSpaceChars = "\t\n\v\f\r ";
724+
725+
auto TrimmedInput = Input.trim();
726+
727+
std::string CurrentLine;
728+
729+
for (size_t CharIndex = 0; CharIndex < TrimmedInput.size();) {
730+
if (TrimmedInput[CharIndex] == '\n') {
731+
// Trim whitespace infront of linebreak
732+
const auto LastNonSpaceCharIndex =
733+
CurrentLine.find_last_not_of(WhiteSpaceChars) + 1;
734+
CurrentLine.erase(LastNonSpaceCharIndex);
735+
736+
if (isParagraphLineBreak(TrimmedInput, CharIndex) ||
737+
isHardLineBreak(TrimmedInput, CharIndex)) {
738+
// FIXME: maybe distinguish between line breaks and paragraphs
739+
Output.addParagraph().appendText(CurrentLine);
740+
CurrentLine = "";
741+
} else {
742+
// Ommit linebreak
743+
CurrentLine += ' ';
744+
}
745+
746+
CharIndex++;
747+
// After a linebreak always remove spaces to avoid 4 space markdown code
748+
// blocks, also skip all additional linebreaks since they have no effect
749+
CharIndex = TrimmedInput.find_first_not_of(WhiteSpaceChars, CharIndex);
750+
} else {
751+
CurrentLine += TrimmedInput[CharIndex];
752+
CharIndex++;
753+
}
754+
}
755+
if (!CurrentLine.empty()) {
756+
Output.addParagraph().appendText(CurrentLine);
757+
}
758+
}
759+
678760
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
679761
const HoverInfo::Param &P) {
680762
std::vector<llvm::StringRef> Output;

clang-tools-extra/clangd/Hover.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ struct HoverInfo {
7474
/// Produce a user-readable information.
7575
markup::Document present() const;
7676
};
77+
78+
// Try to infer structure of a documentation comment (e.g. line breaks).
79+
void parseDocumentation(llvm::StringRef Input, markup::Document &Output);
80+
7781
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const HoverInfo::Param &);
7882
inline bool operator==(const HoverInfo::Param &LHS,
7983
const HoverInfo::Param &RHS) {

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R) {
295295
TextDocument->getObject("semanticHighlightingCapabilities")) {
296296
if (auto SemanticHighlightingSupport =
297297
SemanticHighlighting->getBoolean("semanticHighlighting"))
298-
R.SemanticHighlighting = *SemanticHighlightingSupport;
298+
R.TheiaSemanticHighlighting = *SemanticHighlightingSupport;
299299
}
300300
if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
301301
if (auto CategorySupport = Diagnostics->getBoolean("categorySupport"))
@@ -1131,18 +1131,19 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, OffsetEncoding Enc) {
11311131
return OS << toString(Enc);
11321132
}
11331133

1134-
bool operator==(const SemanticHighlightingInformation &Lhs,
1135-
const SemanticHighlightingInformation &Rhs) {
1134+
bool operator==(const TheiaSemanticHighlightingInformation &Lhs,
1135+
const TheiaSemanticHighlightingInformation &Rhs) {
11361136
return Lhs.Line == Rhs.Line && Lhs.Tokens == Rhs.Tokens;
11371137
}
11381138

1139-
llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting) {
1139+
llvm::json::Value
1140+
toJSON(const TheiaSemanticHighlightingInformation &Highlighting) {
11401141
return llvm::json::Object{{"line", Highlighting.Line},
11411142
{"tokens", Highlighting.Tokens},
11421143
{"isInactive", Highlighting.IsInactive}};
11431144
}
11441145

1145-
llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting) {
1146+
llvm::json::Value toJSON(const TheiaSemanticHighlightingParams &Highlighting) {
11461147
return llvm::json::Object{
11471148
{"textDocument", Highlighting.TextDocument},
11481149
{"lines", std::move(Highlighting.Lines)},

clang-tools-extra/clangd/Protocol.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,11 @@ struct ClientCapabilities {
433433
/// textDocument.codeAction.codeActionLiteralSupport.
434434
bool CodeActionStructure = false;
435435

436-
/// Client supports semantic highlighting.
436+
/// Client supports Theia semantic highlighting extension.
437+
/// https://github.com/microsoft/vscode-languageserver-node/pull/367
437438
/// textDocument.semanticHighlightingCapabilities.semanticHighlighting
438-
bool SemanticHighlighting = false;
439+
/// FIXME: drop this support once clients support LSP 3.16 Semantic Tokens.
440+
bool TheiaSemanticHighlighting = false;
439441

440442
/// Supported encodings for LSP character offsets. (clangd extension).
441443
llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding;
@@ -1342,7 +1344,7 @@ llvm::json::Value toJSON(const FileStatus &FStatus);
13421344

13431345
/// Represents a semantic highlighting information that has to be applied on a
13441346
/// specific line of the text document.
1345-
struct SemanticHighlightingInformation {
1347+
struct TheiaSemanticHighlightingInformation {
13461348
/// The line these highlightings belong to.
13471349
int Line = 0;
13481350
/// The base64 encoded string of highlighting tokens.
@@ -1353,18 +1355,19 @@ struct SemanticHighlightingInformation {
13531355
/// clients should combine line style and token style if possible.
13541356
bool IsInactive = false;
13551357
};
1356-
bool operator==(const SemanticHighlightingInformation &Lhs,
1357-
const SemanticHighlightingInformation &Rhs);
1358-
llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting);
1358+
bool operator==(const TheiaSemanticHighlightingInformation &Lhs,
1359+
const TheiaSemanticHighlightingInformation &Rhs);
1360+
llvm::json::Value
1361+
toJSON(const TheiaSemanticHighlightingInformation &Highlighting);
13591362

13601363
/// Parameters for the semantic highlighting (server-side) push notification.
1361-
struct SemanticHighlightingParams {
1364+
struct TheiaSemanticHighlightingParams {
13621365
/// The textdocument these highlightings belong to.
13631366
VersionedTextDocumentIdentifier TextDocument;
13641367
/// The lines of highlightings that should be sent.
1365-
std::vector<SemanticHighlightingInformation> Lines;
1368+
std::vector<TheiaSemanticHighlightingInformation> Lines;
13661369
};
1367-
llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting);
1370+
llvm::json::Value toJSON(const TheiaSemanticHighlightingParams &Highlighting);
13681371

13691372
struct SelectionRangeParams {
13701373
/// The text document.

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,15 @@ bool operator==(const LineHighlightings &L, const LineHighlightings &R) {
445445
return std::tie(L.Line, L.Tokens) == std::tie(R.Line, R.Tokens);
446446
}
447447

448-
std::vector<SemanticHighlightingInformation>
449-
toSemanticHighlightingInformation(llvm::ArrayRef<LineHighlightings> Tokens) {
448+
std::vector<TheiaSemanticHighlightingInformation>
449+
toTheiaSemanticHighlightingInformation(
450+
llvm::ArrayRef<LineHighlightings> Tokens) {
450451
if (Tokens.size() == 0)
451452
return {};
452453

453454
// FIXME: Tokens might be multiple lines long (block comments) in this case
454455
// this needs to add multiple lines for those tokens.
455-
std::vector<SemanticHighlightingInformation> Lines;
456+
std::vector<TheiaSemanticHighlightingInformation> Lines;
456457
Lines.reserve(Tokens.size());
457458
for (const auto &Line : Tokens) {
458459
llvm::SmallVector<char, 128> LineByteTokens;

clang-tools-extra/clangd/SemanticHighlighting.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST);
8080
llvm::StringRef toTextMateScope(HighlightingKind Kind);
8181

8282
/// Convert to LSP's semantic highlighting information.
83-
std::vector<SemanticHighlightingInformation>
84-
toSemanticHighlightingInformation(llvm::ArrayRef<LineHighlightings> Tokens);
83+
std::vector<TheiaSemanticHighlightingInformation>
84+
toTheiaSemanticHighlightingInformation(
85+
llvm::ArrayRef<LineHighlightings> Tokens);
8586

8687
/// Return a line-by-line diff between two highlightings.
8788
/// - if the tokens on a line are the same in both highlightings, this line is

0 commit comments

Comments
 (0)