Skip to content

tools: add source field (Loc) #900

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

Merged
merged 7 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Sig_type
Expand Down Expand Up @@ -134,6 +135,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Sig_module (ident, {md_type; md_attributes; md_loc}, _) ->
Expand All @@ -152,6 +154,7 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| _ -> []
Expand Down Expand Up @@ -316,6 +319,7 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
}

let rec forSignatureItem ~env ~(exported : Exported.t)
Expand All @@ -335,6 +339,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Tsig_type (recFlag, decls) ->
Expand Down Expand Up @@ -366,6 +371,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t)
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Tsig_recmodule modDecls ->
Expand Down Expand Up @@ -443,6 +449,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
}
:: !items
| Tpat_tuple pats | Tpat_array pats | Tpat_construct (_, _, pats) ->
Expand Down Expand Up @@ -478,6 +485,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Tstr_recmodule modDecls ->
Expand Down Expand Up @@ -509,6 +517,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Tstr_include {incl_mod; incl_type} ->
Expand Down Expand Up @@ -538,6 +547,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
name = declared.name.txt;
docstring = declared.docstring;
deprecated = declared.deprecated;
loc = declared.extentLoc;
};
]
| Tstr_type (recFlag, decls) ->
Expand Down
1 change: 1 addition & 0 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ module Module = struct
and item = {
kind: kind;
name: string;
loc: Location.t;
docstring: string list;
deprecated: string option;
}
Expand Down
4 changes: 4 additions & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## master

#### :rocket: New Feature

- Add `source` property to type, value, module and module alias. https://github.com/rescript-lang/rescript-vscode/pull/900.

#### :bug: Bug Fix

- Print docstrings for nested submodules. https://github.com/rescript-lang/rescript-vscode/pull/897
Expand Down
2 changes: 1 addition & 1 deletion tools/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let main () =
| Some "true" -> Analysis.Cfg.isDocGenFromCompiler := true
| _ -> ()
in
logAndExit (Tools.extractDocs ~path ~debug:false)
logAndExit (Tools.extractDocs ~entryPointFile:path ~debug:false)
| _ -> logAndExit (Error docHelp))
| "reanalyze" :: _ ->
let len = Array.length Sys.argv in
Expand Down
11 changes: 11 additions & 0 deletions tools/npm/Tools_Docgen.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ type detail =
| @as("record") Record({items: array<field>})
| @as("variant") Variant({items: array<constructor>})

type source = {
filepath: string,
line: int,
col: int,
}

@tag("kind")
type rec item =
| @as("value")
Expand All @@ -31,6 +37,7 @@ type rec item =
signature: string,
name: string,
deprecated?: string,
source: source,
})
| @as("type")
Type({
Expand All @@ -39,6 +46,7 @@ type rec item =
signature: string,
name: string,
deprecated?: string,
source: source,
/** Additional documentation for constructors and record fields, if available. */
detail?: detail,
})
Expand All @@ -48,20 +56,23 @@ type rec item =
docstrings: array<string>,
deprecated?: string,
name: string,
source: source,
items: array<item>,
})
| @as("moduleAlias")
ModuleAlias({
id: string,
docstrings: array<string>,
name: string,
source: source,
items: array<item>,
})

type doc = {
name: string,
deprecated: option<string>,
docstrings: array<string>,
source: source,
items: array<item>,
}

Expand Down
18 changes: 17 additions & 1 deletion tools/npm/Tools_Docgen.resi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type detail =
| @as("record") Record({items: array<field>})
| @as("variant") Variant({items: array<constructor>})

type source = {
filepath: string,
line: int,
col: int,
}

@tag("kind")
type rec item =
| @as("value")
Expand All @@ -30,6 +36,7 @@ type rec item =
signature: string,
name: string,
deprecated?: string,
source: source,
})
| @as("type")
Type({
Expand All @@ -38,6 +45,7 @@ type rec item =
signature: string,
name: string,
deprecated?: string,
source: source,
/** Additional documentation for constructors and record fields, if available. */
detail?: detail,
})
Expand All @@ -47,16 +55,24 @@ type rec item =
docstrings: array<string>,
deprecated?: string,
name: string,
source: source,
items: array<item>,
})
| @as("moduleAlias")
ModuleAlias({
id: string,
docstrings: array<string>,
name: string,
source: source,
items: array<item>,
})

type doc = {name: string, deprecated: option<string>, docstrings: array<string>, items: array<item>}
type doc = {
name: string,
deprecated: option<string>,
docstrings: array<string>,
source: source,
items: array<item>,
}

let decodeFromJson: Js.Json.t => doc
2 changes: 1 addition & 1 deletion tools/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"suffix": ".bs.js",
"package-specs": {
"module": "commonjs",
"in-source": true
"in-source": false
}
}
Loading