[clang-tools-extra] edf6a19 - [clangd] Rename theia-derived semantic highlighting protocol. NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 23 16:39:54 PDT 2020
Author: Sam McCall
Date: 2020-03-24T00:39:47+01:00
New Revision: edf6a19adf7acf54f96e78718fb2339e5fcbc444
URL: https://github.com/llvm/llvm-project/commit/edf6a19adf7acf54f96e78718fb2339e5fcbc444
DIFF: https://github.com/llvm/llvm-project/commit/edf6a19adf7acf54f96e78718fb2339e5fcbc444.diff
LOG: [clangd] Rename theia-derived semantic highlighting protocol. NFC
This feature is being added to LSP with a different (request-response)
protocol in 3.16, so this should avoid some confusion.
Added:
Modified:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 748269d5aef4..d0e8d139a40e 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -485,8 +485,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
}
}
- ClangdServerOpts.SemanticHighlighting =
- Params.capabilities.SemanticHighlighting;
+ ClangdServerOpts.TheiaSemanticHighlighting =
+ Params.capabilities.TheiaSemanticHighlighting;
if (Params.rootUri && *Params.rootUri)
ClangdServerOpts.WorkspaceRoot = std::string(Params.rootUri->file());
else if (Params.rootPath && !Params.rootPath->empty())
@@ -611,7 +611,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
}}}};
if (NegotiatedOffsetEncoding)
Result["offsetEncoding"] = *NegotiatedOffsetEncoding;
- if (Params.capabilities.SemanticHighlighting)
+ if (Params.capabilities.TheiaSemanticHighlighting)
Result.getObject("capabilities")
->insert(
{"semanticHighlighting",
@@ -1169,8 +1169,8 @@ void ClangdLSPServer::applyConfiguration(
reparseOpenedFiles(ModifiedFiles);
}
-void ClangdLSPServer::publishSemanticHighlighting(
- const SemanticHighlightingParams &Params) {
+void ClangdLSPServer::publishTheiaSemanticHighlighting(
+ const TheiaSemanticHighlightingParams &Params) {
notify("textDocument/semanticHighlighting", Params);
}
@@ -1376,12 +1376,12 @@ void ClangdLSPServer::onHighlightingsReady(
// LSP allows us to send incremental edits of highlightings. Also need to
diff
// to remove highlightings from tokens that should no longer have them.
std::vector<LineHighlightings> Diffed =
diff Highlightings(Highlightings, Old);
- SemanticHighlightingParams Notification;
+ TheiaSemanticHighlightingParams Notification;
Notification.TextDocument.uri =
URIForFile::canonicalize(File, /*TUPath=*/File);
Notification.TextDocument.version = decodeVersion(Version);
- Notification.Lines = toSemanticHighlightingInformation(Diffed);
- publishSemanticHighlighting(Notification);
+ Notification.Lines = toTheiaSemanticHighlightingInformation(Diffed);
+ publishTheiaSemanticHighlighting(Notification);
}
void ClangdLSPServer::onDiagnosticsReady(PathRef File, llvm::StringRef Version,
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h
index e70b7b56a4f2..c4e9e5fb679c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -135,7 +135,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
void applyConfiguration(const ConfigurationSettings &Settings);
/// Sends a "publishSemanticHighlighting" notification to the LSP client.
- void publishSemanticHighlighting(const SemanticHighlightingParams &);
+ void
+ publishTheiaSemanticHighlighting(const TheiaSemanticHighlightingParams &);
/// Sends a "publishDiagnostics" notification to the LSP client.
void publishDiagnostics(const PublishDiagnosticsParams &);
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 5d2bfa7c8c57..3d68f85b6487 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -58,9 +58,9 @@ namespace {
struct UpdateIndexCallbacks : public ParsingCallbacks {
UpdateIndexCallbacks(FileIndex *FIndex,
ClangdServer::Callbacks *ServerCallbacks,
- bool SemanticHighlighting)
+ bool TheiaSemanticHighlighting)
: FIndex(FIndex), ServerCallbacks(ServerCallbacks),
- SemanticHighlighting(SemanticHighlighting) {}
+ TheiaSemanticHighlighting(TheiaSemanticHighlighting) {}
void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
std::shared_ptr<clang::Preprocessor> PP,
@@ -75,14 +75,14 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
std::vector<Diag> Diagnostics = AST.getDiagnostics();
std::vector<HighlightingToken> Highlightings;
- if (SemanticHighlighting)
+ if (TheiaSemanticHighlighting)
Highlightings = getSemanticHighlightings(AST);
if (ServerCallbacks)
Publish([&]() {
ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
std::move(Diagnostics));
- if (SemanticHighlighting)
+ if (TheiaSemanticHighlighting)
ServerCallbacks->onHighlightingsReady(Path, AST.version(),
std::move(Highlightings));
});
@@ -103,7 +103,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
private:
FileIndex *FIndex;
ClangdServer::Callbacks *ServerCallbacks;
- bool SemanticHighlighting;
+ bool TheiaSemanticHighlighting;
};
} // namespace
@@ -112,7 +112,7 @@ ClangdServer::Options ClangdServer::optsForTest() {
Opts.UpdateDebounce = DebouncePolicy::fixed(/*zero*/ {});
Opts.StorePreamblesInMemory = true;
Opts.AsyncThreadsCount = 4; // Consistent!
- Opts.SemanticHighlighting = true;
+ Opts.TheiaSemanticHighlighting = true;
return Opts;
}
@@ -142,8 +142,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
// critical paths.
WorkScheduler(
CDB, TUScheduler::Options(Opts),
- std::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), Callbacks,
- Opts.SemanticHighlighting)) {
+ std::make_unique<UpdateIndexCallbacks>(
+ DynamicIdx.get(), Callbacks, Opts.TheiaSemanticHighlighting)) {
// Adds an index to the stack, at higher priority than existing indexes.
auto AddIndex = [&](SymbolIndex *Idx) {
if (this->Index != nullptr) {
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 4c3fe56dd7e2..ae3dd8a065d8 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -143,7 +143,7 @@ class ClangdServer {
std::vector<std::string> QueryDriverGlobs;
/// Enable semantic highlighting features.
- bool SemanticHighlighting = false;
+ bool TheiaSemanticHighlighting = false;
/// Returns true if the tweak should be enabled.
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 56ddbfb446f7..462aebc4b046 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -295,7 +295,7 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R) {
TextDocument->getObject("semanticHighlightingCapabilities")) {
if (auto SemanticHighlightingSupport =
SemanticHighlighting->getBoolean("semanticHighlighting"))
- R.SemanticHighlighting = *SemanticHighlightingSupport;
+ R.TheiaSemanticHighlighting = *SemanticHighlightingSupport;
}
if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
if (auto CategorySupport = Diagnostics->getBoolean("categorySupport"))
@@ -1131,18 +1131,19 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, OffsetEncoding Enc) {
return OS << toString(Enc);
}
-bool operator==(const SemanticHighlightingInformation &Lhs,
- const SemanticHighlightingInformation &Rhs) {
+bool operator==(const TheiaSemanticHighlightingInformation &Lhs,
+ const TheiaSemanticHighlightingInformation &Rhs) {
return Lhs.Line == Rhs.Line && Lhs.Tokens == Rhs.Tokens;
}
-llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting) {
+llvm::json::Value
+toJSON(const TheiaSemanticHighlightingInformation &Highlighting) {
return llvm::json::Object{{"line", Highlighting.Line},
{"tokens", Highlighting.Tokens},
{"isInactive", Highlighting.IsInactive}};
}
-llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting) {
+llvm::json::Value toJSON(const TheiaSemanticHighlightingParams &Highlighting) {
return llvm::json::Object{
{"textDocument", Highlighting.TextDocument},
{"lines", std::move(Highlighting.Lines)},
diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index 6ab6bcc920b2..d08e546e3ffb 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -433,9 +433,11 @@ struct ClientCapabilities {
/// textDocument.codeAction.codeActionLiteralSupport.
bool CodeActionStructure = false;
- /// Client supports semantic highlighting.
+ /// Client supports Theia semantic highlighting extension.
+ /// https://github.com/microsoft/vscode-languageserver-node/pull/367
/// textDocument.semanticHighlightingCapabilities.semanticHighlighting
- bool SemanticHighlighting = false;
+ /// FIXME: drop this support once clients support LSP 3.16 Semantic Tokens.
+ bool TheiaSemanticHighlighting = false;
/// Supported encodings for LSP character offsets. (clangd extension).
llvm::Optional<std::vector<OffsetEncoding>> offsetEncoding;
@@ -1342,7 +1344,7 @@ llvm::json::Value toJSON(const FileStatus &FStatus);
/// Represents a semantic highlighting information that has to be applied on a
/// specific line of the text document.
-struct SemanticHighlightingInformation {
+struct TheiaSemanticHighlightingInformation {
/// The line these highlightings belong to.
int Line = 0;
/// The base64 encoded string of highlighting tokens.
@@ -1353,18 +1355,19 @@ struct SemanticHighlightingInformation {
/// clients should combine line style and token style if possible.
bool IsInactive = false;
};
-bool operator==(const SemanticHighlightingInformation &Lhs,
- const SemanticHighlightingInformation &Rhs);
-llvm::json::Value toJSON(const SemanticHighlightingInformation &Highlighting);
+bool operator==(const TheiaSemanticHighlightingInformation &Lhs,
+ const TheiaSemanticHighlightingInformation &Rhs);
+llvm::json::Value
+toJSON(const TheiaSemanticHighlightingInformation &Highlighting);
/// Parameters for the semantic highlighting (server-side) push notification.
-struct SemanticHighlightingParams {
+struct TheiaSemanticHighlightingParams {
/// The textdocument these highlightings belong to.
VersionedTextDocumentIdentifier TextDocument;
/// The lines of highlightings that should be sent.
- std::vector<SemanticHighlightingInformation> Lines;
+ std::vector<TheiaSemanticHighlightingInformation> Lines;
};
-llvm::json::Value toJSON(const SemanticHighlightingParams &Highlighting);
+llvm::json::Value toJSON(const TheiaSemanticHighlightingParams &Highlighting);
struct SelectionRangeParams {
/// The text document.
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index d5c51ebff5e1..b69f9e8f2710 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -445,14 +445,15 @@ bool operator==(const LineHighlightings &L, const LineHighlightings &R) {
return std::tie(L.Line, L.Tokens) == std::tie(R.Line, R.Tokens);
}
-std::vector<SemanticHighlightingInformation>
-toSemanticHighlightingInformation(llvm::ArrayRef<LineHighlightings> Tokens) {
+std::vector<TheiaSemanticHighlightingInformation>
+toTheiaSemanticHighlightingInformation(
+ llvm::ArrayRef<LineHighlightings> Tokens) {
if (Tokens.size() == 0)
return {};
// FIXME: Tokens might be multiple lines long (block comments) in this case
// this needs to add multiple lines for those tokens.
- std::vector<SemanticHighlightingInformation> Lines;
+ std::vector<TheiaSemanticHighlightingInformation> Lines;
Lines.reserve(Tokens.size());
for (const auto &Line : Tokens) {
llvm::SmallVector<char, 128> LineByteTokens;
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h
index cf4a51a341e7..31a97b81d6c2 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.h
+++ b/clang-tools-extra/clangd/SemanticHighlighting.h
@@ -80,8 +80,9 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST);
llvm::StringRef toTextMateScope(HighlightingKind Kind);
/// Convert to LSP's semantic highlighting information.
-std::vector<SemanticHighlightingInformation>
-toSemanticHighlightingInformation(llvm::ArrayRef<LineHighlightings> Tokens);
+std::vector<TheiaSemanticHighlightingInformation>
+toTheiaSemanticHighlightingInformation(
+ llvm::ArrayRef<LineHighlightings> Tokens);
/// Return a line-by-line
diff between two highlightings.
/// - if the tokens on a line are the same in both highlightings, this line is
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 8672a043f186..6a7f700e1f49 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -720,7 +720,7 @@ TEST(SemanticHighlighting, GeneratesHighlightsWhenFileChange) {
ASSERT_EQ(Counter.Count, 1);
}
-TEST(SemanticHighlighting, toSemanticHighlightingInformation) {
+TEST(SemanticHighlighting, toTheiaSemanticHighlightingInformation) {
auto CreatePosition = [](int Line, int Character) -> Position {
Position Pos;
Pos.line = Line;
@@ -739,9 +739,9 @@ TEST(SemanticHighlighting, toSemanticHighlightingInformation) {
{{HighlightingKind::Variable,
Range{CreatePosition(1, 1), CreatePosition(1, 5)}}},
/* IsInactive = */ true}};
- std::vector<SemanticHighlightingInformation> ActualResults =
- toSemanticHighlightingInformation(Tokens);
- std::vector<SemanticHighlightingInformation> ExpectedResults = {
+ std::vector<TheiaSemanticHighlightingInformation> ActualResults =
+ toTheiaSemanticHighlightingInformation(Tokens);
+ std::vector<TheiaSemanticHighlightingInformation> ExpectedResults = {
{3, "AAAACAAEAAAAAAAEAAMAAw=="}, {1, "AAAAAQAEAAA="}};
EXPECT_EQ(ActualResults, ExpectedResults);
}
More information about the cfe-commits
mailing list