- 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>
103 lines
3.9 KiB
C++
103 lines
3.9 KiB
C++
// Step 1914: LSPDiagnosticsAggregator
|
|
// Collects Diagnostic records from multiple language server sources; merges by URI.
|
|
//
|
|
// t1: set and get from one source
|
|
// t2: get merges diagnostics from two sources for the same URI
|
|
// t3: clearSource removes one source without affecting others
|
|
// t4: errorCount counts severity==1 only
|
|
// t5: urisWithDiagnostics lists all affected URIs deduplicated
|
|
|
|
#include "LSPDiagnosticsAggregator.h"
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
namespace ws = whetstone;
|
|
|
|
static int p=0,f=0;
|
|
#define T(n) { std::cout<<" "<<#n<<"... "; }
|
|
#define P() { std::cout<<"PASS\n"; ++p; }
|
|
#define F(m) { std::cout<<"FAIL: "<<m<<"\n"; ++f; }
|
|
#define C(c,m) if(!(c)){F(m);return;}
|
|
|
|
void t1(){
|
|
T(set_and_get_one_source);
|
|
ws::LSPDiagnosticsAggregator agg;
|
|
ws::Diagnostic d;
|
|
d.uri="file:///a.go"; d.severity=1; d.message="undefined: x"; d.source="gopls";
|
|
agg.set("gopls", "file:///a.go", {d});
|
|
auto diags = agg.get("file:///a.go");
|
|
C(diags.size() == 1, "one diagnostic");
|
|
C(diags[0].message == "undefined: x", "message correct");
|
|
C(diags[0].source == "gopls", "source correct");
|
|
C(agg.get("file:///other.go").empty(), "other uri empty");
|
|
P();
|
|
}
|
|
|
|
void t2(){
|
|
T(get_merges_two_sources);
|
|
ws::LSPDiagnosticsAggregator agg;
|
|
ws::Diagnostic d1; d1.uri="file:///x.ts"; d1.severity=1; d1.message="TS error"; d1.source="tsserver";
|
|
ws::Diagnostic d2; d2.uri="file:///x.ts"; d2.severity=2; d2.message="lint warn"; d2.source="eslint";
|
|
agg.set("tsserver", "file:///x.ts", {d1});
|
|
agg.set("eslint", "file:///x.ts", {d2});
|
|
auto diags = agg.get("file:///x.ts");
|
|
C(diags.size() == 2, "two diagnostics merged");
|
|
C(agg.sourceCount() == 2, "two sources");
|
|
P();
|
|
}
|
|
|
|
void t3(){
|
|
T(clearSource_removes_one_source);
|
|
ws::LSPDiagnosticsAggregator agg;
|
|
ws::Diagnostic d1; d1.uri="file:///b.go"; d1.severity=1; d1.message="E1"; d1.source="gopls";
|
|
ws::Diagnostic d2; d2.uri="file:///b.go"; d2.severity=2; d2.message="W1"; d2.source="staticcheck";
|
|
agg.set("gopls", "file:///b.go", {d1});
|
|
agg.set("staticcheck", "file:///b.go", {d2});
|
|
C(agg.get("file:///b.go").size() == 2, "two before clear");
|
|
agg.clearSource("gopls");
|
|
auto diags = agg.get("file:///b.go");
|
|
C(diags.size() == 1, "one after gopls cleared");
|
|
C(diags[0].source == "staticcheck","remaining is staticcheck");
|
|
P();
|
|
}
|
|
|
|
void t4(){
|
|
T(errorCount_counts_severity_1_only);
|
|
ws::LSPDiagnosticsAggregator agg;
|
|
auto makeD = [](const std::string& uri, int sev, const std::string& src) {
|
|
ws::Diagnostic d; d.uri=uri; d.severity=sev; d.message="msg"; d.source=src; return d;
|
|
};
|
|
agg.set("gopls", "file:///c.go", {
|
|
makeD("file:///c.go", 1, "gopls"),
|
|
makeD("file:///c.go", 1, "gopls"),
|
|
makeD("file:///c.go", 2, "gopls")
|
|
});
|
|
C(agg.errorCount("file:///c.go") == 2, "two errors");
|
|
C(agg.errorCount("file:///missing.go") == 0, "no errors for missing");
|
|
P();
|
|
}
|
|
|
|
void t5(){
|
|
T(urisWithDiagnostics_deduplicated);
|
|
ws::LSPDiagnosticsAggregator agg;
|
|
ws::Diagnostic d1; d1.uri="file:///p.go"; d1.severity=1; d1.message="E"; d1.source="gopls";
|
|
ws::Diagnostic d2; d2.uri="file:///q.ts"; d2.severity=2; d2.message="W"; d2.source="tsserver";
|
|
ws::Diagnostic d3; d3.uri="file:///p.go"; d3.severity=2; d3.message="W2"; d3.source="tsserver";
|
|
agg.set("gopls", "file:///p.go", {d1});
|
|
agg.set("tsserver","file:///q.ts", {d2});
|
|
agg.set("tsserver","file:///p.go", {d3});
|
|
auto uris = agg.urisWithDiagnostics();
|
|
C(uris.size() == 2, "two distinct uris");
|
|
// clearAll
|
|
agg.clearAll();
|
|
C(agg.urisWithDiagnostics().empty(), "empty after clearAll");
|
|
P();
|
|
}
|
|
|
|
int main(){
|
|
std::cout << "Step 1914: LSPDiagnosticsAggregator\n";
|
|
t1(); t2(); t3(); t4(); t5();
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
|
return f > 0 ? 1 : 0;
|
|
}
|