Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions internal/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
Loading