shareable-twoslash-comments 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A TypeScript Playground plugin that embeds twoslash (// ^?) type hints as literal comments in your code, making them easy to copy and share.
4
4
 
5
+ https://github.com/user-attachments/assets/2224eec7-3011-4a08-b157-9eb6da700675
6
+
5
7
  ## Running this plugin
6
8
 
7
9
  - [Click this link](https://www.typescriptlang.org/play?install-plugin=shareable-twoslash-comments) to install
package/dist/index.js CHANGED
@@ -60,12 +60,13 @@ define(function () { 'use strict';
60
60
 
61
61
  var twoSlashQueryRegex = /(^[ \t]*)(\/\/\s*\^\?)/gm;
62
62
  var fillTwoSlashQueries = function (sandbox) { return __awaiter(void 0, void 0, void 0, function () {
63
- var multilineEnabled, model, worker, diagnostics, text, editOperations, _i, _a, match, commentPrefix, caretOffset, caretPos, quickInfoPos, quickInfoOffset, quickInfo, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
63
+ var multilineEnabled, truncationDisabled, model, worker, diagnostics, text, editOperations, _i, _a, match, commentPrefix, caretOffset, caretPos, quickInfoPos, quickInfoOffset, quickInfo, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
64
64
  var _b, _c;
65
65
  return __generator(this, function (_d) {
66
66
  switch (_d.label) {
67
67
  case 0:
68
68
  multilineEnabled = localStorage.getItem("shareable-twoslash-comments/enable-multiline-comments") === "true";
69
+ truncationDisabled = localStorage.getItem("shareable-twoslash-comments/disable-truncation") === "true";
69
70
  model = sandbox.getModel();
70
71
  return [4 /*yield*/, sandbox.getWorkerProcess()];
71
72
  case 1:
@@ -97,7 +98,7 @@ define(function () { 'use strict';
97
98
  quickInfoString = (_c = (_b = quickInfo === null || quickInfo === void 0 ? void 0 : quickInfo.displayParts) === null || _b === void 0 ? void 0 : _b.map(function (d) { return d.text; }).join("")) !== null && _c !== void 0 ? _c : "";
98
99
  quickInfoComment = "".concat(match[0], " ").concat(multilineEnabled
99
100
  ? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
100
- : quickInfoString.replace(/\r?\n\s*/g, " "));
101
+ : truncate(quickInfoString.replace(/\r?\n\s*/g, " "), truncationDisabled ? Number.POSITIVE_INFINITY : 100));
101
102
  prevQuickInfoComment = getPreviousQuickInfoComment({
102
103
  model: model,
103
104
  lineNumber: caretPos.lineNumber,
@@ -152,13 +153,17 @@ define(function () { 'use strict';
152
153
  }, delay);
153
154
  };
154
155
  };
156
+ var truncate = function (str, maxLength) {
157
+ return str.length > maxLength ? str.slice(0, maxLength) + "…" : str;
158
+ };
155
159
  //# sourceMappingURL=utils.js.map
156
160
 
157
- var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 600);
161
+ var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 500);
158
162
  var makePlugin = function (utils) {
159
163
  var customPlugin = {
160
164
  id: "shareable-twoslash-comments",
161
165
  displayName: "Shareable Twoslash Comments",
166
+ data: { firstMount: true },
162
167
  didMount: function (sandbox, container) {
163
168
  // Create a design system object to handle
164
169
  // making DOM elements which fit the playground (and handle mobile/light/dark etc)
@@ -171,17 +176,29 @@ define(function () { 'use strict';
171
176
  display: "Enable multiline comments",
172
177
  onchange: function () { return fillTwoSlashQueries(sandbox); },
173
178
  },
179
+ {
180
+ blurb: "Prevent truncation of single line comments. Otherwise, they will be truncated to 100 characters.",
181
+ flag: "shareable-twoslash-comments/disable-truncation",
182
+ display: "Disable truncation",
183
+ onchange: function () { return fillTwoSlashQueries(sandbox); },
184
+ },
174
185
  ], {
175
186
  style: "separated",
176
187
  });
188
+ var model = sandbox.getModel();
189
+ if (customPlugin.data.firstMount) {
190
+ model.onDidChangeContent(function () {
191
+ debouncedFillTwoSlashQueries(sandbox);
192
+ });
193
+ customPlugin.data.firstMount = false;
194
+ }
177
195
  },
178
196
  // This is called occasionally as text changes in monaco,
179
197
  // it does not directly map 1 keyup to once run of the function
180
198
  // because it is intentionally called at most once every 0.3 seconds
181
199
  // and then will always run at the end.
182
- modelChangedDebounce: function (sandbox, model) { return __awaiter(void 0, void 0, void 0, function () {
200
+ modelChangedDebounce: function (_sandbox, _model) { return __awaiter(void 0, void 0, void 0, function () {
183
201
  return __generator(this, function (_a) {
184
- debouncedFillTwoSlashQueries(sandbox);
185
202
  return [2 /*return*/];
186
203
  });
187
204
  }); },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareable-twoslash-comments",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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",