Skip to content

Commit db840d4

Browse files
committed
fix size of constructor/attribute locations
1 parent 71e9710 commit db840d4

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

example-project/src/Other.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ let m = Dog(1);
1313

1414
let z = {name: "hi", age: 20};
1515

16-
let e = z.name;
16+
let e = z.name;

src/Definition.re

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,16 @@ module Get = {
703703
switch (typ_type.type_kind) {
704704
| Types.Type_record(labels, _) => {
705705
labels |> List.iter(({Types.ld_id: {stamp, name: lname}, ld_type, ld_loc}) => {
706-
addStamp(stamp, lname, ld_loc, Attribute(ld_type, name, typ_type), docs);
707-
addLocation(ld_loc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(stamp));
706+
let shortLoc = Utils.clampLocation(ld_loc, String.length(lname));
707+
addStamp(stamp, lname, shortLoc, Attribute(ld_type, name, typ_type), docs);
708+
addLocation(shortLoc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(stamp));
708709
})
709710
}
710711
| Types.Type_variant(constructors) => {
711712
constructors |> List.iter(({Types.cd_id: {stamp, name: cname}, cd_loc} as cd) => {
712-
addStamp(stamp, cname, cd_loc, Constructor(cd, name, typ_type), docs);
713-
addLocation(cd_loc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(stamp));
713+
let shortLoc = Utils.clampLocation(cd_loc, String.length(cname));
714+
addStamp(stamp, cname, shortLoc, Constructor(cd, name, typ_type), docs);
715+
addLocation(shortLoc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(stamp));
714716
})
715717

716718
}

src/util/Utils.re

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ let endOfLocation = (loc, length) => Location.({
2727
}
2828
});
2929

30+
let clampLocation = (loc, length) => Location.({
31+
{
32+
...loc,
33+
loc_end: {
34+
...loc.loc_start,
35+
pos_cnum: loc.loc_start.pos_cnum + length
36+
}
37+
}
38+
});
39+
3040
let chopPrefix = (s, prefix) => sliceToEnd(s, String.length(prefix));
3141

3242
let filterMap = (fn, items) =>

0 commit comments

Comments
 (0)