shareable-twoslash-comments 0.0.2 → 0.0.3
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 +47 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -60,21 +60,31 @@ 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, text, editOperations, _i, _a, match, commentPrefix, caretOffset, caretPos, quickInfoPos, quickInfoOffset, quickInfo, quickInfoString, quickInfoComment, prevQuickInfoComment, prevQuickInfoLines, prevQuickInfoEndLine;
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
var multilineEnabled, 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) {
|
|
66
67
|
case 0:
|
|
67
68
|
multilineEnabled = localStorage.getItem("shareable-twoslash-comments/enable-multiline-comments") === "true";
|
|
68
69
|
model = sandbox.getModel();
|
|
69
70
|
return [4 /*yield*/, sandbox.getWorkerProcess()];
|
|
70
71
|
case 1:
|
|
71
|
-
worker =
|
|
72
|
+
worker = _d.sent();
|
|
73
|
+
return [4 /*yield*/, Promise.all([
|
|
74
|
+
worker.getSyntacticDiagnostics("file://" + model.uri.path),
|
|
75
|
+
worker.getSemanticDiagnostics("file://" + model.uri.path),
|
|
76
|
+
])];
|
|
77
|
+
case 2:
|
|
78
|
+
diagnostics = _d.sent();
|
|
79
|
+
if (diagnostics.flat().length > 0) {
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
72
82
|
text = model.getValue();
|
|
73
83
|
editOperations = [];
|
|
74
84
|
_i = 0, _a = Array.from(text.matchAll(twoSlashQueryRegex));
|
|
75
|
-
|
|
76
|
-
case
|
|
77
|
-
if (!(_i < _a.length)) return [3 /*break*/,
|
|
85
|
+
_d.label = 3;
|
|
86
|
+
case 3:
|
|
87
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
78
88
|
match = _a[_i];
|
|
79
89
|
commentPrefix = "".concat(match[1], "//").padEnd(match[0].length + 1);
|
|
80
90
|
caretOffset = match.index + match[0].length - 1;
|
|
@@ -82,12 +92,9 @@ define(function () { 'use strict';
|
|
|
82
92
|
quickInfoPos = new sandbox.monaco.Position(caretPos.lineNumber - 1, caretPos.column);
|
|
83
93
|
quickInfoOffset = model.getOffsetAt(quickInfoPos);
|
|
84
94
|
return [4 /*yield*/, worker.getQuickInfoAtPosition("file://" + model.uri.path, quickInfoOffset)];
|
|
85
|
-
case
|
|
86
|
-
quickInfo =
|
|
87
|
-
|
|
88
|
-
return [3 /*break*/, 4];
|
|
89
|
-
}
|
|
90
|
-
quickInfoString = quickInfo.displayParts.map(function (d) { return d.text; }).join("");
|
|
95
|
+
case 4:
|
|
96
|
+
quickInfo = _d.sent();
|
|
97
|
+
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 : "";
|
|
91
98
|
quickInfoComment = "".concat(match[0], " ").concat(multilineEnabled
|
|
92
99
|
? quickInfoString.replace(/\r?\n/g, model.getEOL() + commentPrefix)
|
|
93
100
|
: quickInfoString.replace(/\r?\n\s*/g, " "));
|
|
@@ -104,13 +111,13 @@ define(function () { 'use strict';
|
|
|
104
111
|
text: quickInfoComment,
|
|
105
112
|
});
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
case 4:
|
|
109
|
-
_i++;
|
|
110
|
-
return [3 /*break*/, 2];
|
|
114
|
+
_d.label = 5;
|
|
111
115
|
case 5:
|
|
116
|
+
_i++;
|
|
117
|
+
return [3 /*break*/, 3];
|
|
118
|
+
case 6:
|
|
112
119
|
if (editOperations.length > 0) {
|
|
113
|
-
model.
|
|
120
|
+
model.applyEdits(editOperations);
|
|
114
121
|
}
|
|
115
122
|
return [2 /*return*/];
|
|
116
123
|
}
|
|
@@ -118,18 +125,36 @@ define(function () { 'use strict';
|
|
|
118
125
|
}); };
|
|
119
126
|
var getPreviousQuickInfoComment = function (_a) {
|
|
120
127
|
var model = _a.model, lineNumber = _a.lineNumber, commentPrefix = _a.commentPrefix;
|
|
121
|
-
var prevQuickInfoLines = [];
|
|
122
|
-
for (var currLineNumber = lineNumber; currLineNumber <= model.getLineCount(); currLineNumber++) {
|
|
128
|
+
var prevQuickInfoLines = [model.getLineContent(lineNumber)];
|
|
129
|
+
for (var currLineNumber = lineNumber + 1; currLineNumber <= model.getLineCount(); currLineNumber++) {
|
|
123
130
|
var lineContent = model.getLineContent(currLineNumber);
|
|
124
|
-
if (!
|
|
131
|
+
if (!lineContent.startsWith(commentPrefix)) {
|
|
125
132
|
break;
|
|
126
133
|
}
|
|
127
134
|
prevQuickInfoLines.push(lineContent);
|
|
128
135
|
}
|
|
129
136
|
return prevQuickInfoLines.join(model.getEOL());
|
|
130
137
|
};
|
|
138
|
+
var debounce = function (callback, delay) {
|
|
139
|
+
if (delay === void 0) { delay = 1000; }
|
|
140
|
+
var timeoutId;
|
|
141
|
+
return function () {
|
|
142
|
+
var args = [];
|
|
143
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
144
|
+
args[_i] = arguments[_i];
|
|
145
|
+
}
|
|
146
|
+
if (timeoutId) {
|
|
147
|
+
clearTimeout(timeoutId);
|
|
148
|
+
}
|
|
149
|
+
timeoutId = setTimeout(function () {
|
|
150
|
+
callback.apply(void 0, args);
|
|
151
|
+
timeoutId = undefined;
|
|
152
|
+
}, delay);
|
|
153
|
+
};
|
|
154
|
+
};
|
|
131
155
|
//# sourceMappingURL=utils.js.map
|
|
132
156
|
|
|
157
|
+
var debouncedFillTwoSlashQueries = debounce(fillTwoSlashQueries, 600);
|
|
133
158
|
var makePlugin = function (utils) {
|
|
134
159
|
var customPlugin = {
|
|
135
160
|
id: "shareable-twoslash-comments",
|
|
@@ -156,7 +181,7 @@ define(function () { 'use strict';
|
|
|
156
181
|
// and then will always run at the end.
|
|
157
182
|
modelChangedDebounce: function (sandbox, model) { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
183
|
return __generator(this, function (_a) {
|
|
159
|
-
|
|
184
|
+
debouncedFillTwoSlashQueries(sandbox);
|
|
160
185
|
return [2 /*return*/];
|
|
161
186
|
});
|
|
162
187
|
}); },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shareable-twoslash-comments",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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",
|