kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/typescript/kythe.ts (about)

     1  /*
     2   * Copyright 2017 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  /**
    18   * @fileoverview TypeScript types and values of the Kythe schema.
    19   */
    20  
    21  /**
    22   * A VName (Vector Name) for a node in the Kythe schema consists of:
    23   *  - `signature`: a unique, opaque signature for a node
    24   *  - `corpus`: a collection of related files the node is defined in
    25   *  - `root`: a label denoting a distinct subset of the corpus
    26   *  - `path`: the relative path of the file containing the node
    27   *  - `language`: programming language the node belongs to
    28   */
    29  export interface VName {
    30    signature: string;
    31    corpus: string;
    32    root: string;
    33    path: string;
    34    language: string;
    35  }
    36  
    37  /**
    38   * Kythe edge kinds. See
    39   *   https://kythe.io/docs/schema/#_edge_kinds
    40   *   https://github.com/kythe/kythe/tree/master/kythe/data/schema_index.textproto#L17
    41   */
    42  export enum EdgeKind {
    43    ALIASES = '/kythe/edge/aliases',
    44    ALIASES_ROOT = '/kythe/edge/aliases/root',
    45    ANNOTATED_BY = '/kythe/edge/annotatedby',
    46    BOUNDED_LOWER = '/kythe/edge/bounded/lower',
    47    BOUNDED_UPPER = '/kythe/edge/bounded/upper',
    48    CHILD_OF = '/kythe/edge/childof',
    49    CHILD_OF_CONTEXT = '/kythe/edge/childof/context',
    50    DEFINES = '/kythe/edge/defines',
    51    DEFINES_BINDING = '/kythe/edge/defines/binding',
    52    DEFINES_IMPLICIT = '/kythe/edge/defines/implicit',
    53    DEPENDS = '/kythe/edge/depends',
    54    DOCUMENTS = '/kythe/edge/documents',
    55    EXPORTS = '/kythe/edge/exports',
    56    EXTENDS = '/kythe/edge/extends',
    57    GENERATES = '/kythe/edge/generates',
    58    INFLUENCES = '/kythe/edge/influences',
    59    INSTANTIATES = '/kythe/edge/instantiates',
    60    INSTANTIATES_SPECULATIVE = '/kythe/edge/instantiates/speculative',
    61    IMPUTES = '/kythe/edge/imputes',
    62    NAMED = '/kythe/edge/named',
    63    OVERRIDES = '/kythe/edge/overrides',
    64    OVERRIDES_ROOT = '/kythe/edge/overrides/root',
    65    OVERRIDES_TRANSITIVE = '/kythe/edge/overrides/transitive',
    66    PARAM = '/kythe/edge/param',
    67    PROPERTY_READS = '/kythe/edge/property/reads',
    68    PROPERTY_WRITES = '/kythe/edge/property/writes',
    69    REF = '/kythe/edge/ref',
    70    REF_IMPLICIT = '/kythe/edge/ref/implicit',
    71    REF_CALL = '/kythe/edge/ref/call',
    72    REF_CALL_IMPLICIT = '/kythe/edge/ref/call/implicit',
    73    REF_DOC = '/kythe/edge/ref/doc',
    74    REF_EXPANDS = '/kythe/edge/ref/expands',
    75    REF_EXPANDS_TRANSITIVE = '/kythe/edge/ref/expands/transitive',
    76    REF_FILE = '/kythe/edge/ref/file',
    77    REF_IMPORTS = '/kythe/edge/ref/imports',
    78    REF_ID = '/kythe/edge/ref/id',
    79    REF_INCLUDES = '/kythe/edge/ref/includes',
    80    REF_INIT = '/kythe/edge/ref/init',
    81    REF_INIT_IMPLICIT = '/kythe/edge/ref/init/implicit',
    82    REF_QUERIES = '/kythe/edge/ref/queries',
    83    REF_WRITES = '/kythe/edge/ref/writes',
    84    SATISFIES = '/kythe/edge/satisfies',
    85    SPECIALIZES = '/kythe/edge/specializes',
    86    SPECIALIZES_SPECULATIVE = '/kythe/edge/specializes/speculative',
    87    TAGGED = '/kythe/edge/tagged',
    88    TPARAM = '/kythe/edge/tparam',
    89    TYPED = '/kythe/edge/typed',
    90    UNDEFINES = '/kythe/edge/undefines',
    91  }
    92  
    93  /**
    94   * A Kythe ordinal edge has the form of
    95   *   `${EdgeKind}.${number}`
    96   * This is represented as a branded string that is incompatible with a string
    97   * but can be compared to a string.
    98   */
    99  export type OrdinalEdge = string&{
   100    __ordinalBrand: 'ordinal';
   101  };
   102  export function makeOrdinalEdge(edge: EdgeKind, ordinal: number): OrdinalEdge {
   103    const ordinalEdge = `${edge}.${ordinal}`;
   104    return ordinalEdge as OrdinalEdge;
   105  }
   106  
   107  /**
   108   * Kythe node kinds. See
   109   *   https://kythe.io/docs/schema/#_node_kinds
   110   *   https://github.com/kythe/kythe/tree/master/kythe/data/schema_index.textproto#L64
   111   */
   112  export enum NodeKind {
   113    ANCHOR = 'anchor',
   114    CONSTANT = 'constant',
   115    DIAGNOSTIC = 'diagnostic',
   116    DOC = 'doc',
   117    FILE = 'file',
   118    INTERFACE = 'interface',
   119    FUNCTION = 'function',
   120    LOOKUP = 'lookup',
   121    MACRO = 'macro',
   122    META = 'meta',
   123    NAME = 'name',
   124    PACKAGE = 'package',
   125    PROCESS = 'process',
   126    RECORD = 'record',
   127    SUM = 'sum',
   128    SYMBOL = 'symbol',
   129    TALIAS = 'talias',
   130    TAPP = 'tapp',
   131    TBUILTIN = 'tbuiltin',
   132    TNOMINAL = 'tnominal',
   133    TSIGMA = 'tsigma',
   134    TVAR = 'tvar',
   135    VARIABLE = 'variable',
   136    VCS = 'vcs',
   137  }
   138  
   139  /**
   140   * Kythe fact names. See
   141   *   https://github.com/kythe/kythe/tree/master/kythe/data/schema_index.textproto#L92
   142   */
   143  export enum FactName {
   144    BUILD_CONFIG = '/kythe/build/config',
   145    CODE_JSON = '/kythe/code/json',
   146    COMPLETE = '/kythe/complete',
   147    CONTEXT_URL = '/kythe/context/url',
   148    DETAILS = '/kythe/details',
   149    DOC_URI = '/kythe/doc/uri',
   150    LABEL = '/kythe/label',
   151    LOC_END = '/kythe/loc/end',
   152    LOC_START = '/kythe/loc/start',
   153    MESSAGE = '/kythe/message',
   154    NODE_KIND = '/kythe/node/kind',
   155    PARAM_DEFAULT = '/kythe/param/default',
   156    RULE_CLASS = '/kythe/ruleclass',
   157    SEMANTIC_GENERATED = '/kythe/semantic/generated',
   158    SNIPPET_END = '/kythe/snippet/end',
   159    SNIPPET_START = '/kythe/snippet/start',
   160    SUBKIND = '/kythe/subkind',
   161    TAG_DEPRECATED = '/kythe/tag/deprecated',
   162    TEXT = '/kythe/text',
   163    TEXT_ENCODING = '/kythe/text/encoding',
   164    VISIBILITY = '/kythe/visibility',
   165    // TypeScript indexer-specific fact names
   166    TAG_STATIC = '/kythe/tag/static',
   167  }
   168  
   169  /**
   170   * Kythe fact subkinds. See
   171   *   https://github.com/kythe/kythe/tree/master/kythe/data/schema_index.textproto#L115
   172   */
   173  export enum Subkind {
   174    CATEGORY = 'category',
   175    CLASS = 'class',
   176    CONSTRUCTOR = 'constructor',
   177    DESTRUCTOR = 'destructor',
   178    ENUM = 'enum',
   179    ENUM_CLASS = 'enumClass',
   180    FIELD = 'field',
   181    IMPLICIT = 'implicit',
   182    IMPORT = 'import',
   183    INITIALIZER = 'initializer',
   184    LOCAL = 'local',
   185    LOCAL_PARAMETER = 'local/parameter',
   186    METHOD = 'method',
   187    NAMESPACE = 'namespace',
   188    STRUCT = 'struct',
   189    TYPE = 'type',
   190    UNION = 'union',
   191  }
   192  
   193  /**
   194   * An Entry in the Kythe schema is either a Fact or an Edge that describes at
   195   * least one node.
   196   */
   197  export interface Entry {
   198    source: VName;
   199    label: string;
   200  }
   201  
   202  /**
   203   * A Fact is an Entry that also has a fact `value`.
   204   */
   205  export interface Fact extends Entry {
   206    value: string;
   207  }
   208  
   209  /**
   210   * An Edge is an Entry that also has a `target` and an edge `kind`.
   211   */
   212  export interface Edge extends Entry {
   213    target: VName;
   214    kind: string;
   215  }
   216  
   217  /**
   218   * A Kythe fact expressed in the schema JSON-style encoding.
   219   */
   220  export interface JSONFact {
   221    source: VName;
   222    fact_name: FactName;
   223    fact_value: string;
   224  }
   225  
   226  /**
   227   * A Kythe edge expressed in the schema JSON-style encoding.
   228   */
   229  export interface JSONEdge {
   230    source: VName;
   231    target: VName;
   232    edge_kind: EdgeKind|OrdinalEdge;
   233    fact_name: '/';
   234  }
   235  
   236  /*
   237   * Kythe marked source Linkd expressed in the schema JSON-style encoding.
   238   */
   239  export interface JSONLink {
   240    definition: string[];
   241  }
   242  
   243  /*
   244   * Enum corresponding to Kythe MarkedSource.Kind proto enum.
   245   */
   246  export enum MarkedSourceKind {
   247    BOX,
   248    TYPE,
   249    PARAMETER,
   250    IDENTIFIER,
   251    CONTEXT,
   252    INITIALIZER,
   253    PARAMETER_LOOKUP_BY_PARAM,
   254    LOOKUP_BY_PARAM,
   255    PARAMETER_LOOKUP_BY_PARAM_WITH_DEFAULTS,
   256    LOOKUP_BY_TYPED,
   257    PARAMETER_LOOKUP_BY_TPARAM,
   258    LOOKUP_BY_TPARAM,
   259    MODIFIER,
   260  }
   261  
   262  
   263  /*
   264   * Kythe MarkedSource expressed in the schema JSON-style encoding.
   265   */
   266  export interface JSONMarkedSource {
   267    kind: MarkedSourceKind;
   268    pre_text?: string;
   269    child?: JSONMarkedSource[];
   270    post_child_text?: string;
   271    post_text?: string;
   272    lookup_index?: number;
   273    default_children_count?: number;
   274    add_final_list_token?: boolean;
   275    link?: JSONLink[];
   276  }