Tokenize observer-reported type names

The semantic token legend gains a type entry, and the server emits it
for each class name span reported by the observer when it lies in the
open document. The canonical type itself is still not tokenized
because it has no source span. Registered tests cover the legend index,
and a real stdio session decoded the class names as type tokens beside
the function and declaration tokens.
This commit is contained in:
faumaray committed 2026-12-05 23:56:39 +03:00
1 parent 86b9923532
commit 4b534c61ae
7 files changed
+37 -3

No files matched your search

+12
View File
@@ -1311,6 +1311,7 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
auto key = Documents::client_uri_key(uri);
std::shared_ptr<const Receipt> receipt;
std::shared_ptr<const std::vector<Occurrence>> facts;
std::shared_ptr<const std::vector<ReflectedType>> types;
{
std::lock_guard lock{s.mutex};
const auto i = key ? s.entries.find(*key) : s.entries.end();
@@ -1318,6 +1319,7 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
return Json{Json::Object{{"data", Json{Json::Array{}}}}};
receipt = i->second.receipt;
facts = i->second.occurrences;
types = i->second.types;
}
if (!receipt || !facts || !s.valid(*receipt))
return Json{Json::Object{{"data", Json{Json::Array{}}}}};
@@ -1347,6 +1349,16 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
features::semantic_tokens::function_type,
features::semantic_tokens::declaration_modifier});
}
if (types)
for (const auto &type : *types) {
if (type.self.path != snapshot->identity.canonical_path.native() ||
type.self.range.start.line != type.self.range.end.line ||
type.self.range.end.character <= type.self.range.start.character)
continue;
tokens.push_back({type.self.range.start.line, type.self.range.start.character,
type.self.range.end.character - type.self.range.start.character,
features::semantic_tokens::type_type, 0});
}
const auto normalized = features::semantic_tokens::normalize(tokens);
Json::Array data;
for (const auto value : features::semantic_tokens::encode(normalized))