Serve document symbols and highlights over LSP
SymbolIndex::find_by_path exposes one document's records with the same overlay shadowing and coverage as find. EditorDiagnostics maps them to textDocument/documentSymbol, and a bounded same-file highlight core (vls/features/DocumentSymbols.hpp) backs textDocument/documentHighlight from verified occurrence facts with the ambiguous-binding rule. Both are advertised and exercised over a real stdio session with the stock observer. Record the LSP parity matrix.
This commit is contained in:
1 parent
da8003f6d4
commit
8ca3dcbf74
16 files changed
+366
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include <vls/semantic/EditorDiagnostics.hpp>
|
||||
|
||||
#include <vls/features/Completion.hpp>
|
||||
#include <vls/features/DocumentSymbols.hpp>
|
||||
#include <vls/features/IndexNavigation.hpp>
|
||||
#include <vls/features/SignatureHelp.hpp>
|
||||
#include <vls/index/SymbolIndex.hpp>
|
||||
@@ -973,6 +974,85 @@ Json EditorDiagnostics::completion_resolve(const Json &item) const {
|
||||
return Json{std::move(enriched)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::document_symbols(std::string_view uri) const {
|
||||
auto &s = *state_;
|
||||
const auto identity = Documents::normalize_uri(uri);
|
||||
if (!identity || !identity->is_file_uri)
|
||||
return Json{nullptr};
|
||||
index::Result records;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
records = s.symbols.find_by_path(identity->canonical_path.native());
|
||||
}
|
||||
Json::Array symbols;
|
||||
std::set<std::tuple<std::string, int, std::uint32_t, std::uint32_t>> seen;
|
||||
for (const auto &record : records.symbols) {
|
||||
const auto &location = record.location;
|
||||
if (!seen.emplace(record.name, static_cast<int>(record.kind), location.line,
|
||||
location.character)
|
||||
.second)
|
||||
continue;
|
||||
const auto range = range_json(Documents::Range{{location.line, location.character},
|
||||
{location.endLine, location.endCharacter}});
|
||||
symbols.push_back(Json{Json::Object{{"name", Json{record.name}},
|
||||
{"kind", Json{symbol_kind(record.kind)}},
|
||||
{"range", range},
|
||||
{"selectionRange", range}}});
|
||||
}
|
||||
return Json{std::move(symbols)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::document_highlights(std::string_view uri,
|
||||
Documents::Position position) const {
|
||||
auto &s = *state_;
|
||||
auto key = Documents::client_uri_key(uri);
|
||||
std::shared_ptr<const Receipt> receipt;
|
||||
std::shared_ptr<const std::vector<Occurrence>> facts;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
const auto i = key ? s.entries.find(*key) : s.entries.end();
|
||||
if (i == s.entries.end())
|
||||
return Json{nullptr};
|
||||
receipt = i->second.receipt;
|
||||
facts = i->second.occurrences;
|
||||
}
|
||||
if (!receipt || !facts || !s.valid(*receipt))
|
||||
return Json{nullptr};
|
||||
const Documents::DocumentSnapshot *snapshot = nullptr;
|
||||
for (const auto &entry : receipt->capture->entries())
|
||||
if (entry.snapshot && entry.snapshot->identity.canonical_uri == *key) {
|
||||
snapshot = entry.snapshot.get();
|
||||
break;
|
||||
}
|
||||
if (!snapshot)
|
||||
return Json{nullptr};
|
||||
std::vector<features::documents::Use> uses;
|
||||
for (const auto &occurrence : *facts) {
|
||||
if (occurrence.use_file.get() != snapshot)
|
||||
continue;
|
||||
features::documents::Use use;
|
||||
use.binding.name = occurrence.name;
|
||||
if (occurrence.has_definition())
|
||||
use.binding.definition = features::documents::Location{
|
||||
occurrence.definition_file->identity.canonical_path.native(),
|
||||
{{occurrence.definition.start.line, occurrence.definition.start.character},
|
||||
{occurrence.definition.end.line, occurrence.definition.end.character}}};
|
||||
use.path = snapshot->identity.canonical_path.native();
|
||||
use.range = {{occurrence.use.start.line, occurrence.use.start.character},
|
||||
{occurrence.use.end.line, occurrence.use.end.character}};
|
||||
uses.push_back(std::move(use));
|
||||
}
|
||||
const auto ranges = features::documents::highlights(
|
||||
uses, snapshot->identity.canonical_path.native(), {position.line, position.character});
|
||||
Json::Array result;
|
||||
for (const auto &range : ranges)
|
||||
result.push_back(Json{Json::Object{
|
||||
{"range", range_json(Documents::Range{{range.start.line, range.start.character},
|
||||
{range.end.line, range.end.character}})},
|
||||
{"kind", Json{std::int64_t{1}}}}});
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
void EditorDiagnostics::set_transactional_rename(bool supported) {
|
||||
std::lock_guard lock{state_->mutex};
|
||||
state_->transactional_rename = supported;
|
||||
|
||||
Reference in new issue
Block a user