kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/proto/xref.proto (about) 1 /* 2 * Copyright 2014 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 syntax = "proto3"; 18 19 package kythe.proto; 20 21 option go_package = "kythe.io/kythe/proto/xref_go_proto"; 22 option java_package = "com.google.devtools.kythe.proto"; 23 option java_multiple_files = true; 24 25 import "kythe/proto/common.proto"; 26 27 // This file defines a cross-reference service interface, based on Kythe data. 28 // 29 // Tickets are Kythe URIs (http://www.kythe.io/docs/kythe-uri-spec.html). 30 31 // XRefService provides fast read-only access to Kythe cross-reference 32 // relationships. "Cross-references" generally include non-transitive 33 // (single-step) relations like usage of a declaration, instantiation of a 34 // type, invocation of a function, direct inheritance or overrides, and so 35 // forth. Some transitive relations can be converted into cross-references by 36 // precomputing a flattened representation of a transitive relation. 37 // 38 // Key design principles: 39 // - All requests must be satisfied "quickly", e.g., in time proportional to 40 // the size of the returned set. 41 // 42 // - The client should be able to batch related requests. 43 // 44 // - The client specifies exactly what facts should be returned. 45 // 46 service XRefService { 47 // Decorations returns an index of the nodes and edges associated with a 48 // particular file node. 49 rpc Decorations(DecorationsRequest) returns (DecorationsReply) {} 50 51 // CrossReferences returns the global references, definitions, declarations, 52 // callers, and related nodes of a set of requested nodes. 53 rpc CrossReferences(CrossReferencesRequest) returns (CrossReferencesReply) {} 54 55 // Documentation takes a set of tickets for semantic objects and returns 56 // documentation about them, including generated signatures and 57 // user-provided text. The documentation may refer to tickets for other 58 // nodes in the graph. 59 rpc Documentation(DocumentationRequest) returns (DocumentationReply) {} 60 } 61 62 // A Location represents a single span of zero or more contiguous bytes of a 63 // file or buffer. An empty LOCATION denotes the entirety of the referenced 64 // file or buffer. 65 // 66 message Location { 67 // The ticket of the file this location belongs to. If the location 68 // represents a memory buffer, the ticket should be omitted. 69 string ticket = 1; 70 71 enum Kind { 72 // The entire file; the start and end fields are ignored. 73 FILE = 0; 74 75 // The point or span of file subtended by start and end. 76 SPAN = 1; 77 } 78 79 // What kind of location this is. 80 Kind kind = 2; 81 82 // If kind == SPAN, this is the represented span within the file. 83 common.Span span = 5; 84 85 // A location is _valid_ if 0 ≤ span.start.byte_offset ≤ span.end.byte_offset. 86 // If a valid location has span.start.byte_offset = span.end.byte_offset, it 87 // denotes a single point; otherwise it denotes the half-closed interval 88 // [start.offset, end.offset). 89 // 90 // When kind = FILE, span should be unset or set to zero values. 91 92 reserved 3, 4; 93 } 94 95 // Which types of snippets to return from a given CrossReferences or Decorations 96 // RPC. 97 // TODO(schroederc): extend snippet kinds to be (none, indexer-default, or 98 // always line-based) instead of (none, all). 99 enum SnippetsKind { 100 // Return no snippets. 101 NONE = 0; 102 // Return the default snippet for each item that has one. 103 DEFAULT = 1; 104 } 105 106 message DecorationsRequest { 107 // The location of the file to fetch decorations for. The ticket of location 108 // must be non-empty. It is an error in any case if location is invalid. 109 Location location = 1; 110 111 enum SpanKind { 112 // If the location is a SPAN, only decorations contained within the 113 // specified window of the file are returned. This is the default behavior. 114 WITHIN_SPAN = 0; 115 116 // If the location is a SPAN, any decorations that surround it are returned. 117 AROUND_SPAN = 1; 118 } 119 120 // How to treat SPAN locations. 121 SpanKind span_kind = 10; 122 123 // If dirty_buffer is non-empty, the results will be adjusted (patched) to 124 // account for the regions of the specified file differing from the contents 125 // of the dirty buffer. 126 bytes dirty_buffer = 2; 127 128 // If true, return the encoded source text for the selected window. Source 129 // text is not affected by patching. 130 bool source_text = 3; 131 132 // If true, return reference edges whose source nodes are located in the 133 // selected window. References are affected by patching. 134 bool references = 4; 135 136 // If true, return definition locations, if possible, for each returned 137 // reference target in the DecorationsReply. 138 bool target_definitions = 6; 139 140 // A collection of filter globs that specify which facts (by name) should be 141 // returned for each node. If filter is empty or unset, no node facts are 142 // returned. The filter applies to ALL referenced nodes. See EdgesRequest 143 // (graph.proto) for the format of the filter globs. 144 repeated string filter = 5; 145 146 // If true, for every defines/binding Reference in the reply, a NodeInfo 147 // will be provided for each node that Reference extends or overrides. 148 // Furthermore, if definition_locations is true, the response's 149 // definition_locations field will include (where possible) the locations of 150 // the definitions of the nodes that are extended or overridden. 151 bool extends_overrides = 7; 152 153 // If true, return diagnostics for the given file. 154 bool diagnostics = 8; 155 156 // What kind of snippets to return (or none). 157 SnippetsKind snippets = 9; 158 159 // Set of build configurations with which to filter decorations. If empty, 160 // no filtering based on build configs will be done; all decorations for the 161 // file will be returned. 162 repeated string build_config = 11; 163 164 // Whether to return known semantic scopes per Reference. 165 bool semantic_scopes = 12; 166 167 // The user's Workspace. May be used as a target for patching spans to match 168 // the current state of the referenced files. 169 Workspace workspace = 13; 170 171 // Whether to patch spans against the given Workspace. 172 bool patch_against_workspace = 14; 173 } 174 175 // File represents a whole file 176 message File { 177 kythe.proto.common.CorpusPath corpus_path = 1; 178 179 string revision = 2; 180 } 181 182 message DecorationsReply { 183 // The normalized location for which decorations are returned. 184 Location location = 1; 185 186 // The revision of the corpus containing this file's data. 187 string revision = 18; 188 189 // The encoded source text for the selected window. 190 optional bytes source_text = 2; 191 string encoding = 3; 192 193 // Represents a reference edge source ---KIND---> target. Each source is an 194 // anchor within the requested source location. 195 message Reference { 196 string target_ticket = 2; 197 string kind = 3; 198 199 // Anchor ticket of the target's definition. Populated only if 200 // target_definitions is true in the DecorationsRequest and the target has 201 // a single unambiguous definition. For each ticket, an Anchor will be 202 // populated in the top-level definition_locations map. 203 string target_definition = 4; 204 205 // The reference's span within the source file. 206 common.Span span = 5; 207 208 // The build config of the file containing this reference. 209 string build_config = 6; 210 211 // Ticket of the semantic node with the narrowest scope enclosing the 212 // reference. Populated only if semantic_scopes is true in the 213 // DecorationsRequest. 214 string semantic_scope = 7; 215 216 // The revision of the file being targeted by this reference, may be empty 217 // if targeting a non-file. 218 string target_revision = 8; 219 220 reserved 1, 10, 11; 221 } 222 223 message Override { 224 // What kind of override this is. 225 enum Kind { 226 OVERRIDES = 0; 227 EXTENDS = 1; 228 } 229 230 // The target of the override. 231 string target = 1; 232 // Anchor ticket of the override target's definition. Populated only if 233 // target_definitions is true in the DecorationsRequest and the target has 234 // a single unambiguous definition. For each ticket, an Anchor will be 235 // populated in the top-level definition_locations map. 236 string target_definition = 5; 237 238 // The kind of override. 239 Kind kind = 2; 240 241 // A display name for the object at ticket. 242 kythe.proto.common.MarkedSource marked_source = 4; 243 244 reserved 3; 245 } 246 247 message Overrides { 248 repeated Override override = 1; 249 } 250 251 // The reference edges located in the specified window. Sorted in the order 252 // of their position in the file (first by start offset, then by end offset). 253 repeated Reference reference = 4; 254 255 // If requested, a list of diagnostics applying to the requested file 256 // location. 257 // TODO(schroederc): filter spanning diagnostics by build configuration 258 repeated common.Diagnostic diagnostic = 5; 259 260 // List of files that generate the requested file. 261 repeated File generated_by_file = 19; 262 263 // This field will contain one entry, keyed by ticket, for each distinct node 264 // referenced by a reference edge that has at least 1 non-filtered fact. 265 map<string, common.NodeInfo> nodes = 15; 266 267 // Each anchor cited as a target definition in the references/overrides. The 268 // map is keyed by each anchor's ticket. 269 map<string, Anchor> definition_locations = 16; 270 271 // Maps from semantic nodes on the right-hand side of defines/binding 272 // references to the list of their overrides. 273 map<string, Overrides> extends_overrides = 17; 274 275 // A unique identifier for the underlying dataset serving this reply. 276 string build_id = 20; 277 278 reserved 6; 279 } 280 281 message CrossReferencesRequest { 282 // The tickets of nodes for which to return cross-references. 283 // The server must report an error if this field is empty. 284 // The server may limit the number of tickets per request to ensure an 285 // efficient implementation. 286 repeated string ticket = 1; 287 288 enum DefinitionKind { 289 // No definitions will be populated in the CrossReferencesReply. 290 NO_DEFINITIONS = 0; 291 292 // All known definition anchors reached by the "/kythe/edge/defines" edge 293 // kind (or its variants) will be populated in the CrossReferencesReply. 294 ALL_DEFINITIONS = 1; 295 296 // Only definition anchors reached by the "/kythe/edge/defines" edge kind 297 // will be populated in the CrossReferencesReply. 298 FULL_DEFINITIONS = 2; 299 300 // Only definition anchors reached by the "/kythe/edge/defines/binding" edge 301 // kind will be populated in the CrossReferencesReply. 302 BINDING_DEFINITIONS = 3; 303 } 304 305 // Determines what kind of definition anchors, if any, should be returned in 306 // the response. See the documentation for each DefinitionKind for more 307 // information. 308 DefinitionKind definition_kind = 2; 309 310 enum DeclarationKind { 311 // No declarations will be populated in the CrossDeclarationsReply. 312 NO_DECLARATIONS = 0; 313 // When the source node is incomplete, all known declaration anchors reached 314 // by the "/kythe/edge/defines" edge kind (or its variants) will be 315 // populated in the CrossDeclarationsReply. 316 ALL_DECLARATIONS = 1; 317 } 318 319 // Determines what kind of declaration anchors, if any, should be returned in 320 // the response. See the documentation for each DeclarationKind for more 321 // information. 322 DeclarationKind declaration_kind = 7; 323 324 enum ReferenceKind { 325 // No references will be populated in the CrossReferencesReply. 326 NO_REFERENCES = 0; 327 // Only callgraph-related references as described in 328 // http://www.kythe.io/docs/schema/callgraph.html 329 CALL_REFERENCES = 1; 330 // All references except those that are related to the callgraph. 331 NON_CALL_REFERENCES = 2; 332 // All known reference anchors reached by the "/kythe/edge/ref" edge kind 333 // (or its variants) will be populated in the CrossReferencesReply. 334 ALL_REFERENCES = 3; 335 } 336 337 // Determines what kind of reference anchors, if any, should be returned in 338 // the response. See the documentation for each ReferenceKind for more 339 // information. 340 ReferenceKind reference_kind = 3; 341 342 enum CallerKind { 343 // No callgraph information will be populated in the CrossReferencesReply. 344 NO_CALLERS = 0; 345 // Callgraph information will be populated in the CrossReferencesReply. 346 DIRECT_CALLERS = 1; 347 // Callgraph information will be populated in the CrossReferencesReply. 348 // Calls to override-related functions will also be considered and each 349 // RelatedAnchor will be marked as speculative. 350 OVERRIDE_CALLERS = 2; 351 } 352 353 // Determines what kind of callgraph information, if any, should be returned 354 // in the response. See the documentation for each CallerKind for more 355 // information. 356 CallerKind caller_kind = 12; 357 358 // Whether to include scopes for all references. References with scopes will 359 // appear as the sites of a RelatedAnchor with their semantic scope populating 360 // the anchor/ticket/marked_source fields. If the serving data does not 361 // provide a scope for a reference, the RelatedAnchor will have no sites and 362 // the actual reference will be the primary anchor. 363 bool semantic_scopes = 20; 364 365 // Collection of filter globs that determines which facts will be returned for 366 // the related nodes of each requested node. If filter is empty or unset, no 367 // node facts or related nodes are returned. See EdgesRequest (graph.proto) 368 // for the format of the filter globs. 369 repeated string filter = 5; 370 371 // Determines which relation kinds for RelatedNodes should be returned in the 372 // response. If empty, all known RelatedNodes will be returned that match the 373 // above filter. Otherwise, only RelatedNodes with one of these requested 374 // relation kinds, and matching the above filter, will be returned in the 375 // response. 376 // 377 // Importantly, this is not a list of node kinds; this is a list of edge kinds 378 // (i.e. values for RelatedNode.relation_kind field). 379 // 380 // N.B.: When requesting related nodes, you must also set the filter, 381 // otherwise no data will be returned for the relationships requested. 382 repeated string related_node_kind = 14; 383 384 // Determines whether each Anchor in the response should have its text field 385 // populated. 386 bool anchor_text = 6; 387 388 // Determines whether each NodeInfo matching the above filters will have its 389 // definition location populated (assuming it has one). 390 bool node_definitions = 8; 391 392 enum TotalsQuality { 393 UNSPECIFIED_TOTALS = 0; 394 PRECISE_TOTALS = 1; 395 APPROXIMATE_TOTALS = 2; 396 } 397 // Quality of the aggregated xref totals returned for the requested tickets. 398 // If PRECISE, the totals will be accurate across all requested tickets and 399 // pages. If APPROXIMATE, the totals may be partial/approximate so that the 400 // server can return results as soon as possible. 401 TotalsQuality totals_quality = 16; 402 403 // The cross-references matching a request are organized into logical pages. 404 // The size of each page is a number of distinct cross-references 405 // (definitions, references, documentation, and related nodes). 406 // 407 // If page_token is empty, cross-references will be returned starting at the 408 // beginning of the sequence; otherwise the starting point named by the 409 // page_token will be used. Legal values of page_token are returned by the 410 // server in the next_page_token field of the CrossReferencesReply. A page 411 // token should be treated as an opaque value by the client, and is valid only 412 // relative to a particular CrossReferencesRequest. If an invalid page token 413 // is requested, the server will return an error. 414 // 415 // If page_size > 0, at most that number of cross-references will be returned 416 // by the service for this request (see ReferenceSet and CrossReferencesReply 417 // below). If page_size = 0, the default, the server will assume a reasonable 418 // default page size. The server will return an error if page_size < 0. 419 // 420 // The server is allowed to return fewer cross-references than the requested 421 // page_size, even if more are available, save that it must return at least 1 422 // edge if any are available at all. 423 int32 page_size = 10; 424 string page_token = 11; 425 426 // What kind of snippets to return (or none). 427 SnippetsKind snippets = 13; 428 429 // Set of build configurations with which to filter xrefs. If empty, no 430 // filtering based on build configs will be done; all xrefs for the requested 431 // nodes will be returned. 432 repeated string build_config = 15; 433 434 // The user's Workspace. May be used as a target for patching spans to match 435 // the current state of the referenced files. 436 Workspace workspace = 17; 437 438 // Whether to patch spans against the given Workspace. 439 bool patch_against_workspace = 18; 440 441 // Set of filters to apply to each xref's parent file. 442 CorpusPathFilters corpus_path_filters = 19; 443 444 reserved 4; 445 reserved 100; 446 } 447 448 message CorpusPathFilters { 449 repeated CorpusPathFilter filter = 1; 450 } 451 452 // A filter for CorpusPaths. The filter matches if each component pattern 453 // matches (an empty pattern implies no filtering on that component). 454 message CorpusPathFilter { 455 enum Type { 456 DEFAULT = 0; 457 INCLUDE_ONLY = 1; 458 EXCLUDE = 2; 459 } 460 Type type = 1; 461 462 // Corpus pattern to match against. 463 string corpus = 2; 464 // If true, only use filter if the corpus matches. If false, include corpus 465 // in the normal pattern matching behavior for this filter. 466 bool corpus_specific_filter = 6; 467 // Root pattern to match against. 468 string root = 3; 469 // Path pattern to match against. 470 string path = 4; 471 472 // Fully resolved path pattern to match against. The resolved path is 473 // determined by the server implementation. 474 string resolved_path = 5; 475 } 476 477 // TODO(schroederc): eliminate duplicate serving.ExpandedAnchor message 478 // defintion 479 480 message Anchor { 481 // Ticket of the anchor node 482 string ticket = 1; 483 // Edge kind describing the anchor's relationship with its referenced node 484 string kind = 2; 485 486 // Parent ticket of the anchor; this is the file containing the anchor 487 string parent = 3; 488 489 // Span of the anchor within its parent's text 490 common.Span span = 10; 491 // The anchor's spanning text within the anchor parent's text 492 string text = 6; 493 494 // User-readable snippet of the anchor parent's text at the location of this 495 // anchor 496 string snippet = 7; 497 // Span of the anchor's snippet within its parent's text 498 common.Span snippet_span = 11; 499 500 // The build config of the file containing this anchor. 501 string build_config = 12; 502 503 // The revision of the corpus containing this anchor's parent file data. 504 string revision = 14; 505 506 reserved 4, 5, 8, 9; 507 } 508 509 message Printable { 510 // Raw text that can be displayed to the user (but may also contain 511 // markup that can be interpreted, like Doxygen comments). Links are 512 // marked using []. \ is an escape character (where possible escape 513 // sequences are \[, \], and \\). 514 string raw_text = 1; 515 // Annotations for spans in raw_text. The ith Link corresponds to the span 516 // starting at the ith [. 517 repeated kythe.proto.common.Link link = 2; 518 } 519 520 message CrossReferencesReply { 521 message RelatedNode { 522 // Ticket of the node 523 string ticket = 1; 524 // Edge kind describing the node's relation 525 string relation_kind = 2; 526 // Optional ordinal for edges of the same relation_kind. 527 int32 ordinal = 3; 528 } 529 530 message RelatedAnchor { 531 // The anchor covering the related object. The scope/caller of the sites. 532 Anchor anchor = 1; 533 // A name for the related object. 534 kythe.proto.common.MarkedSource marked_source = 5; 535 // Specific locations, usually within the related object, that caused 536 // the relationship to exist. This field is relevant to caller sets and 537 // scoped references. 538 repeated Anchor site = 3; 539 // The relevant semantic object. Populated for callers and scoped 540 // references. 541 string ticket = 4; 542 543 // Whether the anchor, and its sites, are speculative and may not be precise 544 // with respect to a program's execution. Examples include callsites that 545 // may occur through dynamic dispatch or ref/writes/thunk locations. 546 bool speculative = 6; 547 548 reserved 2; 549 } 550 551 message CrossReferenceSet { 552 string ticket = 1; 553 554 // A name for the given node. 555 kythe.proto.common.MarkedSource marked_source = 8; 556 557 // The set of definitions for the given node. 558 repeated RelatedAnchor definition = 2; 559 // The set of declarations for the given node. 560 repeated RelatedAnchor declaration = 5; 561 // The set of simple references for the given node. 562 repeated RelatedAnchor reference = 3; 563 // The set of callers for the given node. 564 repeated RelatedAnchor caller = 6; 565 566 // The set of related nodes to the given node. 567 repeated RelatedNode related_node = 10; 568 569 reserved 4, 7; 570 } 571 572 message Total { 573 int64 definitions = 1; 574 int64 declarations = 2; 575 int64 references = 3 [deprecated = true]; 576 int64 documentation = 4; 577 int64 callers = 5; 578 579 // Map from ref edge type to count. 580 // 581 // Example 582 // /kythe/edge/ref -> 20, 583 // /kythe/edge/ref/writes -> 50 584 map<string, int64> ref_edge_to_count = 7; 585 map<string, int64> related_nodes_by_relation = 6; 586 } 587 // Total number of cross-references on all pages matching requested kinds, 588 // build configs, and filters. This may be an approximation if allowed by the 589 // CrossReferencesRequest. 590 Total total = 5; 591 592 // Total number of cross-references removed based on the request's 593 // corpus_path_filters. This may be an approximation if allowed by the 594 // CrossReferencesRequest. 595 Total filtered = 12; 596 597 // A map from ticket to cross-references for each ticket specified in the 598 // request message. 599 map<string, CrossReferenceSet> cross_references = 1; 600 601 // A map from ticket to the facts provided based on the requested filters, 602 // for each of the tickets provided in the request and their related nodes. 603 map<string, common.NodeInfo> nodes = 2; 604 605 // A map from the ticket of each definition mentioned in the nodes map, to 606 // its corresponding anchor. This map is only populated if the request set 607 // the node_definitions field true. 608 map<string, Anchor> definition_locations = 3; 609 610 // If there are additional pages of cross-references after the ones returned 611 // in this reply, next_page_token is the page token that may be passed to 612 // fetch the next page in sequence after this one. If there are no further 613 // cross-references, this field will be empty. 614 string next_page_token = 10; 615 616 // A unique identifier for the underlying dataset serving this reply. 617 string build_id = 11; 618 } 619 620 message DocumentationRequest { 621 // Semantic tickets about which documentation is sought. 622 repeated string ticket = 1; 623 624 // A collection of filter globs that specify which facts (by name) should be 625 // returned for each node. If filter is empty or unset, no node facts are 626 // returned. The filter applies to ALL documented and linked nodes. 627 // See EdgesRequest (graph.proto) for the format of the filter globs. 628 repeated string filter = 2; 629 630 // If set, this DocumentationRequest will return documents for the requested 631 // tickets as well as their immediate semantic descendants. 632 bool include_children = 3; 633 634 // The user's Workspace. May be used as a target for patching spans to match 635 // the current state of the referenced files. 636 Workspace workspace = 4; 637 638 // Whether to patch spans against the given Workspace. 639 bool patch_against_workspace = 5; 640 } 641 642 message DocumentationReply { 643 message Document { 644 // The ticket to which this Document refers. 645 string ticket = 1; 646 // Documentation that can be displayed to the user. 647 Printable text = 2; 648 // A structured summary of the (qualified) identity of the documented node. 649 kythe.proto.common.MarkedSource marked_source = 8; 650 651 // The children of this Document. This relationship may be distinct from 652 // the `childof` relationship. 653 repeated Document children = 9; 654 655 reserved 3, 4, 5, 6, 7; 656 } 657 repeated Document document = 1; 658 // The facts left from the requested filters of the documented node facts. 659 map<string, common.NodeInfo> nodes = 2; 660 // Map from the definition anchor tickets referred to in each NodeInfo to 661 // their corresponding Anchor data. 662 map<string, Anchor> definition_locations = 3; 663 664 // A unique identifier for the underlying dataset serving this reply. 665 string build_id = 4; 666 } 667 668 // A Workspace is a pointer to the root of a user's workspace. This is 669 // typically the root of a source repository. 670 message Workspace { 671 // The root of a user workspace encoded as a uri. The uri format is dependent 672 // on the capabilities of the server. 673 string uri = 1; 674 }