@lvce-editor/editor-worker 19.28.0 → 19.28.2
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 +107 -40
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1589,7 +1589,7 @@ const sendMessagePortToErrorWorker = async (port, rpcId) => {
|
|
|
1589
1589
|
const command = 'Errors.handleMessagePort';
|
|
1590
1590
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
|
|
1591
1591
|
};
|
|
1592
|
-
const readFile = async uri => {
|
|
1592
|
+
const readFile$1 = async uri => {
|
|
1593
1593
|
return invoke$b('FileSystem.readFile', uri);
|
|
1594
1594
|
};
|
|
1595
1595
|
const handleWorkspaceRefresh = async () => {
|
|
@@ -1639,7 +1639,7 @@ const RendererWorker = {
|
|
|
1639
1639
|
invokeAndTransfer,
|
|
1640
1640
|
openUri,
|
|
1641
1641
|
readClipBoardText,
|
|
1642
|
-
readFile,
|
|
1642
|
+
readFile: readFile$1,
|
|
1643
1643
|
sendMessagePortToDialogWorker,
|
|
1644
1644
|
sendMessagePortToErrorWorker,
|
|
1645
1645
|
sendMessagePortToExtensionHostWorker,
|
|
@@ -3779,7 +3779,8 @@ const splitLines = lines => {
|
|
|
3779
3779
|
};
|
|
3780
3780
|
|
|
3781
3781
|
const {
|
|
3782
|
-
invoke: invoke$7
|
|
3782
|
+
invoke: invoke$7,
|
|
3783
|
+
readFile} = RendererWorker;
|
|
3783
3784
|
|
|
3784
3785
|
const notifyTabModifiedStatusChange = async (uri, modified) => {
|
|
3785
3786
|
try {
|
|
@@ -5025,44 +5026,80 @@ const applyEdit = async (editor, changes) => {
|
|
|
5025
5026
|
|
|
5026
5027
|
// TODO maybe use a separate worker for bulk edits and bulk edit history
|
|
5027
5028
|
|
|
5028
|
-
const
|
|
5029
|
+
const sortEditsDescending = edits => {
|
|
5030
|
+
return edits.toSorted((a, b) => b.offset - a.offset);
|
|
5031
|
+
};
|
|
5032
|
+
const applyEditsToText = (text, edits) => {
|
|
5033
|
+
let newText = text;
|
|
5034
|
+
for (const edit of sortEditsDescending(edits)) {
|
|
5035
|
+
newText = newText.slice(0, edit.offset) + edit.inserted + newText.slice(edit.offset + edit.deleted);
|
|
5036
|
+
}
|
|
5037
|
+
return newText;
|
|
5038
|
+
};
|
|
5039
|
+
const getTextChanges = (editor, edits) => {
|
|
5029
5040
|
const textChanges = [];
|
|
5041
|
+
for (const edit of sortEditsDescending(edits)) {
|
|
5042
|
+
const startPosition = positionAt(editor, edit.offset);
|
|
5043
|
+
const endPosition = positionAt(editor, edit.offset + edit.deleted);
|
|
5044
|
+
const deleted = getSelectionText(editor, {
|
|
5045
|
+
end: endPosition,
|
|
5046
|
+
start: startPosition
|
|
5047
|
+
});
|
|
5048
|
+
const textChange = {
|
|
5049
|
+
deleted,
|
|
5050
|
+
end: endPosition,
|
|
5051
|
+
inserted: [edit.inserted],
|
|
5052
|
+
origin: Rename,
|
|
5053
|
+
start: startPosition
|
|
5054
|
+
};
|
|
5055
|
+
textChanges.push(textChange);
|
|
5056
|
+
}
|
|
5057
|
+
return textChanges;
|
|
5058
|
+
};
|
|
5059
|
+
const groupEditsByUri = changes => {
|
|
5060
|
+
const editsByUri = new Map();
|
|
5030
5061
|
for (const change of changes) {
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
end: endPosition,
|
|
5037
|
-
start: startPosition
|
|
5038
|
-
});
|
|
5039
|
-
const textChange = {
|
|
5040
|
-
deleted,
|
|
5041
|
-
end: endPosition,
|
|
5042
|
-
inserted: [edit.inserted],
|
|
5043
|
-
origin: Rename,
|
|
5044
|
-
start: startPosition
|
|
5045
|
-
};
|
|
5046
|
-
textChanges.push(textChange);
|
|
5047
|
-
}
|
|
5062
|
+
const edits = editsByUri.get(change.uri);
|
|
5063
|
+
if (edits) {
|
|
5064
|
+
edits.push(...change.edits);
|
|
5065
|
+
} else {
|
|
5066
|
+
editsByUri.set(change.uri, [...change.edits]);
|
|
5048
5067
|
}
|
|
5049
5068
|
}
|
|
5050
|
-
return
|
|
5069
|
+
return editsByUri;
|
|
5070
|
+
};
|
|
5071
|
+
const getOpenEditor = (currentEditor, uri) => {
|
|
5072
|
+
if (currentEditor.uri === uri) {
|
|
5073
|
+
return currentEditor;
|
|
5074
|
+
}
|
|
5075
|
+
for (const key of getKeys$2()) {
|
|
5076
|
+
const editor = get$7(Number(key))?.newState;
|
|
5077
|
+
if (editor && !editor.initial && editor.uri === uri) {
|
|
5078
|
+
return editor;
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
return undefined;
|
|
5051
5082
|
};
|
|
5052
5083
|
const applyWorkspaceEdit = async (editor, changes) => {
|
|
5053
5084
|
object(editor);
|
|
5054
5085
|
array(changes);
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5086
|
+
let currentEditor = editor;
|
|
5087
|
+
const editsByUri = groupEditsByUri(changes);
|
|
5088
|
+
for (const [uri, edits] of editsByUri) {
|
|
5089
|
+
const openEditor = getOpenEditor(currentEditor, uri);
|
|
5090
|
+
if (openEditor) {
|
|
5091
|
+
const textChanges = getTextChanges(openEditor, edits);
|
|
5092
|
+
const updatedEditor = await scheduleDocumentAndCursorsSelections(openEditor, textChanges);
|
|
5093
|
+
if (openEditor.uid === currentEditor.uid) {
|
|
5094
|
+
currentEditor = updatedEditor;
|
|
5095
|
+
}
|
|
5096
|
+
continue;
|
|
5097
|
+
}
|
|
5098
|
+
const text = await readFile(uri);
|
|
5099
|
+
const newText = applyEditsToText(text, edits);
|
|
5100
|
+
await invoke$7('FileSystem.writeFile', uri, newText);
|
|
5058
5101
|
}
|
|
5059
|
-
|
|
5060
|
-
// for now only apply edits to single file, if it matches the URI
|
|
5061
|
-
//
|
|
5062
|
-
// in the future:
|
|
5063
|
-
// 1. if a change targets the current editor, apply an edit to this editor
|
|
5064
|
-
// 2. else, use file system worker to write file change
|
|
5065
|
-
return scheduleDocumentAndCursorsSelections(editor, textChanges);
|
|
5102
|
+
return currentEditor;
|
|
5066
5103
|
};
|
|
5067
5104
|
|
|
5068
5105
|
const isPersistentWidget = widgetId => {
|
|
@@ -9760,6 +9797,36 @@ const getSignatureHelpContent = signatureHelp => {
|
|
|
9760
9797
|
};
|
|
9761
9798
|
};
|
|
9762
9799
|
|
|
9800
|
+
const borderHeight = 2;
|
|
9801
|
+
const documentationPaddingHeight = 8;
|
|
9802
|
+
const displayStringLineHeight = 20;
|
|
9803
|
+
const displayStringPaddingHeight = 8;
|
|
9804
|
+
const preferredWidth = 600;
|
|
9805
|
+
const getHeight = (lineCount, documentationHeight, hasDocumentation) => {
|
|
9806
|
+
const displayStringHeight = lineCount * displayStringLineHeight + displayStringPaddingHeight;
|
|
9807
|
+
const fullDocumentationHeight = hasDocumentation ? documentationHeight + documentationPaddingHeight : 0;
|
|
9808
|
+
return borderHeight + displayStringHeight + fullDocumentationHeight;
|
|
9809
|
+
};
|
|
9810
|
+
const getSignatureHelpWidgetBounds = (editor, rowIndex, columnIndex, lineCount, documentationHeight, hasDocumentation) => {
|
|
9811
|
+
const width = Math.min(preferredWidth, editor.width);
|
|
9812
|
+
const height = Math.min(getHeight(lineCount, documentationHeight, hasDocumentation), editor.height);
|
|
9813
|
+
const cursorX = x(editor, rowIndex, columnIndex);
|
|
9814
|
+
const cursorY = y(editor, rowIndex);
|
|
9815
|
+
const editorRight = editor.x + editor.width;
|
|
9816
|
+
const editorBottom = editor.y + editor.height;
|
|
9817
|
+
const x$1 = clamp(cursorX, editor.x, editorRight - width);
|
|
9818
|
+
const yBelow = cursorY;
|
|
9819
|
+
const yAbove = cursorY - editor.rowHeight - height;
|
|
9820
|
+
const preferredY = yBelow + height <= editorBottom ? yBelow : yAbove;
|
|
9821
|
+
const y$1 = clamp(preferredY, editor.y, editorBottom - height);
|
|
9822
|
+
return {
|
|
9823
|
+
height,
|
|
9824
|
+
width,
|
|
9825
|
+
x: x$1,
|
|
9826
|
+
y: y$1
|
|
9827
|
+
};
|
|
9828
|
+
};
|
|
9829
|
+
|
|
9763
9830
|
const getTextDocument$1 = editor => {
|
|
9764
9831
|
return {
|
|
9765
9832
|
documentId: editor.id || editor.uid,
|
|
@@ -9803,14 +9870,11 @@ const getSignatureHelpInfo = async editorUid => {
|
|
|
9803
9870
|
} = content;
|
|
9804
9871
|
const lineInfos = await tokenizeCodeBlock(displayString, editor.languageId || 'typescript', '');
|
|
9805
9872
|
const documentationHeight = await measureTextBlockHeight();
|
|
9806
|
-
const
|
|
9807
|
-
const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
|
|
9873
|
+
const bounds = getSignatureHelpWidgetBounds(editor, rowIndex, columnIndex, lineInfos.length, documentationHeight, Boolean(documentation));
|
|
9808
9874
|
return {
|
|
9875
|
+
...bounds,
|
|
9809
9876
|
documentation,
|
|
9810
|
-
|
|
9811
|
-
lineInfos,
|
|
9812
|
-
x: x$1,
|
|
9813
|
-
y: y$1
|
|
9877
|
+
lineInfos
|
|
9814
9878
|
};
|
|
9815
9879
|
};
|
|
9816
9880
|
|
|
@@ -9824,7 +9888,9 @@ const loadSignatureHelpContent = async state => {
|
|
|
9824
9888
|
}
|
|
9825
9889
|
const {
|
|
9826
9890
|
documentation,
|
|
9891
|
+
height,
|
|
9827
9892
|
lineInfos,
|
|
9893
|
+
width,
|
|
9828
9894
|
x,
|
|
9829
9895
|
y
|
|
9830
9896
|
} = signatureHelpInfo;
|
|
@@ -9832,8 +9898,9 @@ const loadSignatureHelpContent = async state => {
|
|
|
9832
9898
|
...state,
|
|
9833
9899
|
diagnostics: [],
|
|
9834
9900
|
documentation,
|
|
9901
|
+
height,
|
|
9835
9902
|
lineInfos,
|
|
9836
|
-
width
|
|
9903
|
+
width,
|
|
9837
9904
|
x,
|
|
9838
9905
|
y
|
|
9839
9906
|
};
|
|
@@ -12324,7 +12391,7 @@ const loadContent = async (state, savedState) => {
|
|
|
12324
12391
|
let content = existingEditor ? getText$1(existingEditor) : '';
|
|
12325
12392
|
try {
|
|
12326
12393
|
if (!existingEditor) {
|
|
12327
|
-
content = await readFile(uri);
|
|
12394
|
+
content = await readFile$1(uri);
|
|
12328
12395
|
}
|
|
12329
12396
|
} catch (error) {
|
|
12330
12397
|
const newEditor1 = setBounds(newEditor0, x, y, width, height, 9);
|