feat(lsp): pull diagnostics, include links and folding ranges

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-08-30 21:42:12 +02:00
parent 41b387e54d
commit b4da13d0f6
6 changed files with 239 additions and 22 deletions
+78
View File
@@ -493,3 +493,81 @@ func mustResult(t *testing.T, m *rpcMessage) []byte {
}
return b
}
func TestPullDiagnostics(t *testing.T) {
in := session("file:///f_amd64.s", badDoc) +
frame(20, "textDocument/diagnostic", map[string]any{
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
}) + frame(nil, "exit", nil)
msgs := run(t, in)
resp := findByID(msgs, 20)
if resp == nil {
t.Fatal("no diagnostic response")
}
var report documentDiagnosticReport
if err := json.Unmarshal(mustResult(t, resp), &report); err != nil {
t.Fatal(err)
}
if report.Kind != "full" {
t.Errorf("report kind = %q, want full", report.Kind)
}
found := false
for _, d := range report.Items {
if d.Code == "unknown-instruction" {
found = true
}
}
if !found {
t.Errorf("want an unknown-instruction diagnostic, got %+v", report.Items)
}
}
func TestDocumentLinks(t *testing.T) {
in := session("file:///f_amd64.s", cleanDoc) +
frame(21, "textDocument/documentLink", map[string]any{
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
}) + frame(nil, "exit", nil)
msgs := run(t, in)
resp := findByID(msgs, 21)
if resp == nil {
t.Fatal("no documentLink response")
}
var links []DocumentLink
if err := json.Unmarshal(mustResult(t, resp), &links); err != nil {
t.Fatal(err)
}
if len(links) != 1 {
t.Fatalf("want 1 document link, got %d", len(links))
}
if !strings.HasSuffix(links[0].Target, "pkg/include/textflag.h") {
t.Errorf("link target = %q, want the GOROOT pkg/include header", links[0].Target)
}
if links[0].Range.Start.Line != 0 || links[0].Range.Start.Character != 9 {
t.Errorf("link range start = %+v, want line 0 character 9", links[0].Range.Start)
}
}
func TestFoldingRanges(t *testing.T) {
in := session("file:///f_amd64.s", cleanDoc) +
frame(22, "textDocument/foldingRange", map[string]any{
"textDocument": map[string]any{"uri": "file:///f_amd64.s"},
}) + frame(nil, "exit", nil)
msgs := run(t, in)
resp := findByID(msgs, 22)
if resp == nil {
t.Fatal("no foldingRange response")
}
var ranges []FoldingRange
if err := json.Unmarshal(mustResult(t, resp), &ranges); err != nil {
t.Fatal(err)
}
if len(ranges) != 1 {
t.Fatalf("want 1 folding range, got %d", len(ranges))
}
if ranges[0].StartLine != 1 || ranges[0].EndLine != 5 {
t.Errorf("folding range = %d-%d, want 1-5", ranges[0].StartLine, ranges[0].EndLine)
}
if ranges[0].Kind != "region" {
t.Errorf("folding kind = %q, want region", ranges[0].Kind)
}
}