Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 214d220

Browse files
committed
Refactor: rename record Attribute to Field.
1 parent e60f479 commit 214d220

File tree

8 files changed

+76
-96
lines changed

8 files changed

+76
-96
lines changed

src/rescript-editor-support/CodeLens.re

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let forOpen = (tracker: SharedTypes.openTracker) => {
3333
let current =
3434
switch (t) {
3535
| SharedTypes.Constructor(name) => [name, ...current]
36-
| Attribute(name) => [name, ...current]
36+
| Field(name) => [name, ...current]
3737
| _ => current
3838
};
3939
Hashtbl.replace(typeMap, name, current);

src/rescript-editor-support/Hover.re

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let newHover = (~rootUri, ~file: SharedTypes.file, ~getModule, loc) => {
8484
| TopLevelModule(name) =>
8585
let%opt file = getModule(name);
8686
showModule(~name=file.moduleName, ~file, None);
87-
| Typed(_, Definition(_, Attribute(_) | Constructor(_))) => None
87+
| Typed(_, Definition(_, Field(_) | Constructor(_))) => None
8888
| Constant(t) =>
8989
Some(
9090
switch (t) {
@@ -154,7 +154,7 @@ let newHover = (~rootUri, ~file: SharedTypes.file, ~getModule, loc) => {
154154
),
155155
docstring,
156156
];
157-
| `Attribute({typ}) =>
157+
| `Field({typ}) =>
158158
let (typeString, docstring) = typ |> fromType(~docstring);
159159
[typeString, docstring];
160160
};

src/rescript-editor-support/NewCompletions.re

+24-39
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let completionForConstructors =
127127
);
128128
};
129129

