Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 1949594

Browse files
Address feedback abotu optionality, add comments, introduce doc API, more tweaks
1 parent 203e505 commit 1949594

File tree

2 files changed

+244
-35
lines changed

2 files changed

+244
-35
lines changed

cmd/frontend/graphqlbackend/codeintel.codenav.graphql

Lines changed: 214 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,103 @@ extend type GitBlob {
4747
Experimental: This API is likely to change in the future.
4848
"""
4949
symbolInfo(line: Int!, character: Int!): SymbolInfo
50+
51+
"""
52+
If filter.provenance? is not provided, then the API will go through
53+
each provenance one by one in the order Precise -> Syntactic -> SearchBased
54+
and stop when some data is available.
55+
"""
56+
codeGraphData(filter: CodeGraphDataFilter): CodeGraphData
57+
}
58+
59+
input CodeGraphDataFilter {
60+
provenance: ProvenanceComparator
61+
}
62+
63+
"""
64+
Invariants:
65+
1. forall sym in symbols.
66+
(sym.provenance, sym.dataSource) == (scipDocument.provenance, scipDocument.dataSource)
67+
"""
68+
# Implementation notes:
69+
# 1. For precise code nav, we already have a code for inferring
70+
# 'visible uploads' using the commit graph machinery -> infer best upload
71+
# -> get document for that using the given path.
72+
# 2. Syntactic will be similar to precise
73+
# 3. Search-based -> return empty document/lists.
74+
#
75+
# Ref panel logic:
76+
# 1. Request code graph data, specifying 'filter' if needed.
77+
# Either the scipDocument or occurrences is fine.
78+
# 2. When a hover is triggered, attempt to look up occurrence in document or list
79+
# or some other lookup structure constructed from those.
80+
# 3a. If one matching occurrence is found, use symbolName + range to call
81+
# usagesForSymbol
82+
# 3b. If zero matching occurrences are found, use only range to call usagesForSymbol.
83+
# 3c. If more than one matching occurrence is found, use some more complex logic
84+
# to offer a symbol picker.
85+
# - Problem: For a symbol picker, ideally you'd use SymbolInformation.display_name,
86+
# which is stored on SymbolInformation. However, display_name is not supported
87+
# today by most SCIP indexers. And we don't have any API for getting the detailed
88+
# SCIP SymbolInformation for a bunch of occurrences.
89+
type CodeGraphData {
90+
scipDocument: AssociatedSCIPDocument
91+
92+
"""
93+
List of symbols with definitions in this document.
94+
95+
Invariant:
96+
forall sym in symbols.
97+
exists occ in occurrences such that
98+
sym.name == occ.symbolName && occ.roles.contains(Definition)
99+
"""
100+
# TODO: Should this be paginated to gracefully handle large generated files?
101+
symbols: [SymbolInformation!]
102+
103+
"""
104+
Occurrences are guaranteed to be sorted by range.
105+
"""
106+
# TODO: Should this be paginated to gracefully handle large generated files?
107+
occurrences(filter: OccurrencesFilter): [Occurrence!]
108+
}
109+
110+
type Occurrence {
111+
symbolName: String
112+
range: Range!
113+
roles: [SymbolRole!]
114+
# We can add diagnostics etc. here in the future if needed.
115+
}
116+
117+
input OccurrencesFilter {
118+
rangeFilter: RangeFilter
119+
rolesFilter: RolesFilter
120+
# We can add a DiagnosticsFilter etc. here in the future if needed.
121+
}
122+
123+
input RangeFilter {
124+
"""
125+
Zero-based line number, inclusive.
126+
"""
127+
startLine: Int
128+
"""
129+
Zero-based line number, inclusive.
130+
"""
131+
endLine: Int
132+
}
133+
134+
input RolesFilter {
135+
or: [RolesFilter!]
136+
equals: SymbolRole
137+
}
138+
139+
enum SymbolRole {
140+
Definition,
141+
Reference,
142+
"""
143+
Applicable for forward declarations in languages with header files (C, C++ etc.)
144+
as well as standalone signatures in languages with separate interface files (OCaml etc.).
145+
"""
146+
ForwardDefinition,
50147
}
51148

52149
"""
@@ -93,6 +190,8 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
93190

94191
"""
95192
A list of definitions of the symbol under the given document position.
193+
194+
DEPRECATED: Use usagesForSymbol with a Definition filter instead.
96195
"""
97196
definitions(
98197
"""
@@ -105,21 +204,6 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
105204
"""
106205
character: Int!
107206

108-
"""
109-
When specified, indicates that this request should be paginated and
110-
to fetch results starting at this cursor.
111-
A future request can be made for more results by passing in the
112-
'LocationConnection.pageInfo.endCursor' that is returned.
113-
"""
114-
after: String
115-
116-
"""
117-
When specified, indicates that this request should be paginated and
118-
the first N results (relative to the cursor) should be returned. i.e.
119-
how many results to return per page.
120-
"""
121-
first: Int
122-
123207
"""
124208
When specified, it filters references by filename.
125209
"""
@@ -128,6 +212,8 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
128212

129213
"""
130214
A list of references of the symbol under the given document position.
215+
216+
DEPRECATED: Use usagesForSymbol with a Reference filter instead.
131217
"""
132218
references(
133219
"""
@@ -163,6 +249,8 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
163249

164250
"""
165251
A list of implementations of the symbol under the given document position.
252+
253+
DEPRECATED: Use usagesForSymbol with Implementations filter instead.
166254
"""
167255
implementations(
168256
"""
@@ -198,6 +286,8 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
198286

199287
"""
200288
A list of prototypes of the symbol under the given document position.
289+
290+
DEPRECATED: Use usagesForSymbol with a Supers filter instead.
201291
"""
202292
prototypes(
203293
"""
@@ -263,44 +353,114 @@ type GitBlobLSIFData implements TreeEntryLSIFData {
263353
}
264354

265355
extend type Query {
356+
"""
357+
Identify usages for either a semantic symbol, or the symbol(s) implied
358+
by a source range.
359+
360+
Ordering and uniqueness guarantees:
361+
1. The usages returned will already be de-duplicated.
362+
2. Results for a single file are contiguous.
363+
3. Results for a single repository are contiguous.
364+
365+
Related: See `codeGraphData` on GitBlob.
366+
"""
266367
usagesForSymbol(
267-
symbol: LookupSCIPSymbol,
268368
"""
269-
Non-optional due to implementation limitations
369+
Symbol to perform the lookup for.
370+
371+
If provided, then the start and end position in 'range' are optional.
372+
373+
If not provided, then the start and end position in 'range' must be set.
374+
In that case, the results will be merged across all semantic symbols
375+
in the source range specified by [start, end]
376+
"""
377+
symbol: SymbolComparator,
378+
"""
379+
Information about an existing source range for a usage of the symbol.
380+
381+
TODO: Specify behavior for various cases of overlap between LookupRange
382+
and actual occurrence range.
270383
"""
271384
range: LookupRange!,
385+
272386
filter: UsagesFilter,
273-
first: Int,
274-
after: String,
387+
388+
"""
389+
When specified, indicates that this request should be paginated and
390+
the first N results (relative to the cursor) should be returned. i.e.
391+
how many results to return per page.
392+
"""
393+
first: Int
394+
395+
"""
396+
When specified, indicates that this request should be paginated and
397+
to fetch results starting at this cursor.
398+
A future request can be made for more results by passing in the
399+
'UsageConnection.pageInfo.endCursor' that is returned.
400+
"""
401+
after: String
275402
): UsageConnection!
276403
}
277404

278-
input LookupSCIPSymbol {
405+
input SymbolComparator {
279406
name: SymbolNameComparator!
280407
provenance: ProvenanceComparator!
281408
}
282409

283-
"""
284-
In the future, we may want to extend this to allow passing in a suffix or a "symbol pattern".
285-
"""
410+
# Implementation note: In the future, we may want to extend this
411+
# to allow passing in a suffix or a "symbol pattern".
412+
# See https://github.com/sourcegraph/sourcegraph/issues/59957
286413
input SymbolNameComparator {
287-
eq: String
414+
equals: String
288415
}
289416

290417
input ProvenanceComparator {
291-
eq: Provenance
418+
equals: Provenance
292419
}
293420

294-
type SCIPSymbol {
421+
type SymbolInformation implements WithProvenance {
422+
"""
423+
Symbol name using syntax specified by the SCIP schema.
424+
https://github.com/sourcegraph/scip/blob/main/scip.proto#L147-L188
425+
426+
This value will generally be used in conjunction with
427+
the `usagesBySymbol` API.
428+
"""
295429
name: String!
430+
"""
431+
Hover documentation for the symbol, in Markdown format.
432+
433+
The caller must take care to escape any particular strings,
434+
such as raw HTML, as necessary.
435+
436+
The value is null when the hover documentation is not found
437+
by 'dataSource'.
438+
439+
The value is empty when `dataSource` is confident that there
440+
is no appropriate hover documentation to display.
441+
"""
442+
documentation: [String!]
443+
"""
444+
Coarse-grained information about the data source.
445+
"""
296446
provenance: Provenance!
447+
"""
448+
Opaque fine-grained information describing the data source.
449+
450+
Provided only for debugging.
451+
452+
This field should be ignored when checking structural equality.
453+
"""
454+
dataSource: String
297455
}
298456

299457
input LookupRange {
300458
"""
301459
Defaults to instance-wide search if the repo is not specified.
302460
303-
This field is non-optional due to implementation limitations.
461+
This field is necessary if LookupSymbol is a repository-local or
462+
file-local symbol. It is mandatory for cross-repo symbols
463+
due to implementation limitations.
304464
"""
305465
repo: String!
306466
"""
@@ -310,28 +470,40 @@ input LookupRange {
310470
"""
311471
Defaults to repo-wide search if the path is not specified.
312472
313-
This field is non-optional due to implementation limitations.
473+
This field is necessary if LookupSymbol is a file-local symbol.
474+
It is mandatory for repository-local and cross-repo symbols
475+
due to implementation limitations.
314476
"""
315477
path: String!
316478
start: LookupPosition
317479
end: LookupPosition
318480
}
319481

320482
input LookupPosition {
483+
"""
484+
Zero-based count of newline (\n or \r\n) characters before this position.
485+
"""
321486
line: Int!
487+
"""
488+
Zero-based UTF-16 code unit offset from preceding newline (\n or \r\n) character.
489+
"""
322490
character: Int!
323491
}
324492

493+
"""
494+
An empty filter allows all kinds of usages for all paths in all repositories.
495+
496+
However, if the symbol used for lookup is a file-local symbol or a
497+
repository-local symbol, then usages will automatically be limited to the
498+
same file or same repository respectively.
499+
"""
325500
input UsagesFilter {
326501
and: [UsagesFilter!]
327502
or: [UsagesFilter!]
328503
not: UsagesFilter
329504
repository: RepositoryFilter
330505
path: PathFilter
331506
kind: SymbolUsageKind
332-
# TODO: Provide a way of controlling fallback behavior for indexes?
333-
# Not super sure how that would work, given that for different repositories,
334-
# the hashes will all be different?
335507
}
336508

337509
input RepositoryFilter {
@@ -343,7 +515,7 @@ input PathFilter {
343515
}
344516

345517
input StringComparator {
346-
eq: String
518+
equals: String
347519
}
348520

349521
enum SymbolUsageKind {
@@ -358,8 +530,17 @@ type UsageConnection {
358530
pageInfo: PageInfo!
359531
}
360532

533+
type UsageRange {
534+
repo: String!
535+
revision: String!
536+
range: Range!
537+
}
538+
361539
type Usage {
362-
symbol: SCIPSymbol!
540+
symbol: SymbolInformation!
541+
542+
range: UsageRange
543+
363544
"""
364545
NOTE: Do not pass
365546
TODO: For this blob, it is generally more useful to get +N/-N lines

0 commit comments

Comments
 (0)