-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: add JSDoc example #8533
base: master
Are you sure you want to change the base?
feat: add JSDoc example #8533
Changes from 1 commit
602e5ea
270aeba
492d812
ac308e0
b6f219a
a5feb38
c5304b4
43eff4e
cdceedd
8f0d37e
24279cc
e3fc9b4
18517b6
c56afea
06204b1
0c92f1b
562a308
3cc1849
2eaadcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/*\ | ||
// @ts-check | ||
/** | ||
title: $:/core/modules/parsers/wikiparser/rules/codeblock.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to change the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
type: application/javascript | ||
module-type: wikirule | ||
|
@@ -11,7 +12,28 @@ Wiki text rule for code blocks. For example: | |
``` | ||
``` | ||
|
||
@module $:/core/modules/parsers/wikiparser/rules/codeblock.js | ||
|
||
linonetwo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
\*/ | ||
|
||
/** | ||
* Represents the `codeblock` rule. | ||
* | ||
* @typedef {Object} CodeblockNode | ||
* @property {string} type - The type of the widget, which is "codeblock". | ||
* @property {Object} attributes - The attributes of the codeblock. | ||
* @property {Object} attributes.code - The code attribute object. | ||
* @property {string} attributes.code.type - The type of the code attribute, which is "string". | ||
* @property {string} attributes.code.value - The actual code content within the code block. | ||
* @property {number} attributes.code.start - The start position of the code in the source text. | ||
* @property {number} attributes.code.end - The end position of the code in the source text. | ||
* @property {Object} attributes.language - The language attribute object. | ||
* @property {string} attributes.language.type - The type of the language attribute, which is "string". | ||
* @property {string} attributes.language.value - The language specified after the triple backticks, if any. | ||
* @property {number} attributes.language.start - The start position of the language string in the source text. | ||
* @property {number} attributes.language.end - The end position of the language string in the source text. | ||
*/ | ||
|
||
(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO having
eg:
Should be as short as possible and still valid. Especially see I did remove the "full stops" from all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'd copy that. I have to admit, all jsdoc are generated by github copilot. I don't have time for this detail, I will leave it for future refinement. I'm still debugging the type when I'm using it in my plugin project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new type information will significantly increase the TW code-size. So if there is redundant information it should be removed. And even more important it has to be valid. So if the co-pilot only adds comments in a more verbose form than the parameters are. There should not be any comments at all -- They have no value. So if there are no comments, we actually know, that we have to add them manually. IMO for the tooltips it would be OK to start with the type info. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
we must remove comments before publishing HTML wiki. I think these JSDoc will basically double the size.
This won't be a big problem, because 1. I use the method body as input too. And 2. we can auto merge "comment" type of PR based on #7542 , so people can update comment quickly. I find this is quite frequent when maintaining https://github.com/tiddly-gittly/TW5-Typed |
||
|
||
/*jslint node: true, browser: true */ | ||
|
@@ -21,12 +43,22 @@ Wiki text rule for code blocks. For example: | |
exports.name = "codeblock"; | ||
exports.types = {block: true}; | ||
|
||
/** | ||
* Initializes the codeblock rule with the given parser. | ||
* | ||
* @param {Object} parser - The parser object that manages the state of the parsing process. | ||
*/ | ||
exports.init = function(parser) { | ||
this.parser = parser; | ||
// Regexp to match and get language if defined | ||
this.matchRegExp = /```([\w-]*)\r?\n/mg; | ||
}; | ||
|
||
/** | ||
* Parses the code block and returns an array of `codeblock` widgets. | ||
* | ||
* @returns {CodeblockNode[]} An array containing a single codeblock widget object. | ||
*/ | ||
exports.parse = function() { | ||
var reEnd = /(\r?\n```$)/mg; | ||
var languageStart = this.parser.pos + 3, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @ts-check | ||
/** | ||
* @typedef {import('./rules/codeblock').CodeblockNode} CodeblockNode | ||
*/ | ||
|
||
/** | ||
* A function that processes a code block. | ||
* | ||
* @param {CodeblockNode[]} codeblocks - An array of codeblock rules. | ||
*/ | ||
function processCodeblocks(codeblocks) { | ||
codeblocks.forEach(function(cb) { | ||
console.log(cb.attributes.code.value); | ||
}); | ||
} |
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.
What does this do?
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.
It enables VSCode and ts cli regard this file as
.ts
file. Maybe this enable different parse mode of VSCode.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.
The docs seem to imply that one can also use a separate "jsconfig.json" file. Would that be possible here?
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.
I try again and find VScode works with or without this. What make it work is open both file as tab...
I need to do more experiment.