-
Notifications
You must be signed in to change notification settings - Fork 44
/
scip.angle
282 lines (249 loc) · 7.05 KB
/
scip.angle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# Copyright (c) Meta, Inc. and affiliates.
schema scip.1 {
import src
import lsif.types.1
# scip.proto:ProtocolVersion
type ProtocolVersion = enum {
UnspecifiedProtocolVersion
}
# Text encoding of the source files on disk that are referenced from
# `Document.relative_path`.
type TextEncoding = enum { UnspecifiedTextEncoding | UTF8 | UTF16 }
# scip.proto:Metadata
predicate Metadata:
{
version: ProtocolVersion,
toolInfo: maybe lsif.types.ToolInfo,
projectRoot: string,
textEncoding: TextEncoding,
}
# Track SCIP file language
predicate FileLanguage:
{
file: src.File,
language: lsif.types.LanguageId
}
# Occurences in files
predicate FileRange:
{
file: src.File,
range: lsif.types.RangeSpan,
}
# Global (non-local) symbols in SCIP. Globally unique identifiers.
# Distinct from local (anonymous) variables
#
# These are similar in intent to qualified names in Python, or
# symbol ids in Glass.
#
predicate Symbol: string
# Definition occurences
predicate Definition:
{
symbol: Symbol,
location: FileRange
}
# derive index from locations to definitions
predicate DefinitionLocation:
{
file : src.File,
range : lsif.types.RangeSpan,
defn : Definition
} stored { File, Range, Defn } where
Defn = scip.Definition { location = FileRange };
scip.FileRange { File, Range } = FileRange;
# Uses (xref occurences)
predicate Reference:
{
symbol: Symbol,
location: FileRange
}
predicate ReferenceLocation:
{
file : src.File,
range : lsif.types.RangeSpan,
xref : Reference,
} stored { File, Range, Use } where
Use = scip.Reference { location = FileRange };
scip.FileRange { File, Range } = FileRange;
# where we know the definition target of a free xref
# don't think we even need to store these?
predicate ReferenceTarget:
{
xref: Reference,
target: Definition
} { XRef, Defn } where
{ symbol = Symbol } = XRef;
Defn = scip.Definition { symbol = Symbol }
# find-refs table: inverse of ReferenceTarget
# don't think we even need to store these?
predicate DefinitionUses:
{
target: Definition,
xref: Reference
} { Defn, XRef} where
{ symbol = Symbol } = Defn;
XRef = scip.Reference { symbol = Symbol }
# Documentation facts (including type signatures)
predicate Documentation: string
predicate SymbolDocumentation:
{
symbol: Symbol,
docs: Documentation
}
predicate DefinitionDocumentation:
{
defn: Definition,
docs: Documentation
}
{ Defn, Docs } where
{ symbol = Symbol } = Defn; # be careful not to inline to the head
scip.SymbolDocumentation { Symbol, Docs }
# Symbol kinds from the `Symbol` semantic encoding
predicate SymbolKind:
{
symbol: Symbol,
kind: lsif.types.SymbolKind
}
# Parse the "scip.Symbol" to get a local name
predicate LocalName: string
predicate SymbolName:
{
symbol: Symbol,
name: LocalName
}
predicate DefinitionName:
{
defn: Definition,
docs: LocalName
}
{ Defn, Name } where
{ symbol = Symbol } = Defn; # be careful not to inline in to the head
scip.SymbolName { Symbol, Name }
# codemarkup compatibility. Same shape as code.scip.Entity
type Entity =
{
rust: SomeEntity |
go: SomeEntity |
typescript: SomeEntity |
java: SomeEntity |
kotlin: SomeEntity |
}
# entities are scip.Definitions
type SomeEntity =
{
defn: scip.Definition
}
# introduce or eliminate the language tag on the generic scip definition
predicate TagDefinition:
{
language: lsif.types.LanguageId,
defn: scip.Definition,
entity: scip.Entity,
}
{ Language, Defn, Entity } where
SomeEntity = scip.SomeEntity { defn = Defn };
( Rust = Language; { rust = SomeEntity }) |
( Go = Language; { go = SomeEntity }) |
( TypeScript = Language; { typescript = SomeEntity }) |
( Java = Language; { java = SomeEntity }) |
( Kotlin = Language; { kotlin = SomeEntity }) = Entity;
# eliminate entity language tags. inverse of TagDefinition
predicate EntityDefinition:
{
entity : scip.Entity,
defn : scip.Definition
}
{ Entity, Defn } where
({ rust = SomeEntity }) |
({ go = SomeEntity }) |
({ typescript = SomeEntity }) |
({ java = SomeEntity }) |
({ kotlin = SomeEntity }) = Entity;
{ defn = Defn } = SomeEntity
# Symbol locations type. Analog of codemarkup:Location
type Location =
{
file : src.File,
location : src.Range,
name : string,
}
# analog of codemarkup.ResolveLocation, flattens locations and converts spans
predicate ResolveLocation:
{
location: scip.Location,
entity: scip.Entity,
}
{ Location, Entity } where
scip.FileLanguage { File, Language };
{ File, SrcRange, Name } = Location;
lsif.types.FromSrcRange { SrcRange, File, RangeSpan };
scip.DefinitionLocation { File, RangeSpan, Defn };
scip.TagDefinition { Language, Defn, Entity };
scip.DefinitionName { Defn, LocalName };
scip.LocalName Name = LocalName
# unwrap language tag and lookup the decl/defn directly
predicate EntityLocation:
{
entity: scip.Entity,
location: scip.Location,
}
{ Entity, { File, SrcRange, Name } } where
scip.EntityDefinition { Entity, Defn };
{ location = { File, RangeSpan } } = Defn;
lsif.types.ToSrcRange { File, RangeSpan, SrcRange };
scip.DefinitionName { Defn, LocalName };
scip.LocalName Name = LocalName
# xref occurences in a file
predicate FileEntityXRefLocation:
{
file: src.File,
source: src.Range,
target: scip.Location,
entity: scip.Entity,
}
{ File, SrcRange, { TargetFile, TargetRange, Name }, Entity } where
scip.ReferenceLocation { File, RangeSpan, XRef };
lsif.types.ToSrcRange { File, RangeSpan, SrcRange };
scip.ReferenceTarget { XRef, Defn }; # only those with valid Defns
{ location = { TargetFile, TargetRangeSpan } } = Defn;
scip.FileLanguage { TargetFile, Language };
lsif.types.ToSrcRange { TargetFile, TargetRangeSpan, TargetRange };
scip.DefinitionName { Defn, LocalName };
scip.LocalName Name = LocalName;
scip.TagDefinition { Language, Defn, Entity };
# find-refs
predicate EntityUses:
{
target: scip.Entity,
file: src.File,
range: src.Range,
}
{ Entity, File, SrcRange } where
scip.EntityDefinition { Entity, Defn };
scip.DefinitionUses { Defn, XRef };
{ location = { File, RangeSpan } } = XRef;
lsif.types.ToSrcRange { File, RangeSpan, SrcRange };
# and for codemarkup.EntityKind
# we use the kind information from the scip.Symbol tag
# it would be better if kinds were structured in scip.proto
predicate EntityKind:
{
entity: scip.Entity,
kind: lsif.types.SymbolKind,
}
{ Entity, Kind } where
scip.EntityDefinition { Entity, Defn };
{ symbol = Symbol } = Defn;
scip.SymbolKind { Symbol, Kind }
# symbol lookup. O(1) via symbol definition key
predicate SearchBySymbol:
{
symbol : scip.Symbol,
entity : scip.Entity,
}
{ Symbol, Entity } where
Defn = scip.Definition { symbol = Symbol };
{ location = { file = File } } = Defn;
scip.FileLanguage { File, Language };
scip.TagDefinition { Language, Defn, Entity }
}