diff --git a/internal/backend/backend.go b/internal/backend/backend.go index 8ae281e..8ba6399 100644 --- a/internal/backend/backend.go +++ b/internal/backend/backend.go @@ -473,8 +473,12 @@ func (s *Service) invoke(params json.RawMessage, call *lithe.Context) (any, erro } } } - if locations == nil { - locations = []json.RawMessage{} + // Core accepts a reveal only with 1 to 100 locations; no target means no reveal. + if len(locations) == 0 { + return map[string]any{}, nil + } + if len(locations) > maxRevealLocations { + locations = locations[:maxRevealLocations] } return map[string]any{ "reveal": map[string]any{ @@ -483,6 +487,9 @@ func (s *Service) invoke(params json.RawMessage, call *lithe.Context) (any, erro }, nil } +// maxRevealLocations is the most locations Core accepts in one editor-action reveal. +const maxRevealLocations = 100 + func lsRequest(host *lithe.Host, ref lithe.WorkspaceContext, method string, params any, timeoutMs int) (json.RawMessage, error) { raw, err := host.Request(methodLanguageServerReq, map[string]any{ "context": ref, diff --git a/internal/backend/backend_test.go b/internal/backend/backend_test.go index aad348a..900a5a1 100644 --- a/internal/backend/backend_test.go +++ b/internal/backend/backend_test.go @@ -348,6 +348,51 @@ func TestBackendRegistrationCollectAndInvokeWithQuietLogging(t *testing.T) { t.Fatalf("expected operationFinished INFO log for invoke: %+v", invokeLogs) } + // No target: the answer carries no reveal, because Core rejects an empty one. + // Too many targets: the reveal keeps Core's limit of 100. + for i, tc := range []struct { + count int + want int + }{{0, 0}, {150, maxRevealLocations}} { + id := float64(12 + i) + m.request(id, "lithe/function/invoke", map[string]any{ + "functionID": InvokeFunctionID, + "operationID": fmt.Sprintf("op-invoke-limit-%d", i), + "context": ctxRef, + "params": map[string]any{"data": invokeSpec["params"]}, + }) + resp, _ := m.runUntil( + func(f map[string]any) bool { return f["id"] == id }, + func(method string, params map[string]any) any { + if method != "lithe/host/languageServer/request" { + return map[string]any{} + } + value := []any{} + for j := 0; j < tc.count; j++ { + value = append(value, map[string]any{ + "uri": fmt.Sprintf("file:///workspace/lite/src/Impl%d.java", j), + "range": map[string]any{ + "start": map[string]any{"line": 0, "character": 0}, + "end": map[string]any{"line": 0, "character": 1}, + }, + }) + } + return map[string]any{"value": value} + }, + ) + result := mapField(resp, "result") + if tc.want == 0 { + if _, ok := result["reveal"]; ok { + t.Fatalf("empty navigation must omit reveal: %+v", resp) + } + continue + } + got, _ := mapField(result, "reveal")["locations"].([]any) + if len(got) != tc.want { + t.Fatalf("reveal locations = %d, want %d", len(got), tc.want) + } + } + m.request(99, "shutdown", nil) m.runUntil(func(f map[string]any) bool { return f["id"] == float64(99) }, func(string, map[string]any) any { return map[string]any{}