shareable-twoslash-comments 0.0.7 → 0.0.9

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
@@ -1,8 +1,8 @@
1
1
  ## Shareable Twoslash Comments
2
2
 
3
- A TypeScript Playground plugin that embeds twoslash (// ^?) type hints as literal comments in your code, making them easy to copy and share.
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,74 @@ 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, 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
+ model = sandbox.getModel();
72
+ return [4 /*yield*/, sandbox.getWorkerProcess()];
73
+ case 1:
74
+ worker = _d.sent();
75
+ return [4 /*yield*/, Promise.all([
76
+ worker.getSyntacticDiagnostics("file://" + model.uri.path),
77
+ worker.getSemanticDiagnostics("file://" + model.uri.path),
78
+ ])];
79
+ case 2:
80
+ diagnostics = _d.sent();
81
+ if (diagnostics.flat().length > 0) {
82
+ return [2 /*return*/];
83
+ }
84
+ text = model.getValue();
85
+ editOperations = [];
86
+ _i = 0, _a = Array.from(text.matchAll(twoSlashQueryRegex));
87
+ _d.label = 3;
88
+ case 3:
89
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
90
+ match = _a[_i];
91
+ commentPrefix = "".concat(match[1], "//").padEnd(match[0].length + 1);
92
+ caretOffset = match.index + match[0].length - 2;
93
+ caretPos = model.getPositionAt(caretOffset);
94
+ quickInfoPos = new sandbox.monaco.Position(caretPos.lineNumber - 1, caretPos.column);
95
+ quickInfoOffset = model.getOffsetAt(quickInfoPos);
96
+ return [4 /*yield*/, worker.getQuickInfoAtPosition("file://" + model.uri.path, quickInfoOffset)];
97
+ case 4:
98
+ quickInfo = _d.sent();
99
+ 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 : "";
100
+ quickInfoComment = "".concat(match[0]).concat(quickInfoString.length > 0 ? " " : "").concat(multilineEnabled
101
+ ? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
102
+ : truncate(quickInfoString.replace(/\r?\n\s*/g, " "), truncationDisabled ? Number.POSITIVE_INFINITY : 100));
103
+ prevQuickInfoComment = getPreviousQuickInfoComment({
104
+ model: model,
105
+ lineNumber: caretPos.lineNumber,
106
+ commentPrefix: commentPrefix,
113
107
  });
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
- }
108
+ prevQuickInfoLines = prevQuickInfoComment.split("\n").length;
109
+ prevQuickInfoEndLine = caretPos.lineNumber + prevQuickInfoLines - 1;
110
+ if (prevQuickInfoComment !== quickInfoComment) {
111
+ editOperations.push({
112
+ range: new sandbox.monaco.Range(caretPos.lineNumber, 0, prevQuickInfoEndLine, model.getLineContent(prevQuickInfoEndLine).length + 1),
113
+ text: quickInfoComment,
114
+ });
115
+ }
116
+ _d.label = 5;
117
+ case 5:
118
+ _i++;
119
+ return [3 /*break*/, 3];
120
+ case 6:
121
+ if (editOperations.length > 0) {
122
+ model.applyEdits(editOperations);
123
+ }
124
+ return [2 /*return*/];
125
+ }
126
+ });
125
127
  });
126
- }); };
127
- var getPreviousQuickInfoComment = function (_a) {
128
+ }
129
+ function getPreviousQuickInfoComment(_a) {
128
130
  var model = _a.model, lineNumber = _a.lineNumber, commentPrefix = _a.commentPrefix;
129
131
  var prevQuickInfoLines = [model.getLineContent(lineNumber)];
130
132
  for (var currLineNumber = lineNumber + 1; currLineNumber <= model.getLineCount(); currLineNumber++) {
@@ -135,8 +137,8 @@ define(function () { 'use strict';
135
137
  prevQuickInfoLines.push(lineContent);
136
138
  }
137
139
  return prevQuickInfoLines.join(model.getEOL());
138
- };
139
- var debounce = function (callback, delay) {
140
+ }
141
+ function debounce(callback, delay) {
140
142
  if (delay === void 0) { delay = 1000; }
141
143
  var timeoutId;
142
144
  return function () {
@@ -152,10 +154,10 @@ define(function () { 'use strict';
152
154
  timeoutId = undefined;
153
155
  }, delay);
154
156
  };
155
- };
156
- var truncate = function (str, maxLength) {
157
+ }
158
+ function truncate(str, maxLength) {
157
159
  return str.length > maxLength ? str.slice(0, maxLength) + "…" : str;
158
- };
160
+ }
159
161
  //# sourceMappingURL=utils.js.map
160
162
 
161
163
  var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 500);
@@ -212,6 +214,26 @@ define(function () { 'use strict';
212
214
  };
213
215
  return customPlugin;
214
216
  };
217
+ // type GetLeftMostQuickInfo = (args: {
218
+ // sandbox: Sandbox;
219
+ // model: import("monaco-editor").editor.ITextModel;
220
+ // lineNumber: number;
221
+ // }) => Promise<number | undefined>;
222
+ // const getLeftMostQuickInfo: GetLeftMostQuickInfo = async ({ sandbox, model, lineNumber }) => {
223
+ // const worker = await sandbox.getWorkerProcess();
224
+ // const lineLength = model.getLineContent(lineNumber).length;
225
+ // for (let column = 0; column <= lineLength; column++) {
226
+ // const quickInfoPos = new sandbox.monaco.Position(lineNumber, column);
227
+ // const quickInfoOffset = model.getOffsetAt(quickInfoPos);
228
+ // const quickInfo = await worker.getQuickInfoAtPosition(
229
+ // "file://" + model.uri.path,
230
+ // quickInfoOffset,
231
+ // );
232
+ // if (quickInfo) {
233
+ // return column;
234
+ // }
235
+ // }
236
+ // };
215
237
  //# sourceMappingURL=index.js.map
216
238
 
217
239
  return makePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareable-twoslash-comments",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
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",