-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add moduletypeid
field for modules with explicitly annotated module type
#1019
add moduletypeid
field for modules with explicitly annotated module type
#1019
Conversation
annotated module type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your efforts!
Please, see other comments.
@@ -44,7 +44,14 @@ type docItem = | |||
(** Additional documentation for constructors and record fields, if available. *) | |||
} | |||
| Module of docsForModule | |||
| ModuleType of docsForModule | |||
| ModuleType of { | |||
id: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you update the rescript types accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tools/src/tools.ml
Outdated
extractDocsForModule ~modulePath:(m.name :: modulePath) | ||
m | ||
in | ||
Some (Module {docs with moduletype = Some (Path.name p)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same string, which is used for the id of the module type, when generating json for the module type?
For further processing it would make sense, to use the id. If so, the record field should probably renamed as well (moduleTypeId
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed field to moduletypeid
bc all fields are in lowercase.
a67efa5 added full id DocExtractionRes.Example
@@ -311,6 +311,7 @@ | |||
"id": "DocExtractionRes.M", | |||
"name": "M", | |||
"kind": "module", | |||
"moduletypeid": "DocExtractionRes.Example", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@woeps, same id of module type
Perhaps it'd be better to have both the module type name and the module type id? |
Looks good to me! :D The only possible issue I found is, when the explicitly annotated module type is in another file: // Types.res
module type T = {
let x: int
} // Example.res
module M: Types.T = {
let x = 42
} Above will result in PS: module types in the same file are working as expected. |
Tbh, I don't think the name is necessary in the light of progrmatically processing the data to e.g. build a docs website. But if you (@zth) have a usecase in mind, where the name would be convenient to have without further id resolutions, I'm not opposed. |
No I don't have anything specific in mind really. Just a thought. Is this ready to go? |
No, I'll take a look later |
Right, moduletypeid fixed. Example.res module type T = {
let a: int
}
module M: Types.T = {
let x = 42
}
module A: T = {
let a = 1
}
Types.res module type T = {
let x: int
} {
"name": "Example",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.T",
"name": "T",
"kind": "moduleType",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 13
},
"items": [
{
"id": "Example.T.a",
"kind": "value",
"name": "a",
"signature": "let a: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 2,
"col": 3
}
}]
},
{
"id": "Example.M",
"name": "M",
"kind": "module",
"moduletypeid": "Types.T",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.M.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 5,
"col": 7
}
}]
},
{
"id": "Example.A",
"name": "A",
"kind": "module",
"moduletypeid": "T",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.A.a",
"kind": "value",
"name": "a",
"signature": "let a: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 8,
"col": 7
}
}]
}]
} |
Ready to go! |
moduletype
field for modules with explicitly annotated module typemoduletypeid
field for modules with explicitly annotated module type
Sorry to be a downer 🫣: I'll check if this is just a typo in the comments or the actual implementation in a bit. |
I just verified: the json example in the comment above from @aspeddro is according to the implementation. To me, it seems it is a little bit more complicated than just passing My expectation of the generated |
@woeps I interpret this as the PR isn't ready to go just yet? |
Ok, I think is this, right? {
"name": "Example",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.T",
"name": "T",
"kind": "moduleType",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 13
},
"items": [
{
"id": "Example.T.a",
"kind": "value",
"name": "a",
"signature": "let a: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 2,
"col": 3
}
}]
},
{
"id": "Example.M",
"name": "M",
"kind": "module",
"moduletypeid": "Types.T",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.M.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 6,
"col": 7
}
}]
},
{
"id": "Example.A",
"name": "A",
"kind": "module",
"moduletypeid": "Example.T",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.A.a",
"kind": "value",
"name": "a",
"signature": "let a: int",
"docstrings": [],
"source": {
"filepath": "src/Example.res",
"line": 10,
"col": 7
}
}]
}]
} |
@aspeddro great progress! 👍 I found one more case, which needs to be handled (when submodules have explicit module types): // Example.res
module type MT = {
let x: int
}
module A: MT = {
let x = 42
}
module B: Types.T = {
let x = 42
}
module C = {
module D: MT = // generates "moduletypeid": "Example.C.MT" - but should be Example.MT
let x = 42
}
module E: Types.T = {
let x = 3
}
} generates this json: {
"name": "Example",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.MT",
"name": "MT",
"kind": "moduleType",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 13
},
"items": [
{
"id": "Example.MT.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 2,
"col": 3
}
}]
},
{
"id": "Example.A",
"name": "A",
"kind": "module",
"moduletypeid": "Example.MT",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.A.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 6,
"col": 7
}
}]
},
{
"id": "Example.B",
"name": "B",
"kind": "module",
"moduletypeid": "Types.T",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.B.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 10,
"col": 7
}
}]
},
{
"id": "Example.C",
"name": "C",
"kind": "module",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 13,
"col": 8
},
"items": [
{
"id": "Example.C.D",
"name": "D",
"kind": "module",
"moduletypeid": "Example.C.MT", <-- this should be Example.MT
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.C.D.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 15,
"col": 9
}
}]
},
{
"id": "Example.C.E",
"name": "E",
"kind": "module",
"moduletypeid": "Types.T",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 1,
"col": 1
},
"items": [
{
"id": "Example.C.E.x",
"kind": "value",
"name": "x",
"signature": "let x: int",
"docstrings": [],
"source": {
"filepath": "test/Example.res",
"line": 18,
"col": 9
}
}]
}]
}]
} on a side note: It seems |
Thanks for both of your work! Keep it going! 😄 |
Added some tests a40df41 |
@zth I think this is now good to be merged. |
Great work! Do you want me to put out another tools version with this or is there other outstanding things we should try and fix before? |
@zth You may publish a new tools version. |
@woeps |
… type (rescript-lang#1019) * add `moduletype` field for modules with explicitly annotated module type * add full id * remove modulePath * update CHANGELOG.md * fix moduletypeid * ignore parent module name * add tests * remove comment
No description provided.