forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
2136d17d8d
commit
edf6a19adf
|
@ -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 = diffHighlightings(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,
|
||||
|
|
|
@ -135,7 +135,8 @@ private:
|
|||
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 &);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
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) {
|
||||
|
|
|
@ -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)},
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue