From b403ab37b022951a6be1bd1b6c53df54423291b4 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Tue, 1 Dec 2026 17:03:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(navigation):=20=E6=89=BE=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=9B=AE=E6=A0=87=E6=97=B6=E4=B8=8D=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=A9=BA=E7=9A=84=20reveal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core 只接受 1 到 100 个位置的 reveal。语言服务器没有找到实现或父声明时, 插件原来返回空的 locations,桌面端日志里报 plugins.editorActions.decode。 现在没有目标就不带 reveal,超过 100 个只保留前 100 个。 --- internal/backend/backend.go | 11 ++++++-- internal/backend/backend_test.go | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) 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{}