Skip to content

Commit 56a2849

Browse files
committed
rename attributes & constructors!!!
1 parent db840d4 commit 56a2849

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

example-project/src/Hello.re

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
let someLongName = 10;
1+
/* let someLongName = 10;
22
33
let otherLongName = "string";
44
5-
string_of_bool;
5+
string_of_bool; */
66

77
module Something = {
88
open Other;
99

10-
let m = {name: "Me", age: 0};
11-
let animal = Dog(10);
12-
let other = Dog(2);
10+
let m = {firstName: "Me", age: 0};
11+
let animal = Wolf(10);
12+
let other = Wolf(2);
1313
let me = Cat("Hie");
1414
let x = something + 10;
1515
};
1616

17+
/*
1718
open Something;
1819
1920
let y = x + 10;
@@ -116,4 +117,5 @@ switch (y) {
116117

117118
/* let x = [%raw " hello"]; */
118119

119-
let awesome = "hello";
120+
let awesome = "hello";
121+
*/

example-project/src/Other.re

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
let later = 10;
2+
/* let later = 10; */
33

44
/* Ok testing things */
55

66
let something = 10;
77

8-
type person = {name: string, age: int};
8+
type person = {firstName: string, age: int};
99

10-
type animals = Dog(int) | Cat(string) | Mouse;
10+
type animals = Wolf(int) | Cat(string) | Mouse;
1111

12-
let m = Dog(1);
12+
let m = Wolf(1);
1313

14-
let z = {name: "hi", age: 20};
14+
let z = {firstName: "hi", age: 20};
1515

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

