@lvce-editor/editor-worker 4.9.0 → 4.11.0
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/editorWorkerMain.js +53 -32
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -24,7 +24,7 @@ let AssertionError$1 = class AssertionError extends Error {
|
|
|
24
24
|
this.name = 'AssertionError';
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
const getType$
|
|
27
|
+
const getType$1 = value => {
|
|
28
28
|
switch (typeof value) {
|
|
29
29
|
case 'number':
|
|
30
30
|
return 'number';
|
|
@@ -47,31 +47,31 @@ const getType$2 = value => {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
const object = value => {
|
|
50
|
-
const type = getType$
|
|
50
|
+
const type = getType$1(value);
|
|
51
51
|
if (type !== 'object') {
|
|
52
52
|
throw new AssertionError$1('expected value to be of type object');
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
const number$1 = value => {
|
|
56
|
-
const type = getType$
|
|
56
|
+
const type = getType$1(value);
|
|
57
57
|
if (type !== 'number') {
|
|
58
58
|
throw new AssertionError$1('expected value to be of type number');
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
const array = value => {
|
|
62
|
-
const type = getType$
|
|
62
|
+
const type = getType$1(value);
|
|
63
63
|
if (type !== 'array') {
|
|
64
64
|
throw new AssertionError$1('expected value to be of type array');
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
const string = value => {
|
|
68
|
-
const type = getType$
|
|
68
|
+
const type = getType$1(value);
|
|
69
69
|
if (type !== 'string') {
|
|
70
70
|
throw new AssertionError$1('expected value to be of type string');
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
const boolean = value => {
|
|
74
|
-
const type = getType$
|
|
74
|
+
const type = getType$1(value);
|
|
75
75
|
if (type !== 'boolean') {
|
|
76
76
|
throw new AssertionError$1('expected value to be of type boolean');
|
|
77
77
|
}
|
|
@@ -144,6 +144,7 @@ const IndentMore = 'indentMore';
|
|
|
144
144
|
const InsertLineBreak = 'insertLineBreak';
|
|
145
145
|
const ReplaceAll$2 = 'replaceAll';
|
|
146
146
|
const ToggleBlockComment = 'toggleBlockComment';
|
|
147
|
+
const Rename$1 = 'rename';
|
|
147
148
|
|
|
148
149
|
const map$1 = Object.create(null);
|
|
149
150
|
const set$7 = (id, widget) => {
|
|
@@ -398,23 +399,27 @@ const offsetAt = (textDocument, positionRowIndex, positionColumnIndex) => {
|
|
|
398
399
|
return offset;
|
|
399
400
|
};
|
|
400
401
|
const positionAt = (textDocument, offset) => {
|
|
402
|
+
const {
|
|
403
|
+
lines
|
|
404
|
+
} = textDocument;
|
|
401
405
|
let rowIndex = 0;
|
|
402
406
|
let columnIndex = 0;
|
|
403
407
|
let currentOffset = 0;
|
|
404
|
-
while (rowIndex <
|
|
405
|
-
currentOffset +=
|
|
408
|
+
while (rowIndex < lines.length && currentOffset < offset) {
|
|
409
|
+
currentOffset += lines[rowIndex].length + 1;
|
|
406
410
|
rowIndex++;
|
|
407
411
|
}
|
|
408
412
|
if (currentOffset > offset) {
|
|
409
413
|
rowIndex--;
|
|
410
|
-
currentOffset -=
|
|
414
|
+
currentOffset -= lines[rowIndex].length + 1;
|
|
411
415
|
columnIndex = offset - currentOffset;
|
|
412
416
|
} else {
|
|
413
417
|
columnIndex = currentOffset - offset;
|
|
414
418
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
419
|
+
console.log({
|
|
420
|
+
rowIndex,
|
|
421
|
+
columnIndex
|
|
422
|
+
});
|
|
418
423
|
// TODO
|
|
419
424
|
return {
|
|
420
425
|
rowIndex,
|
|
@@ -1043,7 +1048,7 @@ class AssertionError extends Error {
|
|
|
1043
1048
|
this.name = 'AssertionError';
|
|
1044
1049
|
}
|
|
1045
1050
|
}
|
|
1046
|
-
const getType
|
|
1051
|
+
const getType = value => {
|
|
1047
1052
|
switch (typeof value) {
|
|
1048
1053
|
case 'number':
|
|
1049
1054
|
return 'number';
|
|
@@ -1066,7 +1071,7 @@ const getType$1 = value => {
|
|
|
1066
1071
|
}
|
|
1067
1072
|
};
|
|
1068
1073
|
const number = value => {
|
|
1069
|
-
const type = getType
|
|
1074
|
+
const type = getType(value);
|
|
1070
1075
|
if (type !== 'number') {
|
|
1071
1076
|
throw new AssertionError('expected value to be of type number');
|
|
1072
1077
|
}
|
|
@@ -1092,25 +1097,12 @@ const create$3$1 = () => {
|
|
|
1092
1097
|
const warn$1 = (...args) => {
|
|
1093
1098
|
console.warn(...args);
|
|
1094
1099
|
};
|
|
1095
|
-
const withResolvers$2 = () => {
|
|
1096
|
-
/**
|
|
1097
|
-
* @type {any}
|
|
1098
|
-
*/
|
|
1099
|
-
let _resolve;
|
|
1100
|
-
const promise = new Promise(resolve => {
|
|
1101
|
-
_resolve = resolve;
|
|
1102
|
-
});
|
|
1103
|
-
return {
|
|
1104
|
-
resolve: _resolve,
|
|
1105
|
-
promise
|
|
1106
|
-
};
|
|
1107
|
-
};
|
|
1108
1100
|
const registerPromise = () => {
|
|
1109
1101
|
const id = create$3$1();
|
|
1110
1102
|
const {
|
|
1111
1103
|
resolve,
|
|
1112
1104
|
promise
|
|
1113
|
-
} = withResolvers
|
|
1105
|
+
} = Promise.withResolvers();
|
|
1114
1106
|
set$5(id, resolve);
|
|
1115
1107
|
return {
|
|
1116
1108
|
id,
|
|
@@ -1276,7 +1268,7 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
1276
1268
|
throw new JsonRpcError('unexpected response message');
|
|
1277
1269
|
};
|
|
1278
1270
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
1279
|
-
const
|
|
1271
|
+
const getErrorType = prettyError => {
|
|
1280
1272
|
if (prettyError && prettyError.type) {
|
|
1281
1273
|
return prettyError.type;
|
|
1282
1274
|
}
|
|
@@ -1299,7 +1291,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1299
1291
|
data: {
|
|
1300
1292
|
stack: prettyError.stack,
|
|
1301
1293
|
codeFrame: prettyError.codeFrame,
|
|
1302
|
-
type:
|
|
1294
|
+
type: getErrorType(prettyError),
|
|
1303
1295
|
code: prettyError.code,
|
|
1304
1296
|
name: prettyError.name
|
|
1305
1297
|
}
|
|
@@ -3012,7 +3004,6 @@ const cutLine = async editor => {
|
|
|
3012
3004
|
return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
|
|
3013
3005
|
};
|
|
3014
3006
|
|
|
3015
|
-
// @ts-ignore
|
|
3016
3007
|
const cutSelectedText = async editor => {
|
|
3017
3008
|
const {
|
|
3018
3009
|
selections
|
|
@@ -8075,6 +8066,35 @@ const getRenameState = editor => {
|
|
|
8075
8066
|
return getWidgetState(editor, Rename);
|
|
8076
8067
|
};
|
|
8077
8068
|
|
|
8069
|
+
const getRenameChanges = (editor, result) => {
|
|
8070
|
+
if (!result || !result.edits) {
|
|
8071
|
+
return [];
|
|
8072
|
+
}
|
|
8073
|
+
const changes = [];
|
|
8074
|
+
console.log({
|
|
8075
|
+
result
|
|
8076
|
+
});
|
|
8077
|
+
for (const edit of result.edits) {
|
|
8078
|
+
const position = positionAt(editor, edit.offset);
|
|
8079
|
+
const start = position;
|
|
8080
|
+
const end = {
|
|
8081
|
+
...position,
|
|
8082
|
+
columnIndex: start.columnIndex + edit.deleted
|
|
8083
|
+
};
|
|
8084
|
+
const selection = {
|
|
8085
|
+
start,
|
|
8086
|
+
end
|
|
8087
|
+
};
|
|
8088
|
+
changes.push({
|
|
8089
|
+
start,
|
|
8090
|
+
end,
|
|
8091
|
+
inserted: [result.inserted],
|
|
8092
|
+
deleted: getSelectionText(editor, selection),
|
|
8093
|
+
origin: Rename$1
|
|
8094
|
+
});
|
|
8095
|
+
}
|
|
8096
|
+
return changes;
|
|
8097
|
+
};
|
|
8078
8098
|
const accept = async editor => {
|
|
8079
8099
|
const child = getRenameState(editor);
|
|
8080
8100
|
if (!child) {
|
|
@@ -8087,8 +8107,9 @@ const accept = async editor => {
|
|
|
8087
8107
|
// TODO
|
|
8088
8108
|
const offset = getOffsetAtCursor(editor);
|
|
8089
8109
|
const result = await executeRenameProvider(editor, offset, child.newValue);
|
|
8110
|
+
const changes = getRenameChanges(editor, result);
|
|
8090
8111
|
console.log({
|
|
8091
|
-
|
|
8112
|
+
changes
|
|
8092
8113
|
});
|
|
8093
8114
|
// 1. ask extension host for rename edits
|
|
8094
8115
|
// 2. apply rename edit across editor (and whole workspace)
|