Skip to content

Commit 91714d8

Browse files
authored
tools: add source field (Loc) (#900)
* tools: add source field * tools: refactor * tools: fix dir_sep and update rescript files * update CHANGELOG.md * disable in-source * remove findRelativePath * fix dir_sep on windows
1 parent a9e1e18 commit 91714d8

13 files changed

+303
-26
lines changed

analysis/src/ProcessCmt.ml

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
6060
name = declared.name.txt;
6161
docstring = declared.docstring;
6262
deprecated = declared.deprecated;
63+
loc = declared.extentLoc;
6364
};
6465
]
6566
| Sig_type
@@ -134,6 +135,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
134135
name = declared.name.txt;
135136
docstring = declared.docstring;
136137
deprecated = declared.deprecated;
138+
loc = declared.extentLoc;
137139
};
138140
]
139141
| Sig_module (ident, {md_type; md_attributes; md_loc}, _) ->
@@ -152,6 +154,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
152154
name = declared.name.txt;
153155
docstring = declared.docstring;
154156
deprecated = declared.deprecated;
157+
loc = declared.extentLoc;
155158
};
156159
]
157160
| _ -> []
@@ -316,6 +319,7 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
316319
name = declared.name.txt;
317320
docstring = declared.docstring;
318321
deprecated = declared.deprecated;
322+
loc = declared.extentLoc;
319323
}
320324

321325
let rec forSignatureItem ~env ~(exported : Exported.t)
@@ -335,6 +339,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t)
335339
name = declared.name.txt;
336340
docstring = declared.docstring;
337341
deprecated = declared.deprecated;
342+
loc = declared.extentLoc;
338343
};
339344
]
340345
| Tsig_type (recFlag, decls) ->
@@ -366,6 +371,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t)
366371
name = declared.name.txt;
367372
docstring = declared.docstring;
368373
deprecated = declared.deprecated;
374+
loc = declared.extentLoc;
369375
};
370376
]
371377
| Tsig_recmodule modDecls ->
@@ -443,6 +449,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
443449
name = declared.name.txt;
444450
docstring = declared.docstring;
445451
deprecated = declared.deprecated;
452+
loc = declared.extentLoc;
446453
}
447454
:: !items
448455
| Tpat_tuple pats | Tpat_array pats | Tpat_construct (_, _, pats) ->
@@ -478,6 +485,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
478485
name = declared.name.txt;
479486
docstring = declared.docstring;
480487
deprecated = declared.deprecated;
488+
loc = declared.extentLoc;
481489
};
482490
]
483491
| Tstr_recmodule modDecls ->
@@ -509,6 +517,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
509517
name = declared.name.txt;
510518
docstring = declared.docstring;
511519
deprecated = declared.deprecated;
520+
loc = declared.extentLoc;
512521
};
513522
]
514523
| Tstr_include {incl_mod; incl_type} ->
@@ -538,6 +547,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
538547
name = declared.name.txt;
539548
docstring = declared.docstring;
540549
deprecated = declared.deprecated;
550+
loc = declared.extentLoc;
541551
};
542552
]
543553
| Tstr_type (recFlag, decls) ->

analysis/src/SharedTypes.ml

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ module Module = struct
125125
and item = {
126126
kind: kind;
127127
name: string;
128+
loc: Location.t;
128129
docstring: string list;
129130
deprecated: string option;
130131
}

tools/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :rocket: New Feature
16+
17+
- Add `source` property to type, value, module and module alias. https://github.com/rescript-lang/rescript-vscode/pull/900.
18+
1519
#### :bug: Bug Fix
1620

1721
- Print docstrings for nested submodules. https://github.com/rescript-lang/rescript-vscode/pull/897

tools/bin/main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let main () =
4141
| Some "true" -> Analysis.Cfg.isDocGenFromCompiler := true
4242
| _ -> ()
4343
in
44-
logAndExit (Tools.extractDocs ~path ~debug:false)
44+
logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false)
4545
| _ -> logAndExit (Error docHelp))
4646
| "reanalyze" :: _ ->
4747
let len = Array.length Sys.argv in

tools/npm/Tools_Docgen.res

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type detail =
2222
| @as("record") Record({items: array<field>})
2323
| @as("variant") Variant({items: array<constructor>})
2424

25+
type source = {
26+
filepath: string,
27+
line: int,
28+
col: int,
29+
}
30+
2531
@tag("kind")
2632
type rec item =
2733
| @as("value")
@@ -31,6 +37,7 @@ type rec item =
3137
signature: string,
3238
name: string,
3339
deprecated?: string,
40+
source: source,
3441
})
3542
| @as("type")
3643
Type({
@@ -39,6 +46,7 @@ type rec item =
3946
signature: string,
4047
name: string,
4148
deprecated?: string,
49+
source: source,
4250
/** Additional documentation for constructors and record fields, if available. */
4351
detail?: detail,
4452
})
@@ -48,20 +56,23 @@ type rec item =
4856
docstrings: array<string>,
4957
deprecated?: string,
5058
name: string,
59+
source: source,
5160
items: array<item>,
5261
})
5362
| @as("moduleAlias")
5463
ModuleAlias({
5564
id: string,
5665
docstrings: array<string>,
5766
name: string,
67+
source: source,
5868
items: array<item>,
5969
})
6070

6171
type doc = {
6272
name: string,
6373
deprecated: option<string>,
6474
docstrings: array<string>,
75+
source: source,
6576
items: array<item>,
6677
}
6778

tools/npm/Tools_Docgen.resi

+17-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type detail =
2121
| @as("record") Record({items: array<field>})
2222
| @as("variant") Variant({items: array<constructor>})
2323

24+
type source = {
25+
filepath: string,
26+
line: int,
27+
col: int,
28+
}
29+
2430
@tag("kind")
2531
type rec item =
2632
| @as("value")
@@ -30,6 +36,7 @@ type rec item =
3036
signature: string,
3137
name: string,
3238
deprecated?: string,
39+
source: source,
3340
})
3441
| @as("type")
3542
Type({
@@ -38,6 +45,7 @@ type rec item =
3845
signature: string,
3946
name: string,
4047
deprecated?: string,
48+
source: source,
4149
/** Additional documentation for constructors and record fields, if available. */
4250
detail?: detail,
4351
})
@@ -47,16 +55,24 @@ type rec item =
4755
docstrings: array<string>,
4856
deprecated?: string,
4957
name: string,
58+
source: source,
5059
items: array<item>,
5160
})
5261
| @as("moduleAlias")
5362
ModuleAlias({
5463
id: string,
5564
docstrings: array<string>,
5665
name: string,
66+
source: source,
5767
items: array<item>,
5868
})
5969

60-
type doc = {name: string, deprecated: option<string>, docstrings: array<string>, items: array<item>}
70+
type doc = {
71+
name: string,
72+
deprecated: option<string>,
73+
docstrings: array<string>,
74+
source: source,
75+
items: array<item>,
76+
}
6177

6278
let decodeFromJson: Js.Json.t => doc

tools/rescript.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"suffix": ".bs.js",
1010
"package-specs": {
1111
"module": "commonjs",
12-
"in-source": true
12+
"in-source": false
1313
}
1414
}

0 commit comments

Comments
 (0)