130-
let completionForAttributes =
130+
let completionForFields =
131131
(
132132
exportedTypes,
133133
stamps: Hashtbl.t(int, SharedTypes.declared(SharedTypes.Type.t)),
@@ -137,11 +137,11 @@ let completionForAttributes =
137137
(_name, stamp, results) => {
138138
let t = Hashtbl.find(stamps, stamp);
139139
switch (t.item.kind) {
140-
| Record(attributes) =>
140+
| Record(fields) =>
141141
(
142-
attributes
143-
|> List.filter(c => Utils.startsWith(c.aname.txt, prefix))
144-
|> List.map(c => (c, t))
142+
fields
143+
|> List.filter(f => Utils.startsWith(f.fname.txt, prefix))
144+
|> List.map(f => (f, t))
145145
)
146146
@ results
147147
| _ => results
@@ -235,15 +235,15 @@ type k =
235235
| Value(Types.type_expr)
236236
| Type(Type.t)
237237
| Constructor(constructor, declared(Type.t))
238-
| Attribute(attribute, declared(Type.t))
238+
| Field(field, declared(Type.t))
239239
| FileModule(string);
240240

241241
let kindToInt = k =>
242242
switch (k) {
243243
| Module(_) => 9
244244
| FileModule(_) => 9
245245
| Constructor(_, _) => 4
246-
| Attribute(_, _) => 5
246+
| Field(_, _) => 5
247247
| Type(_) => 22
248248
| Value(_) => 12
249249
};
@@ -254,7 +254,7 @@ let detail = (name, contents) =>
254254
| Value(typ) => typ |> Shared.typeToString
255255
| Module(_) => "module"
256256
| FileModule(_) => "file module"
257-
| Attribute({typ}, t) =>
257+
| Field({typ}, t) =>
258258
name
259259
++ ": "
260260
++ (typ |> Shared.typeToString)
@@ -300,13 +300,9 @@ let localValueCompletions = (~pos, ~env: Query.queryEnv, suffix) => {
300300
Type(t)
301301
)
302302
@ (
303-
completionForAttributes(
304-
env.exported.types,
305-
env.file.stamps.types,
306-
suffix,
307-
)
308-
|> List.map(((c, t)) =>
309-
{...emptyDeclared(c.aname.txt), item: Attribute(c, t)}
303+
completionForFields(env.exported.types, env.file.stamps.types, suffix)
304+
|> List.map(((f, t)) =>
305+
{...emptyDeclared(f.fname.txt), item: Field(f, t)}
310306
)
311307
);
312308
} else {
@@ -364,13 +360,9 @@ let valueCompletions = (~env: Query.queryEnv, suffix) => {
364360
Type(t)
365361
)
366362
@ (
367-
completionForAttributes(
368-
env.exported.types,
369-
env.file.stamps.types,
370-
suffix,
371-
)
372-
|> List.map(((c, t)) =>
373-
{...emptyDeclared(c.aname.txt), item: Attribute(c, t)}
363+
completionForFields(env.exported.types, env.file.stamps.types, suffix)
364+
|> List.map(((f, t)) =>
365+
{...emptyDeclared(f.fname.txt), item: Field(f, t)}
374366
)
375367
);
376368
} else {
@@ -405,13 +397,9 @@ let attributeCompletions = (~env: Query.queryEnv, ~suffix) => {
405397
)
406398
/* completionForExporteds(env.exported.types, env.file.stamps.types, suffix, t => Type(t)) @ */
407399
@ (
408-
completionForAttributes(
409-
env.exported.types,
410-
env.file.stamps.types,
411-
suffix,
412-
)
413-
|> List.map(((c, t)) =>
414-
{...emptyDeclared(c.aname.txt), item: Attribute(c, t)}
400+
completionForFields(env.exported.types, env.file.stamps.types, suffix)
401+
|> List.map(((f, t)) =>
402+
{...emptyDeclared(f.fname.txt), item: Field(f, t)}
415403
)
416404
);
417405
} else {
@@ -537,9 +525,9 @@ let getItems =
537525
(current, name) => {
538526
let%opt (env, typ) = current;
539527
switch (typ.item.SharedTypes.Type.kind) {
540-
| Record(attributes) =>
528+
| Record(fields) =>
541529
let%opt attr =
542-
attributes |> List.find_opt(a => a.aname.txt == name);
530+
fields |> List.find_opt(f => f.fname.txt == name);
543531
Log.log("Found attr " ++ name);
544532
let%opt path = attr.typ |> Shared.digConstructor;
545533
Hover.digConstructor(~env, ~getModule, path);
@@ -549,17 +537,14 @@ let getItems =
549537
Some((env, typ)),
550538
);
551539
switch (typ.item.kind) {
552-
| Record(attributes) =>
540+
| Record(fields) =>
553541
Some(
554-
attributes
555-
|> Utils.filterMap(a =>
556-
if (Utils.startsWith(a.aname.txt, suffix)) {
542+
fields
543+
|> Utils.filterMap(f =>
544+
if (Utils.startsWith(f.fname.txt, suffix)) {
557545
Some((
558546
env.file.uri,
559-
{
560-
...emptyDeclared(a.aname.txt),
561-
item: Attribute(a, typ),
562-
},
547+
{...emptyDeclared(f.fname.txt), item: Field(f, typ)},
563548
));
564549
} else {
565550
None;

src/rescript-editor-support/ProcessCmt.re

+11-13
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ type env = {
4646
scope: Location.t,
4747
};
4848

49-
let newDeclared = ProcessAttributes.newDeclared;
50-
5149
let addItem =
5250
(~name, ~extent, ~stamp, ~env, ~item, attributes, exported, stamps) => {
5351
let declared =
54-
newDeclared(
52+
ProcessAttributes.newDeclared(
5553
~item,
5654
~scope={
5755
Location.loc_start: extent.Location.loc_end,
@@ -133,7 +131,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.exported, item) => {
133131
res: cd_res,
134132
};
135133
let declared =
136-
newDeclared(
134+
ProcessAttributes.newDeclared(
137135
~item,
138136
~extent=cd_loc,
139137
~scope={
@@ -153,15 +151,15 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.exported, item) => {
153151
item;
154152
}),
155153
)
156-
| Type_record(labels, _) =>
154+
| Type_record(fields, _) =>
157155
Record(
158-
labels
156+
fields
159157
|> List.map(({ld_id, ld_type}) => {
160158
let astamp = Ident.binding_time(ld_id);
161159
let name = Ident.name(ld_id);
162160
{
163161
stamp: astamp,
164-
aname: Location.mknoloc(name),
162+
fname: Location.mknoloc(name),
165163
typ: ld_type,
166164
};
167165
}),
@@ -280,12 +278,12 @@ let forTypeDeclaration =
280278
};
281279
}),
282280
)
283-
| Ttype_record(labels) =>
281+
| Ttype_record(fields) =>
284282
Record(
285-
labels
286-
|> List.map(({ld_id, ld_name: aname, ld_type: {ctyp_type}}) => {
287-
let astamp = Ident.binding_time(ld_id);
288-
{stamp: astamp, aname, typ: ctyp_type};
283+
fields
284+
|> List.map(({ld_id, ld_name: fname, ld_type: {ctyp_type}}) => {
285+
let fstamp = Ident.binding_time(ld_id);
286+
{stamp: fstamp, fname, typ: ctyp_type};
289287
}),
290288
)
291289
},
@@ -511,7 +509,7 @@ and forModule = (env, mod_desc, moduleName) =>
511509
kind => {
512510
let stamp = Ident.binding_time(ident);
513511
let declared =
514-
newDeclared(
512+
ProcessAttributes.newDeclared(
515513
~item=kind,
516514
~name=argName,
517515
~scope={

src/rescript-editor-support/ProcessExtra.re

+16-16
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ module F =
186186
let {Types.lbl_res} = item;
187187

188188
let (name, typeLident) = handleConstructor(path, txt);
189-
maybeAddUse(path, typeLident, loc, Attribute(name));
189+
maybeAddUse(path, typeLident, loc, Field(name));
190190

191191
let nameLoc = Utils.endOfLocation(loc, String.length(name));
192192
let locType =
193193
switch (t) {
194-
| `Local({stamp, item: {kind: Record(attributes)}}) =>
195-
switch (attributes |> List.find_opt(a => a.aname.txt == name)) {
194+
| `Local({stamp, item: {kind: Record(fields)}}) =>
195+
switch (fields |> List.find_opt(f => f.fname.txt == name)) {
196196
| Some({stamp: astamp}) =>
197197
addReference(astamp, nameLoc);
198-
LocalReference(stamp, Attribute(name));
198+
LocalReference(stamp, Field(name));
199199
| None => NotFound
200200
}
201201
| `Global(moduleName, path) =>
202-
addExternalReference(moduleName, path, Attribute(name), nameLoc);
203-
GlobalReference(moduleName, path, Attribute(name));
202+
addExternalReference(moduleName, path, Field(name), nameLoc);
203+
GlobalReference(moduleName, path, Field(name));
204204
| _ => NotFound
205205
};
206206
addLocation(nameLoc, Typed(lbl_res, locType));
@@ -217,26 +217,26 @@ module F =
217217
/* let name = Longident.last(txt); */
218218

219219
let (name, typeLident) = handleConstructor(path, txt);
220-
maybeAddUse(path, typeLident, loc, Attribute(name));
220+
maybeAddUse(path, typeLident, loc, Field(name));
221221

222222
let nameLoc = Utils.endOfLocation(loc, String.length(name));
223223
let locType =
224224
switch (t) {
225-
| `Local({stamp, item: {kind: Record(attributes)}}) =>
226-
switch (attributes |> List.find_opt(a => a.aname.txt == name)) {
225+
| `Local({stamp, item: {kind: Record(fields)}}) =>
226+
switch (fields |> List.find_opt(f => f.fname.txt == name)) {
227227
| Some({stamp: astamp}) =>
228228
addReference(astamp, nameLoc);
229-
LocalReference(stamp, Attribute(name));
229+
LocalReference(stamp, Field(name));
230230
| None => NotFound
231231
}
232232
| `Global(moduleName, path) =>
233233
addExternalReference(
234234
moduleName,
235235
path,
236-
Attribute(name),
236+
Field(name),
237237
nameLoc,
238238
);
239-
GlobalReference(moduleName, path, Attribute(name));
239+
GlobalReference(moduleName, path, Field(name));
240240
| _ => NotFound
241241
};
242242
addLocation(nameLoc, Typed(lbl_res, locType));
@@ -573,11 +573,11 @@ let forFile = (~file) => {
573573
switch (d.item.Type.kind) {
574574
| Record(labels) =>
575575
labels
576-
|> List.iter(({stamp, aname, typ}) => {
577-
addReference(stamp, aname.loc);
576+
|> List.iter(({stamp, fname, typ}) => {
577+
addReference(stamp, fname.loc);
578578
addLocation(
579-
aname.loc,
580-
Typed(typ, Definition(d.stamp, Attribute(aname.txt))),
579+
fname.loc,
580+
Typed(typ, Definition(d.stamp, Field(fname.txt))),
581581
);
582582
})
583583
| Variant(constructos) =>

src/rescript-editor-support/Query.re

+5-7
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let declaredForExportedTip = (~stamps: stamps, ~exported: exported, name, tip) =
215215
stamp =>
216216
Hashtbl.find_opt(stamps.values, stamp) |?>> (x => {...x, item: ()})
217217
)
218-
| Attribute(_)
218+
| Field(_)
219219
| Constructor(_)
220220
| Type =>
221221
Hashtbl.find_opt(exported.types, name)
@@ -235,20 +235,18 @@ let declaredForTip = (~stamps, stamp, tip) =>
235235
switch (tip) {
236236
| Value =>
237237
Hashtbl.find_opt(stamps.values, stamp) |?>> (x => {...x, item: ()})
238-
| Attribute(_)
238+
| Field(_)
239239
| Constructor(_)
240240
| Type =>
241241
Hashtbl.find_opt(stamps.types, stamp) |?>> (x => {...x, item: ()})
242242
| Module =>
243243
Hashtbl.find_opt(stamps.modules, stamp) |?>> (x => {...x, item: ()})
244244
};
245245

246-
let getAttribute = (file, stamp, name) => {
246+
let getField = (file, stamp, name) => {
247247
let%opt {item: {kind}} = Hashtbl.find_opt(file.stamps.types, stamp);
248248
switch (kind) {
249-
| Record(labels) =>
250-
let%opt label = labels |> List.find_opt(label => label.aname.txt == name);
251-
Some(label);
249+
| Record(fields) => fields |> List.find_opt(f => f.fname.txt == name)
252250
| _ => None
253251
};
254252
};
@@ -267,7 +265,7 @@ let getConstructor = (file, stamp, name) => {
267265
let exportedForTip = (~env, name, tip) =>
268266
switch (tip) {
269267
| Value => Hashtbl.find_opt(env.exported.values, name)
270-
| Attribute(_)
268+
| Field(_)
271269
| Constructor(_)
272270
| Type => Hashtbl.find_opt(env.exported.types, name)
273271
| Module => Hashtbl.find_opt(env.exported.modules, name)

0 commit comments

Comments
 (0)