@lvce-editor/editor-worker 8.6.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 +260 -257
- 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,
|
|
@@ -8152,7 +7959,7 @@ const {
|
|
|
8152
7959
|
const EditorFindWidget = {
|
|
8153
7960
|
__proto__: null,
|
|
8154
7961
|
add: add$6,
|
|
8155
|
-
close: close$
|
|
7962
|
+
close: close$3,
|
|
8156
7963
|
focusCloseButton,
|
|
8157
7964
|
focusFind,
|
|
8158
7965
|
focusNext: focusNext$2,
|
|
@@ -8182,6 +7989,196 @@ const EditorFindWidget = {
|
|
|
8182
7989
|
toggleUseRegularExpression
|
|
8183
7990
|
};
|
|
8184
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
|
+
|
|
8185
8182
|
const loadContent = async (editorUid, state, position) => {
|
|
8186
8183
|
const hoverInfo = await getEditorHoverInfo(editorUid, position);
|
|
8187
8184
|
if (!hoverInfo) {
|
|
@@ -8403,7 +8400,7 @@ const remove$5 = widget => {
|
|
|
8403
8400
|
};
|
|
8404
8401
|
const {
|
|
8405
8402
|
handleInput,
|
|
8406
|
-
close: close$
|
|
8403
|
+
close: close$2,
|
|
8407
8404
|
accept
|
|
8408
8405
|
} = createFns(['handleInput', 'close', 'accept'], 'Rename', Rename$1);
|
|
8409
8406
|
|
|
@@ -8411,7 +8408,7 @@ const EditorRenameWidget = {
|
|
|
8411
8408
|
__proto__: null,
|
|
8412
8409
|
accept,
|
|
8413
8410
|
add: add$5,
|
|
8414
|
-
close: close$
|
|
8411
|
+
close: close$2,
|
|
8415
8412
|
handleInput,
|
|
8416
8413
|
remove: remove$5,
|
|
8417
8414
|
render: render$8
|
|
@@ -8471,13 +8468,13 @@ const {
|
|
|
8471
8468
|
toggleDetails,
|
|
8472
8469
|
closeDetails,
|
|
8473
8470
|
handleWheel,
|
|
8474
|
-
close
|
|
8471
|
+
close: close$1
|
|
8475
8472
|
} = createFns(['focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'selectCurrent', 'selectIndex', 'selectItem', 'toggleDetails', 'closeDetails', 'handleWheel', 'close'], 'SourceActions', SourceAction$1);
|
|
8476
8473
|
|
|
8477
8474
|
const EditorSourceActionWidget = {
|
|
8478
8475
|
__proto__: null,
|
|
8479
8476
|
add: add$4,
|
|
8480
|
-
close,
|
|
8477
|
+
close: close$1,
|
|
8481
8478
|
closeDetails,
|
|
8482
8479
|
focusFirst,
|
|
8483
8480
|
focusIndex,
|
|
@@ -10625,7 +10622,7 @@ const commandMap = {
|
|
|
10625
10622
|
'Editor.setSelections': setSelections,
|
|
10626
10623
|
'Editor.setSelections2': setSelections2,
|
|
10627
10624
|
'Editor.showHover': showHover,
|
|
10628
|
-
'Editor.showHover2':
|
|
10625
|
+
'Editor.showHover2': showHover3,
|
|
10629
10626
|
'Editor.showSourceActions': showSourceActions,
|
|
10630
10627
|
'Editor.showSourceActions2': showSourceActions,
|
|
10631
10628
|
'Editor.showSourceActions3': showSourceActions,
|
|
@@ -10641,7 +10638,7 @@ const commandMap = {
|
|
|
10641
10638
|
'Editor.unIndent': editorUnindent,
|
|
10642
10639
|
'Editor.updateDebugInfo': updateDebugInfo,
|
|
10643
10640
|
'Editor.updateDiagnostics': updateDiagnostics,
|
|
10644
|
-
'EditorCompletion.close': close$
|
|
10641
|
+
'EditorCompletion.close': close$4,
|
|
10645
10642
|
'EditorCompletion.closeDetails': closeDetails$1,
|
|
10646
10643
|
'EditorCompletion.focusFirst': focusFirst$1,
|
|
10647
10644
|
'EditorCompletion.focusIndex': focusIndex$2,
|
|
@@ -10656,7 +10653,7 @@ const commandMap = {
|
|
|
10656
10653
|
'EditorCompletion.selectCurrent': selectCurrent$1,
|
|
10657
10654
|
'EditorCompletion.selectIndex': selectIndex$1,
|
|
10658
10655
|
'EditorCompletion.toggleDetails': toggleDetails$1,
|
|
10659
|
-
'EditorSourceAction.close': close,
|
|
10656
|
+
'EditorSourceAction.close': close$1,
|
|
10660
10657
|
'EditorSourceAction.closeDetails': closeDetails,
|
|
10661
10658
|
'EditorSourceAction.focusFirst': focusFirst,
|
|
10662
10659
|
'EditorSourceAction.focusIndex': focusIndex,
|
|
@@ -10668,10 +10665,10 @@ const commandMap = {
|
|
|
10668
10665
|
'EditorSourceAction.selectItem': selectItem,
|
|
10669
10666
|
'EditorSourceAction.toggleDetails': toggleDetails,
|
|
10670
10667
|
'EditorRename.accept': accept,
|
|
10671
|
-
'EditorRename.close': close$
|
|
10668
|
+
'EditorRename.close': close$2,
|
|
10672
10669
|
'EditorRename.handleInput': handleInput,
|
|
10673
10670
|
'EditorSourceActions.focusNext': focusNext$1,
|
|
10674
|
-
'FindWidget.close': close$
|
|
10671
|
+
'FindWidget.close': close$3,
|
|
10675
10672
|
'FindWidget.focusCloseButton': focusCloseButton,
|
|
10676
10673
|
'FindWidget.focusFind': focusFind,
|
|
10677
10674
|
'FindWidget.focusNext': focusNext$2,
|
|
@@ -10980,14 +10977,14 @@ const EditorCompletionDetailWidget = {
|
|
|
10980
10977
|
};
|
|
10981
10978
|
|
|
10982
10979
|
const render = widget => {
|
|
10983
|
-
const commands =
|
|
10980
|
+
const commands = renderFull$4(widget.oldState, widget.newState);
|
|
10984
10981
|
const wrappedCommands = [];
|
|
10985
10982
|
const {
|
|
10986
10983
|
uid
|
|
10987
10984
|
} = widget.newState;
|
|
10988
10985
|
for (const command of commands) {
|
|
10989
|
-
if (command[0] === SetDom2) {
|
|
10990
|
-
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);
|
|
10991
10988
|
} else {
|
|
10992
10989
|
wrappedCommands.push(['Viewlet.send', uid, ...command]);
|
|
10993
10990
|
}
|
|
@@ -10995,13 +10992,19 @@ const render = widget => {
|
|
|
10995
10992
|
return wrappedCommands;
|
|
10996
10993
|
};
|
|
10997
10994
|
const add = widget => {
|
|
10998
|
-
return addWidget$1(widget, '
|
|
10995
|
+
return addWidget$1(widget, 'EditorCompletion', render);
|
|
10996
|
+
};
|
|
10997
|
+
const remove = widget => {
|
|
10998
|
+
return [['Viewlet.dispose', widget.newState.uid]];
|
|
10999
10999
|
};
|
|
11000
|
-
const
|
|
11000
|
+
const {
|
|
11001
|
+
close
|
|
11002
|
+
} = createFns(['close'], '', Hover);
|
|
11001
11003
|
|
|
11002
11004
|
const EditorHoverWidget = {
|
|
11003
11005
|
__proto__: null,
|
|
11004
11006
|
add,
|
|
11007
|
+
close,
|
|
11005
11008
|
remove,
|
|
11006
11009
|
render
|
|
11007
11010
|
};
|