# Copyright (c) Meta Platforms, Inc. and affiliates. schema codemarkup.buck.2 { import src import buck.4 import code.buck import codemarkup.types # # Resolving locations to entities # predicate BuckResolveLocation: { location: codemarkup.types.Location, entity: code.buck.Entity, } { { Name, File, { span = Span }, nothing }, Entity } where buck.FileEntity { File, BuckEntity }; ( BuckEntity = { locator = Locator} : buck.XRefDestination; buck.TargetLocation { Locator, File, Span }; Locator = buck.Locator { name = Name }; Entity = { locator = Locator } : code.buck.Entity; ) | ( BuckEntity = { definition = Definition} : buck.XRefDestination ; buck.DefinitionLocation { Definition, File, Span }; Definition = buck.Definition { name = Name }; Entity = { definition = Definition } : code.buck.Entity; ) | ( { File, Span } : buck.SourceFileLocation ; src.File Name = File; Entity = { file = File } : code.buck.Entity; ) # # Finding entities' locations # predicate BuckEntityLocation: { entity: code.buck.Entity, location: codemarkup.types.Location, } { Entity, { Name, File, { span = Span }, nothing } } where ( buck.TargetLocation { L, File, Span }; { name = Name } = L; { locator = L } = Entity ) | ( buck.DefinitionLocation { D, File, Span }; { name = Name } = D; { definition = D } = Entity ) | ( buck.SourceFileLocation { File, Span }; src.File Name = File; { file = File } = Entity ) # # Finding references in a file # predicate BuckFileEntityXRefLocations: { file: src.File, xref: codemarkup.types.XRefLocation, entity: code.buck.Entity, } { File, { Location, { span = SrcSpan } }, Entity } where buck.FileXRefs { File, XRefs }; { XRefDestination, SrcSpans } = XRefs[..]; SrcSpan = SrcSpans[..]; ( { locator = Locator } = XRefDestination; { name = Name } = Locator; buck.TargetLocation { Locator, TargetFile, LocatorSpan }; { Name, TargetFile, { span = LocatorSpan }, nothing } = Location; Entity = { locator = Locator } : code.buck.Entity; ) | ( { definition = Definition } = XRefDestination; { name = Name } = Definition ; buck.DefinitionLocation { Definition, DefinitionFile, DefinitionSpan }; { Name, DefinitionFile, { span = DefinitionSpan }, nothing } = Location; Entity = { definition = Definition } : code.buck.Entity; ) | ( { file = SrcFile } = XRefDestination; SrcFile = src.File Name; # we always refer to the beginning of the file { Name, SrcFile, { range = {SrcFile, 1, 1, 1, 1} }, nothing } = Location; Entity = { file = SrcFile } : code.buck.Entity; ) # # Language entity uses # predicate BuckEntityUses: { target: code.buck.Entity, file: src.File, span: src.ByteSpan, } { Destination, File, Span } where buck.DestinationUses { Destination, File, Spans }; Span = Spans[..]; # # Kinds. # predicate BuckEntityKind: { entity: code.buck.Entity, kind: codemarkup.types.SymbolKind } { Entity, Kind } where ( { locator = _ } = Entity; Macro = Kind) | ( { file = _ } = Entity; File = Kind) | ( { definition = _ } = Entity; Value = Kind); }