@lvce-editor/editor-worker 8.6.0 → 9.1.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 +265 -259
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -6775,226 +6775,52 @@ const create$1 = () => {
|
|
|
6775
6775
|
return widget;
|
|
6776
6776
|
};
|
|
6777
6777
|
|
|
6778
|
-
const
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
method: HoverExecute,
|
|
6785
|
-
args: [offset],
|
|
6786
|
-
noProviderFoundMessage: 'No hover provider found'
|
|
6787
|
-
});
|
|
6788
|
-
};
|
|
6789
|
-
|
|
6790
|
-
const getHover = async (editor, offset) => {
|
|
6791
|
-
object(editor);
|
|
6792
|
-
number(offset);
|
|
6793
|
-
// TODO invoke extension host worker directly
|
|
6794
|
-
const hover = await executeHoverProvider(editor, offset);
|
|
6795
|
-
return hover;
|
|
6796
|
-
};
|
|
6797
|
-
|
|
6798
|
-
const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
|
|
6799
|
-
// @ts-ignore
|
|
6800
|
-
// return RendererProcess.invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width)
|
|
6801
|
-
return 100;
|
|
6802
|
-
};
|
|
6803
|
-
|
|
6804
|
-
const deepCopy = value => {
|
|
6805
|
-
return structuredClone(value);
|
|
6806
|
-
};
|
|
6807
|
-
|
|
6808
|
-
const getInitialLineState = initialLineState => {
|
|
6809
|
-
return deepCopy(initialLineState);
|
|
6810
|
-
};
|
|
6811
|
-
|
|
6812
|
-
const getLineInfo$1 = (line, tokens, TokenMap) => {
|
|
6813
|
-
const tokensLength = tokens.length;
|
|
6814
|
-
let end = 0;
|
|
6815
|
-
let start = 0;
|
|
6816
|
-
const lineInfo = [];
|
|
6817
|
-
for (let i = 0; i < tokensLength; i += 2) {
|
|
6818
|
-
const tokenType = tokens[i];
|
|
6819
|
-
const tokenLength = tokens[i + 1];
|
|
6820
|
-
end += tokenLength;
|
|
6821
|
-
const text = line.slice(start, end);
|
|
6822
|
-
const className = `Token ${TokenMap[tokenType] || 'Unknown'}`;
|
|
6823
|
-
const normalizedText = text;
|
|
6824
|
-
lineInfo.push(normalizedText, className);
|
|
6825
|
-
start = end;
|
|
6826
|
-
}
|
|
6827
|
-
return lineInfo;
|
|
6828
|
-
};
|
|
6829
|
-
|
|
6830
|
-
const state = {
|
|
6831
|
-
warned: []
|
|
6832
|
-
};
|
|
6833
|
-
const flattenTokensArray = tokens => {
|
|
6834
|
-
const flattened = [];
|
|
6835
|
-
for (const token of tokens) {
|
|
6836
|
-
object(token);
|
|
6837
|
-
flattened.push(token.type, token.length);
|
|
6838
|
-
}
|
|
6839
|
-
return flattened;
|
|
6840
|
-
};
|
|
6841
|
-
const warnDeprecatedArrayReturn = (languageId, fn) => {
|
|
6842
|
-
if (state.warned.includes(fn)) {
|
|
6843
|
-
return;
|
|
6844
|
-
}
|
|
6845
|
-
state.warned.push(fn);
|
|
6846
|
-
console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
|
|
6847
|
-
};
|
|
6848
|
-
const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
|
|
6849
|
-
try {
|
|
6850
|
-
const lineState = tokenizeLine(line, lineStateAtStart);
|
|
6851
|
-
if (!lineState?.tokens || !lineState.state) {
|
|
6852
|
-
throw new Error('invalid tokenization result');
|
|
6853
|
-
}
|
|
6854
|
-
if (!hasArrayReturn) {
|
|
6855
|
-
warnDeprecatedArrayReturn(languageId, tokenizeLine);
|
|
6856
|
-
// workaround for old tokenizers
|
|
6857
|
-
lineState.tokens = flattenTokensArray(lineState.tokens);
|
|
6858
|
-
}
|
|
6859
|
-
return lineState;
|
|
6860
|
-
} catch (error) {
|
|
6861
|
-
console.error(error);
|
|
6862
|
-
return {
|
|
6863
|
-
tokens: [/* type */0, /* length */line.length],
|
|
6864
|
-
lineState: lineStateAtStart
|
|
6865
|
-
};
|
|
6866
|
-
}
|
|
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;
|
|
6867
6784
|
};
|
|
6868
6785
|
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
initialLineState,
|
|
6874
|
-
hasArrayReturn,
|
|
6875
|
-
TokenMap
|
|
6876
|
-
} = tokenizer;
|
|
6877
|
-
let currentLineState = getInitialLineState(initialLineState);
|
|
6878
|
-
for (const line of lines) {
|
|
6879
|
-
const result = safeTokenizeLine(languageId, tokenizeLine, line, currentLineState, hasArrayReturn);
|
|
6880
|
-
const {
|
|
6881
|
-
tokens
|
|
6882
|
-
} = result;
|
|
6883
|
-
const lineInfo = getLineInfo$1(line, tokens, TokenMap);
|
|
6884
|
-
lineInfos.push(lineInfo);
|
|
6885
|
-
currentLineState = result;
|
|
6786
|
+
let workerPromise$1;
|
|
6787
|
+
const getOrCreate$1 = () => {
|
|
6788
|
+
if (!workerPromise$1) {
|
|
6789
|
+
workerPromise$1 = launchHoverWorker();
|
|
6886
6790
|
}
|
|
6887
|
-
return
|
|
6791
|
+
return workerPromise$1;
|
|
6888
6792
|
};
|
|
6889
|
-
|
|
6890
|
-
const
|
|
6891
|
-
await
|
|
6892
|
-
const tokenizer = getTokenizer(languageId);
|
|
6893
|
-
const lines = splitLines(codeBlock);
|
|
6894
|
-
const lineInfos = getLineInfos(lines, tokenizer, languageId);
|
|
6895
|
-
return lineInfos;
|
|
6793
|
+
const invoke$2 = async (method, ...params) => {
|
|
6794
|
+
const worker = await getOrCreate$1();
|
|
6795
|
+
return await worker.invoke(method, ...params);
|
|
6896
6796
|
};
|
|
6897
6797
|
|
|
6898
|
-
const
|
|
6899
|
-
if (position) {
|
|
6900
|
-
return position;
|
|
6901
|
-
}
|
|
6902
|
-
const rowIndex = selections[0];
|
|
6903
|
-
const columnIndex = selections[1];
|
|
6904
|
-
return {
|
|
6905
|
-
rowIndex,
|
|
6906
|
-
columnIndex
|
|
6907
|
-
};
|
|
6908
|
-
};
|
|
6909
|
-
const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
|
|
6910
|
-
const matching = [];
|
|
6911
|
-
for (const diagnostic of diagnostics) {
|
|
6912
|
-
if (diagnostic.rowIndex === rowIndex) {
|
|
6913
|
-
matching.push(diagnostic);
|
|
6914
|
-
}
|
|
6915
|
-
}
|
|
6916
|
-
return matching;
|
|
6917
|
-
};
|
|
6918
|
-
const fallbackDisplayStringLanguageId = 'typescript'; // TODO remove this
|
|
6919
|
-
const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
|
|
6920
|
-
const x$1 = x(editor, rowIndex, wordStart);
|
|
6921
|
-
const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
|
|
6922
|
-
return {
|
|
6923
|
-
x: x$1,
|
|
6924
|
-
y: y$1
|
|
6925
|
-
};
|
|
6926
|
-
};
|
|
6927
|
-
const getEditorHoverInfo = async (editorUid, position) => {
|
|
6928
|
-
number(editorUid);
|
|
6929
|
-
const instance = get$4(editorUid);
|
|
6930
|
-
const editor = instance.newState;
|
|
6931
|
-
const {
|
|
6932
|
-
selections
|
|
6933
|
-
} = editor;
|
|
6798
|
+
const newStateGenerator$1 = async (state, parentUid) => {
|
|
6934
6799
|
const {
|
|
6935
|
-
|
|
6936
|
-
columnIndex
|
|
6937
|
-
} = getHoverPosition(position, selections);
|
|
6938
|
-
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
6939
|
-
const hover = await getHover(editor, offset);
|
|
6940
|
-
if (!hover) {
|
|
6941
|
-
return undefined;
|
|
6942
|
-
}
|
|
6943
|
-
const {
|
|
6944
|
-
displayString,
|
|
6945
|
-
documentation,
|
|
6946
|
-
displayStringLanguageId
|
|
6947
|
-
} = hover;
|
|
6948
|
-
const tokenizerPath = '';
|
|
6949
|
-
const lineInfos = await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath);
|
|
6950
|
-
const wordPart = getWordBefore(editor, rowIndex, columnIndex);
|
|
6951
|
-
const wordStart = columnIndex - wordPart.length;
|
|
6952
|
-
await measureTextBlockHeight();
|
|
6953
|
-
const {
|
|
6954
|
-
x,
|
|
6955
|
-
y
|
|
6956
|
-
} = getHoverPositionXy(editor, rowIndex, wordStart);
|
|
6957
|
-
const diagnostics = editor.diagnostics || [];
|
|
6958
|
-
const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
|
|
6959
|
-
return {
|
|
6960
|
-
lineInfos,
|
|
6961
|
-
documentation,
|
|
6800
|
+
uid,
|
|
6962
6801
|
x,
|
|
6963
6802
|
y,
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
};
|
|
6967
|
-
|
|
6968
|
-
const loadHoverContent = async state => {
|
|
6969
|
-
// TODO
|
|
6970
|
-
const position = undefined;
|
|
6971
|
-
const hoverInfo = await getEditorHoverInfo(state.editorUid, position);
|
|
6972
|
-
if (!hoverInfo) {
|
|
6973
|
-
return state;
|
|
6974
|
-
}
|
|
6803
|
+
width,
|
|
6804
|
+
height
|
|
6805
|
+
} = state;
|
|
6975
6806
|
const {
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
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);
|
|
6982
6816
|
return {
|
|
6983
6817
|
...state,
|
|
6984
|
-
|
|
6985
|
-
documentation,
|
|
6986
|
-
x,
|
|
6987
|
-
y,
|
|
6988
|
-
width: 600,
|
|
6989
|
-
diagnostics: matchingDiagnostics
|
|
6818
|
+
commands
|
|
6990
6819
|
};
|
|
6991
6820
|
};
|
|
6992
|
-
|
|
6993
|
-
const
|
|
6994
|
-
return
|
|
6995
|
-
};
|
|
6996
|
-
const showHover2 = async editor => {
|
|
6997
|
-
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);
|
|
6998
6824
|
};
|
|
6999
6825
|
|
|
7000
6826
|
const EditorHover = 'EditorHover';
|
|
@@ -7041,15 +6867,15 @@ const launchSourceActionWorker = async () => {
|
|
|
7041
6867
|
return rpc;
|
|
7042
6868
|
};
|
|
7043
6869
|
|
|
7044
|
-
let workerPromise
|
|
7045
|
-
const getOrCreate
|
|
7046
|
-
if (!workerPromise
|
|
7047
|
-
workerPromise
|
|
6870
|
+
let workerPromise;
|
|
6871
|
+
const getOrCreate = () => {
|
|
6872
|
+
if (!workerPromise) {
|
|
6873
|
+
workerPromise = launchSourceActionWorker();
|
|
7048
6874
|
}
|
|
7049
|
-
return workerPromise
|
|
6875
|
+
return workerPromise;
|
|
7050
6876
|
};
|
|
7051
|
-
const invoke$
|
|
7052
|
-
const worker = await getOrCreate
|
|
6877
|
+
const invoke$1 = async (method, ...params) => {
|
|
6878
|
+
const worker = await getOrCreate();
|
|
7053
6879
|
return await worker.invoke(method, ...params);
|
|
7054
6880
|
};
|
|
7055
6881
|
|
|
@@ -7067,10 +6893,10 @@ const newStateGenerator = async (state, parentUid) => {
|
|
|
7067
6893
|
const {
|
|
7068
6894
|
languageId
|
|
7069
6895
|
} = newState;
|
|
7070
|
-
await invoke$
|
|
7071
|
-
await invoke$
|
|
7072
|
-
const diff = await invoke$
|
|
7073
|
-
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);
|
|
7074
6900
|
return {
|
|
7075
6901
|
...state,
|
|
7076
6902
|
commands
|
|
@@ -7877,6 +7703,7 @@ const isFunctional = widgetId => {
|
|
|
7877
7703
|
case Completion:
|
|
7878
7704
|
case Find:
|
|
7879
7705
|
case SourceAction$1:
|
|
7706
|
+
case Hover:
|
|
7880
7707
|
return true;
|
|
7881
7708
|
default:
|
|
7882
7709
|
return false;
|
|
@@ -7914,26 +7741,6 @@ const addWidget$1 = (widget, id, render) => {
|
|
|
7914
7741
|
return allCommands;
|
|
7915
7742
|
};
|
|
7916
7743
|
|
|
7917
|
-
const launchHoverWorker = async () => {
|
|
7918
|
-
const name = 'Hover Worker';
|
|
7919
|
-
const url = 'hoverWorkerMain.js';
|
|
7920
|
-
const intializeCommand = 'Hover.initialize';
|
|
7921
|
-
const rpc = await launchWorker(name, url, intializeCommand);
|
|
7922
|
-
return rpc;
|
|
7923
|
-
};
|
|
7924
|
-
|
|
7925
|
-
let workerPromise;
|
|
7926
|
-
const getOrCreate = () => {
|
|
7927
|
-
if (!workerPromise) {
|
|
7928
|
-
workerPromise = launchHoverWorker();
|
|
7929
|
-
}
|
|
7930
|
-
return workerPromise;
|
|
7931
|
-
};
|
|
7932
|
-
const invoke$1 = async (method, ...params) => {
|
|
7933
|
-
const worker = await getOrCreate();
|
|
7934
|
-
return await worker.invoke(method, ...params);
|
|
7935
|
-
};
|
|
7936
|
-
|
|
7937
7744
|
const getWidgetInvoke = widgetId => {
|
|
7938
7745
|
switch (widgetId) {
|
|
7939
7746
|
case ColorPicker$1:
|
|
@@ -7945,9 +7752,9 @@ const getWidgetInvoke = widgetId => {
|
|
|
7945
7752
|
case Rename$1:
|
|
7946
7753
|
return invoke$6;
|
|
7947
7754
|
case SourceAction$1:
|
|
7948
|
-
return invoke$2;
|
|
7949
|
-
case Hover:
|
|
7950
7755
|
return invoke$1;
|
|
7756
|
+
case Hover:
|
|
7757
|
+
return invoke$2;
|
|
7951
7758
|
default:
|
|
7952
7759
|
return undefined;
|
|
7953
7760
|
}
|
|
@@ -8066,13 +7873,13 @@ const {
|
|
|
8066
7873
|
toggleDetails: toggleDetails$1,
|
|
8067
7874
|
closeDetails: closeDetails$1,
|
|
8068
7875
|
handleWheel: handleWheel$1,
|
|
8069
|
-
close: close$
|
|
7876
|
+
close: close$4
|
|
8070
7877
|
} = createFns(['handleEditorType', 'focusFirst', 'focusNext', 'focusPrevious', 'focusLast', 'handleEditorDeleteLeft', 'openDetails', 'focusIndex', 'handleEditorBlur', 'handleEditorClick', 'openDetails', 'selectCurrent', 'selectIndex', 'toggleDetails', 'closeDetails', 'handleWheel', 'close'], 'Completions', Completion);
|
|
8071
7878
|
|
|
8072
7879
|
const EditorCompletionWidget = {
|
|
8073
7880
|
__proto__: null,
|
|
8074
7881
|
add: add$7,
|
|
8075
|
-
close: close$
|
|
7882
|
+
close: close$4,
|
|
8076
7883
|
closeDetails: closeDetails$1,
|
|
8077
7884
|
focusFirst: focusFirst$1,
|
|
8078
7885
|
focusIndex: focusIndex$2,
|
|
@@ -8121,7 +7928,7 @@ const remove$6 = widget => {
|
|
|
8121
7928
|
return [['Viewlet.dispose', widget.newState.uid]];
|
|
8122
7929
|
};
|
|
8123
7930
|
const {
|
|
8124
|
-
close: close$
|
|
7931
|
+
close: close$3,
|
|
8125
7932
|
focusCloseButton,
|
|
8126
7933
|
focusFind,
|
|
8127
7934
|
focusNext: focusNext$2,
|
|
@@ -8146,13 +7953,14 @@ const {
|
|
|
8146
7953
|
toggleReplace,
|
|
8147
7954
|
toggleUseRegularExpression,
|
|
8148
7955
|
focusNextElement,
|
|
8149
|
-
focusPreviousElement
|
|
8150
|
-
|
|
7956
|
+
focusPreviousElement,
|
|
7957
|
+
togglePreserveCase
|
|
7958
|
+
} = createFns(['close', 'focusCloseButton', 'focusFind', 'focusNext', 'focusNextMatchButton', 'focusPrevious', 'focusPreviousMatchButton', 'focusReplace', 'focusReplaceAllButton', 'focusReplaceButton', 'focusToggleReplace', 'handleBlur', 'handleClickButton', 'handleFocus', 'handleInput', 'handleReplaceFocus', 'handleReplaceInput', 'handleToggleReplaceFocus', 'replace', 'replaceAll', 'toggleMatchCase', 'toggleMatchWholeWord', 'toggleReplace', 'toggleUseRegularExpression', 'focusNextElement', 'focusPreviousElement', 'togglePreserveCase'], 'FindWidget', Find);
|
|
8151
7959
|
|
|
8152
7960
|
const EditorFindWidget = {
|
|
8153
7961
|
__proto__: null,
|
|
8154
7962
|
add: add$6,
|
|
8155
|
-
close: close$
|
|
7963
|
+
close: close$3,
|
|
8156
7964
|
focusCloseButton,
|
|
8157
7965
|
focusFind,
|
|
8158
7966
|
focusNext: focusNext$2,
|
|
@@ -8178,10 +7986,201 @@ const EditorFindWidget = {
|
|
|
8178
7986
|
replaceAll,
|
|
8179
7987
|
toggleMatchCase,
|
|
8180
7988
|
toggleMatchWholeWord,
|
|
7989
|
+
togglePreserveCase,
|
|
8181
7990
|
toggleReplace,
|
|
8182
7991
|
toggleUseRegularExpression
|
|
8183
7992
|
};
|
|
8184
7993
|
|
|
7994
|
+
const executeHoverProvider = async (editor, offset) => {
|
|
7995
|
+
object(editor);
|
|
7996
|
+
number(offset);
|
|
7997
|
+
return execute({
|
|
7998
|
+
event: OnHover,
|
|
7999
|
+
editor,
|
|
8000
|
+
method: HoverExecute,
|
|
8001
|
+
args: [offset],
|
|
8002
|
+
noProviderFoundMessage: 'No hover provider found'
|
|
8003
|
+
});
|
|
8004
|
+
};
|
|
8005
|
+
|
|
8006
|
+
const getHover = async (editor, offset) => {
|
|
8007
|
+
object(editor);
|
|
8008
|
+
number(offset);
|
|
8009
|
+
// TODO invoke extension host worker directly
|
|
8010
|
+
const hover = await executeHoverProvider(editor, offset);
|
|
8011
|
+
return hover;
|
|
8012
|
+
};
|
|
8013
|
+
|
|
8014
|
+
const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
|
|
8015
|
+
// @ts-ignore
|
|
8016
|
+
// return RendererProcess.invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width)
|
|
8017
|
+
return 100;
|
|
8018
|
+
};
|
|
8019
|
+
|
|
8020
|
+
const deepCopy = value => {
|
|
8021
|
+
return structuredClone(value);
|
|
8022
|
+
};
|
|
8023
|
+
|
|
8024
|
+
const getInitialLineState = initialLineState => {
|
|
8025
|
+
return deepCopy(initialLineState);
|
|
8026
|
+
};
|
|
8027
|
+
|
|
8028
|
+
const getLineInfo$1 = (line, tokens, TokenMap) => {
|
|
8029
|
+
const tokensLength = tokens.length;
|
|
8030
|
+
let end = 0;
|
|
8031
|
+
let start = 0;
|
|
8032
|
+
const lineInfo = [];
|
|
8033
|
+
for (let i = 0; i < tokensLength; i += 2) {
|
|
8034
|
+
const tokenType = tokens[i];
|
|
8035
|
+
const tokenLength = tokens[i + 1];
|
|
8036
|
+
end += tokenLength;
|
|
8037
|
+
const text = line.slice(start, end);
|
|
8038
|
+
const className = `Token ${TokenMap[tokenType] || 'Unknown'}`;
|
|
8039
|
+
const normalizedText = text;
|
|
8040
|
+
lineInfo.push(normalizedText, className);
|
|
8041
|
+
start = end;
|
|
8042
|
+
}
|
|
8043
|
+
return lineInfo;
|
|
8044
|
+
};
|
|
8045
|
+
|
|
8046
|
+
const state = {
|
|
8047
|
+
warned: []
|
|
8048
|
+
};
|
|
8049
|
+
const flattenTokensArray = tokens => {
|
|
8050
|
+
const flattened = [];
|
|
8051
|
+
for (const token of tokens) {
|
|
8052
|
+
object(token);
|
|
8053
|
+
flattened.push(token.type, token.length);
|
|
8054
|
+
}
|
|
8055
|
+
return flattened;
|
|
8056
|
+
};
|
|
8057
|
+
const warnDeprecatedArrayReturn = (languageId, fn) => {
|
|
8058
|
+
if (state.warned.includes(fn)) {
|
|
8059
|
+
return;
|
|
8060
|
+
}
|
|
8061
|
+
state.warned.push(fn);
|
|
8062
|
+
console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
|
|
8063
|
+
};
|
|
8064
|
+
const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
|
|
8065
|
+
try {
|
|
8066
|
+
const lineState = tokenizeLine(line, lineStateAtStart);
|
|
8067
|
+
if (!lineState?.tokens || !lineState.state) {
|
|
8068
|
+
throw new Error('invalid tokenization result');
|
|
8069
|
+
}
|
|
8070
|
+
if (!hasArrayReturn) {
|
|
8071
|
+
warnDeprecatedArrayReturn(languageId, tokenizeLine);
|
|
8072
|
+
// workaround for old tokenizers
|
|
8073
|
+
lineState.tokens = flattenTokensArray(lineState.tokens);
|
|
8074
|
+
}
|
|
8075
|
+
return lineState;
|
|
8076
|
+
} catch (error) {
|
|
8077
|
+
console.error(error);
|
|
8078
|
+
return {
|
|
8079
|
+
tokens: [/* type */0, /* length */line.length],
|
|
8080
|
+
lineState: lineStateAtStart
|
|
8081
|
+
};
|
|
8082
|
+
}
|
|
8083
|
+
};
|
|
8084
|
+
|
|
8085
|
+
const getLineInfos = (lines, tokenizer, languageId) => {
|
|
8086
|
+
const lineInfos = [];
|
|
8087
|
+
const {
|
|
8088
|
+
tokenizeLine,
|
|
8089
|
+
initialLineState,
|
|
8090
|
+
hasArrayReturn,
|
|
8091
|
+
TokenMap
|
|
8092
|
+
} = tokenizer;
|
|
8093
|
+
let currentLineState = getInitialLineState(initialLineState);
|
|
8094
|
+
for (const line of lines) {
|
|
8095
|
+
const result = safeTokenizeLine(languageId, tokenizeLine, line, currentLineState, hasArrayReturn);
|
|
8096
|
+
const {
|
|
8097
|
+
tokens
|
|
8098
|
+
} = result;
|
|
8099
|
+
const lineInfo = getLineInfo$1(line, tokens, TokenMap);
|
|
8100
|
+
lineInfos.push(lineInfo);
|
|
8101
|
+
currentLineState = result;
|
|
8102
|
+
}
|
|
8103
|
+
return lineInfos;
|
|
8104
|
+
};
|
|
8105
|
+
|
|
8106
|
+
const tokenizeCodeBlock = async (codeBlock, languageId, tokenizerPath) => {
|
|
8107
|
+
await loadTokenizer(languageId, tokenizerPath);
|
|
8108
|
+
const tokenizer = getTokenizer(languageId);
|
|
8109
|
+
const lines = splitLines(codeBlock);
|
|
8110
|
+
const lineInfos = getLineInfos(lines, tokenizer, languageId);
|
|
8111
|
+
return lineInfos;
|
|
8112
|
+
};
|
|
8113
|
+
|
|
8114
|
+
const getHoverPosition = (position, selections) => {
|
|
8115
|
+
if (position) {
|
|
8116
|
+
return position;
|
|
8117
|
+
}
|
|
8118
|
+
const rowIndex = selections[0];
|
|
8119
|
+
const columnIndex = selections[1];
|
|
8120
|
+
return {
|
|
8121
|
+
rowIndex,
|
|
8122
|
+
columnIndex
|
|
8123
|
+
};
|
|
8124
|
+
};
|
|
8125
|
+
const getMatchingDiagnostics = (diagnostics, rowIndex, columnIndex) => {
|
|
8126
|
+
const matching = [];
|
|
8127
|
+
for (const diagnostic of diagnostics) {
|
|
8128
|
+
if (diagnostic.rowIndex === rowIndex) {
|
|
8129
|
+
matching.push(diagnostic);
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
return matching;
|
|
8133
|
+
};
|
|
8134
|
+
const fallbackDisplayStringLanguageId = 'typescript'; // TODO remove this
|
|
8135
|
+
const getHoverPositionXy = (editor, rowIndex, wordStart, documentationHeight) => {
|
|
8136
|
+
const x$1 = x(editor, rowIndex, wordStart);
|
|
8137
|
+
const y$1 = editor.height - y(editor, rowIndex) + editor.y + 40;
|
|
8138
|
+
return {
|
|
8139
|
+
x: x$1,
|
|
8140
|
+
y: y$1
|
|
8141
|
+
};
|
|
8142
|
+
};
|
|
8143
|
+
const getEditorHoverInfo = async (editorUid, position) => {
|
|
8144
|
+
number(editorUid);
|
|
8145
|
+
const instance = get$4(editorUid);
|
|
8146
|
+
const editor = instance.newState;
|
|
8147
|
+
const {
|
|
8148
|
+
selections
|
|
8149
|
+
} = editor;
|
|
8150
|
+
const {
|
|
8151
|
+
rowIndex,
|
|
8152
|
+
columnIndex
|
|
8153
|
+
} = getHoverPosition(position, selections);
|
|
8154
|
+
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
8155
|
+
const hover = await getHover(editor, offset);
|
|
8156
|
+
if (!hover) {
|
|
8157
|
+
return undefined;
|
|
8158
|
+
}
|
|
8159
|
+
const {
|
|
8160
|
+
displayString,
|
|
8161
|
+
documentation,
|
|
8162
|
+
displayStringLanguageId
|
|
8163
|
+
} = hover;
|
|
8164
|
+
const tokenizerPath = '';
|
|
8165
|
+
const lineInfos = await tokenizeCodeBlock(displayString, displayStringLanguageId || fallbackDisplayStringLanguageId, tokenizerPath);
|
|
8166
|
+
const wordPart = getWordBefore(editor, rowIndex, columnIndex);
|
|
8167
|
+
const wordStart = columnIndex - wordPart.length;
|
|
8168
|
+
await measureTextBlockHeight();
|
|
8169
|
+
const {
|
|
8170
|
+
x,
|
|
8171
|
+
y
|
|
8172
|
+
} = getHoverPositionXy(editor, rowIndex, wordStart);
|
|
8173
|
+
const diagnostics = editor.diagnostics || [];
|
|
8174
|
+
const matchingDiagnostics = getMatchingDiagnostics(diagnostics, rowIndex);
|
|
8175
|
+
return {
|
|
8176
|
+
lineInfos,
|
|
8177
|
+
documentation,
|
|
8178
|
+
x,
|
|
8179
|
+
y,
|
|
8180
|
+
matchingDiagnostics
|
|
8181
|
+
};
|
|
8182
|
+
};
|
|
8183
|
+
|
|
8185
8184
|
const loadContent = async (editorUid, state, position) => {
|
|
8186
8185
|
const hoverInfo = await getEditorHoverInfo(editorUid, position);
|
|
8187
8186
|
if (!hoverInfo) {
|
|
@@ -8403,7 +8402,7 @@ const remove$5 = widget => {
|
|
|
8403
8402
|
};
|
|
8404
8403
|
const {
|
|
8405
8404
|
handleInput,
|
|
8406
|
-
close: close$
|
|
8405
|
+
close: close$2,
|
|
8407
8406
|
accept
|
|
8408
8407
|
} = createFns(['handleInput', 'close', 'accept'], 'Rename', Rename$1);
|
|
8409
8408
|
|
|
@@ -8411,7 +8410,7 @@ const EditorRenameWidget = {
|
|
|
8411
8410
|
__proto__: null,
|
|
8412
8411
|
accept,
|
|
8413
8412
|
add: add$5,
|
|
8414
|
-
close: close$
|
|
8413
|
+
close: close$2,
|
|
8415
8414
|
handleInput,
|
|
8416
8415
|
remove: remove$5,
|
|
8417
8416
|
render: render$8
|
|
@@ -8471,13 +8470,13 @@ const {
|
|
|
8471
8470
|
toggleDetails,
|
|
8472
8471
|
closeDetails,
|
|
8473
8472
|
handleWheel,
|
|
8474
|
-
close
|
|
8473
|
+
close: close$1
|
|
8475
8474
|
} = createFns(['focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'selectCurrent', 'selectIndex', 'selectItem', 'toggleDetails', 'closeDetails', 'handleWheel', 'close'], 'SourceActions', SourceAction$1);
|
|
8476
8475
|
|
|
8477
8476
|
const EditorSourceActionWidget = {
|
|
8478
8477
|
__proto__: null,
|
|
8479
8478
|
add: add$4,
|
|
8480
|
-
close,
|
|
8479
|
+
close: close$1,
|
|
8481
8480
|
closeDetails,
|
|
8482
8481
|
focusFirst,
|
|
8483
8482
|
focusIndex,
|
|
@@ -10625,7 +10624,7 @@ const commandMap = {
|
|
|
10625
10624
|
'Editor.setSelections': setSelections,
|
|
10626
10625
|
'Editor.setSelections2': setSelections2,
|
|
10627
10626
|
'Editor.showHover': showHover,
|
|
10628
|
-
'Editor.showHover2':
|
|
10627
|
+
'Editor.showHover2': showHover3,
|
|
10629
10628
|
'Editor.showSourceActions': showSourceActions,
|
|
10630
10629
|
'Editor.showSourceActions2': showSourceActions,
|
|
10631
10630
|
'Editor.showSourceActions3': showSourceActions,
|
|
@@ -10641,7 +10640,7 @@ const commandMap = {
|
|
|
10641
10640
|
'Editor.unIndent': editorUnindent,
|
|
10642
10641
|
'Editor.updateDebugInfo': updateDebugInfo,
|
|
10643
10642
|
'Editor.updateDiagnostics': updateDiagnostics,
|
|
10644
|
-
'EditorCompletion.close': close$
|
|
10643
|
+
'EditorCompletion.close': close$4,
|
|
10645
10644
|
'EditorCompletion.closeDetails': closeDetails$1,
|
|
10646
10645
|
'EditorCompletion.focusFirst': focusFirst$1,
|
|
10647
10646
|
'EditorCompletion.focusIndex': focusIndex$2,
|
|
@@ -10656,7 +10655,7 @@ const commandMap = {
|
|
|
10656
10655
|
'EditorCompletion.selectCurrent': selectCurrent$1,
|
|
10657
10656
|
'EditorCompletion.selectIndex': selectIndex$1,
|
|
10658
10657
|
'EditorCompletion.toggleDetails': toggleDetails$1,
|
|
10659
|
-
'EditorSourceAction.close': close,
|
|
10658
|
+
'EditorSourceAction.close': close$1,
|
|
10660
10659
|
'EditorSourceAction.closeDetails': closeDetails,
|
|
10661
10660
|
'EditorSourceAction.focusFirst': focusFirst,
|
|
10662
10661
|
'EditorSourceAction.focusIndex': focusIndex,
|
|
@@ -10668,10 +10667,10 @@ const commandMap = {
|
|
|
10668
10667
|
'EditorSourceAction.selectItem': selectItem,
|
|
10669
10668
|
'EditorSourceAction.toggleDetails': toggleDetails,
|
|
10670
10669
|
'EditorRename.accept': accept,
|
|
10671
|
-
'EditorRename.close': close$
|
|
10670
|
+
'EditorRename.close': close$2,
|
|
10672
10671
|
'EditorRename.handleInput': handleInput,
|
|
10673
10672
|
'EditorSourceActions.focusNext': focusNext$1,
|
|
10674
|
-
'FindWidget.close': close$
|
|
10673
|
+
'FindWidget.close': close$3,
|
|
10675
10674
|
'FindWidget.focusCloseButton': focusCloseButton,
|
|
10676
10675
|
'FindWidget.focusFind': focusFind,
|
|
10677
10676
|
'FindWidget.focusNext': focusNext$2,
|
|
@@ -10698,6 +10697,7 @@ const commandMap = {
|
|
|
10698
10697
|
'FindWidget.toggleUseRegularExpression': toggleUseRegularExpression,
|
|
10699
10698
|
'FindWidget.focusNextElement': focusNextElement,
|
|
10700
10699
|
'FindWidget.focusPreviousElement': focusPreviousElement,
|
|
10700
|
+
'FindWidget.togglePreserveCase': togglePreserveCase,
|
|
10701
10701
|
'Font.ensure': ensure,
|
|
10702
10702
|
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
10703
10703
|
'Hover.getHoverInfo': getEditorHoverInfo,
|
|
@@ -10980,14 +10980,14 @@ const EditorCompletionDetailWidget = {
|
|
|
10980
10980
|
};
|
|
10981
10981
|
|
|
10982
10982
|
const render = widget => {
|
|
10983
|
-
const commands =
|
|
10983
|
+
const commands = renderFull$4(widget.oldState, widget.newState);
|
|
10984
10984
|
const wrappedCommands = [];
|
|
10985
10985
|
const {
|
|
10986
10986
|
uid
|
|
10987
10987
|
} = widget.newState;
|
|
10988
10988
|
for (const command of commands) {
|
|
10989
|
-
if (command[0] === SetDom2) {
|
|
10990
|
-
wrappedCommands.push(
|
|
10989
|
+
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') {
|
|
10990
|
+
wrappedCommands.push(command);
|
|
10991
10991
|
} else {
|
|
10992
10992
|
wrappedCommands.push(['Viewlet.send', uid, ...command]);
|
|
10993
10993
|
}
|
|
@@ -10995,13 +10995,19 @@ const render = widget => {
|
|
|
10995
10995
|
return wrappedCommands;
|
|
10996
10996
|
};
|
|
10997
10997
|
const add = widget => {
|
|
10998
|
-
return addWidget$1(widget, '
|
|
10998
|
+
return addWidget$1(widget, 'EditorCompletion', render);
|
|
10999
|
+
};
|
|
11000
|
+
const remove = widget => {
|
|
11001
|
+
return [['Viewlet.dispose', widget.newState.uid]];
|
|
10999
11002
|
};
|
|
11000
|
-
const
|
|
11003
|
+
const {
|
|
11004
|
+
close
|
|
11005
|
+
} = createFns(['close'], '', Hover);
|
|
11001
11006
|
|
|
11002
11007
|
const EditorHoverWidget = {
|
|
11003
11008
|
__proto__: null,
|
|
11004
11009
|
add,
|
|
11010
|
+
close,
|
|
11005
11011
|
remove,
|
|
11006
11012
|
render
|
|
11007
11013
|
};
|