-
Notifications
You must be signed in to change notification settings - Fork 30
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
Documentation and docstrings #25
Comments
Regarding the open questions: If the docstrings are the one and only truth and everything else is generates from them, I'd say yes to all of the three questions above. If there is a plan for displaying docstrings directly on hover and offer additional resources & eplanations in some kind of "extended online api reference", my answers would change to the following:
|
Great feedback! I agree. I think mid to long term we definitively want to provide an "extended online api reference". It's however likely that it'll be a while before that's in place, given that it takes time to build and we're a limited set of contributors with limited time at hand right now. @woeps would you be interested in helping out shaping the initial set of docstrings? They'll set the standard going forward. |
I'm definetly willing to. I just need to see how much time I'll be able to spend. 😉 I'd like to propose to separate more extensive information with a line containing only This would enable us to have all information at one place until more tooling / infrastructure is being worked on. This might also be simple to parse in the vs code extension and potentially truncate the extended info if necessary? |
Don't we all 😉 That sounds good, all for that! That'll be easy to handle and change as needed. Doc extraction tooling is coming fairly soon, so we're not ways off at least. |
Should the content of the comments be indented? Or aligned with
Indenting can affect how the content is presented in the editor. |
I think we should keep it as simple as possible. These comments will be consumed by other tools that can apply this transformation. For editor tools, comments are already rendered with good separation. In Neovim for example, it adds the Maybe add a |
@aspeddro Are you saying, you're against it? I was thinking about more extensive information, and how to seperate it. I wanted to show a real world example on the first docstring I'll work on, but for the sake of the discussion here is a fictive example: /**
Do something very important, based on data t.
`t` is the data being operated on and `arg1` is a random string being used `arg2`-times in this operation.
**This mutates the original `t`.**
\```rescript
let x = makeT("hellp")
let result = fnName(x, ~arg1="!", ~arg2=42)
\```
---
## Explanation
This is a more thorough explanation suited for devs,
who are not familiar with this type of function.
Probably involving further meaningful examples and
step by step walkthrough if necessary.
## References
- [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions) provides further usage information reagrding the bound js function
- there are some specificas to [usage in node](https://nodejs.org/api/n-api.html#napi_threadsafe_function)
## Alternatives
- `fnName` provides an immutable version of this function
- `OtherModule.otherFn` is similar, but provides more fine-grained control
- `AnotherModule.fnName` provides the same operation but on the data type `foo`
*/
external fnNameInPlace: (t, ~arg1: string, ~arg2: int) => t Note: I needed to "escape" the example code block in the doc string to avoid weird rendering of this comment. I was proposing, that the language server could ignore everything after (including) the line containing If we find consesus on the usage of this separator I'll file an issue on the language server repo. |
I think that's a good format @woeps . I say we go for that. Editor tooling wise this will be simple to change/fix later on, so no need to worry about that now, I'll fix that when needed. As long as there's a coherent format. Some thoughts from me:
|
I say we don't indent, keep it aligned to the leading |
I had understood to add |
I think that sounds good. |
A proposal for testing code blocks in the future. Most docstring have checks like: String.startsWithFrom("BuckleScript", "kle", 3) == true However, this code is not valid. Error: We could use assert(String.startsWithFrom("BuckleScript", "kle", 3)) Is it a good format or should we keep the current one? |
That's a good point. Ideally you should be able to run all of the examples as is, although that might not be feasible for more advanced examples that would involve a lot of boiler plate. I'd like to avoid involving
That would both compile, and yield some output. |
assert throws an error, so it would be easier to debug and run tests.
assert can be optional. We use it for simple cases, like JS bindings. Or we can create blocks with a specific notation I'll leave it as it is. We can come back when the document extraction is more advanced. |
I've added docs for the |
When we've covered everything in the list down to Heroic effort so far all contributors! 👏 |
I could start with doc strings for the JSON module. |
@dkirchhof that would be great! I'm going to start on array soon unless someone else picks it up before me. |
A goal for
Core
is to provide a really solid developer experience. One important piece in doing that is providing good documentation, and good docstrings. For those who don't know, docstrings are the strings you prepend functions etc with to explain what they are. They show up via the editor tooling on hovering, auto completion, etc. Example fromPromise.resi
: https://github.com/rescript-association/rescript-core/blob/main/src/Core__Promise.resi#L11-L17We will need help to do this. Crafting good docstrings takes time, and there's a fairly large API surface to cover.
Eventually, these docstrings will also be extracted and used for real documentation, via the doc extraction project that's in the works.
Current state
Array
AsyncIterator
Console
Date
Dict
Error
Float
Global
Int
Iterator
JSON
List
Map
Math
Null
Nullable
Option
Promise
RegExp
Result
Set
String
Type
Undefined
Symbol
BigInt
Intl Collator
Intl DateTimeFormat
Intl Locale
Intl NumberFormat
Intl PluralRules
Intl RelativeTimeFormat
Object
ArrayBuffer
BigInt64Array
BigUint64Array
Float32Array
Float64Array
Int8Array
Int16Array
Int32Array
TypedArray
Uint8Array
Uint8ClampedArray
Uint16Array
Uint32Array
WeakMap
WeakSet
DataView
Suggested format
This example (and the rest in that file) is a good guide: https://github.com/rescript-association/rescript-core/blob/main/src/Core__Promise.resi#L11-L17
Workflow
I propose the following workflow:
.resi
file for the module, if it doesn't have one already. We aim for all modules havingresi
files, and to keep the documentation in there.I can recommend having the compiler running as you work on docstrings, and then use
TempTest.res
to get immediate feedback on your changes. Just use whatever you're working on and hover it in there and you'll see how the docstrings render immediately.Editor integration
We want to make using
Core
an as pleasant experience as possible. Part of that is also that the editor tooling behaves the way we want it to with regards to docstrings etc. #3 this issue covers that, feel free to post things you discover in there.Open questions
First off, please give feedback on the format, so we can ensure we cover everything we want to cover. Here are some additional open questions:
Map
which binds to the native JSMap
, whereBelt.Map
is an immutable alternative.The text was updated successfully, but these errors were encountered: