shareable-twoslash-comments 0.0.8 → 0.0.10

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.
@@ -0,0 +1,15 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [som-sm] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12
+ polar: # Replace with a single Polar username
13
+ buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14
+ thanks_dev: # Replace with a single thanks.dev username
15
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A TypeScript Playground plugin that injects 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/78243c42-a868-4ece-9815-e869a20e30b6
5
+ https://github.com/user-attachments/assets/5e42a08e-7570-4d04-9434-6a93cd898e7f
6
6
 
7
7
  ## Running this plugin
8
8
 
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,5 @@
1
+ .readonly-line {
2
+ color: gray;
3
+ background: black;
4
+ }
5
+
@@ -0,0 +1,5 @@
1
+ .readonly-line {
2
+ color: gray;
3
+ background: black;
4
+ }
5
+
package/dist/index.js CHANGED
@@ -59,72 +59,78 @@ define(function () { 'use strict';
59
59
  };
60
60
 
61
61
  var twoSlashQueryRegex = /(^[ \t]*)(\/\/\s*\^\?)/gm;
62
- var fillTwoSlashQueries = function (sandbox) { return __awaiter(void 0, void 0, void 0, function () {
63
- var multilineEnabled, truncationDisabled, model, worker, diagnostics, text, editOperations, _i, _a, match, commentPrefix, caretOffset, caretPos, quickInfoPos, quickInfoOffset, quickInfo, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
64
- var _b, _c;
65
- return __generator(this, function (_d) {
66
- switch (_d.label) {
67
- case 0:
68
- multilineEnabled = localStorage.getItem("shareable-twoslash-comments/enable-multiline-comments") === "true";
69
- truncationDisabled = localStorage.getItem("shareable-twoslash-comments/disable-truncation") === "true";
70
- model = sandbox.getModel();
71
- return [4 /*yield*/, sandbox.getWorkerProcess()];
72
- case 1:
73
- worker = _d.sent();
74
- return [4 /*yield*/, Promise.all([
75
- worker.getSyntacticDiagnostics("file://" + model.uri.path),
76
- worker.getSemanticDiagnostics("file://" + model.uri.path),
77
- ])];
78
- case 2:
79
- diagnostics = _d.sent();
80
- if (diagnostics.flat().length > 0) {
81
- return [2 /*return*/];
82
- }
83
- text = model.getValue();
84
- editOperations = [];
85
- _i = 0, _a = Array.from(text.matchAll(twoSlashQueryRegex));
86
- _d.label = 3;
87
- case 3:
88
- if (!(_i < _a.length)) return [3 /*break*/, 6];
89
- match = _a[_i];
90
- commentPrefix = "".concat(match[1], "//").padEnd(match[0].length + 1);
91
- caretOffset = match.index + match[0].length - 1;
92
- caretPos = model.getPositionAt(caretOffset);
93
- quickInfoPos = new sandbox.monaco.Position(caretPos.lineNumber - 1, caretPos.column);
94
- quickInfoOffset = model.getOffsetAt(quickInfoPos);
95
- return [4 /*yield*/, worker.getQuickInfoAtPosition("file://" + model.uri.path, quickInfoOffset)];
96
- case 4:
97
- quickInfo = _d.sent();
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 : "";
99
- quickInfoComment = "".concat(match[0]).concat(quickInfoString.length > 0 ? " " : "").concat(multilineEnabled
100
- ? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
101
- : truncate(quickInfoString.replace(/\r?\n\s*/g, " "), truncationDisabled ? Number.POSITIVE_INFINITY : 100));
102
- prevQuickInfoComment = getPreviousQuickInfoComment({
103
- model: model,
104
- lineNumber: caretPos.lineNumber,
105
- commentPrefix: commentPrefix,
106
- });
107
- prevQuickInfoLines = prevQuickInfoComment.split("\n").length;
108
- prevQuickInfoEndLine = caretPos.lineNumber + prevQuickInfoLines - 1;
109
- if (prevQuickInfoComment !== quickInfoComment) {
110
- editOperations.push({
111
- range: new sandbox.monaco.Range(caretPos.lineNumber, 0, prevQuickInfoEndLine, model.getLineContent(prevQuickInfoEndLine).length + 1),
112
- text: quickInfoComment,
62
+ function fillTwoSlashQueries(sandbox) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var multilineEnabled, truncationDisabled, pauseOnError, model, worker, diagnostics, text, editOperations, _i, _a, match, commentPrefix, caretOffset, caretPos, quickInfoPos, quickInfoOffset, quickInfo, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
65
+ var _b, _c;
66
+ return __generator(this, function (_d) {
67
+ switch (_d.label) {
68
+ case 0:
69
+ multilineEnabled = localStorage.getItem("shareable-twoslash-comments/enable-multiline-comments") === "true";
70
+ truncationDisabled = localStorage.getItem("shareable-twoslash-comments/disable-truncation") === "true";
71
+ pauseOnError = localStorage.getItem("shareable-twoslash-comments/pause-on-error") === "true";
72
+ model = sandbox.getModel();
73
+ return [4 /*yield*/, sandbox.getWorkerProcess()];
74
+ case 1:
75
+ worker = _d.sent();
76
+ if (!pauseOnError) return [3 /*break*/, 3];
77
+ return [4 /*yield*/, Promise.all([
78
+ worker.getSyntacticDiagnostics("file://" + model.uri.path),
79
+ worker.getSemanticDiagnostics("file://" + model.uri.path),
80
+ ])];
81
+ case 2:
82
+ diagnostics = _d.sent();
83
+ if (diagnostics.flat().length > 0) {
84
+ return [2 /*return*/];
85
+ }
86
+ _d.label = 3;
87
+ case 3:
88
+ text = model.getValue();
89
+ editOperations = [];
90
+ _i = 0, _a = Array.from(text.matchAll(twoSlashQueryRegex));
91
+ _d.label = 4;
92
+ case 4:
93
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
94
+ match = _a[_i];
95
+ commentPrefix = "".concat(match[1], "//").padEnd(match[0].length + 1);
96
+ caretOffset = match.index + match[0].length - 2;
97
+ caretPos = model.getPositionAt(caretOffset);
98
+ quickInfoPos = new sandbox.monaco.Position(caretPos.lineNumber - 1, caretPos.column);
99
+ quickInfoOffset = model.getOffsetAt(quickInfoPos);
100
+ return [4 /*yield*/, worker.getQuickInfoAtPosition("file://" + model.uri.path, quickInfoOffset)];
101
+ case 5:
102
+ quickInfo = _d.sent();
103
+ 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 : "";
104
+ quickInfoComment = "".concat(match[0]).concat(quickInfoString.length > 0 ? " " : "").concat(multilineEnabled
105
+ ? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
106
+ : truncate(quickInfoString.replace(/\r?\n\s*/g, " "), truncationDisabled ? Number.POSITIVE_INFINITY : 100));
107
+ prevQuickInfoComment = getPreviousQuickInfoComment({
108
+ model: model,
109
+ lineNumber: caretPos.lineNumber,
110
+ commentPrefix: commentPrefix,
113
111
  });
114
- }
115
- _d.label = 5;
116
- case 5:
117
- _i++;
118
- return [3 /*break*/, 3];
119
- case 6:
120
- if (editOperations.length > 0) {
121
- model.applyEdits(editOperations);
122
- }
123
- return [2 /*return*/];
124
- }
112
+ prevQuickInfoLines = prevQuickInfoComment.split("\n").length;
113
+ prevQuickInfoEndLine = caretPos.lineNumber + prevQuickInfoLines - 1;
114
+ if (prevQuickInfoComment !== quickInfoComment) {
115
+ editOperations.push({
116
+ range: new sandbox.monaco.Range(caretPos.lineNumber, 0, prevQuickInfoEndLine, model.getLineContent(prevQuickInfoEndLine).length + 1),
117
+ text: quickInfoComment,
118
+ });
119
+ }
120
+ _d.label = 6;
121
+ case 6:
122
+ _i++;
123
+ return [3 /*break*/, 4];
124
+ case 7:
125
+ if (editOperations.length > 0) {
126
+ model.applyEdits(editOperations);
127
+ }
128
+ return [2 /*return*/];
129
+ }
130
+ });
125
131
  });
126
- }); };
127
- var getPreviousQuickInfoComment = function (_a) {
132
+ }
133
+ function getPreviousQuickInfoComment(_a) {
128
134
  var model = _a.model, lineNumber = _a.lineNumber, commentPrefix = _a.commentPrefix;
129
135
  var prevQuickInfoLines = [model.getLineContent(lineNumber)];
130
136
  for (var currLineNumber = lineNumber + 1; currLineNumber <= model.getLineCount(); currLineNumber++) {
@@ -135,8 +141,8 @@ define(function () { 'use strict';
135
141
  prevQuickInfoLines.push(lineContent);
136
142
  }
137
143
  return prevQuickInfoLines.join(model.getEOL());
138
- };
139
- var debounce = function (callback, delay) {
144
+ }
145
+ function debounce(callback, delay) {
140
146
  if (delay === void 0) { delay = 1000; }
141
147
  var timeoutId;
142
148
  return function () {
@@ -152,10 +158,10 @@ define(function () { 'use strict';
152
158
  timeoutId = undefined;
153
159
  }, delay);
154
160
  };
155
- };
156
- var truncate = function (str, maxLength) {
161
+ }
162
+ function truncate(str, maxLength) {
157
163
  return str.length > maxLength ? str.slice(0, maxLength) + "…" : str;
158
- };
164
+ }
159
165
  //# sourceMappingURL=utils.js.map
160
166
 
161
167
  var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 500);
@@ -183,6 +189,12 @@ define(function () { 'use strict';
183
189
  display: "Disable truncation",
184
190
  onchange: function () { return fillTwoSlashQueries(sandbox); },
185
191
  },
192
+ {
193
+ blurb: "Pause comment generation if there are any errors in the code.",
194
+ flag: "shareable-twoslash-comments/pause-on-error",
195
+ display: "Pause on error",
196
+ onchange: function () { return fillTwoSlashQueries(sandbox); },
197
+ },
186
198
  ], {
187
199
  style: "separated",
188
200
  });
@@ -212,6 +224,26 @@ define(function () { 'use strict';
212
224
  };
213
225
  return customPlugin;
214
226
  };
227
+ // type GetLeftMostQuickInfo = (args: {
228
+ // sandbox: Sandbox;
229
+ // model: import("monaco-editor").editor.ITextModel;
230
+ // lineNumber: number;
231
+ // }) => Promise<number | undefined>;
232
+ // const getLeftMostQuickInfo: GetLeftMostQuickInfo = async ({ sandbox, model, lineNumber }) => {
233
+ // const worker = await sandbox.getWorkerProcess();
234
+ // const lineLength = model.getLineContent(lineNumber).length;
235
+ // for (let column = 0; column <= lineLength; column++) {
236
+ // const quickInfoPos = new sandbox.monaco.Position(lineNumber, column);
237
+ // const quickInfoOffset = model.getOffsetAt(quickInfoPos);
238
+ // const quickInfo = await worker.getQuickInfoAtPosition(
239
+ // "file://" + model.uri.path,
240
+ // quickInfoOffset,
241
+ // );
242
+ // if (quickInfo) {
243
+ // return column;
244
+ // }
245
+ // }
246
+ // };
215
247
  //# sourceMappingURL=index.js.map
216
248
 
217
249
  return makePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareable-twoslash-comments",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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",