Skip to content

Commit 9dc79a8

Browse files
authored
langserver: Extension to limit returned references (sourcegraph#106)
1 parent 9e81305 commit 9dc79a8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

langserver/references.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ func (h *LangHandler) handleTextDocumentReferences(ctx context.Context, conn JSO
164164

165165
locs := goRangesToLSPLocations(fset, refs)
166166
sortBySharedDirWithURI(params.TextDocument.URI, locs)
167+
168+
// Technically we may be able to stop computing references sooner and
169+
// save RAM/CPU, but currently that would have two drawbacks:
170+
// * We can't stop the typechecking anyways
171+
// * We may return results that are not as interesting since sortBySharedDirWithURI won't see everything.
172+
if params.Context.XLimit > 0 && params.Context.XLimit < len(locs) {
173+
locs = locs[:params.Context.XLimit]
174+
}
175+
167176
return locs, nil
168177
}
169178

pkg/lsp/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ type ParameterInformation struct {
156156

157157
type ReferenceContext struct {
158158
IncludeDeclaration bool `json:"includeDeclaration"`
159+
160+
// Sourcegraph extension
161+
XLimit int `json:"xlimit,omitempty"`
159162
}
160163

161164
type ReferenceParams struct {

0 commit comments

Comments
 (0)