@lvce-editor/editor-worker 8.5.0 → 9.0.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 +268 -258
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1216,6 +1216,11 @@ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
|
|
|
1216
1216
|
// @ts-ignore
|
|
1217
1217
|
await invokeAndTransfer$2('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
|
|
1218
1218
|
};
|
|
1219
|
+
const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
|
|
1220
|
+
const command = 'IconTheme.handleMessagePort';
|
|
1221
|
+
// @ts-ignore
|
|
1222
|
+
await invokeAndTransfer$2('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
|
|
1223
|
+
};
|
|
1219
1224
|
const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
|
|
1220
1225
|
const command = 'FileSystem.handleMessagePort';
|
|
1221
1226
|
// @ts-ignore
|
|
@@ -1482,6 +1487,7 @@ const RendererWorker = {
|
|
|
1482
1487
|
sendMessagePortToErrorWorker,
|
|
1483
1488
|
sendMessagePortToExtensionHostWorker,
|
|
1484
1489
|
sendMessagePortToFileSystemWorker,
|
|
1490
|
+
sendMessagePortToIconThemeWorker,
|
|
1485
1491
|
sendMessagePortToMarkdownWorker,
|
|
1486
1492
|
sendMessagePortToRendererProcess,
|
|
1487
1493
|
sendMessagePortToSearchProcess,
|
|
@@ -2943,7 +2949,7 @@ const applyWorkspaceEdit = async (editor, changes) => {
|
|
|
2943
2949
|
array(changes);
|
|
2944
2950
|
const textChanges = getTextChanges(editor, changes);
|
|
2945
2951
|
if (textChanges.length === 0) {
|
|
2946
|
-
return;
|
|
2952
|
+
return editor;
|
|
2947
2953
|
}
|
|
2948
2954
|
// TODO
|
|
2949
2955
|
// for now only apply edits to single file, if it matches the uri
|
|
@@ -6769,226 +6775,52 @@ const create$1 = () => {
|
|
|
6769
6775
|
return widget;
|
|
6770
6776
|
};
|
|
6771
6777
|
|
|
6772
|
-
const
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
method: HoverExecute,
|
|
6779
|
-
args: [offset],
|
|
6780
|
-
noProviderFoundMessage: 'No hover provider found'
|
|
6781
|
-
});
|
|
6782
|
-
};
|
|
6783
|
-
|
|
6784
|
-
const getHover = async (editor, offset) => {
|
|
6785
|
-
object(editor);
|
|
6786
|
-
number(offset);
|
|
6787
|
-
// TODO invoke extension host worker directly
|
|
6788
|
-
const hover = await executeHoverProvider(editor, offset);
|
|
6789
|
-
return hover;
|
|
6790
|
-
};
|
|
6791
|
-
|
|
6792
|
-
const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
|
|
6793
|
-
// @ts-ignore
|
|
6794
|
-
// return RendererProcess.invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width)
|
|
6795
|
-
return 100;
|
|
6796
|
-
};
|
|
6797
|
-
|
|
6798
|
-
const deepCopy = value => {
|
|
6799
|
-
return structuredClone(value);
|
|
6800
|
-
};
|
|
6801
|
-
|
|
6802
|
-
const getInitialLineState = initialLineState => {
|
|
6803
|
-
return deepCopy(initialLineState);
|
|
6804
|
-
};
|
|
6805
|
-
|
|
6806
|
-
const getLineInfo$1 = (line, tokens, TokenMap) => {
|
|
6807
|
-
const tokensLength = tokens.length;
|
|
6808
|
-
let end = 0;
|
|
6809
|
-
let start = 0;
|
|
6810
|
-
const lineInfo = [];
|
|
6811
|
-
for (let i = 0; i < tokensLength; i += 2) {
|
|
6812
|
-
const tokenType = tokens[i];
|
|
6813
|
-
const tokenLength = tokens[i + 1];
|
|
6814
|
-
end += tokenLength;
|
|
6815
|
-
const text = line.slice(start, end);
|
|
6816
|
-
const className = `Token ${TokenMap[tokenType] || 'Unknown'}`;
|
|
6817
|
-
const normalizedText = text;
|
|
6818
|
-
lineInfo.push(normalizedText, className);
|
|
6819
|
-
start = end;
|
|
6820
|
-
}
|
|
6821
|
-
return lineInfo;
|
|
6822
|
-
};
|
|
6823
|
-
|
|
6824
|
-
const state = {
|
|
6825
|
-
warned: []
|
|
6826
|
-
};
|
|
6827
|
-
const flattenTokensArray = tokens => {
|
|
6828
|
-
const flattened = [];
|
|
6829
|
-
for (const token of tokens) {
|
|
6830
|
-
object(token);
|
|
6831
|
-
flattened.push(token.type, token.length);
|
|
6832
|
-
}
|
|
6833
|
-
return flattened;
|
|
6834
|
-
};
|
|
6835
|
-
const warnDeprecatedArrayReturn = (languageId, fn) => {
|
|
6836
|
-
if (state.warned.includes(fn)) {
|
|
6837
|
-
return;
|
|
6838
|
-
}
|
|
6839
|
-
state.warned.push(fn);
|
|
6840
|
-
console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
|
|
6841
|
-
};
|
|
6842
|
-
const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
|
|
6843
|
-
try {
|
|
6844
|
-
const lineState = tokenizeLine(line, lineStateAtStart);
|
|
6845
|
-
if (!lineState?.tokens || !lineState.state) {
|
|
6846
|
-
throw new Error('invalid tokenization result');
|
|
6847
|
-
}
|
|
6848
|
-
if (!hasArrayReturn) {
|
|
6849
|
-
warnDeprecatedArrayReturn(languageId, tokenizeLine);
|
|
6850
|
-
// workaround for old tokenizers
|
|
6851
|
-
lineState.tokens = flattenTokensArray(lineState.tokens);
|
|
6852
|
-
}
|
|
6853
|
-
return lineState;
|
|
6854
|
-
} catch (error) {
|
|
6855
|
-
console.error(error);
|
|
6856
|
-
return {
|
|
6857
|
-
tokens: [/* type */0, /* length */line.length],
|
|
6858
|
-
lineState: lineStateAtStart
|
|
6859
|
-
};
|
|
6860
|
-
}
|
|
6778
|
+
const launchHoverWorker = async () => {
|
|
6779
|
+
const name = 'Hover Worker';
|
|
6780
|
+
const url = 'hoverWorkerMain.js';
|
|
6781
|
+
const intializeCommand = 'Hover.initialize';
|
|
6782
|
+
const rpc = await launchWorker(name, url, intializeCommand);
|
|
6783
|
+
return rpc;
|
|
6861
6784
|
};
|
|
6862
6785
|
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
initialLineState,
|
|
6868
|
-
hasArrayReturn,
|
|
6869
|
-
TokenMap
|
|
6870
|
-
} = tokenizer;
|
|
6871
|
-
let currentLineState = getInitialLineState(initialLineState);
|
|
6872
|
-
for (const line of lines) {
|
|
6873
|
-
const result = safeTokenizeLine(languageId, tokenizeLine, line, currentLineState, hasArrayReturn);
|
|
6874
|
-
const {
|
|
6875
|
-
tokens
|
|
6876
|
-
} = result;
|
|
6877
|
-
const lineInfo = getLineInfo$1(line, tokens, TokenMap);
|
|
6878
|
-
lineInfos.push(lineInfo);
|
|
6879
|
-
currentLineState = result;
|
|
6786
|
+
let workerPromise$1;
|
|
6787
|
+
const getOrCreate$1 = () => {
|
|
6788
|
+
if (!workerPromise$1) {
|
|
6789
|
+
workerPromise$1 = launchHoverWorker();
|
|
6880
6790
|
}
|
|
6881
|
-
return
|
|
6791
|
+
return workerPromise$1;
|
|
6882
6792
|
};
|
|
6883
|
-
|
|
6884
|
-
const
|
|
6885
|
-
await
|
|
6886
|
-
const tokenizer = getTokenizer(languageId);
|
|
6887
|
-
const lines = splitLines(codeBlock);
|
|
6888
|
-
const lineInfos = getLineInfos(lines, tokenizer, languageId);
|
|
6889
|
-
return lineInfos;
|
|
6793
|
+
const invoke$2 = async (method, ...params) => {
|
|
6794
|
+
const worker = await getOrCreate$1();
|
|
6795
|
+
return await worker.invoke(method, ...params);
|
|
6890
6796
|
};
|
|
6891
6797
|
|
|
6892
|
-
const
|
|
6893
|
-
if (position) {
|
|
6894
|
-
return position;
|
|
6895
|
-
}
|
|
6896
|
-
const rowIndex = selections[0];
|
|
6897
|
-
const columnIndex = selections[1];
|
|
6898
|
-
return {
|
|
6899
|
-
rowIndex,
|
|
6900
|
-
columnIndex
|
|
6901
|
-
};
|
|
6902
|
-
};
|
|
6903
|
-
const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
|
|
6904
|
-
const matching = [];
|
|
6905
|
-
for (const diagnostic of diagnostics) {
|
|
6906
|
-
if (diagnostic.rowIndex === rowIndex) {
|
|
6907
|
-
matching.push(diagnostic);
|
|
6908
|
-
}
|
|
6909
|
-
}
|
|
6910
|
-
return matching;
|
|
6911
|
-
};
|
|
6912
|
-
const fallbackDisplayStringLanguageId = 'typescript'; // TODO remove this
|
|
6913
|
-
const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
|
|
6914
|
-
const x$1 = x(editor, rowIndex, wordStart);
|
|
6915
|
-
const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
|
|
6916
|
-
return {
|
|
6917
|
-
x: x$1,
|
|
6918
|
-
y: y$1
|
|
6919
|
-
};
|
|
6920
|
-
};
|
|
6921
|
-
const getEditorHoverInfo = async (editorUid, position) => {
|
|
6922
|
-
number(editorUid);
|
|
6923
|
-
const instance = get$4(editorUid);
|
|
6924
|
-
const editor = instance.newState;
|
|
6925
|
-
const {
|
|
6926
|
-
selections
|
|
6927
|
-
} = editor;
|
|
6928
|
-
const {
|
|
6929
|
-
rowIndex,
|
|
6930
|
-
columnIndex
|
|
6931
|
-
} = getHoverPosition(position, selections);
|
|
6932
|
-
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
6933
|
-
const hover = await getHover(editor, offset);
|
|
6934
|
-
if (!hover) {
|
|
6935
|
-
return undefined;
|
|
6936
|
-
}
|
|
6937
|
-
const {
|
|
6938
|
-
displayString,
|
|
6939
|
-
documentation,
|
|
6940
|
-
displayStringLanguageId
|
|
6941
|
-
} = hover;
|
|
6942
|
-
const tokenizerPath = '';
|
|
6943
|
-
const lineInfos = await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath);
|
|
6944
|
-
const wordPart = getWordBefore(editor, rowIndex, columnIndex);
|
|
6945
|
-
const wordStart = columnIndex - wordPart.length;
|
|
6946
|
-
await measureTextBlockHeight();
|
|
6798
|
+
const newStateGenerator$1 = async (state, parentUid) => {
|
|
6947
6799
|
const {
|
|
6948
|
-
|
|
6949
|
-
y
|
|
6950
|
-
} = getHoverPositionXy(editor, rowIndex, wordStart);
|
|
6951
|
-
const diagnostics = editor.diagnostics || [];
|
|
6952
|
-
const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
|
|
6953
|
-
return {
|
|
6954
|
-
lineInfos,
|
|
6955
|
-
documentation,
|
|
6800
|
+
uid,
|
|
6956
6801
|
x,
|
|
6957
6802
|
y,
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
};
|
|
6961
|
-
|
|
6962
|
-
const loadHoverContent = async state => {
|
|
6963
|
-
// TODO
|
|
6964
|
-
const position = undefined;
|
|
6965
|
-
const hoverInfo = await getEditorHoverInfo(state.editorUid, position);
|
|
6966
|
-
if (!hoverInfo) {
|
|
6967
|
-
return state;
|
|
6968
|
-
}
|
|
6803
|
+
width,
|
|
6804
|
+
height
|
|
6805
|
+
} = state;
|
|
6969
6806
|
const {
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6807
|
+
newState
|
|
6808
|
+
} = get$4(parentUid);
|
|
6809
|
+
const {
|
|
6810
|
+
languageId
|
|
6811
|
+
} = newState;
|
|
6812
|
+
await invoke$2('Hover.create', uid, x, y, width, height, parentUid, languageId);
|
|
6813
|
+
await invoke$2('Hover.loadContent', uid);
|
|
6814
|
+
const diff = await invoke$2('Hover.diff2', uid);
|
|
6815
|
+
const commands = await invoke$2('Hover.render2', uid, diff);
|
|
6976
6816
|
return {
|
|
6977
6817
|
...state,
|
|
6978
|
-
|
|
6979
|
-
documentation,
|
|
6980
|
-
x,
|
|
6981
|
-
y,
|
|
6982
|
-
width: 600,
|
|
6983
|
-
diagnostics: matchingDiagnostics
|
|
6818
|
+
commands
|
|
6984
6819
|
};
|
|
6985
6820
|
};
|
|
6986
|
-
|
|
6987
|
-
const
|
|
6988
|
-
return
|
|
6989
|
-
};
|
|
6990
|
-
const showHover2 = async editor => {
|
|
6991
|
-
return addWidgetToEditor(Hover, FocusEditorHover, editor, create$1, newStateGenerator$1);
|
|
6821
|
+
const showHover3 = async editor => {
|
|
6822
|
+
const fullFocus = false;
|
|
6823
|
+
return addWidgetToEditor(Hover, FocusEditorHover, editor, create$1, newStateGenerator$1, fullFocus);
|
|
6992
6824
|
};
|
|
6993
6825
|
|
|
6994
6826
|
const EditorHover = 'EditorHover';
|
|
@@ -7035,15 +6867,15 @@ const launchSourceActionWorker = async () => {
|
|
|
7035
6867
|
return rpc;
|
|
7036
6868
|
};
|
|
7037
6869
|
|
|
7038
|
-
let workerPromise
|
|
7039
|
-
const getOrCreate
|
|
7040
|
-
if (!workerPromise
|
|
7041
|
-
workerPromise
|
|
6870
|
+
let workerPromise;
|
|
6871
|
+
const getOrCreate = () => {
|
|
6872
|
+
if (!workerPromise) {
|
|
6873
|
+
workerPromise = launchSourceActionWorker();
|
|
7042
6874
|
}
|
|
7043
|
-
return workerPromise
|
|
6875
|
+
return workerPromise;
|
|
7044
6876
|
};
|
|
7045
|
-
const invoke$
|
|
7046
|
-
const worker = await getOrCreate
|
|
6877
|
+
const invoke$1 = async (method, ...params) => {
|
|
6878
|
+
const worker = await getOrCreate();
|
|
7047
6879
|
return await worker.invoke(method, ...params);
|
|
7048
6880
|
};
|
|
7049
6881
|
|
|
@@ -7061,10 +6893,10 @@ const newStateGenerator = async (state, parentUid) => {
|
|
|
7061
6893
|
const {
|
|
7062
6894
|
languageId
|
|
7063
6895
|
} = newState;
|
|
7064
|
-
await invoke$
|
|
7065
|
-
await invoke$
|
|
7066
|
-
const diff = await invoke$
|
|
7067
|
-
const commands = await invoke$
|
|
6896
|
+
await invoke$1('SourceActions.create', uid, x, y, width, height, parentUid, languageId);
|
|
6897
|
+
await invoke$1('SourceActions.loadContent', uid);
|
|
6898
|
+
const diff = await invoke$1('SourceActions.diff2', uid);
|
|
6899
|
+
const commands = await invoke$1('SourceActions.render2', uid, diff);
|
|
7068
6900
|
return {
|
|
7069
6901
|
...state,
|
|
7070
6902
|
commands
|
|
@@ -7871,6 +7703,7 @@ const isFunctional = widgetId => {
|
|
|
7871
7703
|
case Completion:
|
|
7872
7704
|
case Find:
|
|
7873
7705
|
case SourceAction$1:
|
|
7706
|
+
case Hover:
|
|
7874
7707
|
return true;
|
|
7875
7708
|
default:
|
|
7876
7709
|
return false;
|
|
@@ -7908,26 +7741,6 @@ const addWidget$1 = (widget, id, render) => {
|
|
|
7908
7741
|
return allCommands;
|
|
7909
7742
|
};
|
|
7910
7743
|
|
|
7911
|
-
const launchHoverWorker = async () => {
|
|
7912
|
-
const name = 'Hover Worker';
|
|
7913
|
-
const url = 'hoverWorkerMain.js';
|
|
7914
|
-
const intializeCommand = 'Hover.initialize';
|
|
7915
|
-
const rpc = await launchWorker(name, url, intializeCommand);
|
|
7916
|
-
return rpc;
|
|
7917
|
-
};
|
|
7918
|
-
|
|
7919
|
-
let workerPromise;
|
|
7920
|
-
const getOrCreate = () => {
|
|
7921
|
-
if (!workerPromise) {
|
|
7922
|
-
workerPromise = launchHoverWorker();
|
|
7923
|
-
}
|
|
7924
|
-
return workerPromise;
|
|
7925
|
-
};
|
|
7926
|
-
const invoke$1 = async (method, ...params) => {
|
|
7927
|
-
const worker = await getOrCreate();
|
|
7928
|
-
return await worker.invoke(method, ...params);
|
|
7929
|
-
};
|
|
7930
|
-
|
|
7931
7744
|
const getWidgetInvoke = widgetId => {
|
|
7932
7745
|
switch (widgetId) {
|
|
7933
7746
|
case ColorPicker$1:
|
|
@@ -7939,9 +7752,9 @@ const getWidgetInvoke = widgetId => {
|
|
|
7939
7752
|
case Rename$1:
|
|
7940
7753
|
return invoke$6;
|
|
7941
7754
|
case SourceAction$1:
|
|
7942
|
-
return invoke$2;
|
|
7943
|
-
case Hover:
|
|
7944
7755
|
return invoke$1;
|
|
7756
|
+
case Hover:
|
|
7757
|
+
return invoke$2;
|
|
7945
7758
|
default:
|
|
7946
7759
|
return undefined;
|
|
7947
7760
|
}
|
|
@@ -8060,13 +7873,13 @@ const {
|
|
|
8060
7873
|
toggleDetails: toggleDetails$1,
|
|
8061
7874
|
closeDetails: closeDetails$1,
|
|
8062
7875
|
handleWheel: handleWheel$1,
|
|
8063
|
-
close: close$
|
|
7876
|
+
close: close$4
|
|
8064
7877
|
} = createFns(['handleEditorType', 'focusFirst', 'focusNext', 'focusPrevious', 'focusLast', 'handleEditorDeleteLeft', 'openDetails', 'focusIndex', 'handleEditorBlur', 'handleEditorClick', 'openDetails', 'selectCurrent', 'selectIndex', 'toggleDetails', 'closeDetails', 'handleWheel', 'close'], 'Completions', Completion);
|
|
8065
7878
|
|
|
8066
7879
|
const EditorCompletionWidget = {
|
|
8067
7880
|
__proto__: null,
|
|
8068
7881
|
add: add$7,
|
|
8069
|
-
close: close$
|
|
7882
|
+
close: close$4,
|
|
8070
7883
|
closeDetails: closeDetails$1,
|
|
8071
7884
|
focusFirst: focusFirst$1,
|
|
8072
7885
|
focusIndex: focusIndex$2,
|
|
@@ -8115,7 +7928,7 @@ const remove$6 = widget => {
|
|
|
8115
7928
|
return [['Viewlet.dispose', widget.newState.uid]];
|
|
8116
7929
|
};
|
|
8117
7930
|
const {
|
|
8118
|
-
close: close$
|
|
7931
|
+
close: close$3,
|
|
8119
7932
|
focusCloseButton,
|
|
8120
7933
|
focusFind,
|
|
8121
7934
|
focusNext: focusNext$2,
|
|
@@ -8146,7 +7959,7 @@ const {
|
|
|
8146
7959
|
const EditorFindWidget = {
|
|
8147
7960
|
__proto__: null,
|
|
8148
7961
|
add: add$6,
|
|
8149
|
-
close: close$
|
|
7962
|
+
close: close$3,
|
|
8150
7963
|
focusCloseButton,
|
|
8151
7964
|
focusFind,
|
|
8152
7965
|
focusNext: focusNext$2,
|
|
@@ -8176,6 +7989,196 @@ const EditorFindWidget = {
|
|
|
8176
7989
|
toggleUseRegularExpression
|
|
8177
7990
|
};
|
|
8178
7991
|
|
|
7992
|
+
const executeHoverProvider = async (editor, offset) => {
|
|
7993
|
+
object(editor);
|
|
7994
|
+
number(offset);
|
|
7995
|
+
return execute({
|
|
7996
|
+
event: OnHover,
|
|
7997
|
+
editor,
|
|
7998
|
+
method: HoverExecute,
|
|
7999
|
+
args: [offset],
|
|
8000
|
+
noProviderFoundMessage: 'No hover provider found'
|
|
8001
|
+
});
|
|
8002
|
+
};
|
|
8003
|
+
|
|
8004
|
+
const getHover = async (editor, offset) => {
|
|
8005
|
+
object(editor);
|
|
8006
|
+
number(offset);
|
|
8007
|
+
// TODO invoke extension host worker directly
|
|
8008
|
+
const hover = await executeHoverProvider(editor, offset);
|
|
8009
|
+
return hover;
|
|
8010
|
+
};
|
|
8011
|
+
|
|
8012
|
+
const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
|
|
8013
|
+
// @ts-ignore
|
|
8014
|
+
// return RendererProcess.invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width)
|
|
8015
|
+
return 100;
|
|
8016
|
+
};
|
|
8017
|
+
|
|
8018
|
+
const deepCopy = value => {
|
|
8019
|
+
return structuredClone(value);
|
|
8020
|
+
};
|
|
8021
|
+
|
|
8022
|
+
const getInitialLineState = initialLineState => {
|
|
8023
|
+
return deepCopy(initialLineState);
|
|
8024
|
+
};
|
|
8025
|
+
|
|
8026
|
+
const getLineInfo$1 = (line, tokens, TokenMap) => {
|
|
8027
|
+
const tokensLength = tokens.length;
|
|
8028
|
+
let end = 0;
|
|
8029
|
+
let start = 0;
|
|
8030
|
+
const lineInfo = [];
|
|
8031
|
+
for (let i = 0; i < tokensLength; i += 2) {
|
|
8032
|
+
const tokenType = tokens[i];
|
|
8033
|
+
const tokenLength = tokens[i + 1];
|
|
8034
|
+
end += tokenLength;
|
|
8035
|
+
const text = line.slice(start, end);
|
|
8036
|
+
const className = `Token ${TokenMap[tokenType] || 'Unknown'}`;
|
|
8037
|
+
const normalizedText = text;
|
|
8038
|
+
lineInfo.push(normalizedText, className);
|
|
8039
|
+
start = end;
|
|
8040
|
+
}
|
|
8041
|
+
return lineInfo;
|
|
8042
|
+
};
|
|
8043
|
+
|
|
8044
|
+
const state = {
|
|
8045
|
+
warned: []
|
|
8046
|
+
};
|
|
8047
|
+
const flattenTokensArray = tokens => {
|
|
8048
|
+
const flattened = [];
|
|
8049
|
+
for (const token of tokens) {
|
|
8050
|
+
object(token);
|
|
8051
|
+
flattened.push(token.type, token.length);
|
|
8052
|
+
}
|
|
8053
|
+
return flattened;
|
|
8054
|
+
};
|
|
8055
|
+
const warnDeprecatedArrayReturn = (languageId, fn) => {
|
|
8056
|
+
if (state.warned.includes(fn)) {
|
|
8057
|
+
return;
|
|
8058
|
+
}
|
|
8059
|
+
state.warned.push(fn);
|
|
8060
|
+
console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
|
|
8061
|
+
};
|
|
8062
|
+
const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
|
|
8063
|
+
try {
|
|
8064
|
+
const lineState = tokenizeLine(line, lineStateAtStart);
|
|
8065
|
+
if (!lineState?.tokens || !lineState.state) {
|
|
8066
|
+
throw new Error('invalid tokenization result');
|
|
8067
|
+
}
|
|
8068
|
+
if (!hasArrayReturn) {
|
|
8069
|
+
warnDeprecatedArrayReturn(languageId, tokenizeLine);
|
|
8070
|
+
// workaround for old tokenizers
|
|
8071
|
+
lineState.tokens = flattenTokensArray(lineState.tokens);
|
|
8072
|
+
}
|
|
8073
|
+
return lineState;
|
|
8074
|
+
} catch (error) {
|
|
8075
|
+
console.error(error);
|
|
8076
|
+
return {
|
|
8077
|
+
tokens: [/* type */0, /* length */line.length],
|
|
8078
|
+
lineState: lineStateAtStart
|
|
8079
|
+
};
|
|
8080
|
+
}
|
|
8081
|
+
};
|
|
8082
|
+
|
|
8083
|
+
const getLineInfos = (lines, tokenizer, languageId) => {
|
|
8084
|
+
const lineInfos = [];
|
|
8085
|
+
const {
|
|
8086
|
+
tokenizeLine,
|
|
8087
|
+
initialLineState,
|
|
8088
|
+
hasArrayReturn,
|
|
8089
|
+
TokenMap
|
|
8090
|
+
} = tokenizer;
|
|
8091
|
+
let currentLineState = getInitialLineState(initialLineState);
|
|
8092
|
+
for (const line of lines) {
|
|
8093
|
+
const result = safeTokenizeLine(languageId, tokenizeLine, line, currentLineState, hasArrayReturn);
|
|
8094
|
+
const {
|
|
8095
|
+
tokens
|
|
8096
|
+
} = result;
|
|
8097
|
+
const lineInfo = getLineInfo$1(line, tokens, TokenMap);
|
|
8098
|
+
lineInfos.push(lineInfo);
|
|
8099
|
+
currentLineState = result;
|
|
8100
|
+
}
|
|
8101
|
+
return lineInfos;
|
|
8102
|
+
};
|
|
8103
|
+
|
|
8104
|
+
const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
|
|
8105
|
+
await loadTokenizer(languageId, tokenizerPath);
|
|
8106
|
+
const tokenizer = getTokenizer(languageId);
|
|
8107
|
+
const lines = splitLines(codeBlock);
|
|
8108
|
+
const lineInfos = getLineInfos(lines, tokenizer, languageId);
|
|
8109
|
+
return lineInfos;
|
|
8110
|
+
};
|
|
8111
|
+
|
|
8112
|
+
const getHoverPosition = (position, selections) => {
|
|
8113
|
+
if (position) {
|
|
8114
|
+
return position;
|
|
8115
|
+
}
|
|
8116
|
+
const rowIndex = selections[0];
|
|
8117
|
+
const columnIndex = selections[1];
|
|
8118
|
+
return {
|
|
8119
|
+
rowIndex,
|
|
8120
|
+
columnIndex
|
|
8121
|
+
};
|
|
8122
|
+
};
|
|
8123
|
+
const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
|
|
8124
|
+
const matching = [];
|
|
8125
|
+
for (const diagnostic of diagnostics) {
|
|
8126
|
+
if (diagnostic.rowIndex === rowIndex) {
|
|
8127
|
+
matching.push(diagnostic);
|
|
8128
|
+
}
|
|
8129
|
+
}
|
|
8130
|
+
return matching;
|
|
8131
|
+
};
|
|
8132
|
+
const fallbackDisplayStringLanguageId = 'typescript'; // TODO remove this
|
|
8133
|
+
const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
|
|
8134
|
+
const x$1 = x(editor, rowIndex, wordStart);
|
|
8135
|
+
const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
|
|
8136
|
+
return {
|
|
8137
|
+
x: x$1,
|
|
8138
|
+
y: y$1
|
|
8139
|
+
};
|
|
8140
|
+
};
|
|
8141
|
+
const getEditorHoverInfo = async (editorUid, position) => {
|
|
8142
|
+
number(editorUid);
|
|
8143
|
+
const instance = get$4(editorUid);
|
|
8144
|
+
const editor = instance.newState;
|
|
8145
|
+
const {
|
|
8146
|
+
selections
|
|
8147
|
+
} = editor;
|
|
8148
|
+
const {
|
|
8149
|
+
rowIndex,
|
|
8150
|
+
columnIndex
|
|
8151
|
+
} = getHoverPosition(position, selections);
|
|
8152
|
+
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
8153
|
+
const hover = await getHover(editor, offset);
|
|
8154
|
+
if (!hover) {
|
|
8155
|
+
return undefined;
|
|
8156
|
+
}
|
|
8157
|
+
const {
|
|
8158
|
+
displayString,
|
|
8159
|
+
documentation,
|
|
8160
|
+
displayStringLanguageId
|
|
8161
|
+
} = hover;
|
|
8162
|
+
const tokenizerPath = '';
|
|
8163
|
+
const lineInfos = await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath);
|
|
8164
|
+
const wordPart = getWordBefore(editor, rowIndex, columnIndex);
|
|
8165
|
+
const wordStart = columnIndex - wordPart.length;
|
|
8166
|
+
await measureTextBlockHeight();
|
|
8167
|
+
const {
|
|
8168
|
+
x,
|
|
8169
|
+
y
|
|
8170
|
+
} = getHoverPositionXy(editor, rowIndex, wordStart);
|
|
8171
|
+
const diagnostics = editor.diagnostics || [];
|
|
8172
|
+
const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
|
|
8173
|
+
return {
|
|
8174
|
+
lineInfos,
|
|
8175
|
+
documentation,
|
|
8176
|
+
x,
|
|
8177
|
+
y,
|
|
8178
|
+
matchingDiagnostics
|
|
8179
|
+
};
|
|
8180
|
+
};
|
|
8181
|
+
|
|
8179
8182
|
const loadContent = async (editorUid, state, position) => {
|
|
8180
8183
|
const hoverInfo = await getEditorHoverInfo(editorUid, position);
|
|
8181
8184
|
if (!hoverInfo) {
|
|
@@ -8397,7 +8400,7 @@ const remove$5 = widget => {
|
|
|
8397
8400
|
};
|
|
8398
8401
|
const {
|
|
8399
8402
|
handleInput,
|
|
8400
|
-
close: close$
|
|
8403
|
+
close: close$2,
|
|
8401
8404
|
accept
|
|
8402
8405
|
} = createFns(['handleInput', 'close', 'accept'], 'Rename', Rename$1);
|
|
8403
8406
|
|
|
@@ -8405,7 +8408,7 @@ const EditorRenameWidget = {
|
|
|
8405
8408
|
__proto__: null,
|
|
8406
8409
|
accept,
|
|
8407
8410
|
add: add$5,
|
|
8408
|
-
close: close$
|
|
8411
|
+
close: close$2,
|
|
8409
8412
|
handleInput,
|
|
8410
8413
|
remove: remove$5,
|
|
8411
8414
|
render: render$8
|
|
@@ -8465,13 +8468,13 @@ const {
|
|
|
8465
8468
|
toggleDetails,
|
|
8466
8469
|
closeDetails,
|
|
8467
8470
|
handleWheel,
|
|
8468
|
-
close
|
|
8471
|
+
close: close$1
|
|
8469
8472
|
} = createFns(['focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'selectCurrent', 'selectIndex', 'selectItem', 'toggleDetails', 'closeDetails', 'handleWheel', 'close'], 'SourceActions', SourceAction$1);
|
|
8470
8473
|
|
|
8471
8474
|
const EditorSourceActionWidget = {
|
|
8472
8475
|
__proto__: null,
|
|
8473
8476
|
add: add$4,
|
|
8474
|
-
close,
|
|
8477
|
+
close: close$1,
|
|
8475
8478
|
closeDetails,
|
|
8476
8479
|
focusFirst,
|
|
8477
8480
|
focusIndex,
|
|
@@ -9218,6 +9221,7 @@ const getSelections = editorUid => {
|
|
|
9218
9221
|
};
|
|
9219
9222
|
|
|
9220
9223
|
const getText = editorUid => {
|
|
9224
|
+
number(editorUid);
|
|
9221
9225
|
const editor = getEditor(editorUid);
|
|
9222
9226
|
const {
|
|
9223
9227
|
lines
|
|
@@ -10618,7 +10622,7 @@ const commandMap = {
|
|
|
10618
10622
|
'Editor.setSelections': setSelections,
|
|
10619
10623
|
'Editor.setSelections2': setSelections2,
|
|
10620
10624
|
'Editor.showHover': showHover,
|
|
10621
|
-
'Editor.showHover2':
|
|
10625
|
+
'Editor.showHover2': showHover3,
|
|
10622
10626
|
'Editor.showSourceActions': showSourceActions,
|
|
10623
10627
|
'Editor.showSourceActions2': showSourceActions,
|
|
10624
10628
|
'Editor.showSourceActions3': showSourceActions,
|
|
@@ -10634,7 +10638,7 @@ const commandMap = {
|
|
|
10634
10638
|
'Editor.unIndent': editorUnindent,
|
|
10635
10639
|
'Editor.updateDebugInfo': updateDebugInfo,
|
|
10636
10640
|
'Editor.updateDiagnostics': updateDiagnostics,
|
|
10637
|
-
'EditorCompletion.close': close$
|
|
10641
|
+
'EditorCompletion.close': close$4,
|
|
10638
10642
|
'EditorCompletion.closeDetails': closeDetails$1,
|
|
10639
10643
|
'EditorCompletion.focusFirst': focusFirst$1,
|
|
10640
10644
|
'EditorCompletion.focusIndex': focusIndex$2,
|
|
@@ -10649,7 +10653,7 @@ const commandMap = {
|
|
|
10649
10653
|
'EditorCompletion.selectCurrent': selectCurrent$1,
|
|
10650
10654
|
'EditorCompletion.selectIndex': selectIndex$1,
|
|
10651
10655
|
'EditorCompletion.toggleDetails': toggleDetails$1,
|
|
10652
|
-
'EditorSourceAction.close': close,
|
|
10656
|
+
'EditorSourceAction.close': close$1,
|
|
10653
10657
|
'EditorSourceAction.closeDetails': closeDetails,
|
|
10654
10658
|
'EditorSourceAction.focusFirst': focusFirst,
|
|
10655
10659
|
'EditorSourceAction.focusIndex': focusIndex,
|
|
@@ -10661,10 +10665,10 @@ const commandMap = {
|
|
|
10661
10665
|
'EditorSourceAction.selectItem': selectItem,
|
|
10662
10666
|
'EditorSourceAction.toggleDetails': toggleDetails,
|
|
10663
10667
|
'EditorRename.accept': accept,
|
|
10664
|
-
'EditorRename.close': close$
|
|
10668
|
+
'EditorRename.close': close$2,
|
|
10665
10669
|
'EditorRename.handleInput': handleInput,
|
|
10666
10670
|
'EditorSourceActions.focusNext': focusNext$1,
|
|
10667
|
-
'FindWidget.close': close$
|
|
10671
|
+
'FindWidget.close': close$3,
|
|
10668
10672
|
'FindWidget.focusCloseButton': focusCloseButton,
|
|
10669
10673
|
'FindWidget.focusFind': focusFind,
|
|
10670
10674
|
'FindWidget.focusNext': focusNext$2,
|
|
@@ -10973,14 +10977,14 @@ const EditorCompletionDetailWidget = {
|
|
|
10973
10977
|
};
|
|
10974
10978
|
|
|
10975
10979
|
const render = widget => {
|
|
10976
|
-
const commands =
|
|
10980
|
+
const commands = renderFull$4(widget.oldState, widget.newState);
|
|
10977
10981
|
const wrappedCommands = [];
|
|
10978
10982
|
const {
|
|
10979
10983
|
uid
|
|
10980
10984
|
} = widget.newState;
|
|
10981
10985
|
for (const command of commands) {
|
|
10982
|
-
if (command[0] === SetDom2) {
|
|
10983
|
-
wrappedCommands.push(
|
|
10986
|
+
if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetSelectionByName || command[0] === SetValueByName || command[0] === SetFocusContext || command[0] === SetUid || command[0] === 'Viewlet.focusSelector') {
|
|
10987
|
+
wrappedCommands.push(command);
|
|
10984
10988
|
} else {
|
|
10985
10989
|
wrappedCommands.push(['Viewlet.send', uid, ...command]);
|
|
10986
10990
|
}
|
|
@@ -10988,13 +10992,19 @@ const render = widget => {
|
|
|
10988
10992
|
return wrappedCommands;
|
|
10989
10993
|
};
|
|
10990
10994
|
const add = widget => {
|
|
10991
|
-
return addWidget$1(widget, '
|
|
10995
|
+
return addWidget$1(widget, 'EditorCompletion', render);
|
|
10996
|
+
};
|
|
10997
|
+
const remove = widget => {
|
|
10998
|
+
return [['Viewlet.dispose', widget.newState.uid]];
|
|
10992
10999
|
};
|
|
10993
|
-
const
|
|
11000
|
+
const {
|
|
11001
|
+
close
|
|
11002
|
+
} = createFns(['close'], '', Hover);
|
|
10994
11003
|
|
|
10995
11004
|
const EditorHoverWidget = {
|
|
10996
11005
|
__proto__: null,
|
|
10997
11006
|
add,
|
|
11007
|
+
close,
|
|
10998
11008
|
remove,
|
|
10999
11009
|
render
|
|
11000
11010
|
};
|