-
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 8 commits
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ node_modules/ | |
/playwright-report/ | ||
/playwright/.cache/ | ||
$__StoryList.tid | ||
types/generated/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,16 +25,20 @@ Attributes are stored as hashmaps of the following objects: | |
/*global $tw: false */ | ||
"use strict"; | ||
|
||
/* | ||
type: content type of text | ||
text: text to be parsed | ||
options: see below: | ||
parseAsInline: true to parse text as inline instead of block | ||
wiki: reference to wiki to use | ||
_canonical_uri: optional URI of content if text is missing or empty | ||
configTrimWhiteSpace: true to trim whitespace | ||
*/ | ||
var WikiParser = function(type,text,options) { | ||
/** | ||
* WikiParser class for parsing text of a specified MIME type. | ||
* | ||
* @class | ||
* @constructor | ||
* @param {string} type - The content type of the text to be parsed. | ||
* @param {string} text - The text to be parsed. | ||
* @param {Object} options - Options for parsing. | ||
* @param {boolean} [options.parseAsInline=false] - If true, the text will be parsed as an inline run. | ||
* @param {Object} options.wiki - Reference to the wiki to use. | ||
* @param {string} [options._canonical_uri] - Optional URI of the content if the text is missing or empty. | ||
* @param {boolean} [options.configTrimWhiteSpace=false] - If true, trims white space according to configuration. | ||
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 the full-stop at the end of the comment text can be removed.
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, this will be the updated prompt:
|
||
*/ | ||
function WikiParser(type,text,options) { | ||
this.wiki = options.wiki; | ||
var self = this; | ||
// Check for an externally linked tiddler | ||
|
@@ -99,8 +103,11 @@ var WikiParser = function(type,text,options) { | |
// Return the parse tree | ||
}; | ||
|
||
/* | ||
*/ | ||
/** | ||
* Load a remote tiddler from a given URL. | ||
* | ||
* @param {string} url - The URL of the remote tiddler to load. | ||
*/ | ||
WikiParser.prototype.loadRemoteTiddler = function(url) { | ||
var self = this; | ||
$tw.utils.httpRequest({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,8 @@ Adds the following properties to the wiki object: | |
* `globalCache` is a hashmap by cache name of cache objects that are cleared whenever any tiddler change occurs | ||
|
||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
var widget = require("$:/core/modules/widgets/widget.js"); | ||
var Widget = require("$:/core/modules/widgets/widget.js").widget; | ||
|
||
var USER_NAME_TITLE = "$:/status/UserName", | ||
TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable"; | ||
|
@@ -1041,19 +1036,30 @@ exports.initParsers = function(moduleType) { | |
} | ||
}; | ||
|
||
/* | ||
Parse a block of text of a specified MIME type | ||
type: content type of text to be parsed | ||
text: text | ||
options: see below | ||
Options include: | ||
parseAsInline: if true, the text of the tiddler will be parsed as an inline run | ||
_canonical_uri: optional string of the canonical URI of this content | ||
*/ | ||
/** | ||
* @typedef {import('$:/core/modules/parsers/wikiparser/wikiparser.js')["text/vnd.tiddlywiki"]} WikiParser | ||
*/ | ||
|
||
/** | ||
* Parse a block of text of a specified MIME type. | ||
* | ||
* @param {string} type - The content type of the text to be parsed. | ||
* @param {string} text - The text to be parsed. | ||
* @param {Object} [options] - Options for parsing. | ||
* @param {boolean} [options.parseAsInline=false] - If true, the text will be parsed as an inline run. | ||
* @param {string} [options._canonical_uri] - Optional string of the canonical URI of this content. | ||
* @param {string} [options.defaultType="text/vnd.tiddlywiki"] - The default type to use if no parser is found for the specified type. | ||
* @param {boolean} [options.configTrimWhiteSpace=false] - If true, trims white space according to configuration. | ||
* | ||
* @returns {WikiParser|null} The parser instance or null if no parser is found. | ||
*/ | ||
exports.parseText = function(type,text,options) { | ||
text = text || ""; | ||
options = options || {}; | ||
// Select a parser | ||
/** | ||
* @type WikiParser | ||
* Select a parser | ||
*/ | ||
var Parser = $tw.Wiki.parsers[type]; | ||
if(!Parser && $tw.utils.getFileExtensionInfo(type)) { | ||
Parser = $tw.Wiki.parsers[$tw.utils.getFileExtensionInfo(type).type]; | ||
|
@@ -1143,14 +1149,16 @@ exports.getTextReferenceParserInfo = function(title,field,index,options) { | |
return parserInfo; | ||
} | ||
|
||
/* | ||
Parse a block of text of a specified MIME type | ||
text: text on which to perform substitutions | ||
widget | ||
options: see below | ||
Options include: | ||
substitutions: an optional array of substitutions | ||
*/ | ||
/** | ||
* Parse a block of text of a specified MIME type and perform substitutions. | ||
* | ||
* @param {string} text - The text on which to perform substitutions. | ||
* @param {Widget} widget - The widget context used for variable substitution. | ||
* @param {Object} [options] - Options for substitutions. | ||
* @param {Array<{name: string, value: string}>} [options.substitutions] - An optional array of substitutions. | ||
* | ||
* @returns {string} The text with substitutions applied. | ||
*/ | ||
exports.getSubstitutedText = function(text,widget,options) { | ||
options = options || {}; | ||
text = text || ""; | ||
|
@@ -1171,15 +1179,17 @@ exports.getSubstitutedText = function(text,widget,options) { | |
}); | ||
}; | ||
|
||
/* | ||
Make a widget tree for a parse tree | ||
parser: parser object | ||
options: see below | ||
Options include: | ||
document: optional document to use | ||
variables: hashmap of variables to set | ||
parentWidget: optional parent widget for the root node | ||
*/ | ||
/** | ||
* Create a widget tree for a parse tree. | ||
* | ||
* @param {Object} parser - The parser object containing the parse tree. | ||
* @param {Object} [options] - Options for creating the widget tree. | ||
* @param {Document} [options.document] - Optional document to use. | ||
* @param {Object} [options.variables] - Hashmap of variables to set. | ||
* @param {Widget} [options.parentWidget] - Optional parent widget for the root node. | ||
* | ||
* @returns {Widget} The root widget of the created widget tree. | ||
*/ | ||
exports.makeWidget = function(parser,options) { | ||
options = options || {}; | ||
var widgetNode = { | ||
|
@@ -1204,7 +1214,7 @@ exports.makeWidget = function(parser,options) { | |
// Add in the supplied parse tree nodes | ||
currWidgetNode.children = parser ? parser.tree : []; | ||
// Create the widget | ||
return new widget.widget(widgetNode,{ | ||
return new Widget(widgetNode,{ | ||
wiki: this, | ||
document: options.document || $tw.fakeDocument, | ||
parentWidget: options.parentWidget | ||
|
@@ -1487,9 +1497,13 @@ exports.search = function(text,options) { | |
return results; | ||
}; | ||
|
||
/* | ||
Trigger a load for a tiddler if it is skinny. Returns the text, or undefined if the tiddler is missing, null if the tiddler is being lazily loaded. | ||
*/ | ||
/** | ||
* Trigger a load for a tiddler if it is skinny. Returns the text, or undefined if the tiddler is missing, null if the tiddler is being lazily loaded. | ||
* | ||
* @param {string} title - The title of the tiddler. | ||
* @param {string} [defaultText] - The default text to return if the tiddler is missing. | ||
* @returns {string | null | undefined} - The text of the tiddler, undefined if the tiddler is missing, or null if the tiddler is being lazily loaded. | ||
*/ | ||
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 the type text should be as short as possible, but still understandable. Your definition contains "undefined", which is not returned. So I would suggest:
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. When add |
||
exports.getTiddlerText = function(title,defaultText) { | ||
var tiddler = this.getTiddler(title); | ||
// Return undefined if the tiddler isn't found | ||
|
@@ -1781,5 +1795,3 @@ exports.slugify = function(title,options) { | |
} | ||
return slug; | ||
}; | ||
|
||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
// Allow `import('$:/core/modules/...')` instead of `import('../../core/modules/...')`. Only works inside this project. | ||
"$:/core/*": ["./core/*"] | ||
}, | ||
"noImplicitAny": false, | ||
"strict": false, | ||
|
||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"checkJs": true, | ||
"declaration": true, | ||
"declarationDir": "types/generated", | ||
"declarationMap": true, | ||
"emitDeclarationOnly": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "Node16", | ||
"outDir": "types/generated", | ||
"rootDir": ".", | ||
"skipLibCheck": true, | ||
"target": "ESNext" | ||
}, | ||
"include": ["./core/**/*.js", "./core/**/*.d.ts", "types/tw.d.ts"], | ||
"exclude": ["types/generated"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as Wiki from '../core/modules/wiki'; | ||
|
||
declare global { | ||
var $tw: { | ||
wiki: typeof Wiki; | ||
}; | ||
} |
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.
IMO having
@property {string} type
and then- The type of the widget, which is "codeblock".
is the same thing. Both elements describe: "What it is". -- I think the second part should describe: "What it does", otherwise we can skip it.eg:
Should be as short as possible and still valid. Especially see
type, rule, start, end
which are properties of "CodeblockNode"I did remove the "full stops" from all
@
elements. They are not neededThe first intro sentence has a full stop.
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, 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 comment
The 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 comment
The 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