src/Definition.re

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ type anOpen = {
5656
type moduleData = {
5757
mutable toplevelDocs: option(string),
5858
stamps: Hashtbl.t(int, (string, Location.t, item, option(string), ((int, int), (int, int)))),
59-
/* TODO track constructor names, and record attribute names */
6059
internalReferences: Hashtbl.t(int, list(Location.t)),
6160
externalReferences: Hashtbl.t(string, list((list(string), Location.t, option(string)))),
6261
exported: Hashtbl.t(string, int),
62+
mutable exportedSuffixes: list((int, string, string)),
6363
mutable topLevel: list((string, int)),
6464
mutable locations: list((Location.t, Types.type_expr, definition)),
6565
mutable allOpens: list(anOpen)
@@ -391,11 +391,14 @@ let openReferencesAtPos = ({allOpens} as data, pos) => {
391391
};
392392

393393
let isStampExported = (needle, data) =>
394-
Hashtbl.fold(
395-
(name, stamp, found) => found != None ? found : stamp == needle ? Some(name) : None,
394+
switch (Hashtbl.fold(
395+
(name, stamp, found) => found != None ? found : stamp == needle ? Some((name, None)) : None,
396396
data.exported,
397397
None
398-
);
398+
)) {
399+
| Some(m) => Some(m)
400+
| None => data.exportedSuffixes |> Utils.find(((suffixStamp, mainName, suffixName)) => suffixStamp == needle ? Some((mainName, Some(suffixName))) : None)
401+
};
399402

400403
let highlightsForStamp = (stamp, data) =>
401404
maybeFound(Hashtbl.find(data.stamps), stamp)
@@ -437,18 +440,6 @@ let rec stampAtPath = (path, data, suffix) =>
437440
| _ => None
438441
};
439442

440-
/* let suffixAtPath = (path, suffix, data) => {
441-
stampAtPath(path, data) |?> stamp => switch stamp {
442-
| `Global(name, children) => Some(`Global(name, children, suffix))
443-
| `Local(stamp) => (maybeFound(Hashtbl.find(Collector.data.stamps), stamp) |?> ((name, loc, item, docs, range)) => {
444-
switch item {
445-
| Type(t) => getSuffix(t, suffix) |?>> ((loc, stamp)) => `Local(stamp)
446-
| _ => None
447-
}
448-
})
449-
}
450-
}; */
451-
452443
let stampAtPos = (pos, data) =>
453444
locationAtPos(pos, data)
454445
|?> (
@@ -702,19 +693,24 @@ module Get = {
702693

703694
switch (typ_type.type_kind) {
704695
| Types.Type_record(labels, _) => {
705-
labels |> List.iter(({Types.ld_id: {stamp, name: lname}, ld_type, ld_loc}) => {
696+
labels |> List.iter(({Types.ld_id: {stamp: lstamp, name: lname}, ld_type, ld_loc}) => {
706697
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));
698+
addStamp(lstamp, lname, shortLoc, Attribute(ld_type, name, typ_type), docs);
699+
if (maybeFound(Hashtbl.find(Collector.data.exported), name) == Some(stamp)) {
700+
Collector.data.exportedSuffixes = [(lstamp, name, lname), ...Collector.data.exportedSuffixes];
701+
};
702+
addLocation(shortLoc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(lstamp));
709703
})
710704
}
711705
| Types.Type_variant(constructors) => {
712-
constructors |> List.iter(({Types.cd_id: {stamp, name: cname}, cd_loc} as cd) => {
706+
constructors |> List.iter(({Types.cd_id: {stamp: cstamp, name: cname}, cd_loc} as cd) => {
713707
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));
708+
addStamp(cstamp, cname, shortLoc, Constructor(cd, name, typ_type), docs);
709+
addLocation(shortLoc, {Types.desc: Types.Tnil, level: 0, id: 0}, IsDefinition(cstamp));
710+
if (maybeFound(Hashtbl.find(Collector.data.exported), name) == Some(stamp)) {
711+
Collector.data.exportedSuffixes = [(cstamp, name, cname), ...Collector.data.exportedSuffixes];
712+
};
716713
})
717-
718714
}
719715
| _ => ()
720716
}
@@ -884,6 +880,7 @@ module Get = {
884880
stamps: Hashtbl.create(100),
885881
internalReferences: Hashtbl.create(100),
886882
externalReferences: Hashtbl.create(100),
883+
exportedSuffixes: [],
887884
exported: Hashtbl.create(10),
888885
allOpens: [],
889886
topLevel: [],

src/State.re

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,10 @@ let resolveDefinition = (uri, defn, state) =>
134134
| `Local(_, loc, item, docs, _) => Some((loc, docs, uri))
135135
| `Global(top, children, suffix) =>
136136
{
137-
Log.log("Resolving global " ++ top);
138137
switch (
139138
maybeFound(List.assoc(top), state.localModules)
140139
|?> (
141140
((cmt, src)) => {
142-
Log.log("Found it " ++ src);
143141
let uri = "file://" ++ src;
144142
maybeFound(Hashtbl.find(state.compiledDocuments), uri)
145143
|?> AsYouType.getResult
@@ -184,17 +182,17 @@ let referencesForPos = (uri, pos, data, state) => {
184182
/* TODO handle cross-file stamps, e.g. the location isn't a stamp */
185183
Definition.stampAtPos(pos, data)
186184
|?> stamp => {
187-
let externals = (Definition.isStampExported(stamp, data) |?>> exportedName => {
185+
let externals = (Definition.isStampExported(stamp, data) |?>> ((exportedName, suffixName)) => {
188186
let thisModName = FindFiles.getName(uri);
189187
optMap(((modname, (cmt, src))) => {
190188
if (modname == thisModName) {
191189
None
192190
} else {
193191
getDefinitionData("file://" ++ src, state) |?> data => {
194192
Definition.maybeFound(Hashtbl.find(data.Definition.externalReferences), thisModName) |?> uses => {
195-
let realUses = Utils.filterMap(((path, loc, suffix/* TODO */)) => {
196-
if (path == [exportedName]) {
197-
Some((`Read, Utils.endOfLocation(loc, String.length(exportedName))))
193+
let realUses = Utils.filterMap(((path, loc, suffix)) => {
194+
if (path == [exportedName] && suffix == suffixName) {
195+
Some((`Read, Utils.endOfLocation(loc, String.length(suffixName |? exportedName))))
198196
} else {
199197
None
200198
}

0 commit comments

Comments
 (0)