Ingest the generic outline into the symbol index
Each open document's text outline is published as its own context (outline:<uri>, provenance document-outline) on content change and removed on close, so it never replaces compiler facts. workspace/symbol no longer requires the occurrence observer, and documentSymbol skips the outline's index copies. The generic stdio session now resolves a workspace symbol with no compiler-specific artifact.
This commit is contained in:
1 parent
103b38a291
commit
0b33a0cd99
3 files changed
+60
-1
No files matched your search
@@ -117,9 +117,24 @@ struct PublishedDiagnostic {
|
||||
std::vector<DiagnosticFix> fixes;
|
||||
};
|
||||
|
||||
index::SymbolKind outline_kind(features::outline::Kind kind) {
|
||||
switch (kind) {
|
||||
case features::outline::Kind::namespace_:
|
||||
return index::SymbolKind::namespace_;
|
||||
case features::outline::Kind::function:
|
||||
case features::outline::Kind::method:
|
||||
return index::SymbolKind::function;
|
||||
case features::outline::Kind::class_:
|
||||
case features::outline::Kind::enum_:
|
||||
return index::SymbolKind::type;
|
||||
}
|
||||
return index::SymbolKind::unknown;
|
||||
}
|
||||
|
||||
struct EditorReport {
|
||||
Json::Array diagnostics, other_messages;
|
||||
std::vector<PublishedDiagnostic> published;
|
||||
std::string outline_content;
|
||||
std::size_t unlocated{};
|
||||
};
|
||||
|
||||
@@ -172,6 +187,7 @@ struct Entry {
|
||||
bool sent{}, had_findings{};
|
||||
std::shared_ptr<const Receipt> receipt;
|
||||
std::vector<PublishedDiagnostic> published;
|
||||
std::string outline_content;
|
||||
std::shared_ptr<const std::vector<Occurrence>> occurrences;
|
||||
std::shared_ptr<const std::vector<ReflectedType>> types;
|
||||
std::string occurrence_state{"disabled"}, occurrence_reason;
|
||||
@@ -774,6 +790,7 @@ void EditorDiagnostics::finish_update(bool workspace_changed) {
|
||||
else {
|
||||
s.retract(i->second, true);
|
||||
s.symbols.remove(i->first);
|
||||
s.symbols.remove("outline:" + i->first);
|
||||
s.module_work.cancel(i->first);
|
||||
i = s.entries.erase(i);
|
||||
}
|
||||
@@ -787,6 +804,28 @@ void EditorDiagnostics::finish_update(bool workspace_changed) {
|
||||
entry.uri = id.display_uri;
|
||||
entry.version = overlay->version;
|
||||
entry.retry_delay = 1s;
|
||||
// The generic outline is a separate context, so it never replaces the
|
||||
// compiler facts for the same document and needs no observer.
|
||||
if (entry.outline_content != overlay->content_hash.sha256_hex) {
|
||||
index::ContextInput facts;
|
||||
facts.context = "outline:" + id.canonical_uri;
|
||||
facts.complete = true;
|
||||
facts.sources.emplace_back(id.canonical_path.native(),
|
||||
overlay->content_hash.sha256_hex);
|
||||
facts.dependencies.push_back(id.canonical_path.native());
|
||||
for (const auto &symbol : features::outline::outline(overlay->text)) {
|
||||
index::SymbolRecord record;
|
||||
record.name = symbol.name;
|
||||
record.kind = outline_kind(symbol.kind);
|
||||
record.location = {id.canonical_path.native(), symbol.range.start.line,
|
||||
symbol.range.start.character, symbol.range.end.line,
|
||||
symbol.range.end.character};
|
||||
record.provenance = "document-outline";
|
||||
facts.records.push_back(std::move(record));
|
||||
}
|
||||
if (s.symbols.publish(facts))
|
||||
entry.outline_content = overlay->content_hash.sha256_hex;
|
||||
}
|
||||
if (workspace_changed) {
|
||||
s.retract(entry);
|
||||
entry.hints.clear();
|
||||
@@ -1173,6 +1212,9 @@ Json EditorDiagnostics::document_symbols(std::string_view uri) const {
|
||||
}
|
||||
for (const auto &record : records.symbols) {
|
||||
const auto &location = record.location;
|
||||
// The text outline above already represents its own index copies.
|
||||
if (record.provenance == "document-outline")
|
||||
continue;
|
||||
if (!seen.emplace(record.name, static_cast<int>(record.kind), location.line,
|
||||
location.character)
|
||||
.second)
|
||||
@@ -1282,6 +1324,7 @@ Json EditorDiagnostics::code_actions(std::string_view uri, Documents::Range rang
|
||||
if (!identity || !identity->is_file_uri)
|
||||
return Json{nullptr};
|
||||
std::vector<PublishedDiagnostic> published;
|
||||
std::string outline_content;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
const auto i = s.entries.find(identity->canonical_uri);
|
||||
|
||||
Reference in new issue
Block a user