Files
whetstone_DSL/editor/src/LSPCapabilityNegotiator.h
Bill 4d47e894c1 Sprint 278: LSP Proxy Hardening (steps 1918-1922)
- LSPMessageValidator: JSON-RPC 2.0 shape validation (method, id type, params type)
- LSPCapabilityNegotiator: per-source capability tracking; shouldRoute gates on declared caps
- LSPRequestThrottler: per-URI/method debounce; blocks rapid didChange floods
- LSPErrorRecovery: per-source health tracking; stale-cache fallback when crashed
- Sprint278IntegrationSummary: poly-parse (C++ + Haskell) end-to-end integration

26/26 tests passing (5+5+5+5+6). All new headers well under 600 lines.
LoRA recorded: sprint278-2026-03-01 (9 calls, 6437 tokens).

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

59 lines
1.9 KiB
C++

#pragma once
#include <map>
#include <set>
#include <string>
#include <vector>
namespace whetstone {
class LSPCapabilityNegotiator {
public:
void registerSource(const std::string& source,
const std::vector<std::string>& caps) {
caps_[source] = {caps.begin(), caps.end()};
}
bool supports(const std::string& source,
const std::string& capability) const {
auto it = caps_.find(source);
if (it == caps_.end()) return false;
return it->second.count(capability) > 0;
}
// Returns true if the source supports the capability required by this method.
// Unknown methods pass through (return true).
bool shouldRoute(const std::string& source,
const std::string& method) const {
auto it = methodToCap_.find(method);
if (it == methodToCap_.end()) return true; // unknown method: pass through
return supports(source, it->second);
}
std::vector<std::string> capabilitiesFor(const std::string& source) const {
auto it = caps_.find(source);
if (it == caps_.end()) return {};
return {it->second.begin(), it->second.end()};
}
std::vector<std::string> sourcesSupporting(const std::string& cap) const {
std::vector<std::string> result;
for (const auto& [src, capSet] : caps_)
if (capSet.count(cap)) result.push_back(src);
return result;
}
private:
std::map<std::string, std::set<std::string>> caps_;
const std::map<std::string, std::string> methodToCap_ = {
{"textDocument/hover", "hoverProvider"},
{"textDocument/definition", "definitionProvider"},
{"textDocument/references", "referencesProvider"},
{"textDocument/completion", "completionProvider"},
{"textDocument/rename", "renameProvider"},
{"textDocument/formatting", "documentFormattingProvider"},
};
};
} // namespace whetstone