Files
whetstone_DSL/editor/src/LSPCompletionMerger.h
Bill 67c3c73046 Sprint 277: LSP Advanced Orchestration (steps 1913-1917)
- LSPWorkspaceIndex: track open docs, URI→{languageId,content,version}
- LSPDiagnosticsAggregator: merge diagnostics from multiple LSP sources per URI
- LSPCompletionMerger: merge+deduplicate completion items from multiple sources
- LSPOrchestrator: top-level coordinator composing all three + proxy + cross-lang resolver
- Sprint277IntegrationSummary: poly-api (Go+TypeScript) end-to-end integration

26/26 tests passing (5+5+5+5+6). All new headers ≤600 lines.
LoRA recorded: sprint277-2026-03-01 (1 call, 569 tokens).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-01 20:18:23 -07:00

69 lines
1.9 KiB
C++

#pragma once
#include <algorithm>
#include <map>
#include <string>
#include <vector>
namespace whetstone {
struct CompletionItem {
std::string label;
int kind = 1; // 1=Text 2=Method 3=Function 6=Variable etc.
std::string detail;
std::string source; // language server that produced this item
};
class LSPCompletionMerger {
public:
// Add items from a named source. Replaces any previous items from that source.
void addItems(const std::string& source,
const std::vector<CompletionItem>& items) {
bySource_[source] = items;
}
// Return all items merged from all sources, deduplicated by label.
// When two sources offer the same label, the first encountered wins (sorted source order).
std::vector<CompletionItem> getItems() const {
std::vector<CompletionItem> result;
std::map<std::string, bool> seen;
for (const auto& [src, items] : bySource_) {
for (const auto& item : items) {
if (!seen.count(item.label)) {
seen[item.label] = true;
result.push_back(item);
}
}
}
std::sort(result.begin(), result.end(),
[](const CompletionItem& a, const CompletionItem& b){
return a.label < b.label;
});
return result;
}
// Remove all items from one source.
void clearSource(const std::string& source) {
bySource_.erase(source);
}
// Remove all items.
void clearAll() {
bySource_.clear();
}
// Count unique labels across all sources.
int uniqueCount() const {
return static_cast<int>(getItems().size());
}
int sourceCount() const {
return static_cast<int>(bySource_.size());
}
private:
// source → items
std::map<std::string, std::vector<CompletionItem>> bySource_;
};
} // namespace whetstone