shareable-twoslash-comments 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +87 -7
- package/package.json +1 -1
- package/dist/assets/asset-125afa63 +0 -1
- package/dist/assets/asset-e4c236d5 +0 -5
- package/dist/bundle.css +0 -5
package/dist/index.js
CHANGED
|
@@ -79,7 +79,12 @@ define(function () { 'use strict';
|
|
|
79
79
|
case 2:
|
|
80
80
|
quickInfo = _c.sent();
|
|
81
81
|
if (quickInfo === null || quickInfo === void 0 ? void 0 : quickInfo.displayParts) {
|
|
82
|
-
return [2 /*return*/,
|
|
82
|
+
return [2 /*return*/, compactOutputEnabled
|
|
83
|
+
? extractTypeFromDisplayParts(quickInfo.displayParts)
|
|
84
|
+
: quickInfo.displayParts.map(function (_a) {
|
|
85
|
+
var text = _a.text;
|
|
86
|
+
return text;
|
|
87
|
+
}).join("")];
|
|
83
88
|
}
|
|
84
89
|
_c.label = 3;
|
|
85
90
|
case 3:
|
|
@@ -90,25 +95,74 @@ define(function () { 'use strict';
|
|
|
90
95
|
});
|
|
91
96
|
});
|
|
92
97
|
}
|
|
98
|
+
function extractTypeFromDisplayParts(displayParts) {
|
|
99
|
+
// For interfaces and enums, return everything after the keyword.
|
|
100
|
+
var keywordIndex = displayParts.findIndex(function (part) { return part.kind === "keyword" && ["interface", "enum"].includes(part.text); });
|
|
101
|
+
if (keywordIndex !== -1) {
|
|
102
|
+
return displayParts
|
|
103
|
+
.slice(keywordIndex + 1)
|
|
104
|
+
.map(function (part) { return part.text; })
|
|
105
|
+
.join("")
|
|
106
|
+
.trim();
|
|
107
|
+
}
|
|
108
|
+
var depth = 0;
|
|
109
|
+
var separatorIndex = displayParts.findIndex(function (part) {
|
|
110
|
+
if (part.kind === "punctuation") {
|
|
111
|
+
if (["(", "{", "<"].includes(part.text)) {
|
|
112
|
+
depth++;
|
|
113
|
+
}
|
|
114
|
+
else if ([")", "}", ">"].includes(part.text)) {
|
|
115
|
+
depth--;
|
|
116
|
+
}
|
|
117
|
+
else if (part.text === ":" && depth === 0) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (part.kind === "operator" && part.text === "=" && depth === 0) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
// If `separatorIndex` is `-1` (not found), return the entire thing.
|
|
127
|
+
return displayParts
|
|
128
|
+
.slice(separatorIndex + 1)
|
|
129
|
+
.map(function (_a) {
|
|
130
|
+
var text = _a.text;
|
|
131
|
+
return text;
|
|
132
|
+
})
|
|
133
|
+
.join("")
|
|
134
|
+
.trim();
|
|
135
|
+
}
|
|
93
136
|
function getPreviousQuickInfoComment(_a) {
|
|
94
|
-
var lineNumber = _a.lineNumber
|
|
137
|
+
var lineNumber = _a.lineNumber;
|
|
95
138
|
var prevQuickInfoLines = [model.getLineContent(lineNumber)];
|
|
96
139
|
for (var currLineNumber = lineNumber + 1; currLineNumber <= model.getLineCount(); currLineNumber++) {
|
|
97
140
|
var lineContent = model.getLineContent(currLineNumber);
|
|
98
|
-
|
|
141
|
+
/*
|
|
142
|
+
Non-first lines in plugin generated comments are guaranteed to have 3 spaces after `//`.
|
|
143
|
+
```
|
|
144
|
+
let foo = {bar: 1};
|
|
145
|
+
foo
|
|
146
|
+
//^? let foo: {
|
|
147
|
+
// bar: number; [[ 3 spaces after `//` ]]
|
|
148
|
+
// } [[ 3 spaces after `//` ]]
|
|
149
|
+
```
|
|
150
|
+
*/
|
|
151
|
+
if (!/^ *\/\/ {3}/.test(lineContent)) {
|
|
99
152
|
break;
|
|
100
153
|
}
|
|
101
154
|
prevQuickInfoLines.push(lineContent);
|
|
102
155
|
}
|
|
103
156
|
return prevQuickInfoLines.join(model.getEOL());
|
|
104
157
|
}
|
|
105
|
-
var multilineEnabled, truncationDisabled, pauseOnError, model, worker, diagnostics, text, editOperations, matches, _i, matches_1, _a, match, queryType, textBeforeQuery, commentPrefix, isInlineArrowQuery, lineNumber, column, caretOffset, caretPos, quickInfoLine, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
|
|
158
|
+
var multilineEnabled, truncationDisabled, compactOutputEnabled, pauseOnError, model, worker, diagnostics, text, editOperations, matches, _i, matches_1, _a, match, queryType, textBeforeQuery, commentPrefix, isInlineArrowQuery, lineNumber, column, caretOffset, caretPos, quickInfoLine, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
|
|
106
159
|
if (isUndoRedoChange === void 0) { isUndoRedoChange = false; }
|
|
107
160
|
return __generator(this, function (_b) {
|
|
108
161
|
switch (_b.label) {
|
|
109
162
|
case 0:
|
|
110
163
|
multilineEnabled = localStorage.getItem("shareable-twoslash-comments/enable-multiline-comments") === "true";
|
|
111
164
|
truncationDisabled = localStorage.getItem("shareable-twoslash-comments/disable-truncation") === "true";
|
|
165
|
+
compactOutputEnabled = localStorage.getItem("shareable-twoslash-comments/compact-output") === "true";
|
|
112
166
|
pauseOnError = localStorage.getItem("shareable-twoslash-comments/pause-on-error") === "true";
|
|
113
167
|
model = sandbox.getModel();
|
|
114
168
|
return [4 /*yield*/, sandbox.getWorkerProcess()];
|
|
@@ -163,7 +217,7 @@ define(function () { 'use strict';
|
|
|
163
217
|
quickInfoComment = "".concat(match[0]).concat(quickInfoString.length > 0 ? " " : "").concat(multilineEnabled
|
|
164
218
|
? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
|
|
165
219
|
: truncate(quickInfoString.replace(/\r?\n\s*/g, " "), truncationDisabled ? Number.POSITIVE_INFINITY : 100));
|
|
166
|
-
prevQuickInfoComment = getPreviousQuickInfoComment({ lineNumber: lineNumber
|
|
220
|
+
prevQuickInfoComment = getPreviousQuickInfoComment({ lineNumber: lineNumber });
|
|
167
221
|
prevQuickInfoLines = prevQuickInfoComment.split("\n").length;
|
|
168
222
|
prevQuickInfoEndLine = lineNumber + prevQuickInfoLines - 1;
|
|
169
223
|
if (prevQuickInfoComment !== quickInfoComment) {
|
|
@@ -220,7 +274,6 @@ define(function () { 'use strict';
|
|
|
220
274
|
function truncate(str, maxLength) {
|
|
221
275
|
return str.length > maxLength ? str.slice(0, maxLength) + "…" : str;
|
|
222
276
|
}
|
|
223
|
-
//# sourceMappingURL=utils.js.map
|
|
224
277
|
|
|
225
278
|
var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 500);
|
|
226
279
|
var makePlugin = function (utils) {
|
|
@@ -231,6 +284,28 @@ define(function () { 'use strict';
|
|
|
231
284
|
shouldBeSelected: function () { return true; },
|
|
232
285
|
didMount: function (sandbox, container) {
|
|
233
286
|
container.style.paddingRight = "8px";
|
|
287
|
+
var sponsorBanner = document.createElement("a");
|
|
288
|
+
sponsorBanner.href = "https://github.com/sponsors/som-sm";
|
|
289
|
+
sponsorBanner.target = "_blank";
|
|
290
|
+
sponsorBanner.rel = "noopener noreferrer";
|
|
291
|
+
sponsorBanner.textContent = "♡ Support this plugin";
|
|
292
|
+
Object.assign(sponsorBanner.style, {
|
|
293
|
+
display: "block",
|
|
294
|
+
paddingBottom: "8px",
|
|
295
|
+
borderBottom: "1px solid var(--border-color, rgba(128,128,128,0.2))",
|
|
296
|
+
color: "var(--text-color, inherit)",
|
|
297
|
+
textDecoration: "none",
|
|
298
|
+
textAlign: "right",
|
|
299
|
+
fontSize: "0.8em",
|
|
300
|
+
opacity: "0.6",
|
|
301
|
+
});
|
|
302
|
+
sponsorBanner.onmouseenter = function () {
|
|
303
|
+
sponsorBanner.style.opacity = "1";
|
|
304
|
+
};
|
|
305
|
+
sponsorBanner.onmouseleave = function () {
|
|
306
|
+
sponsorBanner.style.opacity = "0.6";
|
|
307
|
+
};
|
|
308
|
+
container.appendChild(sponsorBanner);
|
|
234
309
|
// Create a design system object to handle
|
|
235
310
|
// making DOM elements which fit the playground (and handle mobile/light/dark etc)
|
|
236
311
|
var ds = utils.createDesignSystem(container);
|
|
@@ -251,6 +326,12 @@ define(function () { 'use strict';
|
|
|
251
326
|
display: "Enable multiline comments",
|
|
252
327
|
onchange: function () { return fillTwoSlashQueries(sandbox); },
|
|
253
328
|
},
|
|
329
|
+
{
|
|
330
|
+
blurb: "Generate shorter comments by inserting just the type.",
|
|
331
|
+
flag: "shareable-twoslash-comments/compact-output",
|
|
332
|
+
display: "Compact output",
|
|
333
|
+
onchange: function () { return fillTwoSlashQueries(sandbox); },
|
|
334
|
+
},
|
|
254
335
|
{
|
|
255
336
|
blurb: "Prevent truncation of single line comments. Otherwise, they will be truncated to 100 characters.",
|
|
256
337
|
flag: "shareable-twoslash-comments/disable-truncation",
|
|
@@ -317,7 +398,6 @@ define(function () { 'use strict';
|
|
|
317
398
|
};
|
|
318
399
|
return customPlugin;
|
|
319
400
|
};
|
|
320
|
-
//# sourceMappingURL=index.js.map
|
|
321
401
|
|
|
322
402
|
return makePlugin;
|
|
323
403
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shareable-twoslash-comments",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "A TypeScript Playground plugin that embeds twoslash (// ^?) type hints as literal comments in your code, making them easy to copy and share.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|