@lvce-editor/editor-worker 19.80.2 → 19.81.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/diff-sdk.d.ts +40 -0
- package/dist/diff-sdk.js +2594 -1406
- package/dist/editorWorkerMain.js +2594 -1406
- package/dist/settings.json +10 -2
- package/package.json +1 -1
package/dist/diff-sdk.js
CHANGED
|
@@ -926,7 +926,7 @@ const scanLine = (line, row, stack, ranges, state) => {
|
|
|
926
926
|
state.escaped = false;
|
|
927
927
|
}
|
|
928
928
|
};
|
|
929
|
-
const
|
|
929
|
+
const findRanges = lines => {
|
|
930
930
|
const stack = [];
|
|
931
931
|
const ranges = [];
|
|
932
932
|
const state = {
|
|
@@ -937,7 +937,30 @@ const findRange = (lines, rowIndex) => {
|
|
|
937
937
|
for (let row = 0; row < lines.length; row++) {
|
|
938
938
|
scanLine(lines[row], row, stack, ranges, state);
|
|
939
939
|
}
|
|
940
|
-
return ranges
|
|
940
|
+
return ranges;
|
|
941
|
+
};
|
|
942
|
+
const findInnermostRange = (ranges, rowIndex) => {
|
|
943
|
+
let best;
|
|
944
|
+
for (const range of ranges) {
|
|
945
|
+
if (range.start <= rowIndex && rowIndex <= range.end && (!best || range.end - range.start < best.end - best.start)) {
|
|
946
|
+
best = range;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
return best;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// Nested folds are not supported by the layout, so folding everything keeps only the outermost ranges.
|
|
953
|
+
const getOutermostRanges = ranges => {
|
|
954
|
+
const result = [];
|
|
955
|
+
let coveredUntil = -1;
|
|
956
|
+
for (const range of getSortedRanges(ranges)) {
|
|
957
|
+
if (range.start <= coveredUntil) {
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
result.push(range);
|
|
961
|
+
coveredUntil = range.end;
|
|
962
|
+
}
|
|
963
|
+
return result;
|
|
941
964
|
};
|
|
942
965
|
|
|
943
966
|
function bidiFactory$1() {
|
|
@@ -2481,10 +2504,56 @@ const getHorizontalVisibleDifference = (line, start, deltaX, averageCharWidth, t
|
|
|
2481
2504
|
return getHorizontalDisplayColumn(line, start, tabSize, segments) * charWidth - scrollOffset;
|
|
2482
2505
|
};
|
|
2483
2506
|
|
|
2507
|
+
// Valid JSON strings cannot cross line breaks. Classify each short visible line
|
|
2508
|
+
// independently so jumping to the end of a large file needs no tokenizer state.
|
|
2509
|
+
const maxJsonLineLength = 4096;
|
|
2510
|
+
const jsonTokens = /(?<property>"(?:[^"\\]|\\.)*"(?= *:))|(?<string>"(?:[^"\\]|\\.)*(?<closingQuote>"|$))|(?<number>-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)|(?<constant>true|false|null)|(?<punctuation>[{}\[\],:])| +|./gsu;
|
|
2511
|
+
const jsonTokenClasses = {
|
|
2512
|
+
constant: 'Token LanguageConstant',
|
|
2513
|
+
number: 'Token Numeric',
|
|
2514
|
+
property: 'Token JsonPropertyName',
|
|
2515
|
+
punctuation: 'Token Punctuation',
|
|
2516
|
+
string: 'Token JsonPropertyValueString'
|
|
2517
|
+
};
|
|
2518
|
+
const jsonTokenKinds = Object.keys(jsonTokenClasses);
|
|
2519
|
+
const getVisibleJson = (line, tabSize, firstColumn, lastColumn) => {
|
|
2520
|
+
const tab = ' '.repeat(Math.max(1, tabSize));
|
|
2521
|
+
const text = line.replaceAll('\t', () => tab);
|
|
2522
|
+
const result = [];
|
|
2523
|
+
const append = (start, end, tokenClass) => {
|
|
2524
|
+
const visibleStart = Math.max(start, firstColumn);
|
|
2525
|
+
const visibleEnd = Math.min(end, lastColumn);
|
|
2526
|
+
if (visibleStart < visibleEnd) {
|
|
2527
|
+
result.push(text.slice(visibleStart, visibleEnd), tokenClass);
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
for (const match of text.matchAll(jsonTokens)) {
|
|
2531
|
+
const start = match.index;
|
|
2532
|
+
if (start >= lastColumn) {
|
|
2533
|
+
break;
|
|
2534
|
+
}
|
|
2535
|
+
const end = start + match[0].length;
|
|
2536
|
+
if (end <= firstColumn) {
|
|
2537
|
+
continue;
|
|
2538
|
+
}
|
|
2539
|
+
const kind = jsonTokenKinds.find(key => match.groups?.[key] !== undefined);
|
|
2540
|
+
if (kind === 'property' || kind === 'string') {
|
|
2541
|
+
const contentEnd = kind === 'property' || match.groups?.closingQuote ? end - 1 : end;
|
|
2542
|
+
append(start, start + 1, jsonTokenClasses.punctuation);
|
|
2543
|
+
append(start + 1, contentEnd, jsonTokenClasses[kind]);
|
|
2544
|
+
append(contentEnd, end, jsonTokenClasses.punctuation);
|
|
2545
|
+
} else {
|
|
2546
|
+
append(start, end, kind ? jsonTokenClasses[kind] : 'Token Text');
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
return result;
|
|
2550
|
+
};
|
|
2551
|
+
|
|
2484
2552
|
// Large files have no token cache. Only materialize the text inside the horizontal viewport.
|
|
2485
2553
|
const getLargeFileVisible = editor => {
|
|
2486
2554
|
const {
|
|
2487
2555
|
deltaX,
|
|
2556
|
+
languageId,
|
|
2488
2557
|
lines,
|
|
2489
2558
|
tabSize,
|
|
2490
2559
|
visibleLineIndices,
|
|
@@ -2497,6 +2566,11 @@ const getLargeFileVisible = editor => {
|
|
|
2497
2566
|
const differences = [];
|
|
2498
2567
|
for (const row of visibleLineIndices) {
|
|
2499
2568
|
const line = lines[row];
|
|
2569
|
+
differences.push(firstColumn * charWidth - deltaX);
|
|
2570
|
+
if (languageId === 'json' && line.length <= maxJsonLineLength) {
|
|
2571
|
+
textInfos.push(getVisibleJson(line, tabSize, firstColumn, lastColumn));
|
|
2572
|
+
continue;
|
|
2573
|
+
}
|
|
2500
2574
|
let text = '';
|
|
2501
2575
|
if (line.includes('\t')) {
|
|
2502
2576
|
let column = 0;
|
|
@@ -2513,7 +2587,6 @@ const getLargeFileVisible = editor => {
|
|
|
2513
2587
|
text = line.slice(firstColumn, lastColumn);
|
|
2514
2588
|
}
|
|
2515
2589
|
textInfos.push([text, 'Token Text']);
|
|
2516
|
-
differences.push(firstColumn * charWidth - deltaX);
|
|
2517
2590
|
}
|
|
2518
2591
|
return {
|
|
2519
2592
|
differences,
|
|
@@ -11846,9 +11919,47 @@ const detectLinks = text => {
|
|
|
11846
11919
|
}
|
|
11847
11920
|
return links;
|
|
11848
11921
|
};
|
|
11922
|
+
const isValidPosition = (lines, rowIndex, columnIndex) => rowIndex >= 0 && rowIndex < lines.length && columnIndex >= 0 && columnIndex <= lines[rowIndex].length;
|
|
11923
|
+
|
|
11924
|
+
/**
|
|
11925
|
+
* Converts the provider links stored on the editor into document offset ranges.
|
|
11926
|
+
*/
|
|
11927
|
+
const getProviderLinkRanges = editor => {
|
|
11928
|
+
const {
|
|
11929
|
+
documentLinks,
|
|
11930
|
+
lines
|
|
11931
|
+
} = editor;
|
|
11932
|
+
if (!documentLinks || documentLinks.length === 0) {
|
|
11933
|
+
return [];
|
|
11934
|
+
}
|
|
11935
|
+
const lineOffsets = [];
|
|
11936
|
+
let offset = 0;
|
|
11937
|
+
for (const line of lines) {
|
|
11938
|
+
lineOffsets.push(offset);
|
|
11939
|
+
offset += line.length + 1;
|
|
11940
|
+
}
|
|
11941
|
+
const ranges = [];
|
|
11942
|
+
for (const link of documentLinks) {
|
|
11943
|
+
if (!isValidPosition(lines, link.rowIndex, link.columnIndex) || !isValidPosition(lines, link.endRowIndex, link.endColumnIndex)) {
|
|
11944
|
+
continue;
|
|
11945
|
+
}
|
|
11946
|
+
const startOffset = lineOffsets[link.rowIndex] + link.columnIndex;
|
|
11947
|
+
const endOffset = lineOffsets[link.endRowIndex] + link.endColumnIndex;
|
|
11948
|
+
if (endOffset > startOffset) {
|
|
11949
|
+
ranges.push({
|
|
11950
|
+
length: endOffset - startOffset,
|
|
11951
|
+
link,
|
|
11952
|
+
offset: startOffset
|
|
11953
|
+
});
|
|
11954
|
+
}
|
|
11955
|
+
}
|
|
11956
|
+
return ranges.toSorted((a, b) => a.offset - b.offset);
|
|
11957
|
+
};
|
|
11958
|
+
const overlapsAny = (offset, length, ranges) => ranges.some(range => offset < range.offset + range.length && range.offset < offset + length);
|
|
11849
11959
|
|
|
11850
11960
|
/**
|
|
11851
|
-
* Detects all links in an editor and returns them as decorations
|
|
11961
|
+
* Detects all links in an editor and returns them as decorations.
|
|
11962
|
+
* Links from document link providers take precedence over overlapping regex-detected links.
|
|
11852
11963
|
* @param editor The editor containing lines to scan
|
|
11853
11964
|
* @returns Flat array of decorations in format [offset, length, type, modifiers, ...]
|
|
11854
11965
|
*/
|
|
@@ -11860,19 +11971,50 @@ const detectAllLinksAsDecorations = editor => {
|
|
|
11860
11971
|
const {
|
|
11861
11972
|
lines
|
|
11862
11973
|
} = editor;
|
|
11974
|
+
const providerRanges = getProviderLinkRanges(editor);
|
|
11975
|
+
const ranges = [...providerRanges];
|
|
11863
11976
|
let offset = 0;
|
|
11864
11977
|
for (const line of lines) {
|
|
11865
11978
|
const links = detectLinks(line);
|
|
11866
11979
|
for (const link of links) {
|
|
11867
11980
|
const linkOffset = offset + link.start;
|
|
11868
|
-
|
|
11869
|
-
|
|
11981
|
+
if (providerRanges.length === 0 || !overlapsAny(linkOffset, link.length, providerRanges)) {
|
|
11982
|
+
ranges.push({
|
|
11983
|
+
length: link.length,
|
|
11984
|
+
offset: linkOffset
|
|
11985
|
+
});
|
|
11986
|
+
}
|
|
11870
11987
|
}
|
|
11871
11988
|
offset += line.length + 1; // +1 for newline
|
|
11872
11989
|
}
|
|
11990
|
+
if (providerRanges.length > 0) {
|
|
11991
|
+
ranges.sort((a, b) => a.offset - b.offset);
|
|
11992
|
+
}
|
|
11993
|
+
for (const range of ranges) {
|
|
11994
|
+
// Add link decoration: offset, length, type, modifiers
|
|
11995
|
+
decorations.push(range.offset, range.length, Link, 0);
|
|
11996
|
+
}
|
|
11873
11997
|
return decorations;
|
|
11874
11998
|
};
|
|
11875
11999
|
|
|
12000
|
+
/**
|
|
12001
|
+
* Gets the document link from a document link provider at a given offset
|
|
12002
|
+
* @param editor The editor
|
|
12003
|
+
* @param offset The offset in the document
|
|
12004
|
+
* @returns The provider link at the offset, or undefined
|
|
12005
|
+
*/
|
|
12006
|
+
const getDocumentLinkAtOffset = (editor, offset) => {
|
|
12007
|
+
if (editor.largeFile) {
|
|
12008
|
+
return undefined;
|
|
12009
|
+
}
|
|
12010
|
+
for (const range of getProviderLinkRanges(editor)) {
|
|
12011
|
+
if (offset >= range.offset && offset < range.offset + range.length) {
|
|
12012
|
+
return range.link;
|
|
12013
|
+
}
|
|
12014
|
+
}
|
|
12015
|
+
return undefined;
|
|
12016
|
+
};
|
|
12017
|
+
|
|
11876
12018
|
/**
|
|
11877
12019
|
* Gets the URL text at a given offset in the editor if it's a link
|
|
11878
12020
|
* @param editor The editor
|
|
@@ -11910,512 +12052,319 @@ const getUrlAtOffset = (editor, offset) => {
|
|
|
11910
12052
|
return undefined;
|
|
11911
12053
|
};
|
|
11912
12054
|
|
|
11913
|
-
const
|
|
11914
|
-
const
|
|
11915
|
-
|
|
11916
|
-
const
|
|
11917
|
-
const
|
|
11918
|
-
|
|
12055
|
+
const getSelectionPairs = (selections, i) => {
|
|
12056
|
+
const first = selections[i];
|
|
12057
|
+
const second = selections[i + 1];
|
|
12058
|
+
const third = selections[i + 2];
|
|
12059
|
+
const fourth = selections[i + 3];
|
|
12060
|
+
if (first > third || first === third && second >= fourth) {
|
|
12061
|
+
return [third, fourth, first, second, 1];
|
|
12062
|
+
}
|
|
12063
|
+
return [first, second, third, fourth, 0];
|
|
11919
12064
|
};
|
|
11920
|
-
|
|
11921
|
-
|
|
11922
|
-
|
|
11923
|
-
|
|
11924
|
-
if (
|
|
11925
|
-
|
|
11926
|
-
delivery.supportsDeltas = (await delivery.rpc.invoke('StatusBar.supportsEditorStatusDeltas')) === true;
|
|
11927
|
-
} catch {
|
|
11928
|
-
delivery.supportsDeltas = false;
|
|
11929
|
-
}
|
|
11930
|
-
}
|
|
11931
|
-
if (delivery.disposed) {
|
|
11932
|
-
return;
|
|
11933
|
-
}
|
|
11934
|
-
let update = status;
|
|
11935
|
-
if (delivery.hasBaseline) {
|
|
11936
|
-
if (!delivery.baseline && !status) {
|
|
11937
|
-
continue;
|
|
11938
|
-
}
|
|
11939
|
-
if (delivery.baseline && status) {
|
|
11940
|
-
const delta = getDelta(delivery.baseline, status);
|
|
11941
|
-
if (Object.keys(delta).length === 0) {
|
|
11942
|
-
continue;
|
|
11943
|
-
}
|
|
11944
|
-
if (delivery.supportsDeltas) {
|
|
11945
|
-
update = delta;
|
|
11946
|
-
}
|
|
11947
|
-
}
|
|
11948
|
-
}
|
|
11949
|
-
try {
|
|
11950
|
-
await delivery.rpc.invoke('StatusBar.handleEditorStatusChanged', update);
|
|
11951
|
-
delivery.baseline = status;
|
|
11952
|
-
delivery.hasBaseline = true;
|
|
11953
|
-
} catch (error) {
|
|
11954
|
-
delivery.baseline = undefined;
|
|
11955
|
-
delivery.hasBaseline = false;
|
|
11956
|
-
console.warn('Failed to deliver editor status:', error);
|
|
12065
|
+
|
|
12066
|
+
const getTabCount = string => {
|
|
12067
|
+
let count = 0;
|
|
12068
|
+
for (const element of string) {
|
|
12069
|
+
if (element === Tab) {
|
|
12070
|
+
count++;
|
|
11957
12071
|
}
|
|
11958
12072
|
}
|
|
12073
|
+
return count;
|
|
11959
12074
|
};
|
|
11960
|
-
|
|
11961
|
-
|
|
11962
|
-
|
|
11963
|
-
} finally {
|
|
11964
|
-
delivery.running = undefined;
|
|
11965
|
-
}
|
|
11966
|
-
// An update can arrive after flush returns but before this continuation runs.
|
|
11967
|
-
if (delivery.pending && !delivery.disposed) {
|
|
11968
|
-
await start(delivery);
|
|
11969
|
-
}
|
|
12075
|
+
|
|
12076
|
+
const state$a = {
|
|
12077
|
+
rpc: undefined
|
|
11970
12078
|
};
|
|
11971
|
-
const
|
|
11972
|
-
|
|
11973
|
-
|
|
12079
|
+
const isConnected = () => {
|
|
12080
|
+
const {
|
|
12081
|
+
rpc
|
|
12082
|
+
} = state$a;
|
|
12083
|
+
return rpc !== undefined;
|
|
11974
12084
|
};
|
|
11975
|
-
const
|
|
11976
|
-
|
|
11977
|
-
if (delivery) {
|
|
11978
|
-
delivery.disposed = true;
|
|
11979
|
-
deliveries.delete(rpcId);
|
|
11980
|
-
}
|
|
12085
|
+
const set$5 = value => {
|
|
12086
|
+
state$a.rpc = value;
|
|
11981
12087
|
};
|
|
11982
|
-
const
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
11986
|
-
|
|
11987
|
-
|
|
11988
|
-
disposed: false,
|
|
11989
|
-
hasBaseline: false,
|
|
11990
|
-
pending: false,
|
|
11991
|
-
pendingStatus: undefined,
|
|
11992
|
-
rpc,
|
|
11993
|
-
running: undefined,
|
|
11994
|
-
supportsDeltas: undefined
|
|
11995
|
-
};
|
|
11996
|
-
deliveries.set(rpcId, delivery);
|
|
12088
|
+
const invoke$9 = (method, ...params) => {
|
|
12089
|
+
const {
|
|
12090
|
+
rpc
|
|
12091
|
+
} = state$a;
|
|
12092
|
+
if (!rpc) {
|
|
12093
|
+
throw new Error('Editor renderer process is not connected');
|
|
11997
12094
|
}
|
|
11998
|
-
|
|
11999
|
-
delivery.pending = true;
|
|
12000
|
-
return delivery.running || start(delivery);
|
|
12095
|
+
return rpc.invoke(method, ...params);
|
|
12001
12096
|
};
|
|
12002
12097
|
|
|
12003
|
-
const
|
|
12004
|
-
|
|
12005
|
-
|
|
12006
|
-
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
const
|
|
12011
|
-
|
|
12012
|
-
|
|
12013
|
-
|
|
12014
|
-
|
|
12015
|
-
|
|
12016
|
-
|
|
12017
|
-
|
|
12018
|
-
|
|
12019
|
-
|
|
12020
|
-
|
|
12098
|
+
const joiningScript = /\p{Script=Arabic}/u;
|
|
12099
|
+
const createMeasure = (fontWeight, fontSize, fontFamily, letterSpacing, tabSize, charWidth) => {
|
|
12100
|
+
// Owned by this geometry operation, so edits/font changes cannot reuse stale
|
|
12101
|
+
// shaping information and closing editors leaves no persistent text cache.
|
|
12102
|
+
const cache = new Map();
|
|
12103
|
+
const normalize = text => text.replaceAll('\t', () => ' '.repeat(tabSize));
|
|
12104
|
+
return (text, context) => {
|
|
12105
|
+
const key = JSON.stringify([text, context]);
|
|
12106
|
+
let result = cache.get(key);
|
|
12107
|
+
if (!result) {
|
|
12108
|
+
if (context && context.offset > 0 && context.offset < context.text.length && joiningScript.test(context.text)) {
|
|
12109
|
+
const normalizedOffset = normalize(context.text.slice(0, context.offset)).length;
|
|
12110
|
+
result = invoke$9('MeasureBidi.measurePrefix', normalize(context.text), normalizedOffset, fontWeight, fontSize, fontFamily, letterSpacing, context.rtl ? 'rtl' : 'ltr');
|
|
12111
|
+
} else {
|
|
12112
|
+
// The measurement worker's monospace shortcut assumes every glyph has
|
|
12113
|
+
// the ASCII width; RTL fonts and fallback glyphs need real measurement.
|
|
12114
|
+
result = measureTextWidth(normalize(text), fontWeight, fontSize, fontFamily, letterSpacing, false, charWidth);
|
|
12115
|
+
}
|
|
12116
|
+
cache.set(key, result);
|
|
12117
|
+
}
|
|
12118
|
+
return result;
|
|
12119
|
+
};
|
|
12021
12120
|
};
|
|
12022
12121
|
|
|
12023
|
-
|
|
12024
|
-
|
|
12025
|
-
|
|
12026
|
-
* @param rpcId - The RPC ID of the listener
|
|
12027
|
-
*/
|
|
12028
|
-
const unregisterListener$1 = (listenerType, rpcId) => {
|
|
12029
|
-
number(listenerType);
|
|
12030
|
-
number(rpcId);
|
|
12031
|
-
if (listenerType === EditorSelection$1) {
|
|
12032
|
-
dispose$5(rpcId);
|
|
12122
|
+
const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0, measuredLineWidth, rtl = false) => {
|
|
12123
|
+
if (!line) {
|
|
12124
|
+
return 0;
|
|
12033
12125
|
}
|
|
12034
|
-
|
|
12035
|
-
|
|
12036
|
-
|
|
12037
|
-
|
|
12038
|
-
|
|
12126
|
+
string(line);
|
|
12127
|
+
number(tabSize);
|
|
12128
|
+
number(halfCursorWidth);
|
|
12129
|
+
number(width);
|
|
12130
|
+
boolean(isMonospaceFont);
|
|
12131
|
+
number(averageCharWidth);
|
|
12132
|
+
number(difference);
|
|
12133
|
+
if (isBidi(line, rtl)) {
|
|
12134
|
+
const measure = createMeasure(fontWeight, fontSize, fontFamily, letterSpacing, tabSize, averageCharWidth);
|
|
12135
|
+
const x = await getPosition(line, column, measure);
|
|
12136
|
+
return Math.min(width, x - halfCursorWidth + difference);
|
|
12137
|
+
}
|
|
12138
|
+
if (column === 0) {
|
|
12139
|
+
return difference === 0 ? 0 : Math.min(width, difference);
|
|
12039
12140
|
}
|
|
12141
|
+
// TODO support non-monospace font, emoji, tab character, zero width characters
|
|
12142
|
+
const normalize = shouldNormalizeText(line);
|
|
12143
|
+
const normalizedLine = normalizeText(line, normalize, tabSize);
|
|
12144
|
+
const tabCount = getTabCount(line.slice(0, column));
|
|
12145
|
+
const partialText = normalizedLine.slice(0, column + tabCount * (tabSize - 1));
|
|
12146
|
+
const textWidth = column === line.length && measuredLineWidth !== undefined ? measuredLineWidth : await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
|
|
12147
|
+
return Math.min(width, textWidth - halfCursorWidth + difference);
|
|
12040
12148
|
};
|
|
12041
12149
|
|
|
12042
|
-
|
|
12043
|
-
|
|
12044
|
-
* @param listenerType - The type of event
|
|
12045
|
-
* @returns Array of RPC IDs
|
|
12046
|
-
*/
|
|
12047
|
-
const getListeners = listenerType => {
|
|
12048
|
-
number(listenerType);
|
|
12049
|
-
return state$a[listenerType] || [];
|
|
12150
|
+
const px = value => {
|
|
12151
|
+
return `${value}px`;
|
|
12050
12152
|
};
|
|
12051
12153
|
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12068
|
-
|
|
12069
|
-
|
|
12070
|
-
|
|
12071
|
-
|
|
12072
|
-
// to prevent one failing listener from affecting others
|
|
12073
|
-
console.warn(`Failed to notify listener ${rpcId}:`, error);
|
|
12074
|
-
}
|
|
12075
|
-
});
|
|
12076
|
-
await Promise.all(notifications);
|
|
12077
|
-
};
|
|
12078
|
-
|
|
12079
|
-
const width = 120;
|
|
12080
|
-
const characterWidth = 0.75;
|
|
12081
|
-
const lineHeight = 2;
|
|
12082
|
-
const minimumViewportHeight = 20;
|
|
12083
|
-
|
|
12084
|
-
const resize$2 = (state, dimensions, columnWidth = state.columnWidth) => {
|
|
12085
|
-
const x = dimensions.x ?? state.x;
|
|
12086
|
-
const y = dimensions.y ?? state.y;
|
|
12087
|
-
const outerWidth = dimensions.width ?? state.outerWidth ?? state.width;
|
|
12088
|
-
const outerHeight = dimensions.height ?? state.outerHeight ?? state.height;
|
|
12089
|
-
const width$1 = Math.max(outerWidth - (state.minimapEnabled ? width : 0), 0);
|
|
12090
|
-
const height = Math.max(outerHeight - (state.breadcrumbsEnabled ? 22 : 0), 0);
|
|
12091
|
-
const numberOfVisibleLines = Math.floor(height / state.itemHeight);
|
|
12092
|
-
if (!('foldingRanges' in state)) {
|
|
12093
|
-
const total = state.lines.length;
|
|
12094
|
-
const finalY = Math.max(total - numberOfVisibleLines, 0);
|
|
12095
|
-
const finalDeltaY = Math.max(total * state.itemHeight - height, 0);
|
|
12096
|
-
const deltaY = Math.min(state.deltaY, finalDeltaY);
|
|
12097
|
-
const minLineY = Math.floor(deltaY / state.itemHeight);
|
|
12098
|
-
const maxLineY = Math.min(minLineY + getRenderedLineCount(height, state.itemHeight, deltaY), total);
|
|
12099
|
-
const contentHeight = total * state.rowHeight;
|
|
12100
|
-
const scrollBarHeight = getScrollBarSize(height, contentHeight, state.minimumSliderSize);
|
|
12101
|
-
return {
|
|
12102
|
-
...state,
|
|
12103
|
-
columnWidth,
|
|
12104
|
-
deltaY,
|
|
12105
|
-
finalDeltaY,
|
|
12106
|
-
finalY,
|
|
12107
|
-
height,
|
|
12108
|
-
maxLineY,
|
|
12109
|
-
minLineY,
|
|
12110
|
-
numberOfVisibleLines,
|
|
12111
|
-
...('outerWidth' in state && {
|
|
12112
|
-
outerWidth
|
|
12113
|
-
}),
|
|
12114
|
-
...('outerHeight' in state && {
|
|
12115
|
-
outerHeight
|
|
12116
|
-
}),
|
|
12117
|
-
scrollBarHeight,
|
|
12118
|
-
width: width$1,
|
|
12119
|
-
x,
|
|
12120
|
-
y
|
|
12121
|
-
};
|
|
12154
|
+
// Owned by the editor lifecycle, with only the current document's distinct lines retained.
|
|
12155
|
+
const caches = new WeakMap();
|
|
12156
|
+
const getFontKey = ({
|
|
12157
|
+
charWidth,
|
|
12158
|
+
fontFamily,
|
|
12159
|
+
fontSize,
|
|
12160
|
+
fontWeight,
|
|
12161
|
+
isMonospaceFont,
|
|
12162
|
+
letterSpacing,
|
|
12163
|
+
rtl,
|
|
12164
|
+
tabSize
|
|
12165
|
+
}) => JSON.stringify([charWidth, fontFamily, fontSize, fontWeight, isMonospaceFont, letterSpacing, rtl, tabSize]);
|
|
12166
|
+
const getCachedLineWidth = (state, line) => {
|
|
12167
|
+
const {
|
|
12168
|
+
largeFile,
|
|
12169
|
+
lifecycle,
|
|
12170
|
+
lines
|
|
12171
|
+
} = state;
|
|
12172
|
+
if (largeFile || lifecycle?.disposed) {
|
|
12173
|
+
return undefined;
|
|
12122
12174
|
}
|
|
12123
|
-
const
|
|
12124
|
-
|
|
12125
|
-
columnWidth,
|
|
12126
|
-
height,
|
|
12127
|
-
numberOfVisibleLines,
|
|
12128
|
-
...('outerWidth' in state && {
|
|
12129
|
-
outerWidth
|
|
12130
|
-
}),
|
|
12131
|
-
...('outerHeight' in state && {
|
|
12132
|
-
outerHeight
|
|
12133
|
-
}),
|
|
12134
|
-
width: width$1,
|
|
12135
|
-
x,
|
|
12136
|
-
y
|
|
12137
|
-
};
|
|
12138
|
-
return updateLayout(resized, state.foldingRanges);
|
|
12175
|
+
const cache = caches.get(lifecycle || lines);
|
|
12176
|
+
return cache?.font === getFontKey(state) ? cache.widths.get(line) : undefined;
|
|
12139
12177
|
};
|
|
12140
|
-
|
|
12141
|
-
const
|
|
12142
|
-
|
|
12143
|
-
|
|
12178
|
+
const updateHorizontalLayout = async state => {
|
|
12179
|
+
const {
|
|
12180
|
+
breakPoints = [],
|
|
12181
|
+
deltaX,
|
|
12182
|
+
gutterDecorations = [],
|
|
12183
|
+
largeFile,
|
|
12184
|
+
lifecycle,
|
|
12185
|
+
lightBulbRowIndex = -1,
|
|
12186
|
+
lineNumbers
|
|
12187
|
+
} = state;
|
|
12188
|
+
if (largeFile || lifecycle?.disposed) {
|
|
12189
|
+
return state;
|
|
12144
12190
|
}
|
|
12145
|
-
|
|
12146
|
-
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12191
|
+
const {
|
|
12192
|
+
charWidth,
|
|
12193
|
+
fontFamily,
|
|
12194
|
+
fontSize,
|
|
12195
|
+
fontWeight,
|
|
12196
|
+
isMonospaceFont,
|
|
12197
|
+
letterSpacing,
|
|
12198
|
+
lines,
|
|
12199
|
+
rtl,
|
|
12200
|
+
tabSize,
|
|
12201
|
+
width
|
|
12202
|
+
} = state;
|
|
12203
|
+
const font = getFontKey(state);
|
|
12204
|
+
const owner = lifecycle || lines;
|
|
12205
|
+
const previous = caches.get(owner);
|
|
12206
|
+
const previousWidths = previous?.font === font ? previous.widths : undefined;
|
|
12207
|
+
const widths = new Map();
|
|
12208
|
+
const textsToMeasure = new Set();
|
|
12209
|
+
const textByLine = new Map();
|
|
12210
|
+
for (const line of lines) {
|
|
12211
|
+
const measured = previousWidths?.get(line);
|
|
12212
|
+
if (measured !== undefined) {
|
|
12213
|
+
widths.set(line, measured);
|
|
12214
|
+
continue;
|
|
12215
|
+
}
|
|
12216
|
+
const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
|
|
12217
|
+
textByLine.set(line, text);
|
|
12218
|
+
textsToMeasure.add(text);
|
|
12153
12219
|
}
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
const
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
|
|
12162
|
-
}
|
|
12220
|
+
const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
|
|
12221
|
+
const gutterText = String(lines.length);
|
|
12222
|
+
if (showGutter && !widths.has(gutterText)) {
|
|
12223
|
+
const measured = previousWidths?.get(gutterText);
|
|
12224
|
+
if (measured === undefined) {
|
|
12225
|
+
textsToMeasure.add(gutterText);
|
|
12226
|
+
} else {
|
|
12227
|
+
widths.set(gutterText, measured);
|
|
12228
|
+
}
|
|
12163
12229
|
}
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
const endComparison = comparePositions(position, end);
|
|
12172
|
-
if (startComparison < 0 || startComparison === 0 && affinity === 'left') {
|
|
12173
|
-
return position;
|
|
12230
|
+
const texts = [...textsToMeasure];
|
|
12231
|
+
const regularTexts = texts.filter(text => !isBidi(text, rtl));
|
|
12232
|
+
const bidiTexts = texts.filter(text => isBidi(text, rtl));
|
|
12233
|
+
const [regularWidths, bidiWidths] = await Promise.all([regularTexts.length > 0 ? measureTextWidths(regularTexts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) : [], bidiTexts.length > 0 ? measureTextWidths(bidiTexts, fontWeight, fontSize, fontFamily, letterSpacing, false, charWidth) : []]);
|
|
12234
|
+
const measuredByText = new Map([...regularTexts.map((text, index) => [text, regularWidths[index]]), ...bidiTexts.map((text, index) => [text, bidiWidths[index]])]);
|
|
12235
|
+
for (const [line, text] of textByLine) {
|
|
12236
|
+
widths.set(line, measuredByText.get(text));
|
|
12174
12237
|
}
|
|
12175
|
-
if (
|
|
12176
|
-
|
|
12238
|
+
if (showGutter && !widths.has(gutterText)) {
|
|
12239
|
+
widths.set(gutterText, measuredByText.get(gutterText));
|
|
12177
12240
|
}
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
columnIndex: insertedEnd.columnIndex + position.columnIndex - end.columnIndex,
|
|
12182
|
-
rowIndex: insertedEnd.rowIndex
|
|
12183
|
-
};
|
|
12241
|
+
let longestLineWidth = 0;
|
|
12242
|
+
for (const line of lines) {
|
|
12243
|
+
longestLineWidth = Math.max(longestLineWidth, widths.get(line));
|
|
12184
12244
|
}
|
|
12245
|
+
if (lifecycle?.disposed) {
|
|
12246
|
+
return state;
|
|
12247
|
+
}
|
|
12248
|
+
const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
|
|
12249
|
+
caches.set(owner, {
|
|
12250
|
+
font,
|
|
12251
|
+
widths
|
|
12252
|
+
});
|
|
12185
12253
|
return {
|
|
12186
|
-
|
|
12187
|
-
|
|
12254
|
+
...state,
|
|
12255
|
+
deltaX: clamp(deltaX, 0, Math.max(0, longestLineWidth - Math.max(0, width - gutterWidth))),
|
|
12256
|
+
gutterWidth,
|
|
12257
|
+
longestLineWidth
|
|
12188
12258
|
};
|
|
12189
12259
|
};
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12260
|
+
|
|
12261
|
+
const fromRange = (startRowIndex, startColumnIndex, endRowIndex, endColumnIndex) => {
|
|
12262
|
+
return new Uint32Array([startRowIndex, startColumnIndex, endRowIndex, endColumnIndex]);
|
|
12263
|
+
};
|
|
12264
|
+
const alloc = length => {
|
|
12265
|
+
return new Uint32Array(length);
|
|
12266
|
+
};
|
|
12267
|
+
const clone = selections => {
|
|
12268
|
+
return alloc(selections.length);
|
|
12269
|
+
};
|
|
12270
|
+
const map = (selections, fn) => {
|
|
12271
|
+
const newSelections = clone(selections);
|
|
12272
|
+
for (let i = 0; i < newSelections.length; i += 4) {
|
|
12273
|
+
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
|
|
12274
|
+
fn(newSelections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn);
|
|
12193
12275
|
}
|
|
12194
|
-
|
|
12195
|
-
columnIndex: diagnostic.columnIndex,
|
|
12196
|
-
rowIndex: diagnostic.rowIndex
|
|
12197
|
-
};
|
|
12198
|
-
const diagnosticEnd = {
|
|
12199
|
-
columnIndex: diagnostic.endColumnIndex,
|
|
12200
|
-
rowIndex: diagnostic.endRowIndex
|
|
12201
|
-
};
|
|
12202
|
-
return comparePositions(start, diagnosticEnd) < 0 && comparePositions(end, diagnosticStart) > 0;
|
|
12276
|
+
return newSelections;
|
|
12203
12277
|
};
|
|
12204
|
-
const
|
|
12205
|
-
let
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
const
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
};
|
|
12212
|
-
const end = {
|
|
12213
|
-
columnIndex: change.end.columnIndex,
|
|
12214
|
-
rowIndex: change.end.rowIndex + linesDelta
|
|
12215
|
-
};
|
|
12216
|
-
if (overlapsDeletedText(transformed, start, end)) {
|
|
12217
|
-
return undefined;
|
|
12218
|
-
}
|
|
12219
|
-
const inserted = change.inserted.length > 0 ? change.inserted : [''];
|
|
12220
|
-
const diagnosticStart = transformPosition({
|
|
12221
|
-
columnIndex: transformed.columnIndex,
|
|
12222
|
-
rowIndex: transformed.rowIndex
|
|
12223
|
-
}, start, end, inserted, 'right');
|
|
12224
|
-
const diagnosticEnd = transformPosition({
|
|
12225
|
-
columnIndex: transformed.endColumnIndex,
|
|
12226
|
-
rowIndex: transformed.endRowIndex
|
|
12227
|
-
}, start, end, inserted, 'left');
|
|
12228
|
-
if (comparePositions(diagnosticStart, diagnosticEnd) > 0) {
|
|
12229
|
-
return undefined;
|
|
12230
|
-
}
|
|
12231
|
-
transformed = {
|
|
12232
|
-
...transformed,
|
|
12233
|
-
columnIndex: diagnosticStart.columnIndex,
|
|
12234
|
-
endColumnIndex: diagnosticEnd.columnIndex,
|
|
12235
|
-
endRowIndex: diagnosticEnd.rowIndex,
|
|
12236
|
-
rowIndex: diagnosticStart.rowIndex
|
|
12237
|
-
};
|
|
12238
|
-
linesDelta += inserted.length - change.deleted.length;
|
|
12239
|
-
}
|
|
12240
|
-
return transformed;
|
|
12241
|
-
};
|
|
12242
|
-
const transformDiagnostics = (diagnostics, changes) => {
|
|
12243
|
-
if (changes.length === 0 || diagnostics.length === 0) {
|
|
12244
|
-
return diagnostics;
|
|
12245
|
-
}
|
|
12246
|
-
return diagnostics.flatMap(diagnostic => {
|
|
12247
|
-
const transformed = transformDiagnostic(diagnostic, changes);
|
|
12248
|
-
return transformed ? [transformed] : [];
|
|
12249
|
-
});
|
|
12250
|
-
};
|
|
12251
|
-
|
|
12252
|
-
const queues$1 = {};
|
|
12253
|
-
const enqueue = async (uid, callback) => {
|
|
12254
|
-
const instance = get$a(uid);
|
|
12255
|
-
if (!instance) {
|
|
12256
|
-
return undefined;
|
|
12257
|
-
}
|
|
12258
|
-
const {
|
|
12259
|
-
applicationId,
|
|
12260
|
-
uri
|
|
12261
|
-
} = instance.newState;
|
|
12262
|
-
const key = JSON.stringify([applicationId ?? null, uri || uid]);
|
|
12263
|
-
const previous = queues$1[key];
|
|
12264
|
-
const {
|
|
12265
|
-
promise,
|
|
12266
|
-
resolve
|
|
12267
|
-
} = Promise.withResolvers();
|
|
12268
|
-
queues$1[key] = promise;
|
|
12269
|
-
if (previous) {
|
|
12270
|
-
await previous;
|
|
12271
|
-
}
|
|
12272
|
-
try {
|
|
12273
|
-
return await callback();
|
|
12274
|
-
} finally {
|
|
12275
|
-
resolve();
|
|
12276
|
-
if (queues$1[key] === promise) {
|
|
12277
|
-
delete queues$1[key];
|
|
12278
|
-
}
|
|
12279
|
-
}
|
|
12280
|
-
};
|
|
12281
|
-
|
|
12282
|
-
const logError = async (error, prefix) => {
|
|
12283
|
-
const prettyError = await ErrorWorker.invoke('Errors.prepare', error);
|
|
12284
|
-
await ErrorWorker.invoke('Errors.print', prettyError, prefix);
|
|
12285
|
-
};
|
|
12286
|
-
const logFallback = (error, prefix) => {
|
|
12287
|
-
if (prefix) {
|
|
12288
|
-
console.error(prefix, error);
|
|
12289
|
-
return;
|
|
12290
|
-
}
|
|
12291
|
-
console.error(error);
|
|
12292
|
-
};
|
|
12293
|
-
const handleError$1 = async (error, prefix = '') => {
|
|
12294
|
-
try {
|
|
12295
|
-
await logError(error, prefix);
|
|
12296
|
-
} catch (otherError) {
|
|
12297
|
-
console.warn('ErrorHandling error', otherError);
|
|
12298
|
-
logFallback(error, prefix);
|
|
12278
|
+
const forEach = (selections, fn) => {
|
|
12279
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
12280
|
+
const selectionStartRow = selections[i];
|
|
12281
|
+
const selectionStartColumn = selections[i + 1];
|
|
12282
|
+
const selectionEndRow = selections[i + 2];
|
|
12283
|
+
const selectionEndColumn = selections[i + 3];
|
|
12284
|
+
fn(selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn);
|
|
12299
12285
|
}
|
|
12300
12286
|
};
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
};
|
|
12305
|
-
const invokeAndTransfer = async (applicationId, method, ...args) => {
|
|
12306
|
-
return applicationId === undefined ? ExtensionManagementWorker.invokeAndTransfer(method, ...args) : ExtensionManagementWorker.invokeAndTransfer('Extensions.invokeForApplication', applicationId, method, ...args);
|
|
12307
|
-
};
|
|
12308
|
-
|
|
12309
|
-
const getTextDocument$3 = editor => {
|
|
12310
|
-
return {
|
|
12311
|
-
documentId: editor.id || editor.uid,
|
|
12312
|
-
languageId: editor.languageId,
|
|
12313
|
-
text: getText$1(editor),
|
|
12314
|
-
uri: editor.uri
|
|
12315
|
-
};
|
|
12316
|
-
};
|
|
12317
|
-
const streamIsolatedDiagnosticProvider = async (editor, resultPort) => {
|
|
12318
|
-
const textDocument = getTextDocument$3(editor);
|
|
12319
|
-
return invokeAndTransfer(editor.applicationId, 'Extensions.streamDiagnosticProvider', textDocument, resultPort);
|
|
12287
|
+
const moveRangeToPosition$1 = (selections, i, rowIndex, columnIndex) => {
|
|
12288
|
+
selections[i] = selections[i + 2] = rowIndex;
|
|
12289
|
+
selections[i + 1] = selections[i + 3] = columnIndex;
|
|
12320
12290
|
};
|
|
12321
|
-
const
|
|
12322
|
-
return
|
|
12291
|
+
const isEmpty$1 = (selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
|
|
12292
|
+
return selectionStartRow === selectionEndRow && selectionStartColumn === selectionEndColumn;
|
|
12323
12293
|
};
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
return diagnostic.type;
|
|
12294
|
+
const isSelectionSingleLine = (selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
|
|
12295
|
+
return selectionStartRow === selectionEndRow;
|
|
12327
12296
|
};
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12297
|
+
const isEverySelection = (selections, fn) => {
|
|
12298
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
12299
|
+
const selectionStartRow = selections[i];
|
|
12300
|
+
const selectionStartColumn = selections[i + 1];
|
|
12301
|
+
const selectionEndRow = selections[i + 2];
|
|
12302
|
+
const selectionEndColumn = selections[i + 3];
|
|
12303
|
+
if (!fn(selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn)) {
|
|
12304
|
+
return false;
|
|
12334
12305
|
}
|
|
12335
12306
|
}
|
|
12336
|
-
return
|
|
12337
|
-
};
|
|
12338
|
-
|
|
12339
|
-
const state$9 = {
|
|
12340
|
-
rpc: undefined
|
|
12307
|
+
return true;
|
|
12341
12308
|
};
|
|
12342
|
-
const
|
|
12343
|
-
|
|
12344
|
-
rpc
|
|
12345
|
-
} = state$9;
|
|
12346
|
-
return rpc !== undefined;
|
|
12309
|
+
const isEverySelectionEmpty = selections => {
|
|
12310
|
+
return isEverySelection(selections, isEmpty$1);
|
|
12347
12311
|
};
|
|
12348
|
-
const
|
|
12349
|
-
|
|
12312
|
+
const isEverySelectionSingleLine = selections => {
|
|
12313
|
+
return isEverySelection(selections, isSelectionSingleLine);
|
|
12350
12314
|
};
|
|
12351
|
-
const
|
|
12352
|
-
const
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12356
|
-
|
|
12315
|
+
const from = (array, getSelection) => {
|
|
12316
|
+
const newSelections = alloc(array.length * 4);
|
|
12317
|
+
let i = 0;
|
|
12318
|
+
for (const item of array) {
|
|
12319
|
+
const {
|
|
12320
|
+
end,
|
|
12321
|
+
start
|
|
12322
|
+
} = getSelection(item);
|
|
12323
|
+
newSelections[i++] = start.rowIndex;
|
|
12324
|
+
newSelections[i++] = start.columnIndex;
|
|
12325
|
+
newSelections[i++] = end.rowIndex;
|
|
12326
|
+
newSelections[i++] = end.columnIndex;
|
|
12357
12327
|
}
|
|
12358
|
-
return
|
|
12328
|
+
return newSelections;
|
|
12359
12329
|
};
|
|
12360
12330
|
|
|
12361
|
-
|
|
12362
|
-
const createMeasure = (fontWeight, fontSize, fontFamily, letterSpacing, tabSize, charWidth) => {
|
|
12363
|
-
// Owned by this geometry operation, so edits/font changes cannot reuse stale
|
|
12364
|
-
// shaping information and closing editors leaves no persistent text cache.
|
|
12365
|
-
const cache = new Map();
|
|
12366
|
-
const normalize = text => text.replaceAll('\t', () => ' '.repeat(tabSize));
|
|
12367
|
-
return (text, context) => {
|
|
12368
|
-
const key = JSON.stringify([text, context]);
|
|
12369
|
-
let result = cache.get(key);
|
|
12370
|
-
if (!result) {
|
|
12371
|
-
if (context && context.offset > 0 && context.offset < context.text.length && joiningScript.test(context.text)) {
|
|
12372
|
-
const normalizedOffset = normalize(context.text.slice(0, context.offset)).length;
|
|
12373
|
-
result = invoke$8('MeasureBidi.measurePrefix', normalize(context.text), normalizedOffset, fontWeight, fontSize, fontFamily, letterSpacing, context.rtl ? 'rtl' : 'ltr');
|
|
12374
|
-
} else {
|
|
12375
|
-
// The measurement worker's monospace shortcut assumes every glyph has
|
|
12376
|
-
// the ASCII width; RTL fonts and fallback glyphs need real measurement.
|
|
12377
|
-
result = measureTextWidth(normalize(text), fontWeight, fontSize, fontFamily, letterSpacing, false, charWidth);
|
|
12378
|
-
}
|
|
12379
|
-
cache.set(key, result);
|
|
12380
|
-
}
|
|
12381
|
-
return result;
|
|
12382
|
-
};
|
|
12383
|
-
};
|
|
12331
|
+
// TODO maybe only accept sorted selection edits in the first place
|
|
12384
12332
|
|
|
12385
|
-
const
|
|
12386
|
-
|
|
12387
|
-
|
|
12333
|
+
const emptyCursors = [];
|
|
12334
|
+
const getCursorArray = (visibleCursors, isFocused) => {
|
|
12335
|
+
if (!isFocused) {
|
|
12336
|
+
return emptyCursors;
|
|
12388
12337
|
}
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
|
|
12394
|
-
number(averageCharWidth);
|
|
12395
|
-
number(difference);
|
|
12396
|
-
if (isBidi(line, rtl)) {
|
|
12397
|
-
const measure = createMeasure(fontWeight, fontSize, fontFamily, letterSpacing, tabSize, averageCharWidth);
|
|
12398
|
-
const x = await getPosition(line, column, measure);
|
|
12399
|
-
return Math.min(width, x - halfCursorWidth + difference);
|
|
12338
|
+
const cursorArray = [];
|
|
12339
|
+
for (let i = 0; i < visibleCursors.length; i += 2) {
|
|
12340
|
+
const x = visibleCursors[i];
|
|
12341
|
+
const y = visibleCursors[i + 1];
|
|
12342
|
+
cursorArray.push(`${px(x)} ${px(y)}`);
|
|
12400
12343
|
}
|
|
12401
|
-
|
|
12402
|
-
|
|
12344
|
+
return cursorArray;
|
|
12345
|
+
};
|
|
12346
|
+
const getSelectionArray = visibleSelections => {
|
|
12347
|
+
const selectionsArray = [];
|
|
12348
|
+
for (let i = 0; i < visibleSelections.length; i += 4) {
|
|
12349
|
+
const x = visibleSelections[i];
|
|
12350
|
+
const y = visibleSelections[i + 1];
|
|
12351
|
+
const width = visibleSelections[i + 2];
|
|
12352
|
+
const height = visibleSelections[i + 3];
|
|
12353
|
+
selectionsArray.push(px(x), px(y), px(width), px(height));
|
|
12403
12354
|
}
|
|
12404
|
-
|
|
12405
|
-
const normalize = shouldNormalizeText(line);
|
|
12406
|
-
const normalizedLine = normalizeText(line, normalize, tabSize);
|
|
12407
|
-
const tabCount = getTabCount(line.slice(0, column));
|
|
12408
|
-
const partialText = normalizedLine.slice(0, column + tabCount * (tabSize - 1));
|
|
12409
|
-
const textWidth = column === line.length && measuredLineWidth !== undefined ? measuredLineWidth : await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
|
|
12410
|
-
return Math.min(width, textWidth - halfCursorWidth + difference);
|
|
12355
|
+
return selectionsArray;
|
|
12411
12356
|
};
|
|
12357
|
+
const getVisible = async editor => {
|
|
12358
|
+
const visibleCursors = [];
|
|
12359
|
+
const visibleSelections = [];
|
|
12360
|
+
// // TODO binary search
|
|
12412
12361
|
|
|
12413
|
-
const getVisibleDiagnostics = async (editor, diagnostics) => {
|
|
12414
|
-
const visibleDiagnostics = [];
|
|
12415
12362
|
const {
|
|
12416
12363
|
charWidth,
|
|
12417
|
-
|
|
12364
|
+
cursorWidth,
|
|
12418
12365
|
deltaY,
|
|
12366
|
+
focused,
|
|
12367
|
+
foldingRanges = [],
|
|
12419
12368
|
fontFamily,
|
|
12420
12369
|
fontSize,
|
|
12421
12370
|
fontWeight,
|
|
@@ -12423,596 +12372,976 @@ const getVisibleDiagnostics = async (editor, diagnostics) => {
|
|
|
12423
12372
|
itemHeight,
|
|
12424
12373
|
letterSpacing,
|
|
12425
12374
|
lines,
|
|
12375
|
+
maxLineY,
|
|
12376
|
+
minLineY,
|
|
12426
12377
|
rowHeight,
|
|
12378
|
+
selections,
|
|
12427
12379
|
tabSize,
|
|
12428
|
-
viewLineIndices
|
|
12380
|
+
viewLineIndices,
|
|
12381
|
+
visibleLineIndices,
|
|
12382
|
+
visibleViewLineIndices,
|
|
12383
|
+
width
|
|
12429
12384
|
} = editor;
|
|
12430
|
-
|
|
12431
|
-
|
|
12432
|
-
const {
|
|
12433
|
-
columnIndex,
|
|
12434
|
-
endColumnIndex,
|
|
12435
|
-
rowIndex
|
|
12436
|
-
} = diagnostic;
|
|
12437
|
-
const endLineDifference = -deltaX;
|
|
12438
|
-
const halfCursorWidth = 0;
|
|
12439
|
-
const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
|
|
12440
|
-
const endX = await getX(lines[rowIndex], endColumnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
|
|
12441
|
-
const diagnosticWidth = Math.max(charWidth, endX - x);
|
|
12442
|
-
const visualRow = viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, viewLineIndices) : rowIndex;
|
|
12443
|
-
const y = (visualRow - startVisualRow) * rowHeight;
|
|
12444
|
-
visibleDiagnostics.push({
|
|
12445
|
-
height: rowHeight,
|
|
12446
|
-
type: getDiagnosticType(diagnostic),
|
|
12447
|
-
width: diagnosticWidth,
|
|
12448
|
-
x,
|
|
12449
|
-
y
|
|
12450
|
-
});
|
|
12385
|
+
if (editor.rtl && actualSelectionHasBidi(editor)) {
|
|
12386
|
+
return getBidiVisible(editor);
|
|
12451
12387
|
}
|
|
12452
|
-
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
const
|
|
12462
|
-
|
|
12463
|
-
const
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12388
|
+
const averageCharWidth = charWidth;
|
|
12389
|
+
const halfCursorWidth = cursorWidth / 2;
|
|
12390
|
+
const actualVisibleLineIndices = visibleLineIndices || Array.from({
|
|
12391
|
+
length: maxLineY - minLineY
|
|
12392
|
+
}, (_, index) => minLineY + index);
|
|
12393
|
+
const getVisualRow = rowIndex => viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, viewLineIndices) : getVisualRowForDocumentRow(rowIndex, foldingRanges);
|
|
12394
|
+
const visibleStartVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : getVisualRow(minLineY);
|
|
12395
|
+
const visibleEndVisualRow = visibleStartVisualRow + (visibleViewLineIndices?.length || actualVisibleLineIndices.length);
|
|
12396
|
+
const getRelativeRow = rowIndex => getVisualRow(rowIndex) - visibleStartVisualRow;
|
|
12397
|
+
const horizontalOffset = -(editor.deltaX ?? 0);
|
|
12398
|
+
const lineWidths = new Map();
|
|
12399
|
+
const textsToMeasure = new Set();
|
|
12400
|
+
const textByLine = new Map();
|
|
12401
|
+
const addLineWidth = line => {
|
|
12402
|
+
if (!line) {
|
|
12403
|
+
return;
|
|
12404
|
+
}
|
|
12405
|
+
const cachedWidth = getCachedLineWidth(editor, line);
|
|
12406
|
+
if (cachedWidth !== undefined) {
|
|
12407
|
+
lineWidths.set(line, cachedWidth);
|
|
12408
|
+
return;
|
|
12409
|
+
}
|
|
12410
|
+
const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
|
|
12411
|
+
textByLine.set(line, text);
|
|
12412
|
+
textsToMeasure.add(text);
|
|
12413
|
+
};
|
|
12414
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
12415
|
+
const [selectionStartRow,, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
|
|
12416
|
+
const selectionStartVisualRow = getVisualRow(selectionStartRow);
|
|
12417
|
+
const selectionEndVisualRow = getVisualRow(selectionEndRow);
|
|
12418
|
+
if (selectionEndVisualRow < visibleStartVisualRow || selectionStartVisualRow >= visibleEndVisualRow) {
|
|
12419
|
+
continue;
|
|
12420
|
+
}
|
|
12421
|
+
if (selectionStartRow !== selectionEndRow && selectionStartVisualRow >= visibleStartVisualRow && selectionStartVisualRow < visibleEndVisualRow) {
|
|
12422
|
+
const startLine = lines[selectionStartRow];
|
|
12423
|
+
addLineWidth(startLine);
|
|
12424
|
+
}
|
|
12425
|
+
if (selectionEndColumn === lines[selectionEndRow].length && selectionEndVisualRow >= visibleStartVisualRow && selectionEndVisualRow < visibleEndVisualRow) {
|
|
12426
|
+
const endLine = lines[selectionEndRow];
|
|
12427
|
+
addLineWidth(endLine);
|
|
12428
|
+
}
|
|
12429
|
+
const selectedVisibleRows = actualVisibleLineIndices.filter(rowIndex => rowIndex > selectionStartRow && rowIndex < selectionEndRow);
|
|
12430
|
+
for (const rowIndex of selectedVisibleRows) {
|
|
12431
|
+
const line = lines[rowIndex];
|
|
12432
|
+
addLineWidth(line);
|
|
12433
|
+
}
|
|
12477
12434
|
}
|
|
12478
|
-
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12435
|
+
const texts = [...textsToMeasure];
|
|
12436
|
+
if (texts.length > 0) {
|
|
12437
|
+
const widths = await measureTextWidths(texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
|
|
12438
|
+
const widthByText = new Map(texts.map((text, index) => [text, widths[index]]));
|
|
12439
|
+
for (const [line, text] of textByLine) {
|
|
12440
|
+
lineWidths.set(line, widthByText.get(text));
|
|
12441
|
+
}
|
|
12484
12442
|
}
|
|
12485
|
-
|
|
12443
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
12444
|
+
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn, reversed] = getSelectionPairs(selections, i);
|
|
12445
|
+
const selectionStartVisualRow = getVisualRow(selectionStartRow);
|
|
12446
|
+
const selectionEndVisualRow = getVisualRow(selectionEndRow);
|
|
12447
|
+
if (selectionEndVisualRow < visibleStartVisualRow || selectionStartVisualRow >= visibleEndVisualRow) {
|
|
12448
|
+
continue;
|
|
12449
|
+
}
|
|
12450
|
+
const relativeEndLineRow = getRelativeRow(selectionEndRow);
|
|
12451
|
+
const endLineDifference = horizontalOffset;
|
|
12452
|
+
const endLine = lines[selectionEndRow];
|
|
12453
|
+
const endLineEndX = await getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference, lineWidths.get(endLine) ?? getCachedLineWidth(editor, endLine));
|
|
12454
|
+
const endLineY = relativeEndLineRow * rowHeight;
|
|
12455
|
+
if (isEmpty$1(selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) && endLineEndX > 0) {
|
|
12456
|
+
visibleCursors.push(endLineEndX, endLineY);
|
|
12457
|
+
continue;
|
|
12458
|
+
}
|
|
12459
|
+
const startLineYRelative = getRelativeRow(selectionStartRow);
|
|
12460
|
+
const startLineY = startLineYRelative * rowHeight;
|
|
12461
|
+
const startLineDifference = horizontalOffset;
|
|
12462
|
+
if (selectionStartRow === selectionEndRow) {
|
|
12463
|
+
const startX = await getX(endLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
|
|
12464
|
+
if (reversed) {
|
|
12465
|
+
visibleCursors.push(startX, endLineY);
|
|
12466
|
+
} else if (endLineEndX >= 0) {
|
|
12467
|
+
visibleCursors.push(endLineEndX, endLineY);
|
|
12468
|
+
}
|
|
12469
|
+
const selectionWidth = endLineEndX - startX;
|
|
12470
|
+
visibleSelections.push(startX, startLineY, selectionWidth, rowHeight);
|
|
12471
|
+
} else {
|
|
12472
|
+
if (selectionStartVisualRow >= visibleStartVisualRow) {
|
|
12473
|
+
const startLine = lines[selectionStartRow];
|
|
12474
|
+
const startLineStartX = await getX(startLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
|
|
12475
|
+
const startLineEndX = await getX(startLine, startLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference, lineWidths.get(startLine) ?? getCachedLineWidth(editor, startLine));
|
|
12476
|
+
const startLineStartY = startLineYRelative * rowHeight;
|
|
12477
|
+
const selectionWidth = startLineEndX - startLineStartX;
|
|
12478
|
+
if (reversed) {
|
|
12479
|
+
visibleCursors.push(startLineStartX, startLineStartY);
|
|
12480
|
+
}
|
|
12481
|
+
visibleSelections.push(startLineStartX, startLineStartY, selectionWidth, rowHeight);
|
|
12482
|
+
}
|
|
12483
|
+
const selectedVisibleRows = actualVisibleLineIndices.filter(rowIndex => rowIndex > selectionStartRow && rowIndex < selectionEndRow);
|
|
12484
|
+
for (const rowIndex of selectedVisibleRows) {
|
|
12485
|
+
const currentLine = lines[rowIndex];
|
|
12486
|
+
const relativeLine = getRelativeRow(rowIndex);
|
|
12487
|
+
const currentLineY = relativeLine * rowHeight;
|
|
12488
|
+
const difference = horizontalOffset;
|
|
12489
|
+
const selectionWidth = await getX(currentLine, currentLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference, lineWidths.get(currentLine) ?? getCachedLineWidth(editor, currentLine));
|
|
12490
|
+
visibleSelections.push(0, currentLineY, selectionWidth, rowHeight);
|
|
12491
|
+
}
|
|
12492
|
+
if (selectionEndVisualRow < visibleEndVisualRow) {
|
|
12493
|
+
const selectionWidth = endLineEndX;
|
|
12494
|
+
visibleSelections.push(0, endLineY, selectionWidth, rowHeight);
|
|
12495
|
+
if (!reversed) {
|
|
12496
|
+
visibleCursors.push(selectionWidth, endLineY);
|
|
12497
|
+
}
|
|
12498
|
+
}
|
|
12499
|
+
}
|
|
12500
|
+
}
|
|
12501
|
+
// TODO maybe use Uint32array or Float64Array?
|
|
12502
|
+
return {
|
|
12503
|
+
cursorInfos: getCursorArray(visibleCursors, focused),
|
|
12504
|
+
selectionInfos: getSelectionArray(visibleSelections)
|
|
12505
|
+
};
|
|
12486
12506
|
};
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
const
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12507
|
+
const actualSelectionHasBidi = editor => {
|
|
12508
|
+
for (let i = 0; i < editor.selections.length; i += 4) {
|
|
12509
|
+
const [startRow,, endRow] = getSelectionPairs(editor.selections, i);
|
|
12510
|
+
for (let row = Math.max(startRow, editor.minLineY); row <= Math.min(endRow, editor.maxLineY - 1); row++) {
|
|
12511
|
+
if (isBidi(editor.lines[row], true)) {
|
|
12512
|
+
return true;
|
|
12513
|
+
}
|
|
12514
|
+
}
|
|
12515
|
+
}
|
|
12516
|
+
return false;
|
|
12494
12517
|
};
|
|
12495
|
-
const
|
|
12496
|
-
const
|
|
12497
|
-
|
|
12498
|
-
|
|
12518
|
+
const getBidiVisible = async editor => {
|
|
12519
|
+
const {
|
|
12520
|
+
charWidth,
|
|
12521
|
+
cursorWidth,
|
|
12522
|
+
deltaX = 0,
|
|
12523
|
+
deltaY,
|
|
12524
|
+
focused,
|
|
12525
|
+
foldingRanges = [],
|
|
12526
|
+
fontFamily,
|
|
12527
|
+
fontSize,
|
|
12528
|
+
fontWeight,
|
|
12529
|
+
itemHeight,
|
|
12530
|
+
letterSpacing,
|
|
12531
|
+
lines,
|
|
12532
|
+
maxLineY,
|
|
12533
|
+
minLineY,
|
|
12534
|
+
rowHeight,
|
|
12535
|
+
selections,
|
|
12536
|
+
tabSize,
|
|
12537
|
+
viewLineIndices
|
|
12538
|
+
} = editor;
|
|
12539
|
+
const measure = createMeasure(fontWeight, fontSize, fontFamily, letterSpacing, tabSize, charWidth);
|
|
12540
|
+
const visibleRows = editor.visibleLineIndices || Array.from({
|
|
12541
|
+
length: maxLineY - minLineY
|
|
12542
|
+
}, (_, index) => minLineY + index);
|
|
12543
|
+
const visualRow = row => viewLineIndices ? getVisualRowForDocumentRow$1(row, viewLineIndices) : getVisualRowForDocumentRow(row, foldingRanges);
|
|
12544
|
+
const top = itemHeight ? Math.floor(deltaY / itemHeight) : visualRow(minLineY);
|
|
12545
|
+
const cursors = [];
|
|
12546
|
+
const rectangles = [];
|
|
12547
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
12548
|
+
const activeRow = selections[i + 2];
|
|
12549
|
+
const activeColumn = selections[i + 3];
|
|
12550
|
+
if (visibleRows.includes(activeRow)) {
|
|
12551
|
+
const line = lines[activeRow];
|
|
12552
|
+
const x = isBidi(line, true) ? await getPosition(line, activeColumn, measure) : await measure(line.slice(0, activeColumn));
|
|
12553
|
+
cursors.push(x - deltaX - cursorWidth / 2, (visualRow(activeRow) - top) * rowHeight);
|
|
12554
|
+
}
|
|
12555
|
+
const [startRow, startColumn, endRow, endColumn] = getSelectionPairs(selections, i);
|
|
12556
|
+
const selectedRows = visibleRows.filter(row => row >= startRow && row <= endRow);
|
|
12557
|
+
for (const row of selectedRows) {
|
|
12558
|
+
const line = lines[row];
|
|
12559
|
+
const start = row === startRow ? startColumn : 0;
|
|
12560
|
+
const end = row === endRow ? endColumn : line.length;
|
|
12561
|
+
const ranges = isBidi(line, true) ? await getSelectionRanges(line, start, end, measure) : [{
|
|
12562
|
+
width: await measure(line.slice(start, end)),
|
|
12563
|
+
x: await measure(line.slice(0, start))
|
|
12564
|
+
}];
|
|
12565
|
+
for (const range of ranges) {
|
|
12566
|
+
if (range.width > 0) {
|
|
12567
|
+
rectangles.push(range.x - deltaX - cursorWidth / 2, (visualRow(row) - top) * rowHeight, range.width, rowHeight);
|
|
12568
|
+
}
|
|
12569
|
+
}
|
|
12570
|
+
}
|
|
12571
|
+
}
|
|
12499
12572
|
return {
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
diagnostics,
|
|
12503
|
-
lightBulbRowIndex: -1,
|
|
12504
|
-
visualDecorations
|
|
12573
|
+
cursorInfos: getCursorArray(cursors, focused),
|
|
12574
|
+
selectionInfos: getSelectionArray(rectangles)
|
|
12505
12575
|
};
|
|
12506
12576
|
};
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12577
|
+
|
|
12578
|
+
const getSelectionFromChange = change => {
|
|
12579
|
+
const {
|
|
12580
|
+
inserted,
|
|
12581
|
+
start
|
|
12582
|
+
} = change;
|
|
12583
|
+
const startRowIndex = start.rowIndex;
|
|
12584
|
+
const startColumnIndex = start.columnIndex;
|
|
12585
|
+
const insertedLength = inserted.length;
|
|
12586
|
+
if (insertedLength === 1) {
|
|
12587
|
+
const newPosition = {
|
|
12588
|
+
columnIndex: inserted.at(-1).length + startColumnIndex,
|
|
12589
|
+
rowIndex: startRowIndex + insertedLength - 1
|
|
12590
|
+
};
|
|
12591
|
+
return {
|
|
12592
|
+
end: newPosition,
|
|
12593
|
+
start: newPosition
|
|
12594
|
+
};
|
|
12510
12595
|
}
|
|
12511
|
-
|
|
12512
|
-
|
|
12596
|
+
const newPosition = {
|
|
12597
|
+
columnIndex: startColumnIndex,
|
|
12598
|
+
rowIndex: startRowIndex + insertedLength - 1
|
|
12599
|
+
};
|
|
12600
|
+
return {
|
|
12601
|
+
end: newPosition,
|
|
12602
|
+
start: newPosition
|
|
12603
|
+
};
|
|
12513
12604
|
};
|
|
12514
|
-
const
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12605
|
+
const setSelections$2 = (editor, selections, centerOffscreenSelection = false) => {
|
|
12606
|
+
object(editor);
|
|
12607
|
+
const {
|
|
12608
|
+
foldingRanges = []
|
|
12609
|
+
} = editor;
|
|
12610
|
+
const primarySelectionIndex = editor.primarySelectionIndex || 0;
|
|
12611
|
+
const activeRowIndex = selections[primarySelectionIndex + 2];
|
|
12612
|
+
if ('foldingRanges' in editor) {
|
|
12613
|
+
const normalizedSelections = foldingRanges.length === 0 ? selections : map(selections, (result, index, startRow, startColumn, endRow, endColumn) => {
|
|
12614
|
+
const previousRow = editor.selections[index + 2] ?? endRow;
|
|
12615
|
+
result[index] = getUnhiddenRow(startRow, previousRow, editor.lines.length, foldingRanges);
|
|
12616
|
+
result[index + 1] = startColumn;
|
|
12617
|
+
result[index + 2] = getUnhiddenRow(endRow, previousRow, editor.lines.length, foldingRanges);
|
|
12618
|
+
result[index + 3] = endColumn;
|
|
12619
|
+
});
|
|
12620
|
+
const previousActiveRowIndex = editor.selections[primarySelectionIndex + 2] ?? activeRowIndex;
|
|
12621
|
+
const rowIndex = getUnhiddenRow(activeRowIndex, previousActiveRowIndex, editor.lines.length, foldingRanges);
|
|
12622
|
+
const visualRow = editor.viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, editor.viewLineIndices) : getVisualRowForDocumentRow(rowIndex, foldingRanges);
|
|
12623
|
+
const startVisualRow = Math.floor(editor.deltaY / editor.itemHeight);
|
|
12624
|
+
const endVisualRow = startVisualRow + editor.numberOfVisibleLines;
|
|
12625
|
+
if (visualRow >= startVisualRow && visualRow < endVisualRow) {
|
|
12626
|
+
return {
|
|
12627
|
+
...editor,
|
|
12628
|
+
selections: normalizedSelections
|
|
12629
|
+
};
|
|
12630
|
+
}
|
|
12631
|
+
const desiredStartVisualRow = centerOffscreenSelection ? visualRow - Math.floor(editor.numberOfVisibleLines / 2) : visualRow < startVisualRow ? visualRow : visualRow - editor.numberOfVisibleLines + 1;
|
|
12632
|
+
const desiredDeltaY = desiredStartVisualRow * editor.itemHeight;
|
|
12633
|
+
const deltaY = centerOffscreenSelection ? clamp(desiredDeltaY, 0, editor.finalDeltaY ?? 0) : desiredDeltaY;
|
|
12634
|
+
return updateLayout({
|
|
12635
|
+
...editor,
|
|
12636
|
+
deltaY,
|
|
12637
|
+
selections: normalizedSelections
|
|
12638
|
+
}, foldingRanges);
|
|
12519
12639
|
}
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12640
|
+
const newEditor = {
|
|
12641
|
+
...editor,
|
|
12642
|
+
selections
|
|
12643
|
+
};
|
|
12644
|
+
const {
|
|
12645
|
+
maxLineY,
|
|
12646
|
+
minLineY,
|
|
12647
|
+
numberOfVisibleLines
|
|
12648
|
+
} = editor;
|
|
12649
|
+
if (maxLineY === undefined || minLineY === undefined || numberOfVisibleLines === undefined || numberOfVisibleLines <= 0) {
|
|
12650
|
+
return newEditor;
|
|
12524
12651
|
}
|
|
12525
|
-
|
|
12526
|
-
|
|
12652
|
+
const rowIndex = activeRowIndex;
|
|
12653
|
+
if (rowIndex === undefined) {
|
|
12654
|
+
return newEditor;
|
|
12527
12655
|
}
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12656
|
+
if (rowIndex >= minLineY && rowIndex < maxLineY) {
|
|
12657
|
+
return newEditor;
|
|
12658
|
+
}
|
|
12659
|
+
const {
|
|
12660
|
+
finalDeltaY,
|
|
12661
|
+
height,
|
|
12662
|
+
itemHeight,
|
|
12663
|
+
lines,
|
|
12664
|
+
scrollBarHeight
|
|
12665
|
+
} = editor;
|
|
12666
|
+
const desiredMinLineY = centerOffscreenSelection ? rowIndex - Math.floor(numberOfVisibleLines / 2) : rowIndex < minLineY ? rowIndex : rowIndex - numberOfVisibleLines + 1;
|
|
12667
|
+
const deltaY = clamp(desiredMinLineY * itemHeight, 0, finalDeltaY);
|
|
12668
|
+
const newMinLineY = Math.floor(deltaY / itemHeight);
|
|
12669
|
+
const newMaxLineY = Math.min(newMinLineY + numberOfVisibleLines, lines.length);
|
|
12670
|
+
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height, scrollBarHeight);
|
|
12671
|
+
return {
|
|
12672
|
+
...newEditor,
|
|
12673
|
+
deltaY,
|
|
12674
|
+
maxLineY: newMaxLineY,
|
|
12675
|
+
minLineY: newMinLineY,
|
|
12676
|
+
scrollBarY
|
|
12677
|
+
};
|
|
12532
12678
|
};
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
return
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12679
|
+
|
|
12680
|
+
// TODO maybe only accept sorted selection edits in the first place
|
|
12681
|
+
|
|
12682
|
+
// TODO avoid allocating too many objects when creating new selection from changes
|
|
12683
|
+
// @ts-ignore
|
|
12684
|
+
const applyEdit$1 = (editor, changes) => {
|
|
12685
|
+
object(editor);
|
|
12686
|
+
array(changes);
|
|
12687
|
+
const newSelections = from(changes, getSelectionFromChange);
|
|
12688
|
+
// setSelections(editor, newSelections)
|
|
12689
|
+
return newSelections;
|
|
12690
|
+
};
|
|
12691
|
+
|
|
12692
|
+
// Used when a provider returns no word pattern: anything except whitespace and separators.
|
|
12693
|
+
const defaultWordPattern = /[^`~!@#$%^&*()\-=+[{\]}\\|;:'",.<>/?\s]+/;
|
|
12694
|
+
const mirroredOrigins = new Set([CompositionUpdate, ContentEditableInput, DeleteHorizontalRight, DeleteLeft, EditorCut, EditorPasteText, EditorSnippet, EditorType, EditorTypeWithAutoClosing]);
|
|
12695
|
+
const parseWordPattern = wordPattern => {
|
|
12696
|
+
if (typeof wordPattern === 'string' && wordPattern) {
|
|
12697
|
+
try {
|
|
12698
|
+
return new RegExp(wordPattern);
|
|
12699
|
+
} catch {
|
|
12700
|
+
// fall back to the default word pattern
|
|
12547
12701
|
}
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12702
|
+
}
|
|
12703
|
+
return defaultWordPattern;
|
|
12704
|
+
};
|
|
12705
|
+
const matchesWordPattern = (value, wordPattern) => {
|
|
12706
|
+
const match = value.match(wordPattern);
|
|
12707
|
+
return (match ? match[0].length : 0) === value.length;
|
|
12708
|
+
};
|
|
12709
|
+
const compareRanges = (a, b) => a.rowIndex - b.rowIndex || a.startColumnIndex - b.startColumnIndex;
|
|
12710
|
+
|
|
12711
|
+
/**
|
|
12712
|
+
* Converts provider ranges (document offsets) to sorted single line ranges. Returns undefined
|
|
12713
|
+
* when the ranges are invalid or don't contain the given offset.
|
|
12714
|
+
*/
|
|
12715
|
+
const toLinkedEditingRanges = (lines, ranges, offset) => {
|
|
12716
|
+
if (!Array.isArray(ranges) || ranges.length === 0 || lines.length === 0) {
|
|
12717
|
+
return undefined;
|
|
12718
|
+
}
|
|
12719
|
+
const lineOffsets = [];
|
|
12720
|
+
let lineOffset = 0;
|
|
12721
|
+
for (const line of lines) {
|
|
12722
|
+
lineOffsets.push(lineOffset);
|
|
12723
|
+
lineOffset += line.length + 1;
|
|
12724
|
+
}
|
|
12725
|
+
const result = [];
|
|
12726
|
+
let containsOffset = false;
|
|
12727
|
+
for (const range of ranges) {
|
|
12728
|
+
const startOffset = range?.startOffset;
|
|
12729
|
+
const endOffset = range?.endOffset;
|
|
12730
|
+
if (!Number.isSafeInteger(startOffset) || !Number.isSafeInteger(endOffset) || startOffset < 0 || endOffset < startOffset) {
|
|
12731
|
+
return undefined;
|
|
12554
12732
|
}
|
|
12555
|
-
let
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
while (isApplicable(latest, editor, generation) && !diagnosticLayoutEqual(calculationState, latest.newState)) {
|
|
12559
|
-
calculationState = latest.newState;
|
|
12560
|
-
editorWithDiagnostics = await addDiagnostics(calculationState, diagnostics);
|
|
12561
|
-
latest = get$a(editor.id);
|
|
12733
|
+
let rowIndex = lineOffsets.length - 1;
|
|
12734
|
+
while (rowIndex > 0 && lineOffsets[rowIndex] > startOffset) {
|
|
12735
|
+
rowIndex--;
|
|
12562
12736
|
}
|
|
12563
|
-
|
|
12564
|
-
|
|
12737
|
+
const startColumnIndex = startOffset - lineOffsets[rowIndex];
|
|
12738
|
+
const endColumnIndex = endOffset - lineOffsets[rowIndex];
|
|
12739
|
+
if (endColumnIndex > lines[rowIndex].length) {
|
|
12740
|
+
return undefined;
|
|
12565
12741
|
}
|
|
12566
|
-
if (
|
|
12567
|
-
|
|
12742
|
+
if (startOffset <= offset && offset <= endOffset) {
|
|
12743
|
+
containsOffset = true;
|
|
12568
12744
|
}
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12745
|
+
result.push({
|
|
12746
|
+
endColumnIndex,
|
|
12747
|
+
rowIndex,
|
|
12748
|
+
startColumnIndex
|
|
12749
|
+
});
|
|
12750
|
+
}
|
|
12751
|
+
result.sort(compareRanges);
|
|
12752
|
+
for (let i = 1; i < result.length; i++) {
|
|
12753
|
+
const previous = result[i - 1];
|
|
12754
|
+
const current = result[i];
|
|
12755
|
+
if (previous.rowIndex === current.rowIndex && previous.endColumnIndex > current.startColumnIndex) {
|
|
12756
|
+
return undefined;
|
|
12757
|
+
}
|
|
12758
|
+
}
|
|
12759
|
+
return containsOffset ? result : undefined;
|
|
12578
12760
|
};
|
|
12579
|
-
const
|
|
12580
|
-
return
|
|
12581
|
-
diagnostics
|
|
12582
|
-
}) => diagnostics);
|
|
12761
|
+
const findRangeIndex = (ranges, rowIndex, startColumnIndex, endColumnIndex) => {
|
|
12762
|
+
return ranges.findIndex(range => range.rowIndex === rowIndex && range.startColumnIndex <= startColumnIndex && endColumnIndex <= range.endColumnIndex);
|
|
12583
12763
|
};
|
|
12584
|
-
const
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
}
|
|
12764
|
+
const getActiveLinkedEditing = editor => {
|
|
12765
|
+
const {
|
|
12766
|
+
lines,
|
|
12767
|
+
linkedEditing,
|
|
12768
|
+
selections
|
|
12769
|
+
} = editor;
|
|
12770
|
+
if (!linkedEditing || !editor.linkedEditingEnabled || linkedEditing.lines !== lines || !selections || selections.length !== 4) {
|
|
12771
|
+
return undefined;
|
|
12772
|
+
}
|
|
12773
|
+
return linkedEditing;
|
|
12590
12774
|
};
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12775
|
+
|
|
12776
|
+
/**
|
|
12777
|
+
* Returns the linked ranges when they are still current and the single cursor (or selection) is inside one of them.
|
|
12778
|
+
*/
|
|
12779
|
+
const getActiveRanges = editor => {
|
|
12780
|
+
const linkedEditing = getActiveLinkedEditing(editor);
|
|
12781
|
+
if (!linkedEditing) {
|
|
12782
|
+
return undefined;
|
|
12595
12783
|
}
|
|
12596
|
-
|
|
12597
|
-
|
|
12784
|
+
const [startRowIndex, startColumnIndex, endRowIndex, endColumnIndex] = getSelectionPairs(editor.selections, 0);
|
|
12785
|
+
if (startRowIndex !== endRowIndex || findRangeIndex(linkedEditing.ranges, startRowIndex, startColumnIndex, endColumnIndex) === -1) {
|
|
12786
|
+
return undefined;
|
|
12598
12787
|
}
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12788
|
+
return linkedEditing.ranges;
|
|
12789
|
+
};
|
|
12790
|
+
const isTypingChange = change => change.origin === EditorType && change.deleted.length === 1 && change.deleted[0] === '' && change.inserted[0].length > 0;
|
|
12791
|
+
|
|
12792
|
+
/**
|
|
12793
|
+
* Applies a single line edit inside one linked range to all other linked ranges.
|
|
12794
|
+
* Returns undefined when the edit can't be mirrored, which ends linked editing.
|
|
12795
|
+
*/
|
|
12796
|
+
const getLinkedEdit = (editor, changes, selectionChanges) => {
|
|
12797
|
+
const linkedEditing = getActiveLinkedEditing(editor);
|
|
12798
|
+
if (!linkedEditing || changes.length !== 1) {
|
|
12799
|
+
return undefined;
|
|
12608
12800
|
}
|
|
12801
|
+
const change = changes[0];
|
|
12609
12802
|
const {
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
|
|
12617
|
-
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
|
|
12638
|
-
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
return;
|
|
12668
|
-
}
|
|
12669
|
-
if (message.type === 'done') {
|
|
12670
|
-
if (strict && (providerCount < 0 || receivedProviders.size !== providerCount)) {
|
|
12671
|
-
throw new Error('Diagnostics stream ended without all provider results');
|
|
12672
|
-
}
|
|
12673
|
-
if (providerCount === 0) {
|
|
12674
|
-
providers.clear();
|
|
12675
|
-
await commitDiagnostics(editor, generation, [], () => saveProviderResults(editor, providers));
|
|
12676
|
-
}
|
|
12677
|
-
if (requestGenerations.get(editor.id) === generation) {
|
|
12678
|
-
saveProviderResults(editor, providers);
|
|
12679
|
-
}
|
|
12680
|
-
port1.close();
|
|
12681
|
-
completed.resolve();
|
|
12682
|
-
}
|
|
12683
|
-
} catch (error) {
|
|
12684
|
-
port1.close();
|
|
12685
|
-
if (strict) {
|
|
12686
|
-
completed.reject(error);
|
|
12687
|
-
} else {
|
|
12688
|
-
completed.resolve();
|
|
12689
|
-
await handleError(error, editor);
|
|
12690
|
-
}
|
|
12803
|
+
deleted,
|
|
12804
|
+
end,
|
|
12805
|
+
inserted,
|
|
12806
|
+
origin,
|
|
12807
|
+
start
|
|
12808
|
+
} = change;
|
|
12809
|
+
if (!mirroredOrigins.has(origin) || start.rowIndex !== end.rowIndex || inserted.length !== 1 || deleted.length > 1) {
|
|
12810
|
+
return undefined;
|
|
12811
|
+
}
|
|
12812
|
+
const {
|
|
12813
|
+
lines
|
|
12814
|
+
} = editor;
|
|
12815
|
+
const {
|
|
12816
|
+
ranges,
|
|
12817
|
+
wordPattern
|
|
12818
|
+
} = linkedEditing;
|
|
12819
|
+
const {
|
|
12820
|
+
rowIndex
|
|
12821
|
+
} = start;
|
|
12822
|
+
const primaryIndex = findRangeIndex(ranges, rowIndex, start.columnIndex, end.columnIndex);
|
|
12823
|
+
if (primaryIndex === -1) {
|
|
12824
|
+
return undefined;
|
|
12825
|
+
}
|
|
12826
|
+
const primary = ranges[primaryIndex];
|
|
12827
|
+
const line = lines[rowIndex];
|
|
12828
|
+
const text = inserted[0];
|
|
12829
|
+
const delta = text.length - (end.columnIndex - start.columnIndex);
|
|
12830
|
+
const newValue = line.slice(primary.startColumnIndex, start.columnIndex) + text + line.slice(end.columnIndex, primary.endColumnIndex);
|
|
12831
|
+
if (!matchesWordPattern(newValue, wordPattern)) {
|
|
12832
|
+
return undefined;
|
|
12833
|
+
}
|
|
12834
|
+
const oldValue = line.slice(primary.startColumnIndex, primary.endColumnIndex);
|
|
12835
|
+
const relativeStart = start.columnIndex - primary.startColumnIndex;
|
|
12836
|
+
const relativeEnd = end.columnIndex - primary.startColumnIndex;
|
|
12837
|
+
const newChanges = [];
|
|
12838
|
+
const newRanges = [];
|
|
12839
|
+
const rowShifts = new Map();
|
|
12840
|
+
let mirroredBeforePrimary = 0;
|
|
12841
|
+
// Ranges are sorted, so every edit is relative to the text after the previous edits on the same row.
|
|
12842
|
+
for (const [index, range] of ranges.entries()) {
|
|
12843
|
+
const rangeLine = lines[range.rowIndex];
|
|
12844
|
+
if (index !== primaryIndex && rangeLine.slice(range.startColumnIndex, range.endColumnIndex) !== oldValue) {
|
|
12845
|
+
return undefined;
|
|
12846
|
+
}
|
|
12847
|
+
const shift = rowShifts.get(range.rowIndex) ?? 0;
|
|
12848
|
+
const editStart = range.startColumnIndex + relativeStart;
|
|
12849
|
+
const editEnd = range.startColumnIndex + relativeEnd;
|
|
12850
|
+
newChanges.push({
|
|
12851
|
+
...change,
|
|
12852
|
+
deleted: index === primaryIndex ? deleted : [rangeLine.slice(editStart, editEnd)],
|
|
12853
|
+
end: {
|
|
12854
|
+
columnIndex: editEnd + shift,
|
|
12855
|
+
rowIndex: range.rowIndex
|
|
12856
|
+
},
|
|
12857
|
+
start: {
|
|
12858
|
+
columnIndex: editStart + shift,
|
|
12859
|
+
rowIndex: range.rowIndex
|
|
12691
12860
|
}
|
|
12692
|
-
})
|
|
12861
|
+
});
|
|
12862
|
+
newRanges.push({
|
|
12863
|
+
endColumnIndex: range.endColumnIndex + shift + delta,
|
|
12864
|
+
rowIndex: range.rowIndex,
|
|
12865
|
+
startColumnIndex: range.startColumnIndex + shift
|
|
12866
|
+
});
|
|
12867
|
+
rowShifts.set(range.rowIndex, shift + delta);
|
|
12868
|
+
if (index < primaryIndex && range.rowIndex === rowIndex) {
|
|
12869
|
+
mirroredBeforePrimary++;
|
|
12870
|
+
}
|
|
12871
|
+
}
|
|
12872
|
+
const baseSelections = selectionChanges || applyEdit$1(editor, changes);
|
|
12873
|
+
const selections = new Uint32Array(baseSelections);
|
|
12874
|
+
for (let i = 0; i < selections.length; i += 2) {
|
|
12875
|
+
if (selections[i] === rowIndex) {
|
|
12876
|
+
selections[i + 1] += mirroredBeforePrimary * delta;
|
|
12877
|
+
}
|
|
12878
|
+
}
|
|
12879
|
+
return {
|
|
12880
|
+
canCoalesceTyping: newChanges.every(isTypingChange),
|
|
12881
|
+
changes: newChanges,
|
|
12882
|
+
ranges: newRanges,
|
|
12883
|
+
selections
|
|
12693
12884
|
};
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
12885
|
+
};
|
|
12886
|
+
|
|
12887
|
+
/**
|
|
12888
|
+
* Merges consecutive linked typing edits into one undo step, like single cursor typing.
|
|
12889
|
+
*/
|
|
12890
|
+
const mergeTypingGroups = (previous, changes) => {
|
|
12891
|
+
if (!previous || previous.length !== changes.length || previous.length < 2) {
|
|
12892
|
+
return undefined;
|
|
12893
|
+
}
|
|
12894
|
+
const merged = [];
|
|
12895
|
+
const rowShifts = new Map();
|
|
12896
|
+
for (const [index, change] of changes.entries()) {
|
|
12897
|
+
const old = previous[index];
|
|
12898
|
+
if (!isTypingChange(change) || old.origin !== EditorType || old.inserted.length !== 1 || old.start.rowIndex !== old.end.rowIndex || old.start.rowIndex !== change.start.rowIndex) {
|
|
12899
|
+
return undefined;
|
|
12699
12900
|
}
|
|
12700
|
-
|
|
12701
|
-
|
|
12702
|
-
|
|
12901
|
+
const shift = rowShifts.get(change.start.rowIndex) ?? 0;
|
|
12902
|
+
if (change.start.columnIndex !== old.start.columnIndex + old.inserted[0].length + shift) {
|
|
12903
|
+
return undefined;
|
|
12904
|
+
}
|
|
12905
|
+
merged.push({
|
|
12906
|
+
...old,
|
|
12907
|
+
end: {
|
|
12908
|
+
...old.end,
|
|
12909
|
+
columnIndex: old.end.columnIndex + shift
|
|
12910
|
+
},
|
|
12911
|
+
inserted: [old.inserted[0] + change.inserted[0]],
|
|
12912
|
+
start: {
|
|
12913
|
+
...old.start,
|
|
12914
|
+
columnIndex: old.start.columnIndex + shift
|
|
12915
|
+
}
|
|
12916
|
+
});
|
|
12917
|
+
rowShifts.set(change.start.rowIndex, shift + change.inserted[0].length);
|
|
12918
|
+
}
|
|
12919
|
+
return merged;
|
|
12920
|
+
};
|
|
12921
|
+
|
|
12922
|
+
const EditorChange = 1;
|
|
12923
|
+
const EditorSelection$1 = 2;
|
|
12924
|
+
|
|
12925
|
+
const deliveries = new Map();
|
|
12926
|
+
const getDelta = (previous, next) => {
|
|
12927
|
+
return Object.fromEntries(Object.entries(next).filter(([key, value]) => previous[key] !== value));
|
|
12928
|
+
};
|
|
12929
|
+
const flush = async delivery => {
|
|
12930
|
+
while (delivery.pending && !delivery.disposed) {
|
|
12931
|
+
const status = delivery.pendingStatus;
|
|
12932
|
+
delivery.pending = false;
|
|
12933
|
+
if (delivery.supportsDeltas === undefined) {
|
|
12934
|
+
try {
|
|
12935
|
+
delivery.supportsDeltas = (await delivery.rpc.invoke('StatusBar.supportsEditorStatusDeltas')) === true;
|
|
12936
|
+
} catch {
|
|
12937
|
+
delivery.supportsDeltas = false;
|
|
12703
12938
|
}
|
|
12704
|
-
providers.set('legacy', {
|
|
12705
|
-
diagnostics: response,
|
|
12706
|
-
providerIndex: 0
|
|
12707
|
-
});
|
|
12708
|
-
await commitDiagnostics(editor, generation, response, () => saveProviderResults(editor, providers));
|
|
12709
|
-
port1.close();
|
|
12710
|
-
completed.resolve();
|
|
12711
12939
|
}
|
|
12712
|
-
|
|
12713
|
-
|
|
12714
|
-
await Promise.all([request(), completed.promise]);
|
|
12715
|
-
const latest = get$a(editor.id);
|
|
12716
|
-
if (strict && !isApplicable(latest, editor, generation)) {
|
|
12717
|
-
throw new Error('Editor changed or closed while waiting for diagnostics');
|
|
12940
|
+
if (delivery.disposed) {
|
|
12941
|
+
return;
|
|
12718
12942
|
}
|
|
12719
|
-
|
|
12720
|
-
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12943
|
+
let update = status;
|
|
12944
|
+
if (delivery.hasBaseline) {
|
|
12945
|
+
if (!delivery.baseline && !status) {
|
|
12946
|
+
continue;
|
|
12947
|
+
}
|
|
12948
|
+
if (delivery.baseline && status) {
|
|
12949
|
+
const delta = getDelta(delivery.baseline, status);
|
|
12950
|
+
if (Object.keys(delta).length === 0) {
|
|
12951
|
+
continue;
|
|
12952
|
+
}
|
|
12953
|
+
if (delivery.supportsDeltas) {
|
|
12954
|
+
update = delta;
|
|
12955
|
+
}
|
|
12724
12956
|
}
|
|
12725
|
-
throw error;
|
|
12726
12957
|
}
|
|
12727
|
-
|
|
12958
|
+
try {
|
|
12959
|
+
await delivery.rpc.invoke('StatusBar.handleEditorStatusChanged', update);
|
|
12960
|
+
delivery.baseline = status;
|
|
12961
|
+
delivery.hasBaseline = true;
|
|
12962
|
+
} catch (error) {
|
|
12963
|
+
delivery.baseline = undefined;
|
|
12964
|
+
delivery.hasBaseline = false;
|
|
12965
|
+
console.warn('Failed to deliver editor status:', error);
|
|
12966
|
+
}
|
|
12967
|
+
}
|
|
12968
|
+
};
|
|
12969
|
+
const run$2 = async delivery => {
|
|
12970
|
+
try {
|
|
12971
|
+
await flush(delivery);
|
|
12728
12972
|
} finally {
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12973
|
+
delivery.running = undefined;
|
|
12974
|
+
}
|
|
12975
|
+
// An update can arrive after flush returns but before this continuation runs.
|
|
12976
|
+
if (delivery.pending && !delivery.disposed) {
|
|
12977
|
+
await start(delivery);
|
|
12733
12978
|
}
|
|
12734
12979
|
};
|
|
12735
|
-
const
|
|
12736
|
-
|
|
12737
|
-
return
|
|
12738
|
-
};
|
|
12739
|
-
const clearDiagnosticRequestState = editorId => {
|
|
12740
|
-
requestGenerations.delete(editorId);
|
|
12741
|
-
requestDiagnosticSnapshots.delete(editorId);
|
|
12742
|
-
previousProviderResults.delete(editorId);
|
|
12743
|
-
pendingDiagnosticNotifications.delete(editorId);
|
|
12980
|
+
const start = delivery => {
|
|
12981
|
+
delivery.running = run$2(delivery);
|
|
12982
|
+
return delivery.running;
|
|
12744
12983
|
};
|
|
12745
|
-
const
|
|
12746
|
-
const
|
|
12747
|
-
if (
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
const providers = new Map();
|
|
12751
|
-
for (const [providerId, result] of previous.providers) {
|
|
12752
|
-
const diagnostics = transformDiagnostics(result.diagnostics, changes);
|
|
12753
|
-
if (!diagnosticsEqual(result.diagnostics, diagnostics)) {
|
|
12754
|
-
pendingDiagnosticNotifications.add(editorId);
|
|
12755
|
-
}
|
|
12756
|
-
providers.set(providerId, {
|
|
12757
|
-
...result,
|
|
12758
|
-
diagnostics
|
|
12759
|
-
});
|
|
12984
|
+
const dispose$5 = rpcId => {
|
|
12985
|
+
const delivery = deliveries.get(rpcId);
|
|
12986
|
+
if (delivery) {
|
|
12987
|
+
delivery.disposed = true;
|
|
12988
|
+
deliveries.delete(rpcId);
|
|
12760
12989
|
}
|
|
12761
|
-
previousProviderResults.set(editorId, {
|
|
12762
|
-
...previous,
|
|
12763
|
-
providers
|
|
12764
|
-
});
|
|
12765
12990
|
};
|
|
12766
|
-
const
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12771
|
-
|
|
12991
|
+
const send = (rpcId, rpc, status) => {
|
|
12992
|
+
let delivery = deliveries.get(rpcId);
|
|
12993
|
+
if (!delivery || delivery.rpc !== rpc) {
|
|
12994
|
+
dispose$5(rpcId);
|
|
12995
|
+
delivery = {
|
|
12996
|
+
baseline: undefined,
|
|
12997
|
+
disposed: false,
|
|
12998
|
+
hasBaseline: false,
|
|
12999
|
+
pending: false,
|
|
13000
|
+
pendingStatus: undefined,
|
|
13001
|
+
rpc,
|
|
13002
|
+
running: undefined,
|
|
13003
|
+
supportsDeltas: undefined
|
|
13004
|
+
};
|
|
13005
|
+
deliveries.set(rpcId, delivery);
|
|
12772
13006
|
}
|
|
13007
|
+
delivery.pendingStatus = status;
|
|
13008
|
+
delivery.pending = true;
|
|
13009
|
+
return delivery.running || start(delivery);
|
|
12773
13010
|
};
|
|
12774
13011
|
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
13012
|
+
const state$9 = Object.create(null);
|
|
13013
|
+
|
|
13014
|
+
/**
|
|
13015
|
+
* Register a listener for a specific event type
|
|
13016
|
+
* @param listenerType - The type of event to listen for
|
|
13017
|
+
* @param rpcId - The RPC ID of the listener
|
|
13018
|
+
*/
|
|
13019
|
+
const registerListener$1 = (listenerType, rpcId) => {
|
|
13020
|
+
number(listenerType);
|
|
13021
|
+
number(rpcId);
|
|
13022
|
+
if (!Object.hasOwn(state$9, listenerType)) {
|
|
13023
|
+
state$9[listenerType] = [];
|
|
12779
13024
|
}
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
13025
|
+
|
|
13026
|
+
// Avoid duplicate registrations
|
|
13027
|
+
if (!state$9[listenerType].includes(rpcId)) {
|
|
13028
|
+
state$9[listenerType].push(rpcId);
|
|
12783
13029
|
}
|
|
12784
|
-
await updateDiagnostics(editor, timeoutMs);
|
|
12785
13030
|
};
|
|
12786
13031
|
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
13032
|
+
/**
|
|
13033
|
+
* Unregister a listener for a specific event type
|
|
13034
|
+
* @param listenerType - The type of event to listen for
|
|
13035
|
+
* @param rpcId - The RPC ID of the listener
|
|
13036
|
+
*/
|
|
13037
|
+
const unregisterListener$1 = (listenerType, rpcId) => {
|
|
13038
|
+
number(listenerType);
|
|
13039
|
+
number(rpcId);
|
|
13040
|
+
if (listenerType === EditorSelection$1) {
|
|
13041
|
+
dispose$5(rpcId);
|
|
13042
|
+
}
|
|
13043
|
+
if (Object.hasOwn(state$9, listenerType)) {
|
|
13044
|
+
const index = state$9[listenerType].indexOf(rpcId);
|
|
13045
|
+
if (index !== -1) {
|
|
13046
|
+
state$9[listenerType].splice(index, 1);
|
|
13047
|
+
}
|
|
12794
13048
|
}
|
|
12795
|
-
return [first, second, third, fourth, 0];
|
|
12796
13049
|
};
|
|
12797
13050
|
|
|
12798
|
-
|
|
12799
|
-
|
|
13051
|
+
/**
|
|
13052
|
+
* Get all registered listeners for a specific event type
|
|
13053
|
+
* @param listenerType - The type of event
|
|
13054
|
+
* @returns Array of RPC IDs
|
|
13055
|
+
*/
|
|
13056
|
+
const getListeners = listenerType => {
|
|
13057
|
+
number(listenerType);
|
|
13058
|
+
return state$9[listenerType] || [];
|
|
12800
13059
|
};
|
|
12801
13060
|
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
const
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
return cache?.font === getFontKey(state) ? cache.widths.get(line) : undefined;
|
|
12825
|
-
};
|
|
12826
|
-
const updateHorizontalLayout = async state => {
|
|
12827
|
-
const {
|
|
12828
|
-
breakPoints = [],
|
|
12829
|
-
deltaX,
|
|
12830
|
-
gutterDecorations = [],
|
|
12831
|
-
largeFile,
|
|
12832
|
-
lifecycle,
|
|
12833
|
-
lightBulbRowIndex = -1,
|
|
12834
|
-
lineNumbers
|
|
12835
|
-
} = state;
|
|
12836
|
-
if (largeFile || lifecycle?.disposed) {
|
|
12837
|
-
return state;
|
|
12838
|
-
}
|
|
12839
|
-
const {
|
|
12840
|
-
charWidth,
|
|
12841
|
-
fontFamily,
|
|
12842
|
-
fontSize,
|
|
12843
|
-
fontWeight,
|
|
12844
|
-
isMonospaceFont,
|
|
12845
|
-
letterSpacing,
|
|
12846
|
-
lines,
|
|
12847
|
-
rtl,
|
|
12848
|
-
tabSize,
|
|
12849
|
-
width
|
|
12850
|
-
} = state;
|
|
12851
|
-
const font = getFontKey(state);
|
|
12852
|
-
const owner = lifecycle || lines;
|
|
12853
|
-
const previous = caches.get(owner);
|
|
12854
|
-
const previousWidths = previous?.font === font ? previous.widths : undefined;
|
|
12855
|
-
const widths = new Map();
|
|
12856
|
-
const textsToMeasure = new Set();
|
|
12857
|
-
const textByLine = new Map();
|
|
12858
|
-
for (const line of lines) {
|
|
12859
|
-
const measured = previousWidths?.get(line);
|
|
12860
|
-
if (measured !== undefined) {
|
|
12861
|
-
widths.set(line, measured);
|
|
12862
|
-
continue;
|
|
12863
|
-
}
|
|
12864
|
-
const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
|
|
12865
|
-
textByLine.set(line, text);
|
|
12866
|
-
textsToMeasure.add(text);
|
|
12867
|
-
}
|
|
12868
|
-
const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
|
|
12869
|
-
const gutterText = String(lines.length);
|
|
12870
|
-
if (showGutter && !widths.has(gutterText)) {
|
|
12871
|
-
const measured = previousWidths?.get(gutterText);
|
|
12872
|
-
if (measured === undefined) {
|
|
12873
|
-
textsToMeasure.add(gutterText);
|
|
12874
|
-
} else {
|
|
12875
|
-
widths.set(gutterText, measured);
|
|
13061
|
+
/**
|
|
13062
|
+
* Notify all registered listeners of a specific event type
|
|
13063
|
+
* @param listenerType - The type of event that occurred
|
|
13064
|
+
* @param method - The method name to invoke on the listener
|
|
13065
|
+
* @param params - Parameters to pass to the listener method
|
|
13066
|
+
*/
|
|
13067
|
+
const notifyListeners = async (listenerType, method, ...params) => {
|
|
13068
|
+
number(listenerType);
|
|
13069
|
+
string(method);
|
|
13070
|
+
const rpcIds = getListeners(listenerType);
|
|
13071
|
+
|
|
13072
|
+
// Notify all listeners in parallel
|
|
13073
|
+
const notifications = rpcIds.map(async rpcId => {
|
|
13074
|
+
try {
|
|
13075
|
+
const rpc = get$c(rpcId);
|
|
13076
|
+
if (rpc) {
|
|
13077
|
+
await rpc.invoke(method, ...params);
|
|
13078
|
+
}
|
|
13079
|
+
} catch (error) {
|
|
13080
|
+
// Silently ignore errors from individual listeners
|
|
13081
|
+
// to prevent one failing listener from affecting others
|
|
13082
|
+
console.warn(`Failed to notify listener ${rpcId}:`, error);
|
|
12876
13083
|
}
|
|
13084
|
+
});
|
|
13085
|
+
await Promise.all(notifications);
|
|
13086
|
+
};
|
|
13087
|
+
|
|
13088
|
+
const width = 120;
|
|
13089
|
+
const characterWidth = 0.75;
|
|
13090
|
+
const lineHeight = 2;
|
|
13091
|
+
const minimumViewportHeight = 20;
|
|
13092
|
+
|
|
13093
|
+
const resize$2 = (state, dimensions, columnWidth = state.columnWidth) => {
|
|
13094
|
+
const x = dimensions.x ?? state.x;
|
|
13095
|
+
const y = dimensions.y ?? state.y;
|
|
13096
|
+
const outerWidth = dimensions.width ?? state.outerWidth ?? state.width;
|
|
13097
|
+
const outerHeight = dimensions.height ?? state.outerHeight ?? state.height;
|
|
13098
|
+
const width$1 = Math.max(outerWidth - (state.minimapEnabled ? width : 0), 0);
|
|
13099
|
+
const height = Math.max(outerHeight - (state.breadcrumbsEnabled ? 22 : 0), 0);
|
|
13100
|
+
const numberOfVisibleLines = Math.floor(height / state.itemHeight);
|
|
13101
|
+
if (!('foldingRanges' in state)) {
|
|
13102
|
+
const total = state.lines.length;
|
|
13103
|
+
const finalY = Math.max(total - numberOfVisibleLines, 0);
|
|
13104
|
+
const finalDeltaY = Math.max(total * state.itemHeight - height, 0);
|
|
13105
|
+
const deltaY = Math.min(state.deltaY, finalDeltaY);
|
|
13106
|
+
const minLineY = Math.floor(deltaY / state.itemHeight);
|
|
13107
|
+
const maxLineY = Math.min(minLineY + getRenderedLineCount(height, state.itemHeight, deltaY), total);
|
|
13108
|
+
const contentHeight = total * state.rowHeight;
|
|
13109
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, state.minimumSliderSize);
|
|
13110
|
+
return {
|
|
13111
|
+
...state,
|
|
13112
|
+
columnWidth,
|
|
13113
|
+
deltaY,
|
|
13114
|
+
finalDeltaY,
|
|
13115
|
+
finalY,
|
|
13116
|
+
height,
|
|
13117
|
+
maxLineY,
|
|
13118
|
+
minLineY,
|
|
13119
|
+
numberOfVisibleLines,
|
|
13120
|
+
...('outerWidth' in state && {
|
|
13121
|
+
outerWidth
|
|
13122
|
+
}),
|
|
13123
|
+
...('outerHeight' in state && {
|
|
13124
|
+
outerHeight
|
|
13125
|
+
}),
|
|
13126
|
+
scrollBarHeight,
|
|
13127
|
+
width: width$1,
|
|
13128
|
+
x,
|
|
13129
|
+
y
|
|
13130
|
+
};
|
|
12877
13131
|
}
|
|
12878
|
-
const
|
|
12879
|
-
const regularTexts = texts.filter(text => !isBidi(text, rtl));
|
|
12880
|
-
const bidiTexts = texts.filter(text => isBidi(text, rtl));
|
|
12881
|
-
const [regularWidths, bidiWidths] = await Promise.all([regularTexts.length > 0 ? measureTextWidths(regularTexts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) : [], bidiTexts.length > 0 ? measureTextWidths(bidiTexts, fontWeight, fontSize, fontFamily, letterSpacing, false, charWidth) : []]);
|
|
12882
|
-
const measuredByText = new Map([...regularTexts.map((text, index) => [text, regularWidths[index]]), ...bidiTexts.map((text, index) => [text, bidiWidths[index]])]);
|
|
12883
|
-
for (const [line, text] of textByLine) {
|
|
12884
|
-
widths.set(line, measuredByText.get(text));
|
|
12885
|
-
}
|
|
12886
|
-
if (showGutter && !widths.has(gutterText)) {
|
|
12887
|
-
widths.set(gutterText, measuredByText.get(gutterText));
|
|
12888
|
-
}
|
|
12889
|
-
let longestLineWidth = 0;
|
|
12890
|
-
for (const line of lines) {
|
|
12891
|
-
longestLineWidth = Math.max(longestLineWidth, widths.get(line));
|
|
12892
|
-
}
|
|
12893
|
-
if (lifecycle?.disposed) {
|
|
12894
|
-
return state;
|
|
12895
|
-
}
|
|
12896
|
-
const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
|
|
12897
|
-
caches.set(owner, {
|
|
12898
|
-
font,
|
|
12899
|
-
widths
|
|
12900
|
-
});
|
|
12901
|
-
return {
|
|
13132
|
+
const resized = {
|
|
12902
13133
|
...state,
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
13134
|
+
columnWidth,
|
|
13135
|
+
height,
|
|
13136
|
+
numberOfVisibleLines,
|
|
13137
|
+
...('outerWidth' in state && {
|
|
13138
|
+
outerWidth
|
|
13139
|
+
}),
|
|
13140
|
+
...('outerHeight' in state && {
|
|
13141
|
+
outerHeight
|
|
13142
|
+
}),
|
|
13143
|
+
width: width$1,
|
|
13144
|
+
x,
|
|
13145
|
+
y
|
|
12906
13146
|
};
|
|
13147
|
+
return updateLayout(resized, state.foldingRanges);
|
|
12907
13148
|
};
|
|
12908
13149
|
|
|
12909
|
-
const
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
return
|
|
13150
|
+
const splitLines = lines => {
|
|
13151
|
+
if (!lines) {
|
|
13152
|
+
return [''];
|
|
13153
|
+
}
|
|
13154
|
+
return lines.split('\n');
|
|
12914
13155
|
};
|
|
12915
|
-
|
|
12916
|
-
|
|
13156
|
+
|
|
13157
|
+
const notifyTabModifiedStatusChange = async (uri, modified, applicationId) => {
|
|
13158
|
+
try {
|
|
13159
|
+
await invoke$a(applicationId, 'Main.handleModifiedStatusChange', uri, modified);
|
|
13160
|
+
} catch {
|
|
13161
|
+
// ignore
|
|
13162
|
+
}
|
|
12917
13163
|
};
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
13164
|
+
|
|
13165
|
+
const comparePositions = (left, right) => left.rowIndex - right.rowIndex || left.columnIndex - right.columnIndex;
|
|
13166
|
+
const getInsertedEnd = (start, inserted) => {
|
|
13167
|
+
if (inserted.length === 1) {
|
|
13168
|
+
return {
|
|
13169
|
+
columnIndex: start.columnIndex + inserted[0].length,
|
|
13170
|
+
rowIndex: start.rowIndex
|
|
13171
|
+
};
|
|
12923
13172
|
}
|
|
12924
|
-
return
|
|
13173
|
+
return {
|
|
13174
|
+
columnIndex: inserted.at(-1).length,
|
|
13175
|
+
rowIndex: start.rowIndex + inserted.length - 1
|
|
13176
|
+
};
|
|
12925
13177
|
};
|
|
12926
|
-
const
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
13178
|
+
const transformPosition = (position, start, end, inserted, affinity) => {
|
|
13179
|
+
const startComparison = comparePositions(position, start);
|
|
13180
|
+
const endComparison = comparePositions(position, end);
|
|
13181
|
+
if (startComparison < 0 || startComparison === 0 && affinity === 'left') {
|
|
13182
|
+
return position;
|
|
13183
|
+
}
|
|
13184
|
+
if (endComparison <= 0) {
|
|
13185
|
+
return getInsertedEnd(start, inserted);
|
|
13186
|
+
}
|
|
13187
|
+
const insertedEnd = getInsertedEnd(start, inserted);
|
|
13188
|
+
if (position.rowIndex === end.rowIndex) {
|
|
13189
|
+
return {
|
|
13190
|
+
columnIndex: insertedEnd.columnIndex + position.columnIndex - end.columnIndex,
|
|
13191
|
+
rowIndex: insertedEnd.rowIndex
|
|
13192
|
+
};
|
|
12933
13193
|
}
|
|
13194
|
+
return {
|
|
13195
|
+
columnIndex: position.columnIndex,
|
|
13196
|
+
rowIndex: insertedEnd.rowIndex + position.rowIndex - end.rowIndex
|
|
13197
|
+
};
|
|
12934
13198
|
};
|
|
12935
|
-
const
|
|
12936
|
-
|
|
12937
|
-
|
|
13199
|
+
const overlapsDeletedText = (diagnostic, start, end) => {
|
|
13200
|
+
if (comparePositions(start, end) === 0) {
|
|
13201
|
+
return false;
|
|
13202
|
+
}
|
|
13203
|
+
const diagnosticStart = {
|
|
13204
|
+
columnIndex: diagnostic.columnIndex,
|
|
13205
|
+
rowIndex: diagnostic.rowIndex
|
|
13206
|
+
};
|
|
13207
|
+
const diagnosticEnd = {
|
|
13208
|
+
columnIndex: diagnostic.endColumnIndex,
|
|
13209
|
+
rowIndex: diagnostic.endRowIndex
|
|
13210
|
+
};
|
|
13211
|
+
return comparePositions(start, diagnosticEnd) < 0 && comparePositions(end, diagnosticStart) > 0;
|
|
12938
13212
|
};
|
|
12939
|
-
const
|
|
12940
|
-
|
|
13213
|
+
const transformDiagnostic = (diagnostic, changes) => {
|
|
13214
|
+
let transformed = diagnostic;
|
|
13215
|
+
let linesDelta = 0;
|
|
13216
|
+
for (const change of changes) {
|
|
13217
|
+
const start = {
|
|
13218
|
+
columnIndex: change.start.columnIndex,
|
|
13219
|
+
rowIndex: change.start.rowIndex + linesDelta
|
|
13220
|
+
};
|
|
13221
|
+
const end = {
|
|
13222
|
+
columnIndex: change.end.columnIndex,
|
|
13223
|
+
rowIndex: change.end.rowIndex + linesDelta
|
|
13224
|
+
};
|
|
13225
|
+
if (overlapsDeletedText(transformed, start, end)) {
|
|
13226
|
+
return undefined;
|
|
13227
|
+
}
|
|
13228
|
+
const inserted = change.inserted.length > 0 ? change.inserted : [''];
|
|
13229
|
+
const diagnosticStart = transformPosition({
|
|
13230
|
+
columnIndex: transformed.columnIndex,
|
|
13231
|
+
rowIndex: transformed.rowIndex
|
|
13232
|
+
}, start, end, inserted, 'right');
|
|
13233
|
+
const diagnosticEnd = transformPosition({
|
|
13234
|
+
columnIndex: transformed.endColumnIndex,
|
|
13235
|
+
rowIndex: transformed.endRowIndex
|
|
13236
|
+
}, start, end, inserted, 'left');
|
|
13237
|
+
if (comparePositions(diagnosticStart, diagnosticEnd) > 0) {
|
|
13238
|
+
return undefined;
|
|
13239
|
+
}
|
|
13240
|
+
transformed = {
|
|
13241
|
+
...transformed,
|
|
13242
|
+
columnIndex: diagnosticStart.columnIndex,
|
|
13243
|
+
endColumnIndex: diagnosticEnd.columnIndex,
|
|
13244
|
+
endRowIndex: diagnosticEnd.rowIndex,
|
|
13245
|
+
rowIndex: diagnosticStart.rowIndex
|
|
13246
|
+
};
|
|
13247
|
+
linesDelta += inserted.length - change.deleted.length;
|
|
13248
|
+
}
|
|
13249
|
+
return transformed;
|
|
12941
13250
|
};
|
|
12942
|
-
const
|
|
12943
|
-
|
|
13251
|
+
const transformRanges = (diagnostics, changes) => {
|
|
13252
|
+
if (changes.length === 0 || diagnostics.length === 0) {
|
|
13253
|
+
return diagnostics;
|
|
13254
|
+
}
|
|
13255
|
+
return diagnostics.flatMap(diagnostic => {
|
|
13256
|
+
const transformed = transformDiagnostic(diagnostic, changes);
|
|
13257
|
+
return transformed ? [transformed] : [];
|
|
13258
|
+
});
|
|
12944
13259
|
};
|
|
12945
|
-
const
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
13260
|
+
const transformDiagnostics = (diagnostics, changes) => transformRanges(diagnostics, changes);
|
|
13261
|
+
|
|
13262
|
+
const queues$1 = {};
|
|
13263
|
+
const enqueue = async (uid, callback) => {
|
|
13264
|
+
const instance = get$a(uid);
|
|
13265
|
+
if (!instance) {
|
|
13266
|
+
return undefined;
|
|
13267
|
+
}
|
|
13268
|
+
const {
|
|
13269
|
+
applicationId,
|
|
13270
|
+
uri
|
|
13271
|
+
} = instance.newState;
|
|
13272
|
+
const key = JSON.stringify([applicationId ?? null, uri || uid]);
|
|
13273
|
+
const previous = queues$1[key];
|
|
13274
|
+
const {
|
|
13275
|
+
promise,
|
|
13276
|
+
resolve
|
|
13277
|
+
} = Promise.withResolvers();
|
|
13278
|
+
queues$1[key] = promise;
|
|
13279
|
+
if (previous) {
|
|
13280
|
+
await previous;
|
|
13281
|
+
}
|
|
13282
|
+
try {
|
|
13283
|
+
return await callback();
|
|
13284
|
+
} finally {
|
|
13285
|
+
resolve();
|
|
13286
|
+
if (queues$1[key] === promise) {
|
|
13287
|
+
delete queues$1[key];
|
|
12953
13288
|
}
|
|
12954
13289
|
}
|
|
12955
|
-
return true;
|
|
12956
13290
|
};
|
|
12957
|
-
|
|
12958
|
-
|
|
13291
|
+
|
|
13292
|
+
const logError = async (error, prefix) => {
|
|
13293
|
+
const prettyError = await ErrorWorker.invoke('Errors.prepare', error);
|
|
13294
|
+
await ErrorWorker.invoke('Errors.print', prettyError, prefix);
|
|
12959
13295
|
};
|
|
12960
|
-
const
|
|
12961
|
-
|
|
13296
|
+
const logFallback = (error, prefix) => {
|
|
13297
|
+
if (prefix) {
|
|
13298
|
+
console.error(prefix, error);
|
|
13299
|
+
return;
|
|
13300
|
+
}
|
|
13301
|
+
console.error(error);
|
|
12962
13302
|
};
|
|
12963
|
-
const
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
start
|
|
12970
|
-
} = getSelection(item);
|
|
12971
|
-
newSelections[i++] = start.rowIndex;
|
|
12972
|
-
newSelections[i++] = start.columnIndex;
|
|
12973
|
-
newSelections[i++] = end.rowIndex;
|
|
12974
|
-
newSelections[i++] = end.columnIndex;
|
|
13303
|
+
const handleError$1 = async (error, prefix = '') => {
|
|
13304
|
+
try {
|
|
13305
|
+
await logError(error, prefix);
|
|
13306
|
+
} catch (otherError) {
|
|
13307
|
+
console.warn('ErrorHandling error', otherError);
|
|
13308
|
+
logFallback(error, prefix);
|
|
12975
13309
|
}
|
|
12976
|
-
return newSelections;
|
|
12977
13310
|
};
|
|
12978
13311
|
|
|
12979
|
-
|
|
13312
|
+
const invoke$8 = async (applicationId, method, ...args) => {
|
|
13313
|
+
return applicationId === undefined ? ExtensionManagementWorker.invoke(method, ...args) : ExtensionManagementWorker.invoke('Extensions.invokeForApplication', applicationId, method, ...args);
|
|
13314
|
+
};
|
|
13315
|
+
const invokeAndTransfer = async (applicationId, method, ...args) => {
|
|
13316
|
+
return applicationId === undefined ? ExtensionManagementWorker.invokeAndTransfer(method, ...args) : ExtensionManagementWorker.invokeAndTransfer('Extensions.invokeForApplication', applicationId, method, ...args);
|
|
13317
|
+
};
|
|
12980
13318
|
|
|
12981
|
-
const
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
const x = visibleCursors[i];
|
|
12989
|
-
const y = visibleCursors[i + 1];
|
|
12990
|
-
cursorArray.push(`${px(x)} ${px(y)}`);
|
|
12991
|
-
}
|
|
12992
|
-
return cursorArray;
|
|
13319
|
+
const getTextDocument$3 = editor => {
|
|
13320
|
+
return {
|
|
13321
|
+
documentId: editor.id || editor.uid,
|
|
13322
|
+
languageId: editor.languageId,
|
|
13323
|
+
text: getText$1(editor),
|
|
13324
|
+
uri: editor.uri
|
|
13325
|
+
};
|
|
12993
13326
|
};
|
|
12994
|
-
const
|
|
12995
|
-
const
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
return
|
|
13327
|
+
const streamIsolatedDiagnosticProvider = async (editor, resultPort) => {
|
|
13328
|
+
const textDocument = getTextDocument$3(editor);
|
|
13329
|
+
return invokeAndTransfer(editor.applicationId, 'Extensions.streamDiagnosticProvider', textDocument, resultPort);
|
|
13330
|
+
};
|
|
13331
|
+
const streamDiagnosticProvider = async (editor, resultPort) => {
|
|
13332
|
+
return streamIsolatedDiagnosticProvider(editor, resultPort);
|
|
13333
|
+
};
|
|
13334
|
+
|
|
13335
|
+
const getDiagnosticType = diagnostic => {
|
|
13336
|
+
return diagnostic.type;
|
|
13004
13337
|
};
|
|
13005
|
-
const getVisible = async editor => {
|
|
13006
|
-
const visibleCursors = [];
|
|
13007
|
-
const visibleSelections = [];
|
|
13008
|
-
// // TODO binary search
|
|
13009
13338
|
|
|
13339
|
+
const getVisibleDiagnostics = async (editor, diagnostics) => {
|
|
13340
|
+
const visibleDiagnostics = [];
|
|
13010
13341
|
const {
|
|
13011
13342
|
charWidth,
|
|
13012
|
-
|
|
13343
|
+
deltaX = 0,
|
|
13013
13344
|
deltaY,
|
|
13014
|
-
focused,
|
|
13015
|
-
foldingRanges = [],
|
|
13016
13345
|
fontFamily,
|
|
13017
13346
|
fontSize,
|
|
13018
13347
|
fontWeight,
|
|
@@ -13020,321 +13349,365 @@ const getVisible = async editor => {
|
|
|
13020
13349
|
itemHeight,
|
|
13021
13350
|
letterSpacing,
|
|
13022
13351
|
lines,
|
|
13023
|
-
maxLineY,
|
|
13024
|
-
minLineY,
|
|
13025
13352
|
rowHeight,
|
|
13026
|
-
selections,
|
|
13027
13353
|
tabSize,
|
|
13028
|
-
viewLineIndices
|
|
13029
|
-
visibleLineIndices,
|
|
13030
|
-
visibleViewLineIndices,
|
|
13031
|
-
width
|
|
13354
|
+
viewLineIndices
|
|
13032
13355
|
} = editor;
|
|
13033
|
-
|
|
13034
|
-
|
|
13356
|
+
const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : editor.minLineY || 0;
|
|
13357
|
+
for (const diagnostic of diagnostics) {
|
|
13358
|
+
const {
|
|
13359
|
+
columnIndex,
|
|
13360
|
+
endColumnIndex,
|
|
13361
|
+
rowIndex
|
|
13362
|
+
} = diagnostic;
|
|
13363
|
+
const endLineDifference = -deltaX;
|
|
13364
|
+
const halfCursorWidth = 0;
|
|
13365
|
+
const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
|
|
13366
|
+
const endX = await getX(lines[rowIndex], endColumnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
|
|
13367
|
+
const diagnosticWidth = Math.max(charWidth, endX - x);
|
|
13368
|
+
const visualRow = viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, viewLineIndices) : rowIndex;
|
|
13369
|
+
const y = (visualRow - startVisualRow) * rowHeight;
|
|
13370
|
+
visibleDiagnostics.push({
|
|
13371
|
+
height: rowHeight,
|
|
13372
|
+
type: getDiagnosticType(diagnostic),
|
|
13373
|
+
width: diagnosticWidth,
|
|
13374
|
+
x,
|
|
13375
|
+
y
|
|
13376
|
+
});
|
|
13035
13377
|
}
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
const
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13378
|
+
return visibleDiagnostics;
|
|
13379
|
+
};
|
|
13380
|
+
|
|
13381
|
+
const invoke$7 = (...args) => RendererWorker.invoke(...args);
|
|
13382
|
+
|
|
13383
|
+
/**
|
|
13384
|
+
* Merges link decorations with diagnostic decorations
|
|
13385
|
+
* Links should always be present, but we also need to include any diagnostic decorations
|
|
13386
|
+
*/
|
|
13387
|
+
const mergeLinksWithDiagnosticDecorations = (editor, diagnosticDecorations) => {
|
|
13388
|
+
// Get link decorations
|
|
13389
|
+
const linkDecorations = detectAllLinksAsDecorations(editor);
|
|
13390
|
+
|
|
13391
|
+
// Merge with diagnostic decorations
|
|
13392
|
+
const allDecorations = [...linkDecorations, ...diagnosticDecorations];
|
|
13393
|
+
|
|
13394
|
+
// Sort by offset to maintain proper order
|
|
13395
|
+
const sortedDecorations = [];
|
|
13396
|
+
for (let i = 0; i < allDecorations.length; i += 4) {
|
|
13397
|
+
sortedDecorations.push({
|
|
13398
|
+
length: allDecorations[i + 1],
|
|
13399
|
+
modifiers: allDecorations[i + 3],
|
|
13400
|
+
offset: allDecorations[i],
|
|
13401
|
+
type: allDecorations[i + 2]
|
|
13402
|
+
});
|
|
13403
|
+
}
|
|
13404
|
+
sortedDecorations.sort((a, b) => a.offset - b.offset);
|
|
13405
|
+
|
|
13406
|
+
// Flatten back to array format
|
|
13407
|
+
const result = [];
|
|
13408
|
+
for (const dec of sortedDecorations) {
|
|
13409
|
+
result.push(dec.offset, dec.length, dec.type, dec.modifiers);
|
|
13410
|
+
}
|
|
13411
|
+
return result;
|
|
13412
|
+
};
|
|
13413
|
+
|
|
13414
|
+
const requestGenerations = new Map();
|
|
13415
|
+
const requestDiagnosticSnapshots = new Map();
|
|
13416
|
+
const previousProviderResults = new Map();
|
|
13417
|
+
const pendingDiagnosticNotifications = new Set();
|
|
13418
|
+
const getDiagnostics$1 = async (editor, resultPort) => {
|
|
13419
|
+
return streamDiagnosticProvider(editor, resultPort);
|
|
13420
|
+
};
|
|
13421
|
+
const addDiagnostics = async (editor, diagnostics) => {
|
|
13422
|
+
const visualDecorations = await getVisibleDiagnostics(editor, diagnostics);
|
|
13423
|
+
const diagnosticDecorations = visualDecorations.flatMap(decoration => [decoration.offset, decoration.length, decoration.type, decoration.modifiers || 0]);
|
|
13424
|
+
const decorations = mergeLinksWithDiagnosticDecorations(editor, diagnosticDecorations);
|
|
13425
|
+
return {
|
|
13426
|
+
...editor,
|
|
13427
|
+
decorations,
|
|
13428
|
+
diagnostics,
|
|
13429
|
+
lightBulbRowIndex: -1,
|
|
13430
|
+
visualDecorations
|
|
13061
13431
|
};
|
|
13062
|
-
|
|
13063
|
-
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
if (selectionEndVisualRow < visibleStartVisualRow || selectionStartVisualRow >= visibleEndVisualRow) {
|
|
13067
|
-
continue;
|
|
13068
|
-
}
|
|
13069
|
-
if (selectionStartRow !== selectionEndRow && selectionStartVisualRow >= visibleStartVisualRow && selectionStartVisualRow < visibleEndVisualRow) {
|
|
13070
|
-
const startLine = lines[selectionStartRow];
|
|
13071
|
-
addLineWidth(startLine);
|
|
13072
|
-
}
|
|
13073
|
-
if (selectionEndColumn === lines[selectionEndRow].length && selectionEndVisualRow >= visibleStartVisualRow && selectionEndVisualRow < visibleEndVisualRow) {
|
|
13074
|
-
const endLine = lines[selectionEndRow];
|
|
13075
|
-
addLineWidth(endLine);
|
|
13076
|
-
}
|
|
13077
|
-
const selectedVisibleRows = actualVisibleLineIndices.filter(rowIndex => rowIndex > selectionStartRow && rowIndex < selectionEndRow);
|
|
13078
|
-
for (const rowIndex of selectedVisibleRows) {
|
|
13079
|
-
const line = lines[rowIndex];
|
|
13080
|
-
addLineWidth(line);
|
|
13081
|
-
}
|
|
13432
|
+
};
|
|
13433
|
+
const handleError = async (error, editor) => {
|
|
13434
|
+
if (error instanceof Error && error.message.includes('No diagnostic provider found')) {
|
|
13435
|
+
return editor;
|
|
13082
13436
|
}
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13437
|
+
await handleError$1(error, 'Failed to update diagnostics: ');
|
|
13438
|
+
return editor;
|
|
13439
|
+
};
|
|
13440
|
+
const notifyDiagnosticsChange = async (uri, applicationId) => {
|
|
13441
|
+
try {
|
|
13442
|
+
await invoke$a(applicationId, 'Layout.handleDiagnosticsChange', uri);
|
|
13443
|
+
} catch {
|
|
13444
|
+
// Older renderer workers do not support diagnostics change listeners.
|
|
13090
13445
|
}
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
13096
|
-
|
|
13097
|
-
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
const
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
const startLineEndX = await getX(startLine, startLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference, lineWidths.get(startLine) ?? getCachedLineWidth(editor, startLine));
|
|
13124
|
-
const startLineStartY = startLineYRelative * rowHeight;
|
|
13125
|
-
const selectionWidth = startLineEndX - startLineStartX;
|
|
13126
|
-
if (reversed) {
|
|
13127
|
-
visibleCursors.push(startLineStartX, startLineStartY);
|
|
13128
|
-
}
|
|
13129
|
-
visibleSelections.push(startLineStartX, startLineStartY, selectionWidth, rowHeight);
|
|
13130
|
-
}
|
|
13131
|
-
const selectedVisibleRows = actualVisibleLineIndices.filter(rowIndex => rowIndex > selectionStartRow && rowIndex < selectionEndRow);
|
|
13132
|
-
for (const rowIndex of selectedVisibleRows) {
|
|
13133
|
-
const currentLine = lines[rowIndex];
|
|
13134
|
-
const relativeLine = getRelativeRow(rowIndex);
|
|
13135
|
-
const currentLineY = relativeLine * rowHeight;
|
|
13136
|
-
const difference = horizontalOffset;
|
|
13137
|
-
const selectionWidth = await getX(currentLine, currentLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference, lineWidths.get(currentLine) ?? getCachedLineWidth(editor, currentLine));
|
|
13138
|
-
visibleSelections.push(0, currentLineY, selectionWidth, rowHeight);
|
|
13139
|
-
}
|
|
13140
|
-
if (selectionEndVisualRow < visibleEndVisualRow) {
|
|
13141
|
-
const selectionWidth = endLineEndX;
|
|
13142
|
-
visibleSelections.push(0, endLineY, selectionWidth, rowHeight);
|
|
13143
|
-
if (!reversed) {
|
|
13144
|
-
visibleCursors.push(selectionWidth, endLineY);
|
|
13145
|
-
}
|
|
13446
|
+
};
|
|
13447
|
+
const diagnosticsEqual = (left, right) => {
|
|
13448
|
+
if (left === right) {
|
|
13449
|
+
return true;
|
|
13450
|
+
}
|
|
13451
|
+
if ((left?.length ?? 0) !== right.length) {
|
|
13452
|
+
return false;
|
|
13453
|
+
}
|
|
13454
|
+
return right.every((diagnostic, index) => {
|
|
13455
|
+
const other = left[index];
|
|
13456
|
+
return other.code === diagnostic.code && other.columnIndex === diagnostic.columnIndex && other.endColumnIndex === diagnostic.endColumnIndex && other.endRowIndex === diagnostic.endRowIndex && other.message === diagnostic.message && other.rowIndex === diagnostic.rowIndex && other.source === diagnostic.source && (other.tags === diagnostic.tags || (other.tags?.length ?? 0) === (diagnostic.tags?.length ?? 0) && (other.tags ?? []).every((tag, index) => tag === diagnostic.tags?.[index])) && other.type === diagnostic.type && other.uri === diagnostic.uri;
|
|
13457
|
+
});
|
|
13458
|
+
};
|
|
13459
|
+
const diagnosticLayoutEqual = (left, right) => left.charWidth === right.charWidth && left.deltaY === right.deltaY && left.fontFamily === right.fontFamily && left.fontSize === right.fontSize && left.fontWeight === right.fontWeight && left.isMonospaceFont === right.isMonospaceFont && left.itemHeight === right.itemHeight && left.letterSpacing === right.letterSpacing && left.lines === right.lines && left.minLineY === right.minLineY && left.rowHeight === right.rowHeight && left.tabSize === right.tabSize && left.viewLineIndices === right.viewLineIndices && left.width === right.width;
|
|
13460
|
+
const isApplicable = (latest, editor, generation) => latest && requestGenerations.get(editor.id) === generation && latest.newState.diagnostics === requestDiagnosticSnapshots.get(editor.id) && latest.newState.diagnosticsEnabled && !latest.newState.loadError && latest.newState.languageId === editor.languageId && latest.newState.lines === editor.lines && latest.newState.uri === editor.uri;
|
|
13461
|
+
const mergeDiagnostics = (editor, editorWithDiagnostics) => ({
|
|
13462
|
+
...editor,
|
|
13463
|
+
decorations: editorWithDiagnostics.decorations,
|
|
13464
|
+
diagnostics: editorWithDiagnostics.diagnostics,
|
|
13465
|
+
lightBulbRowIndex: editorWithDiagnostics.lightBulbRowIndex,
|
|
13466
|
+
visualDecorations: editorWithDiagnostics.visualDecorations
|
|
13467
|
+
});
|
|
13468
|
+
const commitDiagnostics = async (editor, generation, diagnostics, onAccepted) => {
|
|
13469
|
+
return (await enqueue(editor.id, async () => {
|
|
13470
|
+
let latest = get$a(editor.id);
|
|
13471
|
+
if (!isApplicable(latest, editor, generation)) {
|
|
13472
|
+
return editor;
|
|
13473
|
+
}
|
|
13474
|
+
if (diagnosticsEqual(latest.newState.diagnostics, diagnostics)) {
|
|
13475
|
+
onAccepted?.();
|
|
13476
|
+
if (pendingDiagnosticNotifications.delete(editor.id)) {
|
|
13477
|
+
await notifyDiagnosticsChange(latest.newState.uri, latest.newState.applicationId);
|
|
13146
13478
|
}
|
|
13479
|
+
return latest.newState;
|
|
13147
13480
|
}
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13481
|
+
let calculationState = latest.newState;
|
|
13482
|
+
let editorWithDiagnostics = await addDiagnostics(calculationState, diagnostics);
|
|
13483
|
+
latest = get$a(editor.id);
|
|
13484
|
+
while (isApplicable(latest, editor, generation) && !diagnosticLayoutEqual(calculationState, latest.newState)) {
|
|
13485
|
+
calculationState = latest.newState;
|
|
13486
|
+
editorWithDiagnostics = await addDiagnostics(calculationState, diagnostics);
|
|
13487
|
+
latest = get$a(editor.id);
|
|
13488
|
+
}
|
|
13489
|
+
if (!isApplicable(latest, editor, generation)) {
|
|
13490
|
+
return editor;
|
|
13491
|
+
}
|
|
13492
|
+
if (diagnosticsEqual(latest.newState.diagnostics, diagnostics)) {
|
|
13493
|
+
return latest.newState;
|
|
13494
|
+
}
|
|
13495
|
+
const newEditor = mergeDiagnostics(latest.newState, editorWithDiagnostics);
|
|
13496
|
+
set$b(editor.id, latest.oldState, newEditor);
|
|
13497
|
+
requestDiagnosticSnapshots.set(editor.id, diagnostics);
|
|
13498
|
+
onAccepted?.();
|
|
13499
|
+
await invoke$7('Editor.renderPending', newEditor.id);
|
|
13500
|
+
pendingDiagnosticNotifications.delete(editor.id);
|
|
13501
|
+
await notifyDiagnosticsChange(newEditor.uri, newEditor.applicationId);
|
|
13502
|
+
return newEditor;
|
|
13503
|
+
})) ?? editor;
|
|
13154
13504
|
};
|
|
13155
|
-
const
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13505
|
+
const flattenProviderDiagnostics = providers => {
|
|
13506
|
+
return providers.values().toArray().toSorted((left, right) => left.providerIndex - right.providerIndex).flatMap(({
|
|
13507
|
+
diagnostics
|
|
13508
|
+
}) => diagnostics);
|
|
13509
|
+
};
|
|
13510
|
+
const saveProviderResults = (editor, providers) => {
|
|
13511
|
+
previousProviderResults.set(editor.id, {
|
|
13512
|
+
languageId: editor.languageId,
|
|
13513
|
+
providers: new Map(providers),
|
|
13514
|
+
uri: editor.uri
|
|
13515
|
+
});
|
|
13516
|
+
};
|
|
13517
|
+
const updateDiagnostics = async (editor, timeoutMs = 0) => {
|
|
13518
|
+
const strict = timeoutMs > 0;
|
|
13519
|
+
if (strict && editor.loadError) {
|
|
13520
|
+
throw new Error(`Cannot await diagnostics: ${editor.loadError}`);
|
|
13521
|
+
}
|
|
13522
|
+
if (!editor.diagnosticsEnabled || editor.loadError) {
|
|
13523
|
+
return editor;
|
|
13524
|
+
}
|
|
13525
|
+
const generation = (requestGenerations.get(editor.id) ?? 0) + 1;
|
|
13526
|
+
requestGenerations.set(editor.id, generation);
|
|
13527
|
+
requestDiagnosticSnapshots.set(editor.id, get$a(editor.id)?.newState.diagnostics ?? editor.diagnostics);
|
|
13528
|
+
const providers = new Map();
|
|
13529
|
+
const previous = previousProviderResults.get(editor.id);
|
|
13530
|
+
if (previous && previous.languageId === editor.languageId && previous.uri === editor.uri) {
|
|
13531
|
+
for (const [providerId, result] of previous.providers) {
|
|
13532
|
+
providers.set(providerId, result);
|
|
13162
13533
|
}
|
|
13163
13534
|
}
|
|
13164
|
-
return false;
|
|
13165
|
-
};
|
|
13166
|
-
const getBidiVisible = async editor => {
|
|
13167
13535
|
const {
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13536
|
+
port1,
|
|
13537
|
+
port2
|
|
13538
|
+
} = new MessageChannel();
|
|
13539
|
+
const completed = Promise.withResolvers();
|
|
13540
|
+
let commitQueue = Promise.resolve();
|
|
13541
|
+
let providerCount = -1;
|
|
13542
|
+
let finished = false;
|
|
13543
|
+
const receivedProviders = new Set();
|
|
13544
|
+
const timeout = strict ? setTimeout(() => completed.reject(new Error(`Diagnostics timed out after ${timeoutMs}ms for ${editor.uri}`)), timeoutMs) : undefined;
|
|
13545
|
+
port1.onmessage = event => {
|
|
13546
|
+
const previousCommit = commitQueue;
|
|
13547
|
+
commitQueue = (async () => {
|
|
13548
|
+
await previousCommit;
|
|
13549
|
+
try {
|
|
13550
|
+
if (finished) {
|
|
13551
|
+
return;
|
|
13552
|
+
}
|
|
13553
|
+
const message = event.data;
|
|
13554
|
+
if (requestGenerations.get(editor.id) !== generation) {
|
|
13555
|
+
if (strict) {
|
|
13556
|
+
throw new Error('Diagnostics request was superseded');
|
|
13557
|
+
}
|
|
13558
|
+
if (message.type === 'done') {
|
|
13559
|
+
port1.close();
|
|
13560
|
+
completed.resolve();
|
|
13561
|
+
}
|
|
13562
|
+
return;
|
|
13563
|
+
}
|
|
13564
|
+
if (message.type === 'providers') {
|
|
13565
|
+
providerCount = message.providerCount ?? 0;
|
|
13566
|
+
const providerIds = message.providerIds ?? [];
|
|
13567
|
+
for (const providerId of providers.keys()) {
|
|
13568
|
+
if (providerIds.includes(providerId)) {
|
|
13569
|
+
const previousResult = providers.get(providerId);
|
|
13570
|
+
providers.set(providerId, {
|
|
13571
|
+
...previousResult,
|
|
13572
|
+
providerIndex: providerIds.indexOf(providerId)
|
|
13573
|
+
});
|
|
13574
|
+
} else {
|
|
13575
|
+
providers.delete(providerId);
|
|
13576
|
+
}
|
|
13577
|
+
}
|
|
13578
|
+
if (requestGenerations.get(editor.id) === generation) {
|
|
13579
|
+
saveProviderResults(editor, providers);
|
|
13580
|
+
}
|
|
13581
|
+
return;
|
|
13582
|
+
}
|
|
13583
|
+
if (message.type === 'result' && message.providerId !== undefined) {
|
|
13584
|
+
if (strict && message.error !== undefined) {
|
|
13585
|
+
throw new Error(`Diagnostic provider ${message.providerId} failed: ${message.error}`);
|
|
13586
|
+
}
|
|
13587
|
+
receivedProviders.add(message.providerId);
|
|
13588
|
+
providers.set(message.providerId, {
|
|
13589
|
+
diagnostics: message.diagnostics ?? [],
|
|
13590
|
+
providerIndex: message.providerIndex ?? providers.size
|
|
13591
|
+
});
|
|
13592
|
+
await commitDiagnostics(editor, generation, flattenProviderDiagnostics(providers), () => saveProviderResults(editor, providers));
|
|
13593
|
+
return;
|
|
13594
|
+
}
|
|
13595
|
+
if (message.type === 'done') {
|
|
13596
|
+
if (strict && (providerCount < 0 || receivedProviders.size !== providerCount)) {
|
|
13597
|
+
throw new Error('Diagnostics stream ended without all provider results');
|
|
13598
|
+
}
|
|
13599
|
+
if (providerCount === 0) {
|
|
13600
|
+
providers.clear();
|
|
13601
|
+
await commitDiagnostics(editor, generation, [], () => saveProviderResults(editor, providers));
|
|
13602
|
+
}
|
|
13603
|
+
if (requestGenerations.get(editor.id) === generation) {
|
|
13604
|
+
saveProviderResults(editor, providers);
|
|
13605
|
+
}
|
|
13606
|
+
port1.close();
|
|
13607
|
+
completed.resolve();
|
|
13608
|
+
}
|
|
13609
|
+
} catch (error) {
|
|
13610
|
+
port1.close();
|
|
13611
|
+
if (strict) {
|
|
13612
|
+
completed.reject(error);
|
|
13613
|
+
} else {
|
|
13614
|
+
completed.resolve();
|
|
13615
|
+
await handleError(error, editor);
|
|
13216
13616
|
}
|
|
13217
13617
|
}
|
|
13218
|
-
}
|
|
13219
|
-
}
|
|
13220
|
-
return {
|
|
13221
|
-
cursorInfos: getCursorArray(cursors, focused),
|
|
13222
|
-
selectionInfos: getSelectionArray(rectangles)
|
|
13223
|
-
};
|
|
13224
|
-
};
|
|
13225
|
-
|
|
13226
|
-
const getSelectionFromChange = change => {
|
|
13227
|
-
const {
|
|
13228
|
-
inserted,
|
|
13229
|
-
start
|
|
13230
|
-
} = change;
|
|
13231
|
-
const startRowIndex = start.rowIndex;
|
|
13232
|
-
const startColumnIndex = start.columnIndex;
|
|
13233
|
-
const insertedLength = inserted.length;
|
|
13234
|
-
if (insertedLength === 1) {
|
|
13235
|
-
const newPosition = {
|
|
13236
|
-
columnIndex: inserted.at(-1).length + startColumnIndex,
|
|
13237
|
-
rowIndex: startRowIndex + insertedLength - 1
|
|
13238
|
-
};
|
|
13239
|
-
return {
|
|
13240
|
-
end: newPosition,
|
|
13241
|
-
start: newPosition
|
|
13242
|
-
};
|
|
13243
|
-
}
|
|
13244
|
-
const newPosition = {
|
|
13245
|
-
columnIndex: startColumnIndex,
|
|
13246
|
-
rowIndex: startRowIndex + insertedLength - 1
|
|
13618
|
+
})();
|
|
13247
13619
|
};
|
|
13248
|
-
|
|
13249
|
-
|
|
13250
|
-
|
|
13620
|
+
port1.start();
|
|
13621
|
+
const request = async () => {
|
|
13622
|
+
const response = await getDiagnostics$1(editor, port2);
|
|
13623
|
+
if (finished) {
|
|
13624
|
+
return;
|
|
13625
|
+
}
|
|
13626
|
+
if (Array.isArray(response) && providerCount === -1) {
|
|
13627
|
+
if (strict) {
|
|
13628
|
+
throw new Error('Diagnostic provider does not support completion and error reporting');
|
|
13629
|
+
}
|
|
13630
|
+
providers.set('legacy', {
|
|
13631
|
+
diagnostics: response,
|
|
13632
|
+
providerIndex: 0
|
|
13633
|
+
});
|
|
13634
|
+
await commitDiagnostics(editor, generation, response, () => saveProviderResults(editor, providers));
|
|
13635
|
+
port1.close();
|
|
13636
|
+
completed.resolve();
|
|
13637
|
+
}
|
|
13251
13638
|
};
|
|
13252
|
-
|
|
13253
|
-
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
} = editor;
|
|
13258
|
-
const primarySelectionIndex = editor.primarySelectionIndex || 0;
|
|
13259
|
-
const activeRowIndex = selections[primarySelectionIndex + 2];
|
|
13260
|
-
if ('foldingRanges' in editor) {
|
|
13261
|
-
const normalizedSelections = foldingRanges.length === 0 ? selections : map(selections, (result, index, startRow, startColumn, endRow, endColumn) => {
|
|
13262
|
-
const previousRow = editor.selections[index + 2] ?? endRow;
|
|
13263
|
-
result[index] = getUnhiddenRow(startRow, previousRow, editor.lines.length, foldingRanges);
|
|
13264
|
-
result[index + 1] = startColumn;
|
|
13265
|
-
result[index + 2] = getUnhiddenRow(endRow, previousRow, editor.lines.length, foldingRanges);
|
|
13266
|
-
result[index + 3] = endColumn;
|
|
13267
|
-
});
|
|
13268
|
-
const previousActiveRowIndex = editor.selections[primarySelectionIndex + 2] ?? activeRowIndex;
|
|
13269
|
-
const rowIndex = getUnhiddenRow(activeRowIndex, previousActiveRowIndex, editor.lines.length, foldingRanges);
|
|
13270
|
-
const visualRow = editor.viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, editor.viewLineIndices) : getVisualRowForDocumentRow(rowIndex, foldingRanges);
|
|
13271
|
-
const startVisualRow = Math.floor(editor.deltaY / editor.itemHeight);
|
|
13272
|
-
const endVisualRow = startVisualRow + editor.numberOfVisibleLines;
|
|
13273
|
-
if (visualRow >= startVisualRow && visualRow < endVisualRow) {
|
|
13274
|
-
return {
|
|
13275
|
-
...editor,
|
|
13276
|
-
selections: normalizedSelections
|
|
13277
|
-
};
|
|
13639
|
+
try {
|
|
13640
|
+
await Promise.all([request(), completed.promise]);
|
|
13641
|
+
const latest = get$a(editor.id);
|
|
13642
|
+
if (strict && !isApplicable(latest, editor, generation)) {
|
|
13643
|
+
throw new Error('Editor changed or closed while waiting for diagnostics');
|
|
13278
13644
|
}
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13285
|
-
|
|
13286
|
-
}
|
|
13645
|
+
return isApplicable(latest, editor, generation) ? latest.newState : editor;
|
|
13646
|
+
} catch (error) {
|
|
13647
|
+
if (strict) {
|
|
13648
|
+
if (requestGenerations.get(editor.id) === generation) {
|
|
13649
|
+
requestGenerations.set(editor.id, generation + 1);
|
|
13650
|
+
}
|
|
13651
|
+
throw error;
|
|
13652
|
+
}
|
|
13653
|
+
return handleError(error, editor);
|
|
13654
|
+
} finally {
|
|
13655
|
+
finished = true;
|
|
13656
|
+
clearTimeout(timeout);
|
|
13657
|
+
port1.close();
|
|
13658
|
+
port2.close();
|
|
13287
13659
|
}
|
|
13288
|
-
|
|
13289
|
-
|
|
13290
|
-
|
|
13291
|
-
|
|
13292
|
-
|
|
13293
|
-
|
|
13294
|
-
|
|
13295
|
-
|
|
13296
|
-
|
|
13297
|
-
|
|
13298
|
-
|
|
13660
|
+
};
|
|
13661
|
+
const requestDiagnostics = editor => {
|
|
13662
|
+
void updateDiagnostics(editor);
|
|
13663
|
+
return editor;
|
|
13664
|
+
};
|
|
13665
|
+
const clearDiagnosticRequestState = editorId => {
|
|
13666
|
+
requestGenerations.delete(editorId);
|
|
13667
|
+
requestDiagnosticSnapshots.delete(editorId);
|
|
13668
|
+
previousProviderResults.delete(editorId);
|
|
13669
|
+
pendingDiagnosticNotifications.delete(editorId);
|
|
13670
|
+
};
|
|
13671
|
+
const transformCachedDiagnostics = (editorId, changes) => {
|
|
13672
|
+
const previous = previousProviderResults.get(editorId);
|
|
13673
|
+
if (!previous) {
|
|
13674
|
+
return;
|
|
13299
13675
|
}
|
|
13300
|
-
const
|
|
13301
|
-
|
|
13302
|
-
|
|
13676
|
+
const providers = new Map();
|
|
13677
|
+
for (const [providerId, result] of previous.providers) {
|
|
13678
|
+
const diagnostics = transformDiagnostics(result.diagnostics, changes);
|
|
13679
|
+
if (!diagnosticsEqual(result.diagnostics, diagnostics)) {
|
|
13680
|
+
pendingDiagnosticNotifications.add(editorId);
|
|
13681
|
+
}
|
|
13682
|
+
providers.set(providerId, {
|
|
13683
|
+
...result,
|
|
13684
|
+
diagnostics
|
|
13685
|
+
});
|
|
13303
13686
|
}
|
|
13304
|
-
|
|
13305
|
-
|
|
13687
|
+
previousProviderResults.set(editorId, {
|
|
13688
|
+
...previous,
|
|
13689
|
+
providers
|
|
13690
|
+
});
|
|
13691
|
+
};
|
|
13692
|
+
const updateDiagnosticsAll = async () => {
|
|
13693
|
+
for (const key of getKeys$1()) {
|
|
13694
|
+
const editor = get$a(Number(key))?.newState;
|
|
13695
|
+
if (editor) {
|
|
13696
|
+
await updateDiagnostics(editor);
|
|
13697
|
+
}
|
|
13306
13698
|
}
|
|
13307
|
-
const {
|
|
13308
|
-
finalDeltaY,
|
|
13309
|
-
height,
|
|
13310
|
-
itemHeight,
|
|
13311
|
-
lines,
|
|
13312
|
-
scrollBarHeight
|
|
13313
|
-
} = editor;
|
|
13314
|
-
const desiredMinLineY = centerOffscreenSelection ? rowIndex - Math.floor(numberOfVisibleLines / 2) : rowIndex < minLineY ? rowIndex : rowIndex - numberOfVisibleLines + 1;
|
|
13315
|
-
const deltaY = clamp(desiredMinLineY * itemHeight, 0, finalDeltaY);
|
|
13316
|
-
const newMinLineY = Math.floor(deltaY / itemHeight);
|
|
13317
|
-
const newMaxLineY = Math.min(newMinLineY + numberOfVisibleLines, lines.length);
|
|
13318
|
-
const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height, scrollBarHeight);
|
|
13319
|
-
return {
|
|
13320
|
-
...newEditor,
|
|
13321
|
-
deltaY,
|
|
13322
|
-
maxLineY: newMaxLineY,
|
|
13323
|
-
minLineY: newMinLineY,
|
|
13324
|
-
scrollBarY
|
|
13325
|
-
};
|
|
13326
13699
|
};
|
|
13327
13700
|
|
|
13328
|
-
//
|
|
13329
|
-
|
|
13330
|
-
|
|
13331
|
-
|
|
13332
|
-
|
|
13333
|
-
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
|
|
13701
|
+
// Do not wrap this command in EditorCommandQueue: streamed results need that queue to commit.
|
|
13702
|
+
const waitForDiagnostics = async (editorId, timeoutMs = 30_000) => {
|
|
13703
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 300_000) {
|
|
13704
|
+
throw new Error('Diagnostics timeout must be between 1 and 300000ms');
|
|
13705
|
+
}
|
|
13706
|
+
const editor = get$a(editorId)?.newState;
|
|
13707
|
+
if (!editor || editor.initial) {
|
|
13708
|
+
throw new Error(`Editor is not ready: ${editorId}`);
|
|
13709
|
+
}
|
|
13710
|
+
await updateDiagnostics(editor, timeoutMs);
|
|
13338
13711
|
};
|
|
13339
13712
|
|
|
13340
13713
|
// TODO
|
|
@@ -13375,7 +13748,12 @@ const applyAutoClosingRangesEdit = (editor, changes) => {
|
|
|
13375
13748
|
const updateTransformedDiagnostics = async (editor, changes) => {
|
|
13376
13749
|
transformCachedDiagnostics(editor.id ?? editor.uid, changes);
|
|
13377
13750
|
const diagnostics = transformDiagnostics(editor.diagnostics ?? [], changes);
|
|
13378
|
-
|
|
13751
|
+
// Keep provider links at their position until the debounced refresh replaces them.
|
|
13752
|
+
const editorWithLinks = editor.documentLinks?.length ? {
|
|
13753
|
+
...editor,
|
|
13754
|
+
documentLinks: transformRanges(editor.documentLinks, changes)
|
|
13755
|
+
} : editor;
|
|
13756
|
+
return addDiagnostics(editorWithLinks, diagnostics);
|
|
13379
13757
|
};
|
|
13380
13758
|
const scheduleSelections = (editor, selectionEdits) => {
|
|
13381
13759
|
return {
|
|
@@ -13406,6 +13784,12 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
13406
13784
|
if (changes.length === 0) {
|
|
13407
13785
|
return editor;
|
|
13408
13786
|
}
|
|
13787
|
+
const originalChanges = changes;
|
|
13788
|
+
const linkedEdit = editor.linkedEditing ? getLinkedEdit(editor, changes, selectionChanges) : undefined;
|
|
13789
|
+
if (linkedEdit) {
|
|
13790
|
+
changes = [...linkedEdit.changes];
|
|
13791
|
+
selectionChanges = linkedEdit.selections;
|
|
13792
|
+
}
|
|
13409
13793
|
const newLines = applyEdits(editor, changes);
|
|
13410
13794
|
const partialNewEditor = updateLines(editor, newLines);
|
|
13411
13795
|
const partialNewEditorWithDiagnostics = await updateTransformedDiagnostics(partialNewEditor, changes);
|
|
@@ -13426,12 +13810,23 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
13426
13810
|
// TODO maybe put undostack into indexeddb so that there is no memory leak in app
|
|
13427
13811
|
// then clear old undostack from indexeddb after 3 days
|
|
13428
13812
|
// TODO should push to undostack after rendering
|
|
13429
|
-
const autoClosingRanges = applyAutoClosingRangesEdit(editor,
|
|
13813
|
+
const autoClosingRanges = applyAutoClosingRangesEdit(editor, originalChanges);
|
|
13430
13814
|
const change = changes[0];
|
|
13431
|
-
const canCoalesceTyping = changes.length === 1 && change.origin === EditorType && change.deleted[0] === '' && change.inserted[0].length > 0 && change.inserted.length === 1 && change.start.rowIndex === change.end.rowIndex && change.start.columnIndex === change.end.columnIndex;
|
|
13432
|
-
const
|
|
13433
|
-
const
|
|
13434
|
-
const
|
|
13815
|
+
const canCoalesceTyping = linkedEdit ? linkedEdit.canCoalesceTyping : changes.length === 1 && change.origin === EditorType && change.deleted[0] === '' && change.inserted[0].length > 0 && change.inserted.length === 1 && change.start.rowIndex === change.end.rowIndex && change.start.columnIndex === change.end.columnIndex;
|
|
13816
|
+
const previousGroup = editor.undoStack.at(-1);
|
|
13817
|
+
const previous = previousGroup?.[0];
|
|
13818
|
+
const mergedLinkedGroup = linkedEdit && editor.canCoalesceTyping && canCoalesceTyping ? mergeTypingGroups(previousGroup, changes) : undefined;
|
|
13819
|
+
if (mergedLinkedGroup) {
|
|
13820
|
+
Object.defineProperty(mergedLinkedGroup, 'selectionHistory', {
|
|
13821
|
+
configurable: true,
|
|
13822
|
+
value: {
|
|
13823
|
+
after: newSelections,
|
|
13824
|
+
before: previousGroup.selectionHistory?.before ?? editor.selections
|
|
13825
|
+
}
|
|
13826
|
+
});
|
|
13827
|
+
}
|
|
13828
|
+
const shouldCoalesce = !linkedEdit && editor.canCoalesceTyping && canCoalesceTyping && previousGroup?.length === 1 && change.start.rowIndex === previous.start.rowIndex && change.start.columnIndex === previous.start.columnIndex + previous.inserted[0].length;
|
|
13829
|
+
const undoStack = mergedLinkedGroup ? [...editor.undoStack.slice(0, -1), mergedLinkedGroup] : shouldCoalesce ? [...editor.undoStack.slice(0, -1), [{
|
|
13435
13830
|
...previous,
|
|
13436
13831
|
inserted: [previous.inserted[0] + change.inserted[0]]
|
|
13437
13832
|
}]] : [...editor.undoStack, changes];
|
|
@@ -13445,7 +13840,14 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
13445
13840
|
redoStack: [],
|
|
13446
13841
|
selections: newSelections,
|
|
13447
13842
|
snippetTabStops: changes.every(change => change.origin === EditorType || change.origin === EditorTypeWithAutoClosing) ? editor.snippetTabStops : undefined,
|
|
13448
|
-
undoStack
|
|
13843
|
+
undoStack,
|
|
13844
|
+
...(editor.linkedEditing && {
|
|
13845
|
+
linkedEditing: linkedEdit && {
|
|
13846
|
+
...editor.linkedEditing,
|
|
13847
|
+
lines: newLines,
|
|
13848
|
+
ranges: linkedEdit.ranges
|
|
13849
|
+
}
|
|
13850
|
+
})
|
|
13449
13851
|
};
|
|
13450
13852
|
// Update link decorations after text changes
|
|
13451
13853
|
const linkDecorations = detectAllLinksAsDecorations(newEditor);
|
|
@@ -13468,7 +13870,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
13468
13870
|
console.warn('Failed to notify editor change listeners:', error);
|
|
13469
13871
|
}
|
|
13470
13872
|
const incrementalEdits = await getIncrementalEdits(editor, newEditorWithDecorations);
|
|
13471
|
-
const editorWithNewWidgets = await applyWidgetChanges(newEditorWithDecorations,
|
|
13873
|
+
const editorWithNewWidgets = await applyWidgetChanges(newEditorWithDecorations, originalChanges);
|
|
13472
13874
|
const newEditor2 = {
|
|
13473
13875
|
...newEditorWithDecorations,
|
|
13474
13876
|
...editorWithNewWidgets,
|
|
@@ -13707,6 +14109,9 @@ const updateColorPickerValue$1 = async (editor, value) => {
|
|
|
13707
14109
|
};
|
|
13708
14110
|
};
|
|
13709
14111
|
|
|
14112
|
+
const emptyDocumentHighlights = [];
|
|
14113
|
+
const emptyDocumentHighlightInfos = [];
|
|
14114
|
+
|
|
13710
14115
|
const getDocument = editor => ({
|
|
13711
14116
|
documentId: editor.id,
|
|
13712
14117
|
languageId: editor.languageId,
|
|
@@ -13732,7 +14137,7 @@ const execute = async ({
|
|
|
13732
14137
|
return noProviderFoundResult;
|
|
13733
14138
|
}
|
|
13734
14139
|
const textDocument = getTextDocument$2(editor);
|
|
13735
|
-
const result = await invoke$
|
|
14140
|
+
const result = await invoke$8(editor.applicationId, 'Extensions.executeLanguageProvider', kind, method, textDocument, ...args);
|
|
13736
14141
|
if (!result.found) {
|
|
13737
14142
|
return noProviderFoundResult;
|
|
13738
14143
|
}
|
|
@@ -13788,7 +14193,7 @@ const getEditorGutterDecorations = async editor => {
|
|
|
13788
14193
|
uri: editor.uri
|
|
13789
14194
|
};
|
|
13790
14195
|
try {
|
|
13791
|
-
const results = await invoke$
|
|
14196
|
+
const results = await invoke$8(editor.applicationId, 'Extensions.executeProvidersByEvent', 'onEditorGutterDecoration', 'ExtensionApi.executeEditorGutterDecorationProvider', textDocument);
|
|
13792
14197
|
return getProviderDecorations$1(results);
|
|
13793
14198
|
} catch {
|
|
13794
14199
|
return [];
|
|
@@ -13824,7 +14229,7 @@ const getEditorTextDecorations = async editor => {
|
|
|
13824
14229
|
});
|
|
13825
14230
|
}
|
|
13826
14231
|
try {
|
|
13827
|
-
const results = await invoke$
|
|
14232
|
+
const results = await invoke$8(editor.applicationId, 'Extensions.executeProvidersByEvent', 'onEditorTextDecoration', 'ExtensionApi.executeEditorTextDecorationProvider', {
|
|
13828
14233
|
languageId: editor.languageId,
|
|
13829
14234
|
selections,
|
|
13830
14235
|
text: getText$1(editor),
|
|
@@ -13899,7 +14304,7 @@ const getLightBulbRowIndex = async editor => {
|
|
|
13899
14304
|
};
|
|
13900
14305
|
const offset = getOffsetAtCursor$1(editor);
|
|
13901
14306
|
try {
|
|
13902
|
-
const actions = await invoke$
|
|
14307
|
+
const actions = await invoke$8(editor.applicationId, 'Extensions.executeCodeActionProviders', textDocument, offset);
|
|
13903
14308
|
return Array.isArray(actions) && actions.length > 0 ? rowIndex : -1;
|
|
13904
14309
|
} catch {
|
|
13905
14310
|
return -1;
|
|
@@ -14208,7 +14613,7 @@ const findBracketPair = (lines, rowIndex, columnIndex) => {
|
|
|
14208
14613
|
|
|
14209
14614
|
const getPositionKey = position => `${position.rowIndex}:${position.columnIndex}`;
|
|
14210
14615
|
const bracketMatchCache = new WeakMap();
|
|
14211
|
-
const selectionsEqual$
|
|
14616
|
+
const selectionsEqual$2 = (left, right) => {
|
|
14212
14617
|
if (left.length !== right.length) {
|
|
14213
14618
|
return false;
|
|
14214
14619
|
}
|
|
@@ -14221,7 +14626,7 @@ const selectionsEqual$1 = (left, right) => {
|
|
|
14221
14626
|
};
|
|
14222
14627
|
const findBracketMatchPositions = (lines, selections) => {
|
|
14223
14628
|
const cached = bracketMatchCache.get(lines);
|
|
14224
|
-
if (cached && selectionsEqual$
|
|
14629
|
+
if (cached && selectionsEqual$2(cached.selections, selections)) {
|
|
14225
14630
|
return cached.positions;
|
|
14226
14631
|
}
|
|
14227
14632
|
const positions = new Map();
|
|
@@ -14247,7 +14652,7 @@ const findBracketMatchPositions = (lines, selections) => {
|
|
|
14247
14652
|
bracketMatchCache.set(lines, entry);
|
|
14248
14653
|
return entry.positions;
|
|
14249
14654
|
};
|
|
14250
|
-
const getInfo = async (editor, position, visibleLineIndices, startVisualRow) => {
|
|
14655
|
+
const getInfo$1 = async (editor, position, visibleLineIndices, startVisualRow) => {
|
|
14251
14656
|
if (!visibleLineIndices.includes(position.rowIndex)) {
|
|
14252
14657
|
return undefined;
|
|
14253
14658
|
}
|
|
@@ -14295,10 +14700,184 @@ const getVisibleBracketMatches = async editor => {
|
|
|
14295
14700
|
}, (_, index) => minLineY + index);
|
|
14296
14701
|
const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : viewLineIndices ? getVisualRowForDocumentRow$1(minLineY, viewLineIndices) : getVisualRowForDocumentRow(minLineY, foldingRanges);
|
|
14297
14702
|
const positions = findBracketMatchPositions(lines, selections);
|
|
14298
|
-
const infos = await Promise.all(positions.map(position => getInfo(editor, position, actualVisibleLineIndices, startVisualRow)));
|
|
14703
|
+
const infos = await Promise.all(positions.map(position => getInfo$1(editor, position, actualVisibleLineIndices, startVisualRow)));
|
|
14704
|
+
return infos.filter(info => info !== undefined);
|
|
14705
|
+
};
|
|
14706
|
+
|
|
14707
|
+
const containsCursor = (highlight, rowIndex, columnIndex) => {
|
|
14708
|
+
const {
|
|
14709
|
+
endColumnIndex,
|
|
14710
|
+
endRowIndex,
|
|
14711
|
+
startColumnIndex,
|
|
14712
|
+
startRowIndex
|
|
14713
|
+
} = highlight;
|
|
14714
|
+
if (rowIndex < startRowIndex || rowIndex > endRowIndex) {
|
|
14715
|
+
return false;
|
|
14716
|
+
}
|
|
14717
|
+
if (rowIndex === startRowIndex && columnIndex < startColumnIndex) {
|
|
14718
|
+
return false;
|
|
14719
|
+
}
|
|
14720
|
+
return rowIndex !== endRowIndex || columnIndex <= endColumnIndex;
|
|
14721
|
+
};
|
|
14722
|
+
const isSingleCursorIn = (highlights, selections) => {
|
|
14723
|
+
if (selections?.length !== 4 || selections[0] !== selections[2] || selections[1] !== selections[3]) {
|
|
14724
|
+
return false;
|
|
14725
|
+
}
|
|
14726
|
+
return highlights.some(highlight => containsCursor(highlight, selections[0], selections[1]));
|
|
14727
|
+
};
|
|
14728
|
+
|
|
14729
|
+
/**
|
|
14730
|
+
* Highlights are cleared on edits until the provider refreshes them. Moving the cursor
|
|
14731
|
+
* inside a highlighted range keeps them to avoid flicker while a new request is pending.
|
|
14732
|
+
*/
|
|
14733
|
+
const getRetainedDocumentHighlights = (oldState, newState) => {
|
|
14734
|
+
const highlights = newState.documentHighlights || emptyDocumentHighlights;
|
|
14735
|
+
if (highlights.length === 0 || !newState.documentHighlightsEnabled) {
|
|
14736
|
+
return emptyDocumentHighlights;
|
|
14737
|
+
}
|
|
14738
|
+
if (highlights !== oldState.documentHighlights) {
|
|
14739
|
+
return highlights;
|
|
14740
|
+
}
|
|
14741
|
+
if (oldState.lines !== newState.lines || oldState.uri !== newState.uri) {
|
|
14742
|
+
return emptyDocumentHighlights;
|
|
14743
|
+
}
|
|
14744
|
+
if (oldState.selections !== newState.selections && !isSingleCursorIn(highlights, newState.selections)) {
|
|
14745
|
+
return emptyDocumentHighlights;
|
|
14746
|
+
}
|
|
14747
|
+
return highlights;
|
|
14748
|
+
};
|
|
14749
|
+
const getInfo = async (editor, highlight, rowIndex, difference, y) => {
|
|
14750
|
+
const {
|
|
14751
|
+
charWidth,
|
|
14752
|
+
fontFamily,
|
|
14753
|
+
fontSize,
|
|
14754
|
+
fontWeight,
|
|
14755
|
+
isMonospaceFont,
|
|
14756
|
+
letterSpacing,
|
|
14757
|
+
lines,
|
|
14758
|
+
rowHeight,
|
|
14759
|
+
tabSize,
|
|
14760
|
+
width
|
|
14761
|
+
} = editor;
|
|
14762
|
+
const {
|
|
14763
|
+
endColumnIndex,
|
|
14764
|
+
endRowIndex,
|
|
14765
|
+
kind,
|
|
14766
|
+
startColumnIndex,
|
|
14767
|
+
startRowIndex
|
|
14768
|
+
} = highlight;
|
|
14769
|
+
const line = lines[rowIndex];
|
|
14770
|
+
const start = rowIndex === startRowIndex ? startColumnIndex : 0;
|
|
14771
|
+
const end = rowIndex === endRowIndex ? endColumnIndex : line.length;
|
|
14772
|
+
if (end <= start) {
|
|
14773
|
+
return undefined;
|
|
14774
|
+
}
|
|
14775
|
+
const getX$1 = columnIndex => getX(line, columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, 0, width, charWidth, difference);
|
|
14776
|
+
const [x, endX] = await Promise.all([getX$1(start), getX$1(end)]);
|
|
14777
|
+
if (endX <= x) {
|
|
14778
|
+
return undefined;
|
|
14779
|
+
}
|
|
14780
|
+
return {
|
|
14781
|
+
height: rowHeight,
|
|
14782
|
+
kind,
|
|
14783
|
+
width: endX - x,
|
|
14784
|
+
x,
|
|
14785
|
+
y
|
|
14786
|
+
};
|
|
14787
|
+
};
|
|
14788
|
+
const getVisibleDocumentHighlights = async editor => {
|
|
14789
|
+
const highlights = editor.documentHighlights || emptyDocumentHighlights;
|
|
14790
|
+
if (highlights.length === 0) {
|
|
14791
|
+
return emptyDocumentHighlightInfos;
|
|
14792
|
+
}
|
|
14793
|
+
const {
|
|
14794
|
+
deltaY,
|
|
14795
|
+
differences,
|
|
14796
|
+
foldingRanges,
|
|
14797
|
+
itemHeight,
|
|
14798
|
+
lines,
|
|
14799
|
+
maxLineY,
|
|
14800
|
+
minLineY,
|
|
14801
|
+
rowHeight,
|
|
14802
|
+
viewLineIndices,
|
|
14803
|
+
visibleLineIndices
|
|
14804
|
+
} = editor;
|
|
14805
|
+
const actualVisibleLineIndices = visibleLineIndices || Array.from({
|
|
14806
|
+
length: Math.max(0, maxLineY - minLineY)
|
|
14807
|
+
}, (_, index) => minLineY + index);
|
|
14808
|
+
if (actualVisibleLineIndices.length === 0) {
|
|
14809
|
+
return emptyDocumentHighlightInfos;
|
|
14810
|
+
}
|
|
14811
|
+
const visibleIndexByRow = new Map();
|
|
14812
|
+
for (const [index, rowIndex] of actualVisibleLineIndices.entries()) {
|
|
14813
|
+
visibleIndexByRow.set(rowIndex, index);
|
|
14814
|
+
}
|
|
14815
|
+
const firstVisibleRow = actualVisibleLineIndices[0];
|
|
14816
|
+
const lastVisibleRow = actualVisibleLineIndices.at(-1);
|
|
14817
|
+
const getVisualRow = rowIndex => viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, viewLineIndices) : getVisualRowForDocumentRow(rowIndex, foldingRanges);
|
|
14818
|
+
const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : getVisualRow(minLineY);
|
|
14819
|
+
const pending = [];
|
|
14820
|
+
for (const highlight of highlights) {
|
|
14821
|
+
const from = Math.max(highlight.startRowIndex, firstVisibleRow);
|
|
14822
|
+
const to = Math.min(highlight.endRowIndex, lastVisibleRow, lines.length - 1);
|
|
14823
|
+
for (let rowIndex = from; rowIndex <= to; rowIndex++) {
|
|
14824
|
+
const visibleIndex = visibleIndexByRow.get(rowIndex);
|
|
14825
|
+
if (visibleIndex !== undefined) {
|
|
14826
|
+
const y = (getVisualRow(rowIndex) - startVisualRow) * rowHeight;
|
|
14827
|
+
pending.push(getInfo(editor, highlight, rowIndex, differences?.[visibleIndex] ?? 0, y));
|
|
14828
|
+
}
|
|
14829
|
+
}
|
|
14830
|
+
}
|
|
14831
|
+
const infos = await Promise.all(pending);
|
|
14299
14832
|
return infos.filter(info => info !== undefined);
|
|
14300
14833
|
};
|
|
14301
14834
|
|
|
14835
|
+
const emptyDom = [];
|
|
14836
|
+
const getLinkedEditingVirtualDom = async editor => {
|
|
14837
|
+
const ranges = getActiveRanges(editor);
|
|
14838
|
+
if (!ranges) {
|
|
14839
|
+
return emptyDom;
|
|
14840
|
+
}
|
|
14841
|
+
const {
|
|
14842
|
+
deltaY,
|
|
14843
|
+
foldingRanges = [],
|
|
14844
|
+
itemHeight,
|
|
14845
|
+
lines,
|
|
14846
|
+
maxLineY,
|
|
14847
|
+
minLineY,
|
|
14848
|
+
rowHeight,
|
|
14849
|
+
viewLineIndices
|
|
14850
|
+
} = editor;
|
|
14851
|
+
const visibleRows = editor.visibleLineIndices || Array.from({
|
|
14852
|
+
length: Math.max(0, maxLineY - minLineY)
|
|
14853
|
+
}, (_, index) => minLineY + index);
|
|
14854
|
+
const getVisualRow = row => viewLineIndices ? getVisualRowForDocumentRow$1(row, viewLineIndices) : getVisualRowForDocumentRow(row, foldingRanges);
|
|
14855
|
+
const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : getVisualRow(minLineY);
|
|
14856
|
+
const dom = [];
|
|
14857
|
+
for (const {
|
|
14858
|
+
endColumnIndex,
|
|
14859
|
+
rowIndex,
|
|
14860
|
+
startColumnIndex
|
|
14861
|
+
} of ranges) {
|
|
14862
|
+
if (!visibleRows.includes(rowIndex)) {
|
|
14863
|
+
continue;
|
|
14864
|
+
}
|
|
14865
|
+
const getX$1 = column => getX(lines[rowIndex], column, editor.fontWeight, editor.fontSize, editor.fontFamily, editor.isMonospaceFont, editor.letterSpacing, editor.tabSize, 0, Infinity, editor.charWidth, -(editor.deltaX || 0));
|
|
14866
|
+
const left = await getX$1(startColumnIndex);
|
|
14867
|
+
const right = await getX$1(endColumnIndex);
|
|
14868
|
+
dom.push({
|
|
14869
|
+
childCount: 0,
|
|
14870
|
+
className: 'LinkedEditingRange',
|
|
14871
|
+
height: rowHeight,
|
|
14872
|
+
left,
|
|
14873
|
+
top: (getVisualRow(rowIndex) - startVisualRow) * rowHeight,
|
|
14874
|
+
type: Div,
|
|
14875
|
+
width: Math.max(1, right - left)
|
|
14876
|
+
});
|
|
14877
|
+
}
|
|
14878
|
+
return dom;
|
|
14879
|
+
};
|
|
14880
|
+
|
|
14302
14881
|
const shouldUpdateDiagnosticData = (oldState, newState) => {
|
|
14303
14882
|
return oldState.diagnostics !== newState.diagnostics || (newState.diagnostics?.length ?? 0) > 0 && (oldState.deltaX !== newState.deltaX || oldState.minLineY !== newState.minLineY || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.rtl !== newState.rtl || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width);
|
|
14304
14883
|
};
|
|
@@ -14309,7 +14888,10 @@ const shouldUpdateBracketMatchData = (oldState, newState) => {
|
|
|
14309
14888
|
if (!('bracketMatchInfos' in newState)) {
|
|
14310
14889
|
return false;
|
|
14311
14890
|
}
|
|
14312
|
-
return oldState.selections !== newState.selections || oldState
|
|
14891
|
+
return oldState.selections !== newState.selections || isVisibleTextLayoutChanged(oldState, newState);
|
|
14892
|
+
};
|
|
14893
|
+
const isVisibleTextLayoutChanged = (oldState, newState) => {
|
|
14894
|
+
return oldState.lines !== newState.lines || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.visibleLineIndices !== newState.visibleLineIndices || oldState.visibleViewLineIndices !== newState.visibleViewLineIndices || oldState.foldingRanges !== newState.foldingRanges || oldState.differences !== newState.differences || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.rowHeight !== newState.rowHeight || oldState.rtl !== newState.rtl || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width;
|
|
14313
14895
|
};
|
|
14314
14896
|
const shouldUpdateLightBulb = (oldState, newState) => oldState.diagnostics !== newState.diagnostics || oldState.languageId !== newState.languageId || oldState.selections !== newState.selections || oldState.uri !== newState.uri;
|
|
14315
14897
|
const shouldUpdateVisibleTextData = (oldState, newState) => {
|
|
@@ -14394,6 +14976,17 @@ const updateDerivedState = async (oldState, newState, deferGutterDecorations = f
|
|
|
14394
14976
|
bracketMatchInfos: await getVisibleBracketMatches(finalState)
|
|
14395
14977
|
};
|
|
14396
14978
|
}
|
|
14979
|
+
const documentHighlights = getRetainedDocumentHighlights(oldState, finalState);
|
|
14980
|
+
if (documentHighlights !== (oldState.documentHighlights || emptyDocumentHighlights) || documentHighlights.length > 0 && isVisibleTextLayoutChanged(oldState, finalState)) {
|
|
14981
|
+
const highlightedState = {
|
|
14982
|
+
...finalState,
|
|
14983
|
+
documentHighlights
|
|
14984
|
+
};
|
|
14985
|
+
finalState = {
|
|
14986
|
+
...highlightedState,
|
|
14987
|
+
documentHighlightInfos: await getVisibleDocumentHighlights(highlightedState)
|
|
14988
|
+
};
|
|
14989
|
+
}
|
|
14397
14990
|
if (shouldUpdateDiagnosticData(oldState, nextState)) {
|
|
14398
14991
|
const visualDecorations = await getVisibleDiagnostics(finalState, finalState.diagnostics ?? []);
|
|
14399
14992
|
finalState = {
|
|
@@ -14419,10 +15012,14 @@ const updateDerivedState = async (oldState, newState, deferGutterDecorations = f
|
|
|
14419
15012
|
gutterDecorations: await getEditorGutterDecorations(finalState)
|
|
14420
15013
|
};
|
|
14421
15014
|
}
|
|
14422
|
-
|
|
15015
|
+
|
|
15016
|
+
// Linked editing ranges are rendered as part of the text decoration layer.
|
|
15017
|
+
const linkedEditingDom = finalState.linkedEditing ? await getLinkedEditingVirtualDom(finalState) : [];
|
|
15018
|
+
if ((finalState.textDecorations?.length || 0) > 0 || (oldState.textDecorationDom?.length || 0) > 0 || linkedEditingDom.length > 0) {
|
|
15019
|
+
const textDecorationDom = await getTextDecorationsVirtualDom(finalState);
|
|
14423
15020
|
finalState = {
|
|
14424
15021
|
...finalState,
|
|
14425
|
-
textDecorationDom:
|
|
15022
|
+
textDecorationDom: linkedEditingDom.length > 0 ? [...textDecorationDom, ...linkedEditingDom] : textDecorationDom
|
|
14426
15023
|
};
|
|
14427
15024
|
}
|
|
14428
15025
|
if (!shouldUpdateSelectionData(oldState, nextState)) {
|
|
@@ -14517,16 +15114,16 @@ const pendingSaves = new Map();
|
|
|
14517
15114
|
const state$7 = {
|
|
14518
15115
|
nextToken: 0
|
|
14519
15116
|
};
|
|
14520
|
-
const run = async (uid, token, save) => {
|
|
15117
|
+
const run$1 = async (uid, token, save) => {
|
|
14521
15118
|
if (!isLatest(uid, token)) {
|
|
14522
15119
|
return;
|
|
14523
15120
|
}
|
|
14524
15121
|
await save(token);
|
|
14525
15122
|
};
|
|
14526
|
-
const schedule$
|
|
15123
|
+
const schedule$3 = (uid, save) => {
|
|
14527
15124
|
dispose$4(uid);
|
|
14528
15125
|
const token = ++state$7.nextToken;
|
|
14529
|
-
const timeout = setTimeout(run, autoSaveDelay, uid, token, save);
|
|
15126
|
+
const timeout = setTimeout(run$1, autoSaveDelay, uid, token, save);
|
|
14530
15127
|
pendingSaves.set(uid, {
|
|
14531
15128
|
timeout,
|
|
14532
15129
|
token
|
|
@@ -14614,9 +15211,9 @@ const toRows = (result, lineCount) => {
|
|
|
14614
15211
|
}
|
|
14615
15212
|
return rows;
|
|
14616
15213
|
};
|
|
14617
|
-
const request = async editor => {
|
|
15214
|
+
const request$3 = async editor => {
|
|
14618
15215
|
try {
|
|
14619
|
-
const result = await invoke$
|
|
15216
|
+
const result = await invoke$8(editor.applicationId, 'Extensions.executeCodeLensProviders', getDocument(editor));
|
|
14620
15217
|
if (!Array.isArray(result) || result.length === 0) {
|
|
14621
15218
|
return;
|
|
14622
15219
|
}
|
|
@@ -14647,9 +15244,9 @@ const request = async editor => {
|
|
|
14647
15244
|
// Code lenses are optional and should never interrupt editing.
|
|
14648
15245
|
}
|
|
14649
15246
|
};
|
|
14650
|
-
const requestIfChanged = (oldState, newState) => {
|
|
15247
|
+
const requestIfChanged$2 = (oldState, newState) => {
|
|
14651
15248
|
if (newState.codeLensEnabled && !newState.initial && !newState.largeFile && !newState.loadError && (oldState.initial || !oldState.codeLensEnabled || !sameDocument(oldState, newState))) {
|
|
14652
|
-
void request(newState);
|
|
15249
|
+
void request$3(newState);
|
|
14653
15250
|
}
|
|
14654
15251
|
};
|
|
14655
15252
|
|
|
@@ -15023,7 +15620,7 @@ const getFormattingEdits$1 = async editor => {
|
|
|
15023
15620
|
text: getText$1(editor),
|
|
15024
15621
|
uri: editor.uri
|
|
15025
15622
|
};
|
|
15026
|
-
return invoke$
|
|
15623
|
+
return invoke$8(editor.applicationId, 'Extensions.executeFormattingProvider', textDocument);
|
|
15027
15624
|
};
|
|
15028
15625
|
|
|
15029
15626
|
const expectedErrorMessage$1 = 'Failed to execute formatting provider: FormattingError:';
|
|
@@ -15033,7 +15630,7 @@ const isFormattingError = error => {
|
|
|
15033
15630
|
};
|
|
15034
15631
|
|
|
15035
15632
|
const dismissals$1 = new Map();
|
|
15036
|
-
const clear$
|
|
15633
|
+
const clear$4 = editorUid => {
|
|
15037
15634
|
const dismissal = dismissals$1.get(editorUid);
|
|
15038
15635
|
if (!dismissal) {
|
|
15039
15636
|
return;
|
|
@@ -15042,7 +15639,7 @@ const clear$3 = editorUid => {
|
|
|
15042
15639
|
dismissals$1.delete(editorUid);
|
|
15043
15640
|
};
|
|
15044
15641
|
const set$4 = (editorUid, dismissal) => {
|
|
15045
|
-
clear$
|
|
15642
|
+
clear$4(editorUid);
|
|
15046
15643
|
dismissals$1.set(editorUid, dismissal);
|
|
15047
15644
|
};
|
|
15048
15645
|
|
|
@@ -15333,7 +15930,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, _isErro
|
|
|
15333
15930
|
};
|
|
15334
15931
|
if (typeof editor.uid === 'number') {
|
|
15335
15932
|
const timeout = setTimeout(async () => {
|
|
15336
|
-
clear$
|
|
15933
|
+
clear$4(editor.uid);
|
|
15337
15934
|
const latestInstance = get$a(editor.uid);
|
|
15338
15935
|
if (!latestInstance) {
|
|
15339
15936
|
return;
|
|
@@ -15438,111 +16035,518 @@ const showFilePicker = async platform => {
|
|
|
15438
16035
|
if (canceled) {
|
|
15439
16036
|
return '';
|
|
15440
16037
|
}
|
|
15441
|
-
return filePath;
|
|
16038
|
+
return filePath;
|
|
16039
|
+
};
|
|
16040
|
+
|
|
16041
|
+
const saveUntitledFile = async (uri, content, platform, applicationId) => {
|
|
16042
|
+
const filePath = await showFilePicker(platform);
|
|
16043
|
+
if (!filePath) {
|
|
16044
|
+
return;
|
|
16045
|
+
}
|
|
16046
|
+
await invoke$a(applicationId, 'FileSystem.writeFile', filePath, content);
|
|
16047
|
+
await invoke$a(applicationId, 'Layout.handleWorkspaceRefresh');
|
|
16048
|
+
return filePath;
|
|
16049
|
+
};
|
|
16050
|
+
|
|
16051
|
+
const isPermissionDeniedError = error => {
|
|
16052
|
+
const errorCode = 'code' in error ? error.code : undefined;
|
|
16053
|
+
return errorCode === 'EACCES' || error.message.includes('EACCES:');
|
|
16054
|
+
};
|
|
16055
|
+
const showSaveErrorDialog = async error => {
|
|
16056
|
+
if (isPermissionDeniedError(error)) {
|
|
16057
|
+
await DialogWorker.invoke('ElectronDialog.showMessageBox', {
|
|
16058
|
+
buttons: ['OK'],
|
|
16059
|
+
defaultId: 0,
|
|
16060
|
+
message: "You don't have permission to save changes to this file.",
|
|
16061
|
+
title: 'Unable to Save File',
|
|
16062
|
+
type: 'error'
|
|
16063
|
+
});
|
|
16064
|
+
return;
|
|
16065
|
+
}
|
|
16066
|
+
await DialogWorker.invoke('ElectronDialog.showMessageBox', {
|
|
16067
|
+
buttons: ['OK'],
|
|
16068
|
+
defaultId: 0,
|
|
16069
|
+
detail: error.message,
|
|
16070
|
+
message: 'Saving the file failed.',
|
|
16071
|
+
title: 'Failed to Save File',
|
|
16072
|
+
type: 'error'
|
|
16073
|
+
});
|
|
16074
|
+
};
|
|
16075
|
+
|
|
16076
|
+
const save$1 = async (editor, skipFormatting = false) => {
|
|
16077
|
+
try {
|
|
16078
|
+
const {
|
|
16079
|
+
applicationId,
|
|
16080
|
+
platform,
|
|
16081
|
+
uri
|
|
16082
|
+
} = editor;
|
|
16083
|
+
if (!isUntitledFile(uri) && (await isReadonlyFile(uri, applicationId))) {
|
|
16084
|
+
return editor;
|
|
16085
|
+
}
|
|
16086
|
+
const shouldFormat = editor.formatOnSave && !skipFormatting;
|
|
16087
|
+
const formatBeforeSave = shouldFormat && editor.formatActions === 'pre-save';
|
|
16088
|
+
const editorToSave = formatBeforeSave ? await getNewEditor(editor) : editor;
|
|
16089
|
+
const content = applyLineEndings(getText$1(editorToSave), editorToSave.endOfLine);
|
|
16090
|
+
if (isUntitledFile(uri)) {
|
|
16091
|
+
const pickedFilePath = await saveUntitledFile(uri, content, platform, applicationId);
|
|
16092
|
+
if (pickedFilePath) {
|
|
16093
|
+
const savedEditor = {
|
|
16094
|
+
...editorToSave,
|
|
16095
|
+
uri: pickedFilePath
|
|
16096
|
+
};
|
|
16097
|
+
if (editor.modified || savedEditor.modified) {
|
|
16098
|
+
await notifyTabModifiedStatusChange(uri, false, applicationId);
|
|
16099
|
+
}
|
|
16100
|
+
return {
|
|
16101
|
+
...savedEditor,
|
|
16102
|
+
modified: false,
|
|
16103
|
+
uri: pickedFilePath,
|
|
16104
|
+
...(shouldFormat && !formatBeforeSave && {
|
|
16105
|
+
postSaveFormat: true
|
|
16106
|
+
})
|
|
16107
|
+
};
|
|
16108
|
+
}
|
|
16109
|
+
return editorToSave;
|
|
16110
|
+
}
|
|
16111
|
+
await saveNormalFile(uri, content, applicationId);
|
|
16112
|
+
if (editor.modified || editorToSave.modified) {
|
|
16113
|
+
await notifyTabModifiedStatusChange(uri, false, applicationId);
|
|
16114
|
+
}
|
|
16115
|
+
return {
|
|
16116
|
+
...editorToSave,
|
|
16117
|
+
modified: false,
|
|
16118
|
+
...(shouldFormat && !formatBeforeSave && {
|
|
16119
|
+
postSaveFormat: true
|
|
16120
|
+
})
|
|
16121
|
+
};
|
|
16122
|
+
} catch (error) {
|
|
16123
|
+
// @ts-ignore
|
|
16124
|
+
const betterError = new VError(error, `Failed to save file "${editor.uri}"`);
|
|
16125
|
+
await handleError$1(betterError);
|
|
16126
|
+
if (editor.platform === Electron) {
|
|
16127
|
+
try {
|
|
16128
|
+
await showSaveErrorDialog(betterError);
|
|
16129
|
+
} catch (dialogError) {
|
|
16130
|
+
await handleError$1(dialogError);
|
|
16131
|
+
}
|
|
16132
|
+
}
|
|
16133
|
+
return editor;
|
|
16134
|
+
}
|
|
16135
|
+
};
|
|
16136
|
+
|
|
16137
|
+
const editorDiagnosticEffect = {
|
|
16138
|
+
// TODO set effects delay / diagnostic delay
|
|
16139
|
+
apply(editor) {
|
|
16140
|
+
return updateDiagnostics(editor);
|
|
16141
|
+
},
|
|
16142
|
+
isActive: (oldEditor, newEditor) => !oldEditor.initial && !newEditor.loadError && newEditor.diagnosticsEnabled && (oldEditor.lines !== newEditor.lines || oldEditor.languageId !== newEditor.languageId)
|
|
16143
|
+
};
|
|
16144
|
+
|
|
16145
|
+
// Highlights are decorations for the visible viewport; ignore runaway provider results.
|
|
16146
|
+
const maxDocumentHighlights = 10_000;
|
|
16147
|
+
const getTextLength = lines => {
|
|
16148
|
+
let length = Math.max(0, lines.length - 1);
|
|
16149
|
+
for (const line of lines) {
|
|
16150
|
+
length += line.length;
|
|
16151
|
+
}
|
|
16152
|
+
return length;
|
|
16153
|
+
};
|
|
16154
|
+
const isValid = (value, textLength) => {
|
|
16155
|
+
if (!value || typeof value !== 'object') {
|
|
16156
|
+
return false;
|
|
16157
|
+
}
|
|
16158
|
+
const {
|
|
16159
|
+
endOffset,
|
|
16160
|
+
startOffset
|
|
16161
|
+
} = value;
|
|
16162
|
+
return Number.isSafeInteger(startOffset) && Number.isSafeInteger(endOffset) && startOffset >= 0 && startOffset < endOffset && endOffset <= textLength;
|
|
16163
|
+
};
|
|
16164
|
+
const getKind = kind => kind === 'read' || kind === 'write' ? kind : 'text';
|
|
16165
|
+
const toDocumentHighlights = (lines, result) => {
|
|
16166
|
+
if (!Array.isArray(result) || result.length === 0) {
|
|
16167
|
+
return emptyDocumentHighlights;
|
|
16168
|
+
}
|
|
16169
|
+
const textLength = getTextLength(lines);
|
|
16170
|
+
const valid = result.filter(item => isValid(item, textLength)).slice(0, maxDocumentHighlights);
|
|
16171
|
+
if (valid.length === 0) {
|
|
16172
|
+
return emptyDocumentHighlights;
|
|
16173
|
+
}
|
|
16174
|
+
const offsets = [...new Set(valid.flatMap(({
|
|
16175
|
+
endOffset,
|
|
16176
|
+
startOffset
|
|
16177
|
+
}) => [startOffset, endOffset]))].toSorted((a, b) => a - b);
|
|
16178
|
+
const positions = new Map();
|
|
16179
|
+
let rowIndex = 0;
|
|
16180
|
+
let lineStart = 0;
|
|
16181
|
+
for (const offset of offsets) {
|
|
16182
|
+
while (rowIndex < lines.length - 1 && offset > lineStart + lines[rowIndex].length) {
|
|
16183
|
+
lineStart += lines[rowIndex].length + 1;
|
|
16184
|
+
rowIndex++;
|
|
16185
|
+
}
|
|
16186
|
+
positions.set(offset, {
|
|
16187
|
+
columnIndex: offset - lineStart,
|
|
16188
|
+
rowIndex
|
|
16189
|
+
});
|
|
16190
|
+
}
|
|
16191
|
+
return valid.map(({
|
|
16192
|
+
endOffset,
|
|
16193
|
+
kind,
|
|
16194
|
+
startOffset
|
|
16195
|
+
}) => {
|
|
16196
|
+
const start = positions.get(startOffset);
|
|
16197
|
+
const end = positions.get(endOffset);
|
|
16198
|
+
return {
|
|
16199
|
+
endColumnIndex: end.columnIndex,
|
|
16200
|
+
endRowIndex: end.rowIndex,
|
|
16201
|
+
kind: getKind(kind),
|
|
16202
|
+
startColumnIndex: start.columnIndex,
|
|
16203
|
+
startRowIndex: start.rowIndex
|
|
16204
|
+
};
|
|
16205
|
+
});
|
|
16206
|
+
};
|
|
16207
|
+
const getDocumentHighlights = async (editor, offset) => {
|
|
16208
|
+
try {
|
|
16209
|
+
const result = await execute({
|
|
16210
|
+
args: [offset],
|
|
16211
|
+
editor,
|
|
16212
|
+
kind: 'document highlight',
|
|
16213
|
+
method: 'provideDocumentHighlights',
|
|
16214
|
+
noProviderFoundResult: emptyDocumentHighlights
|
|
16215
|
+
});
|
|
16216
|
+
return toDocumentHighlights(editor.lines, result);
|
|
16217
|
+
} catch {
|
|
16218
|
+
// Matching extensions may not register a document highlight provider.
|
|
16219
|
+
return emptyDocumentHighlights;
|
|
16220
|
+
}
|
|
16221
|
+
};
|
|
16222
|
+
|
|
16223
|
+
// Wait until cursor movement and typing settle before asking extensions.
|
|
16224
|
+
const documentHighlightDelay = 100;
|
|
16225
|
+
const timeouts$2 = new Map();
|
|
16226
|
+
const canRequest = editor => {
|
|
16227
|
+
const {
|
|
16228
|
+
documentHighlightsEnabled,
|
|
16229
|
+
initial,
|
|
16230
|
+
largeFile,
|
|
16231
|
+
loadError,
|
|
16232
|
+
selections
|
|
16233
|
+
} = editor;
|
|
16234
|
+
return Boolean(documentHighlightsEnabled) && !initial && !largeFile && !loadError && selections?.length === 4 && selections[0] === selections[2] && selections[1] === selections[3];
|
|
16235
|
+
};
|
|
16236
|
+
const selectionsEqual$1 = (left, right) => {
|
|
16237
|
+
if (left === right) {
|
|
16238
|
+
return true;
|
|
16239
|
+
}
|
|
16240
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
16241
|
+
};
|
|
16242
|
+
const highlightsEqual = (left = [], right) => {
|
|
16243
|
+
return left.length === right.length && left.every((highlight, index) => {
|
|
16244
|
+
const other = right[index];
|
|
16245
|
+
return highlight.kind === other.kind && highlight.startRowIndex === other.startRowIndex && highlight.startColumnIndex === other.startColumnIndex && highlight.endRowIndex === other.endRowIndex && highlight.endColumnIndex === other.endColumnIndex;
|
|
16246
|
+
});
|
|
16247
|
+
};
|
|
16248
|
+
const isSameRequest = (snapshot, current) => {
|
|
16249
|
+
return current.lines === snapshot.lines && current.uri === snapshot.uri && current.languageId === snapshot.languageId && current.lifecycle === snapshot.lifecycle && Boolean(current.documentHighlightsEnabled) && selectionsEqual$1(current.selections, snapshot.selections);
|
|
16250
|
+
};
|
|
16251
|
+
const request$2 = async uid => {
|
|
16252
|
+
const snapshot = get$a(uid)?.newState;
|
|
16253
|
+
if (!snapshot || !canRequest(snapshot)) {
|
|
16254
|
+
return;
|
|
16255
|
+
}
|
|
16256
|
+
const [rowIndex, columnIndex] = snapshot.selections;
|
|
16257
|
+
// A cursor placed past the end of a line must not resolve to an offset on the next line.
|
|
16258
|
+
const offset = offsetAt(snapshot, rowIndex, Math.min(columnIndex, snapshot.lines[rowIndex]?.length ?? 0));
|
|
16259
|
+
const documentHighlights = await getDocumentHighlights(snapshot, offset);
|
|
16260
|
+
try {
|
|
16261
|
+
const committed = await enqueue(uid, async () => {
|
|
16262
|
+
const current = get$a(uid)?.newState;
|
|
16263
|
+
if (!current || !isSameRequest(snapshot, current) || highlightsEqual(current.documentHighlights, documentHighlights)) {
|
|
16264
|
+
return false;
|
|
16265
|
+
}
|
|
16266
|
+
const nextState = await updateDerivedState(current, {
|
|
16267
|
+
...current,
|
|
16268
|
+
documentHighlights
|
|
16269
|
+
});
|
|
16270
|
+
const latest = get$a(uid);
|
|
16271
|
+
if (!latest || latest.newState !== current || current.lifecycle?.disposed) {
|
|
16272
|
+
return false;
|
|
16273
|
+
}
|
|
16274
|
+
set$b(uid, latest.oldState, nextState);
|
|
16275
|
+
return true;
|
|
16276
|
+
});
|
|
16277
|
+
if (committed) {
|
|
16278
|
+
await invoke$7('Editor.renderPending', uid);
|
|
16279
|
+
}
|
|
16280
|
+
} catch {
|
|
16281
|
+
// Document highlights are optional and should never interrupt editing.
|
|
16282
|
+
}
|
|
16283
|
+
};
|
|
16284
|
+
const cancel = uid => {
|
|
16285
|
+
const timeout = timeouts$2.get(uid);
|
|
16286
|
+
if (timeout !== undefined) {
|
|
16287
|
+
clearTimeout(timeout);
|
|
16288
|
+
timeouts$2.delete(uid);
|
|
16289
|
+
}
|
|
16290
|
+
};
|
|
16291
|
+
const scheduleIfChanged = (oldState, newState) => {
|
|
16292
|
+
const {
|
|
16293
|
+
uid
|
|
16294
|
+
} = newState;
|
|
16295
|
+
if (!canRequest(newState)) {
|
|
16296
|
+
cancel(uid);
|
|
16297
|
+
return;
|
|
16298
|
+
}
|
|
16299
|
+
if (!oldState.initial && oldState.documentHighlightsEnabled && oldState.lines === newState.lines && oldState.uri === newState.uri && selectionsEqual$1(oldState.selections, newState.selections)) {
|
|
16300
|
+
return;
|
|
16301
|
+
}
|
|
16302
|
+
cancel(uid);
|
|
16303
|
+
timeouts$2.set(uid, setTimeout(() => {
|
|
16304
|
+
timeouts$2.delete(uid);
|
|
16305
|
+
void request$2(uid);
|
|
16306
|
+
}, documentHighlightDelay));
|
|
16307
|
+
};
|
|
16308
|
+
|
|
16309
|
+
const isValidLink = (link, textLength) => Boolean(link) && Number.isSafeInteger(link.startOffset) && Number.isSafeInteger(link.endOffset) && link.startOffset >= 0 && link.startOffset < link.endOffset && link.endOffset <= textLength && typeof link.target === 'string' && link.target.length > 0;
|
|
16310
|
+
|
|
16311
|
+
/**
|
|
16312
|
+
* Converts provider offsets (end exclusive) into row/column ranges in one pass over the lines.
|
|
16313
|
+
*/
|
|
16314
|
+
const toDocumentLinks = (lines, result) => {
|
|
16315
|
+
if (!Array.isArray(result) || result.length === 0) {
|
|
16316
|
+
return [];
|
|
16317
|
+
}
|
|
16318
|
+
let textLength = 0;
|
|
16319
|
+
for (const line of lines) {
|
|
16320
|
+
textLength += line.length + 1;
|
|
16321
|
+
}
|
|
16322
|
+
textLength = Math.max(textLength - 1, 0);
|
|
16323
|
+
const links = result.filter(link => isValidLink(link, textLength)).toSorted((a, b) => a.startOffset - b.startOffset);
|
|
16324
|
+
const documentLinks = [];
|
|
16325
|
+
let rowIndex = 0;
|
|
16326
|
+
let lineStart = 0;
|
|
16327
|
+
const positionAt = offset => {
|
|
16328
|
+
while (rowIndex < lines.length - 1 && offset > lineStart + lines[rowIndex].length) {
|
|
16329
|
+
lineStart += lines[rowIndex].length + 1;
|
|
16330
|
+
rowIndex++;
|
|
16331
|
+
}
|
|
16332
|
+
return {
|
|
16333
|
+
columnIndex: offset - lineStart,
|
|
16334
|
+
rowIndex
|
|
16335
|
+
};
|
|
16336
|
+
};
|
|
16337
|
+
for (const link of links) {
|
|
16338
|
+
// Ends are not monotonic, so convert them with a separate cursor copy.
|
|
16339
|
+
const start = positionAt(link.startOffset);
|
|
16340
|
+
const savedRowIndex = rowIndex;
|
|
16341
|
+
const savedLineStart = lineStart;
|
|
16342
|
+
const end = positionAt(link.endOffset);
|
|
16343
|
+
rowIndex = savedRowIndex;
|
|
16344
|
+
lineStart = savedLineStart;
|
|
16345
|
+
documentLinks.push({
|
|
16346
|
+
columnIndex: start.columnIndex,
|
|
16347
|
+
endColumnIndex: end.columnIndex,
|
|
16348
|
+
endRowIndex: end.rowIndex,
|
|
16349
|
+
rowIndex: start.rowIndex,
|
|
16350
|
+
target: link.target,
|
|
16351
|
+
...(typeof link.tooltip === 'string' && {
|
|
16352
|
+
tooltip: link.tooltip
|
|
16353
|
+
})
|
|
16354
|
+
});
|
|
16355
|
+
}
|
|
16356
|
+
return documentLinks;
|
|
16357
|
+
};
|
|
16358
|
+
const getDocumentLinks = async editor => {
|
|
16359
|
+
try {
|
|
16360
|
+
const result = await execute({
|
|
16361
|
+
args: [],
|
|
16362
|
+
editor,
|
|
16363
|
+
kind: 'document link',
|
|
16364
|
+
method: 'provideDocumentLinks',
|
|
16365
|
+
noProviderFoundResult: []
|
|
16366
|
+
});
|
|
16367
|
+
return toDocumentLinks(editor.lines, result);
|
|
16368
|
+
} catch {
|
|
16369
|
+
// Extensions activated for the language may not provide document links.
|
|
16370
|
+
return [];
|
|
16371
|
+
}
|
|
16372
|
+
};
|
|
16373
|
+
|
|
16374
|
+
const documentLinksDelay = 250;
|
|
16375
|
+
const timeouts$1 = new Map();
|
|
16376
|
+
const linksEqual = (left, right) => left.length === right.length && left.every((link, index) => {
|
|
16377
|
+
const other = right[index];
|
|
16378
|
+
return link.rowIndex === other.rowIndex && link.columnIndex === other.columnIndex && link.endRowIndex === other.endRowIndex && link.endColumnIndex === other.endColumnIndex && link.target === other.target && link.tooltip === other.tooltip;
|
|
16379
|
+
});
|
|
16380
|
+
|
|
16381
|
+
/**
|
|
16382
|
+
* Replaces the link decorations of an editor, keeping other decorations such as diagnostics.
|
|
16383
|
+
*/
|
|
16384
|
+
const updateLinkDecorations = editor => {
|
|
16385
|
+
const linkDecorations = detectAllLinksAsDecorations(editor);
|
|
16386
|
+
const decorations = editor.decorations || [];
|
|
16387
|
+
const entries = [];
|
|
16388
|
+
for (let i = 0; i < decorations.length; i += 4) {
|
|
16389
|
+
if (decorations[i + 2] !== Link) {
|
|
16390
|
+
entries.push(decorations.slice(i, i + 4));
|
|
16391
|
+
}
|
|
16392
|
+
}
|
|
16393
|
+
if (entries.length === 0) {
|
|
16394
|
+
return linkDecorations;
|
|
16395
|
+
}
|
|
16396
|
+
for (let i = 0; i < linkDecorations.length; i += 4) {
|
|
16397
|
+
entries.push(linkDecorations.slice(i, i + 4));
|
|
16398
|
+
}
|
|
16399
|
+
return entries.toSorted((a, b) => a[0] - b[0]).flat();
|
|
16400
|
+
};
|
|
16401
|
+
const commit = async (editor, documentLinks) => {
|
|
16402
|
+
const committed = await enqueue(editor.uid, async () => {
|
|
16403
|
+
const current = get$a(editor.uid);
|
|
16404
|
+
if (!current || editor.lifecycle?.disposed || !sameDocument(editor, current.newState)) {
|
|
16405
|
+
return false;
|
|
16406
|
+
}
|
|
16407
|
+
const currentLinks = current.newState.documentLinks ?? [];
|
|
16408
|
+
if (linksEqual(currentLinks, documentLinks)) {
|
|
16409
|
+
return false;
|
|
16410
|
+
}
|
|
16411
|
+
const withLinks = {
|
|
16412
|
+
...current.newState,
|
|
16413
|
+
documentLinks
|
|
16414
|
+
};
|
|
16415
|
+
const nextState = await updateDerivedState(current.newState, {
|
|
16416
|
+
...withLinks,
|
|
16417
|
+
decorations: updateLinkDecorations(withLinks)
|
|
16418
|
+
});
|
|
16419
|
+
const latest = get$a(editor.uid);
|
|
16420
|
+
if (!latest || latest.newState !== current.newState || editor.lifecycle?.disposed) {
|
|
16421
|
+
return false;
|
|
16422
|
+
}
|
|
16423
|
+
set$b(editor.uid, latest.oldState, nextState);
|
|
16424
|
+
return true;
|
|
16425
|
+
});
|
|
16426
|
+
return committed === true;
|
|
16427
|
+
};
|
|
16428
|
+
const request$1 = async editor => {
|
|
16429
|
+
try {
|
|
16430
|
+
const documentLinks = await getDocumentLinks(editor);
|
|
16431
|
+
const committed = await commit(editor, documentLinks);
|
|
16432
|
+
if (committed) {
|
|
16433
|
+
await invoke$7('Editor.renderPending', editor.uid);
|
|
16434
|
+
}
|
|
16435
|
+
} catch {
|
|
16436
|
+
// Document links are optional and should never interrupt editing.
|
|
16437
|
+
}
|
|
15442
16438
|
};
|
|
15443
|
-
|
|
15444
|
-
|
|
15445
|
-
const
|
|
15446
|
-
if (!
|
|
16439
|
+
const run = uid => {
|
|
16440
|
+
timeouts$1.delete(uid);
|
|
16441
|
+
const editor = get$a(uid)?.newState;
|
|
16442
|
+
if (!editor || editor.initial || editor.largeFile || editor.loadError || editor.lifecycle?.disposed) {
|
|
15447
16443
|
return;
|
|
15448
16444
|
}
|
|
15449
|
-
|
|
15450
|
-
await invoke$a(applicationId, 'Layout.handleWorkspaceRefresh');
|
|
15451
|
-
return filePath;
|
|
16445
|
+
void request$1(editor);
|
|
15452
16446
|
};
|
|
15453
|
-
|
|
15454
|
-
|
|
15455
|
-
|
|
15456
|
-
return errorCode === 'EACCES' || error.message.includes('EACCES:');
|
|
16447
|
+
const schedule$2 = (uid, delay) => {
|
|
16448
|
+
clear$3(uid);
|
|
16449
|
+
timeouts$1.set(uid, setTimeout(run, delay, uid));
|
|
15457
16450
|
};
|
|
15458
|
-
const
|
|
15459
|
-
|
|
15460
|
-
|
|
15461
|
-
|
|
15462
|
-
|
|
15463
|
-
|
|
15464
|
-
|
|
15465
|
-
|
|
15466
|
-
|
|
16451
|
+
const clear$3 = uid => {
|
|
16452
|
+
const timeout = timeouts$1.get(uid);
|
|
16453
|
+
if (timeout !== undefined) {
|
|
16454
|
+
clearTimeout(timeout);
|
|
16455
|
+
timeouts$1.delete(uid);
|
|
16456
|
+
}
|
|
16457
|
+
};
|
|
16458
|
+
const requestIfChanged$1 = (oldState, newState) => {
|
|
16459
|
+
if (newState.initial || newState.largeFile || newState.loadError) {
|
|
15467
16460
|
return;
|
|
15468
16461
|
}
|
|
15469
|
-
|
|
15470
|
-
|
|
15471
|
-
|
|
15472
|
-
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
});
|
|
16462
|
+
if (oldState.initial) {
|
|
16463
|
+
schedule$2(newState.uid, 0);
|
|
16464
|
+
return;
|
|
16465
|
+
}
|
|
16466
|
+
if (!sameDocument(oldState, newState)) {
|
|
16467
|
+
schedule$2(newState.uid, documentLinksDelay);
|
|
16468
|
+
}
|
|
15477
16469
|
};
|
|
15478
16470
|
|
|
15479
|
-
const
|
|
16471
|
+
const requestDelay = 100;
|
|
16472
|
+
const timeouts = new Map();
|
|
16473
|
+
const sameSelections = (left, right) => left.length === right.length && left.every((value, i) => value === right[i]);
|
|
16474
|
+
const getLinkedEditing = async editor => {
|
|
16475
|
+
const [rowIndex, columnIndex] = getSelectionPairs(editor.selections, 0);
|
|
16476
|
+
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
15480
16477
|
try {
|
|
15481
|
-
const {
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
const editorToSave = formatBeforeSave ? await getNewEditor(editor) : editor;
|
|
15492
|
-
const content = applyLineEndings(getText$1(editorToSave), editorToSave.endOfLine);
|
|
15493
|
-
if (isUntitledFile(uri)) {
|
|
15494
|
-
const pickedFilePath = await saveUntitledFile(uri, content, platform, applicationId);
|
|
15495
|
-
if (pickedFilePath) {
|
|
15496
|
-
const savedEditor = {
|
|
15497
|
-
...editorToSave,
|
|
15498
|
-
uri: pickedFilePath
|
|
15499
|
-
};
|
|
15500
|
-
if (editor.modified || savedEditor.modified) {
|
|
15501
|
-
await notifyTabModifiedStatusChange(uri, false, applicationId);
|
|
15502
|
-
}
|
|
15503
|
-
return {
|
|
15504
|
-
...savedEditor,
|
|
15505
|
-
modified: false,
|
|
15506
|
-
uri: pickedFilePath,
|
|
15507
|
-
...(shouldFormat && !formatBeforeSave && {
|
|
15508
|
-
postSaveFormat: true
|
|
15509
|
-
})
|
|
15510
|
-
};
|
|
15511
|
-
}
|
|
15512
|
-
return editorToSave;
|
|
15513
|
-
}
|
|
15514
|
-
await saveNormalFile(uri, content, applicationId);
|
|
15515
|
-
if (editor.modified || editorToSave.modified) {
|
|
15516
|
-
await notifyTabModifiedStatusChange(uri, false, applicationId);
|
|
16478
|
+
const result = await execute({
|
|
16479
|
+
args: [offset],
|
|
16480
|
+
editor,
|
|
16481
|
+
kind: 'linked editing range',
|
|
16482
|
+
method: 'provideLinkedEditingRanges',
|
|
16483
|
+
noProviderFoundResult: undefined
|
|
16484
|
+
});
|
|
16485
|
+
const ranges = toLinkedEditingRanges(editor.lines, result?.ranges, offset);
|
|
16486
|
+
if (!ranges) {
|
|
16487
|
+
return undefined;
|
|
15517
16488
|
}
|
|
15518
16489
|
return {
|
|
15519
|
-
|
|
15520
|
-
|
|
15521
|
-
|
|
15522
|
-
postSaveFormat: true
|
|
15523
|
-
})
|
|
16490
|
+
lines: editor.lines,
|
|
16491
|
+
ranges,
|
|
16492
|
+
wordPattern: parseWordPattern(result.wordPattern)
|
|
15524
16493
|
};
|
|
15525
|
-
} catch
|
|
15526
|
-
//
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
16494
|
+
} catch {
|
|
16495
|
+
// Linked editing is optional; extensions without this provider throw here.
|
|
16496
|
+
return undefined;
|
|
16497
|
+
}
|
|
16498
|
+
};
|
|
16499
|
+
const request = async uid => {
|
|
16500
|
+
const snapshot = await enqueue(uid, async () => get$a(uid)?.newState);
|
|
16501
|
+
if (!snapshot || !snapshot.linkedEditingEnabled || snapshot.selections.length !== 4 || snapshot.lifecycle?.disposed) {
|
|
16502
|
+
return;
|
|
16503
|
+
}
|
|
16504
|
+
const linkedEditing = await getLinkedEditing(snapshot);
|
|
16505
|
+
const committed = await enqueue(uid, async () => {
|
|
16506
|
+
const current = get$a(uid)?.newState;
|
|
16507
|
+
if (!current || current.lines !== snapshot.lines || current.lifecycle !== snapshot.lifecycle || !sameSelections(current.selections, snapshot.selections) || !linkedEditing && !current.linkedEditing) {
|
|
16508
|
+
return false;
|
|
15535
16509
|
}
|
|
15536
|
-
|
|
16510
|
+
const nextState = await updateDerivedState(current, {
|
|
16511
|
+
...current,
|
|
16512
|
+
linkedEditing
|
|
16513
|
+
});
|
|
16514
|
+
const latest = get$a(uid);
|
|
16515
|
+
if (!latest || latest.newState !== current || current.lifecycle?.disposed) {
|
|
16516
|
+
return false;
|
|
16517
|
+
}
|
|
16518
|
+
set$b(uid, latest.oldState, nextState);
|
|
16519
|
+
return true;
|
|
16520
|
+
});
|
|
16521
|
+
if (committed) {
|
|
16522
|
+
await invoke$7('Editor.renderPending', uid);
|
|
15537
16523
|
}
|
|
15538
16524
|
};
|
|
16525
|
+
const schedule$1 = uid => {
|
|
16526
|
+
clearTimeout(timeouts.get(uid));
|
|
16527
|
+
timeouts.set(uid, setTimeout(() => {
|
|
16528
|
+
timeouts.delete(uid);
|
|
16529
|
+
void request(uid).catch(() => {
|
|
16530
|
+
// ignore, linked editing must never interrupt editing
|
|
16531
|
+
});
|
|
16532
|
+
}, requestDelay));
|
|
16533
|
+
};
|
|
15539
16534
|
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
16535
|
+
/**
|
|
16536
|
+
* Fetches linked editing ranges (debounced) after the cursor or the document changed,
|
|
16537
|
+
* unless the cursor is still inside the current linked ranges.
|
|
16538
|
+
*/
|
|
16539
|
+
const requestIfChanged = (oldState, newState) => {
|
|
16540
|
+
if (newState.linkedEditingEnabled !== true || newState.initial || newState.largeFile || newState.loadError || !newState.selections || newState.selections.length !== 4) {
|
|
16541
|
+
return;
|
|
16542
|
+
}
|
|
16543
|
+
if (oldState.lines === newState.lines && oldState.selections === newState.selections && !oldState.initial) {
|
|
16544
|
+
return;
|
|
16545
|
+
}
|
|
16546
|
+
if (getActiveRanges(newState)) {
|
|
16547
|
+
return;
|
|
16548
|
+
}
|
|
16549
|
+
schedule$1(newState.uid);
|
|
15546
16550
|
};
|
|
15547
16551
|
|
|
15548
16552
|
const getOffset = (lines, rowIndex, columnIndex) => {
|
|
@@ -15851,6 +16855,9 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
|
|
|
15851
16855
|
if (editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
|
|
15852
16856
|
void editorDiagnosticEffect.apply(newEditorWithDerivedState);
|
|
15853
16857
|
}
|
|
16858
|
+
requestIfChanged$2(state, newEditorWithDerivedState);
|
|
16859
|
+
requestIfChanged$1(state, newEditorWithDerivedState);
|
|
16860
|
+
scheduleIfChanged(state, newEditorWithDerivedState);
|
|
15854
16861
|
requestIfChanged(state, newEditorWithDerivedState);
|
|
15855
16862
|
const finalEditor = newEditorWithDerivedState;
|
|
15856
16863
|
if (deferGutterDecorations) {
|
|
@@ -15873,6 +16880,7 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
|
|
|
15873
16880
|
...editor,
|
|
15874
16881
|
decorations: finalEditor.decorations,
|
|
15875
16882
|
diagnostics: finalEditor.diagnostics,
|
|
16883
|
+
documentLinks: finalEditor.documentLinks ?? [],
|
|
15876
16884
|
endOfLine: finalEditor.endOfLine,
|
|
15877
16885
|
incrementalEdits: emptyIncrementalEdits,
|
|
15878
16886
|
insertSpaces: finalEditor.insertSpaces,
|
|
@@ -15888,7 +16896,8 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
|
|
|
15888
16896
|
continue;
|
|
15889
16897
|
}
|
|
15890
16898
|
set$b(otherUid, latest.oldState, synchronizedEditor);
|
|
15891
|
-
requestIfChanged(editor, synchronizedEditor);
|
|
16899
|
+
requestIfChanged$2(editor, synchronizedEditor);
|
|
16900
|
+
requestIfChanged$1(editor, synchronizedEditor);
|
|
15892
16901
|
if (deferGutterDecorations) {
|
|
15893
16902
|
schedule(synchronizedEditor);
|
|
15894
16903
|
}
|
|
@@ -15901,7 +16910,7 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
|
|
|
15901
16910
|
setTimeout(() => void formatAfterSave(uid, finalEditor), 0);
|
|
15902
16911
|
}
|
|
15903
16912
|
if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
|
|
15904
|
-
schedule$
|
|
16913
|
+
schedule$3(uid, token => saveAfterDelay(uid, token));
|
|
15905
16914
|
} else if (modified && !finalEditor.modified) {
|
|
15906
16915
|
dispose$4(uid);
|
|
15907
16916
|
}
|
|
@@ -16351,7 +17360,7 @@ const getLanguageId$1 = (uri, languages) => {
|
|
|
16351
17360
|
const getLanguages = async (platform, assetDir, applicationId) => {
|
|
16352
17361
|
number(platform);
|
|
16353
17362
|
string(assetDir);
|
|
16354
|
-
return invoke$
|
|
17363
|
+
return invoke$8(applicationId, 'Extensions.getLanguages', platform, assetDir);
|
|
16355
17364
|
};
|
|
16356
17365
|
|
|
16357
17366
|
const loaded = Object.create(null);
|
|
@@ -16671,7 +17680,7 @@ const isEqual$3 = (oldState, newState) => {
|
|
|
16671
17680
|
};
|
|
16672
17681
|
|
|
16673
17682
|
const isEqual$2 = (oldState, newState) => {
|
|
16674
|
-
return oldState.textDecorationDom === newState.textDecorationDom && oldState.breadcrumbFileIcon === newState.breadcrumbFileIcon && oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.focused === newState.focused && oldState.gutterDecorations === newState.gutterDecorations && oldState.highlightActiveLineNumber === newState.highlightActiveLineNumber && oldState.highlightedLine === newState.highlightedLine && oldState.problemsHighlightedRow === newState.problemsHighlightedRow && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.visibleViewLineIndices === newState.visibleViewLineIndices && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.deltaX === newState.deltaX && oldState.width === newState.width && oldState.gutterWidth === newState.gutterWidth && oldState.longestLineWidth === newState.longestLineWidth && oldState.minimumSliderSize === newState.minimumSliderSize && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
|
|
17683
|
+
return oldState.textDecorationDom === newState.textDecorationDom && oldState.breadcrumbFileIcon === newState.breadcrumbFileIcon && oldState.breadcrumbsEnabled === newState.breadcrumbsEnabled && oldState.breakPoints === newState.breakPoints && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.documentHighlightInfos === newState.documentHighlightInfos && oldState.cursorInfos === newState.cursorInfos && oldState.diagnostics === newState.diagnostics && oldState.documentSymbols === newState.documentSymbols && oldState.endOfLineDecorations === newState.endOfLineDecorations && oldState.focused === newState.focused && oldState.gutterDecorations === newState.gutterDecorations && oldState.highlightActiveLineNumber === newState.highlightActiveLineNumber && oldState.highlightedLine === newState.highlightedLine && oldState.problemsHighlightedRow === newState.problemsHighlightedRow && oldState.lineNumbers === newState.lineNumbers && oldState.loadError === newState.loadError && oldState.textInfos === newState.textInfos && oldState.visibleViewLineIndices === newState.visibleViewLineIndices && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.deltaX === newState.deltaX && oldState.width === newState.width && oldState.gutterWidth === newState.gutterWidth && oldState.longestLineWidth === newState.longestLineWidth && oldState.minimumSliderSize === newState.minimumSliderSize && oldState.selectionInfos === newState.selectionInfos && oldState.selections === newState.selections && oldState.workspaceUri === newState.workspaceUri;
|
|
16675
17684
|
};
|
|
16676
17685
|
|
|
16677
17686
|
const isEqual$1 = (oldState, newState) => {
|
|
@@ -16869,9 +17878,11 @@ const disposeEditor = async editorUid => {
|
|
|
16869
17878
|
}
|
|
16870
17879
|
dispose$1(editorUid);
|
|
16871
17880
|
dispose$4(editorUid);
|
|
17881
|
+
clear$3(editorUid);
|
|
17882
|
+
cancel(editorUid);
|
|
16872
17883
|
clear$1(editorUid);
|
|
16873
17884
|
clear$2(editorUid);
|
|
16874
|
-
clear$
|
|
17885
|
+
clear$4(editorUid);
|
|
16875
17886
|
dispose$3(editorUid);
|
|
16876
17887
|
const pending = [];
|
|
16877
17888
|
if (getEnabled$1()) {
|
|
@@ -17324,7 +18335,7 @@ const activateCodeLens = async (state, rowIndex, lensId) => {
|
|
|
17324
18335
|
}
|
|
17325
18336
|
const document = getDocument(state);
|
|
17326
18337
|
try {
|
|
17327
|
-
const edit = await invoke$
|
|
18338
|
+
const edit = await invoke$8(applicationId, 'Extensions.resolveCodeLens', document, lens.extensionId, lens.providerId, lens.action);
|
|
17328
18339
|
if (!edit || !Number.isSafeInteger(edit.offset) || !Number.isSafeInteger(edit.deleted) || edit.offset < 0 || edit.deleted < 0 || edit.offset + edit.deleted > document.text.length || typeof edit.inserted !== 'string' || /[\r\n]/.test(edit.inserted)) {
|
|
17329
18340
|
return state;
|
|
17330
18341
|
}
|
|
@@ -19142,24 +20153,74 @@ const findAllReferences$1 = async editor => {
|
|
|
19142
20153
|
return editor;
|
|
19143
20154
|
};
|
|
19144
20155
|
|
|
19145
|
-
const
|
|
20156
|
+
const isValidRow = value => {
|
|
20157
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
20158
|
+
};
|
|
20159
|
+
const normalizeRanges = (result, lineCount) => {
|
|
20160
|
+
if (!Array.isArray(result)) {
|
|
20161
|
+
return [];
|
|
20162
|
+
}
|
|
20163
|
+
const ranges = [];
|
|
20164
|
+
for (const item of result) {
|
|
20165
|
+
if (!item || typeof item !== 'object') {
|
|
20166
|
+
continue;
|
|
20167
|
+
}
|
|
20168
|
+
const {
|
|
20169
|
+
end,
|
|
20170
|
+
start
|
|
20171
|
+
} = item;
|
|
20172
|
+
if (!isValidRow(start) || !isValidRow(end)) {
|
|
20173
|
+
continue;
|
|
20174
|
+
}
|
|
20175
|
+
const clampedEnd = Math.min(end, lineCount - 1);
|
|
20176
|
+
if (start < clampedEnd) {
|
|
20177
|
+
ranges.push({
|
|
20178
|
+
end: clampedEnd,
|
|
20179
|
+
start
|
|
20180
|
+
});
|
|
20181
|
+
}
|
|
20182
|
+
}
|
|
20183
|
+
return ranges;
|
|
20184
|
+
};
|
|
20185
|
+
const getFoldingRanges = async editor => {
|
|
20186
|
+
try {
|
|
20187
|
+
const result = await execute({
|
|
20188
|
+
args: [],
|
|
20189
|
+
editor,
|
|
20190
|
+
kind: 'folding range',
|
|
20191
|
+
method: 'provideFoldingRanges',
|
|
20192
|
+
noProviderFoundResult: []
|
|
20193
|
+
});
|
|
20194
|
+
return normalizeRanges(result, editor.lines.length);
|
|
20195
|
+
} catch {
|
|
20196
|
+
// An extension can match the language without registering a folding range provider.
|
|
20197
|
+
return [];
|
|
20198
|
+
}
|
|
20199
|
+
};
|
|
20200
|
+
|
|
20201
|
+
const getAvailableRanges = async editor => {
|
|
20202
|
+
const providerRanges = await getFoldingRanges(editor);
|
|
20203
|
+
if (providerRanges.length > 0) {
|
|
20204
|
+
return providerRanges;
|
|
20205
|
+
}
|
|
20206
|
+
return findRanges(editor.lines);
|
|
20207
|
+
};
|
|
20208
|
+
const getContainingRange = (ranges, startRow, endRow) => {
|
|
20209
|
+
for (const range of ranges) {
|
|
20210
|
+
if (startRow >= range.start && endRow <= range.end) {
|
|
20211
|
+
return range;
|
|
20212
|
+
}
|
|
20213
|
+
}
|
|
20214
|
+
return undefined;
|
|
20215
|
+
};
|
|
20216
|
+
const applyFoldingRanges = (editor, foldingRanges) => {
|
|
19146
20217
|
const {
|
|
19147
|
-
foldingRanges = [],
|
|
19148
20218
|
lines,
|
|
19149
|
-
primarySelectionIndex = 0,
|
|
19150
20219
|
selections
|
|
19151
20220
|
} = editor;
|
|
19152
|
-
const rowIndex = selections[primarySelectionIndex];
|
|
19153
|
-
const range = findRange(lines, rowIndex);
|
|
19154
|
-
if (!range) {
|
|
19155
|
-
return editor;
|
|
19156
|
-
}
|
|
19157
|
-
const newRanges = addRange(foldingRanges, range);
|
|
19158
|
-
if (newRanges === foldingRanges) {
|
|
19159
|
-
return editor;
|
|
19160
|
-
}
|
|
19161
20221
|
const newSelections = map(selections, (result, index, startRow, startColumn, endRow, endColumn) => {
|
|
19162
|
-
|
|
20222
|
+
const range = getContainingRange(foldingRanges, startRow, endRow);
|
|
20223
|
+
if (range) {
|
|
19163
20224
|
moveRangeToPosition$1(result, index, range.start, Math.min(endColumn, lines[range.start].length));
|
|
19164
20225
|
return;
|
|
19165
20226
|
}
|
|
@@ -19171,7 +20232,38 @@ const fold$1 = editor => {
|
|
|
19171
20232
|
return updateLayout({
|
|
19172
20233
|
...editor,
|
|
19173
20234
|
selections: newSelections
|
|
19174
|
-
},
|
|
20235
|
+
}, foldingRanges);
|
|
20236
|
+
};
|
|
20237
|
+
|
|
20238
|
+
const fold$1 = async editor => {
|
|
20239
|
+
const {
|
|
20240
|
+
foldingRanges = [],
|
|
20241
|
+
primarySelectionIndex = 0,
|
|
20242
|
+
selections
|
|
20243
|
+
} = editor;
|
|
20244
|
+
const rowIndex = selections[primarySelectionIndex];
|
|
20245
|
+
const ranges = await getAvailableRanges(editor);
|
|
20246
|
+
const range = findInnermostRange(ranges, rowIndex);
|
|
20247
|
+
if (!range) {
|
|
20248
|
+
return editor;
|
|
20249
|
+
}
|
|
20250
|
+
const newRanges = addRange(foldingRanges, range);
|
|
20251
|
+
if (newRanges === foldingRanges) {
|
|
20252
|
+
return editor;
|
|
20253
|
+
}
|
|
20254
|
+
return applyFoldingRanges(editor, newRanges);
|
|
20255
|
+
};
|
|
20256
|
+
|
|
20257
|
+
const foldAll$1 = async editor => {
|
|
20258
|
+
const {
|
|
20259
|
+
foldingRanges = []
|
|
20260
|
+
} = editor;
|
|
20261
|
+
const ranges = await getAvailableRanges(editor);
|
|
20262
|
+
if (ranges.length === 0) {
|
|
20263
|
+
return editor;
|
|
20264
|
+
}
|
|
20265
|
+
const newRanges = getOutermostRanges([...foldingRanges, ...ranges]);
|
|
20266
|
+
return applyFoldingRanges(editor, newRanges);
|
|
19175
20267
|
};
|
|
19176
20268
|
|
|
19177
20269
|
/* eslint-disable sonarjs/super-linear-regex */
|
|
@@ -19299,6 +20391,7 @@ const EscapeToClose = 'Escape to close';
|
|
|
19299
20391
|
const FindAllImplementations = 'Find All Implementations';
|
|
19300
20392
|
const FindAllReferences = 'Find All References';
|
|
19301
20393
|
const Fold = 'Editor: Fold';
|
|
20394
|
+
const FoldAll = 'Editor: Fold All';
|
|
19302
20395
|
const FormatDocument = 'Format Document';
|
|
19303
20396
|
const GoToDefinition = 'Go to Definition';
|
|
19304
20397
|
const GoToBracket = 'Go to Bracket';
|
|
@@ -19317,6 +20410,7 @@ const ToggleBlockComment = 'Toggle Block Comment';
|
|
|
19317
20410
|
const ToggleBreakpoint = 'Toggle Breakpoint';
|
|
19318
20411
|
const Undo = 'Undo';
|
|
19319
20412
|
const Unfold = 'Editor: Unfold';
|
|
20413
|
+
const UnfoldAll = 'Editor: Unfold All';
|
|
19320
20414
|
const ViewToggleMinimap = 'View: Toggle Minimap';
|
|
19321
20415
|
|
|
19322
20416
|
const goToDefinition$1 = () => {
|
|
@@ -19365,6 +20459,9 @@ const findAllReferences = () => {
|
|
|
19365
20459
|
const fold = () => {
|
|
19366
20460
|
return i18nString(Fold);
|
|
19367
20461
|
};
|
|
20462
|
+
const foldAll = () => {
|
|
20463
|
+
return i18nString(FoldAll);
|
|
20464
|
+
};
|
|
19368
20465
|
const findAllImplementations = () => {
|
|
19369
20466
|
return i18nString(FindAllImplementations);
|
|
19370
20467
|
};
|
|
@@ -19392,6 +20489,9 @@ const redo$1 = () => {
|
|
|
19392
20489
|
const unfold$1 = () => {
|
|
19393
20490
|
return i18nString(Unfold);
|
|
19394
20491
|
};
|
|
20492
|
+
const unfoldAll$1 = () => {
|
|
20493
|
+
return i18nString(UnfoldAll);
|
|
20494
|
+
};
|
|
19395
20495
|
const toggleBlockComment$1 = () => {
|
|
19396
20496
|
return i18nString(ToggleBlockComment);
|
|
19397
20497
|
};
|
|
@@ -19622,6 +20722,16 @@ const openExternal = async (url, platform) => {
|
|
|
19622
20722
|
await OpenerWorker.openUrl(url, platform);
|
|
19623
20723
|
};
|
|
19624
20724
|
|
|
20725
|
+
const EXTERNAL_TARGET_PATTERN = /^(?:https?:|mailto:)/i;
|
|
20726
|
+
const isExternalTarget = target => EXTERNAL_TARGET_PATTERN.test(target);
|
|
20727
|
+
const openDocumentLink = async (link, platform) => {
|
|
20728
|
+
if (isExternalTarget(link.target)) {
|
|
20729
|
+
await openExternal(link.target, platform);
|
|
20730
|
+
return;
|
|
20731
|
+
}
|
|
20732
|
+
await RendererWorker.openUri(link.target, true);
|
|
20733
|
+
};
|
|
20734
|
+
|
|
19625
20735
|
// TODO first change cursor position, then run go to definition
|
|
19626
20736
|
// cursor should appear at mousedown position immediately
|
|
19627
20737
|
const handleSingleClickWithAlt = async (editor, position) => {
|
|
@@ -19635,6 +20745,11 @@ const handleSingleClickWithAlt = async (editor, position) => {
|
|
|
19635
20745
|
|
|
19636
20746
|
// Check if the click is on a link
|
|
19637
20747
|
const offset = offsetAt(editor, rowIndex, columnIndex);
|
|
20748
|
+
const documentLink = getDocumentLinkAtOffset(editor, offset);
|
|
20749
|
+
if (documentLink) {
|
|
20750
|
+
await openDocumentLink(documentLink, platform);
|
|
20751
|
+
return editor;
|
|
20752
|
+
}
|
|
19638
20753
|
const url = getUrlAtOffset(editor, offset);
|
|
19639
20754
|
if (url) {
|
|
19640
20755
|
// Open the link
|
|
@@ -19736,7 +20851,7 @@ const getEditorLineDecorations = async (editor, rowIndex) => {
|
|
|
19736
20851
|
uri: editor.uri
|
|
19737
20852
|
};
|
|
19738
20853
|
try {
|
|
19739
|
-
const results = await invoke$
|
|
20854
|
+
const results = await invoke$8(editor.applicationId, 'Extensions.executeProvidersByEvent', 'onEditorLineDecoration', 'ExtensionApi.executeEditorLineDecorationProvider', textDocument, rowIndex);
|
|
19740
20855
|
return getProviderDecorations(results, rowIndex);
|
|
19741
20856
|
} catch {
|
|
19742
20857
|
return [];
|
|
@@ -20218,7 +21333,7 @@ const getTextDocument$1 = editor => {
|
|
|
20218
21333
|
};
|
|
20219
21334
|
const executeIsolatedHoverProvider = async (editor, offset) => {
|
|
20220
21335
|
const textDocument = getTextDocument$1(editor);
|
|
20221
|
-
return invoke$
|
|
21336
|
+
return invoke$8(editor.applicationId, 'Extensions.executeHoverProvider', textDocument, offset);
|
|
20222
21337
|
};
|
|
20223
21338
|
const executeHoverProvider = async (editor, offset) => {
|
|
20224
21339
|
object(editor);
|
|
@@ -22323,7 +23438,7 @@ const getOrganizeImportEdits = async editor => {
|
|
|
22323
23438
|
text: getText$1(editor),
|
|
22324
23439
|
uri: editor.uri
|
|
22325
23440
|
};
|
|
22326
|
-
const result = await invoke$
|
|
23441
|
+
const result = await invoke$8(editor.applicationId, 'Extensions.executeOrganizeImportsProvider', textDocument);
|
|
22327
23442
|
return result.found ? result.result ?? [] : [];
|
|
22328
23443
|
};
|
|
22329
23444
|
|
|
@@ -23175,7 +24290,7 @@ const executeSignatureHelpProvider = async (editor, offset) => {
|
|
|
23175
24290
|
object(editor);
|
|
23176
24291
|
number(offset);
|
|
23177
24292
|
const textDocument = getTextDocument(editor);
|
|
23178
|
-
return invoke$
|
|
24293
|
+
return invoke$8(editor.applicationId, 'Extensions.executeSignatureHelpProvider', textDocument, offset);
|
|
23179
24294
|
};
|
|
23180
24295
|
|
|
23181
24296
|
const getSignatureHelp = async (editor, offset) => {
|
|
@@ -24190,6 +25305,16 @@ const unfold = editor => {
|
|
|
24190
25305
|
return updateLayout(editor, newRanges);
|
|
24191
25306
|
};
|
|
24192
25307
|
|
|
25308
|
+
const unfoldAll = editor => {
|
|
25309
|
+
const {
|
|
25310
|
+
foldingRanges = []
|
|
25311
|
+
} = editor;
|
|
25312
|
+
if (foldingRanges.length === 0) {
|
|
25313
|
+
return editor;
|
|
25314
|
+
}
|
|
25315
|
+
return updateLayout(editor, []);
|
|
25316
|
+
};
|
|
25317
|
+
|
|
24193
25318
|
// @ts-ignore
|
|
24194
25319
|
|
|
24195
25320
|
// const INDENT = ' '
|
|
@@ -24850,6 +25975,20 @@ ${editorSelector} .BracketMatch {
|
|
|
24850
25975
|
background: var(--EditorBracketMatchBackground, rgba(128, 128, 128, 0.25));
|
|
24851
25976
|
pointer-events: none;
|
|
24852
25977
|
}
|
|
25978
|
+
${editorSelector} .EditorDocumentHighlight {
|
|
25979
|
+
position: absolute;
|
|
25980
|
+
background: var(--EditorDocumentHighlightBackground, rgba(128, 128, 128, 0.3));
|
|
25981
|
+
pointer-events: none;
|
|
25982
|
+
}
|
|
25983
|
+
${editorSelector} .EditorDocumentHighlightWrite {
|
|
25984
|
+
background: var(--EditorDocumentHighlightWriteBackground, rgba(0, 122, 204, 0.3));
|
|
25985
|
+
}
|
|
25986
|
+
${editorSelector} .LinkedEditingRange {
|
|
25987
|
+
position: absolute;
|
|
25988
|
+
box-sizing: border-box;
|
|
25989
|
+
border: 1px solid var(--EditorLinkedEditingBorder, rgba(255, 0, 0, 0.5));
|
|
25990
|
+
pointer-events: none;
|
|
25991
|
+
}
|
|
24853
25992
|
${editorSelector} .ScrollBarThumbVertical {
|
|
24854
25993
|
height: var(--ScrollBarHeight);
|
|
24855
25994
|
translate: 0px var(--ScrollBarTop);
|
|
@@ -24938,6 +26077,34 @@ const combineWhitespaceTokens = tokens => {
|
|
|
24938
26077
|
return combined;
|
|
24939
26078
|
};
|
|
24940
26079
|
|
|
26080
|
+
const getClassName = kind => {
|
|
26081
|
+
switch (kind) {
|
|
26082
|
+
case 'read':
|
|
26083
|
+
return 'EditorDocumentHighlight EditorDocumentHighlightRead';
|
|
26084
|
+
case 'write':
|
|
26085
|
+
return 'EditorDocumentHighlight EditorDocumentHighlightWrite';
|
|
26086
|
+
default:
|
|
26087
|
+
return 'EditorDocumentHighlight';
|
|
26088
|
+
}
|
|
26089
|
+
};
|
|
26090
|
+
const getDocumentHighlightsVirtualDom = (infos = []) => {
|
|
26091
|
+
return infos.map(({
|
|
26092
|
+
height,
|
|
26093
|
+
kind,
|
|
26094
|
+
width,
|
|
26095
|
+
x,
|
|
26096
|
+
y
|
|
26097
|
+
}) => ({
|
|
26098
|
+
childCount: 0,
|
|
26099
|
+
className: getClassName(kind),
|
|
26100
|
+
height,
|
|
26101
|
+
left: x,
|
|
26102
|
+
top: y,
|
|
26103
|
+
type: Div,
|
|
26104
|
+
width
|
|
26105
|
+
}));
|
|
26106
|
+
};
|
|
26107
|
+
|
|
24941
26108
|
const getPathname = uri => {
|
|
24942
26109
|
return decodeURIComponent(URL.canParse(uri) ? new URL(uri).pathname : uri);
|
|
24943
26110
|
};
|
|
@@ -25794,6 +26961,7 @@ const getEditorVirtualDom = ({
|
|
|
25794
26961
|
cursorInfos = [],
|
|
25795
26962
|
diagnostics: fallbackDiagnostics = [],
|
|
25796
26963
|
differences,
|
|
26964
|
+
documentHighlightInfos,
|
|
25797
26965
|
documentSymbols = [],
|
|
25798
26966
|
endOfLineDecorations = [],
|
|
25799
26967
|
focused = true,
|
|
@@ -25894,7 +27062,7 @@ const getEditorVirtualDom = ({
|
|
|
25894
27062
|
scrollBarWidth,
|
|
25895
27063
|
selectionInfos,
|
|
25896
27064
|
tabSize,
|
|
25897
|
-
textDecorationDom,
|
|
27065
|
+
textDecorationDom: documentHighlightInfos?.length ? [...getDocumentHighlightsVirtualDom(documentHighlightInfos), ...textDecorationDom] : textDecorationDom,
|
|
25898
27066
|
textInfos: combineWhitespaceTokens$1 ? textInfos.map(combineWhitespaceTokens) : textInfos,
|
|
25899
27067
|
unnecessaryDiagnostics,
|
|
25900
27068
|
visibleLineIndices: visibleLineIndices || [],
|
|
@@ -26002,7 +27170,7 @@ const canRenderPlainTextAppend = (oldState, newState) => {
|
|
|
26002
27170
|
if (oldState.initial || newState.initial || !oldState.focused || !newState.focused || oldState.uid !== newState.uid || oldTextInfos[0][1] !== newTextInfos[0][1] || oldState.cursorInfos.length !== 1 || newState.cursorInfos.length !== 1 || oldState.selectionInfos.length > 0 || newState.selectionInfos.length > 0 || oldState.selections.length !== 4 || newState.selections.length !== 4 || oldState.selections[0] !== 0 || oldState.selections[1] !== oldLine.length || oldState.selections[2] !== 0 || oldState.selections[3] !== oldLine.length || newState.selections[0] !== 0 || newState.selections[1] !== newLine.length || newState.selections[2] !== 0 || newState.selections[3] !== newLine.length) {
|
|
26003
27171
|
return false;
|
|
26004
27172
|
}
|
|
26005
|
-
if (oldState.breadcrumbsEnabled || newState.breadcrumbsEnabled || oldState.minimapEnabled || newState.minimapEnabled || oldState.lineNumbers !== newState.lineNumbers || oldState.highlightActiveLineNumber !== newState.highlightActiveLineNumber || oldState.highlightedLine !== newState.highlightedLine || oldState.problemsHighlightedRow !== newState.problemsHighlightedRow || oldState.focused !== newState.focused || oldState.roundedSelection !== newState.roundedSelection || oldState.deltaX !== newState.deltaX || oldState.gutterWidth !== newState.gutterWidth || (newState.deltaX ?? 0) !== 0 && oldState.longestLineWidth !== newState.longestLineWidth || oldState.width !== newState.width || oldState.height !== newState.height || oldState.minimumSliderSize !== newState.minimumSliderSize || getScrollBarSize(getHorizontalScrollDimensions(oldState).width, oldState.longestLineWidth, oldState.minimumSliderSize) !== getScrollBarSize(getHorizontalScrollDimensions(newState).width, newState.longestLineWidth, newState.minimumSliderSize) || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || !sameValues(oldState.visibleLineIndices, newState.visibleLineIndices) || !sameValues(oldState.visibleViewLineIndices, newState.visibleViewLineIndices) || oldState.differences !== newState.differences && !sameValues(oldState.differences, newState.differences) || oldState.scrollBarHeight !== newState.scrollBarHeight || oldState.uri !== newState.uri || oldState.workspaceUri !== newState.workspaceUri || oldState.assetDir !== newState.assetDir || oldState.loadError !== newState.loadError || oldState.combineWhitespaceTokens !== newState.combineWhitespaceTokens || oldState.widgets?.length > 0 || newState.widgets?.length > 0 || Boolean(oldState.codeLensRows) || Boolean(newState.codeLensRows) || oldState.mergeConflicts.length > 0 || newState.mergeConflicts.length > 0 || !isEmpty(oldState.diagnostics) || !isEmpty(newState.diagnostics) || !isEmpty(oldState.textDecorationDom) || !isEmpty(newState.textDecorationDom) || !isEmpty(oldState.visualDecorations) || !isEmpty(newState.visualDecorations) || !isEmpty(oldState.bracketMatchInfos) || !isEmpty(newState.bracketMatchInfos) || !isEmpty(oldState.endOfLineDecorations) || !isEmpty(newState.endOfLineDecorations) || !isEmpty(oldState.gutterDecorations) || !isEmpty(newState.gutterDecorations) || !isEmpty(oldState.breakPoints) || !isEmpty(newState.breakPoints)) {
|
|
27173
|
+
if (oldState.breadcrumbsEnabled || newState.breadcrumbsEnabled || oldState.minimapEnabled || newState.minimapEnabled || oldState.lineNumbers !== newState.lineNumbers || oldState.highlightActiveLineNumber !== newState.highlightActiveLineNumber || oldState.highlightedLine !== newState.highlightedLine || oldState.problemsHighlightedRow !== newState.problemsHighlightedRow || oldState.focused !== newState.focused || oldState.roundedSelection !== newState.roundedSelection || oldState.deltaX !== newState.deltaX || oldState.gutterWidth !== newState.gutterWidth || (newState.deltaX ?? 0) !== 0 && oldState.longestLineWidth !== newState.longestLineWidth || oldState.width !== newState.width || oldState.height !== newState.height || oldState.minimumSliderSize !== newState.minimumSliderSize || getScrollBarSize(getHorizontalScrollDimensions(oldState).width, oldState.longestLineWidth, oldState.minimumSliderSize) !== getScrollBarSize(getHorizontalScrollDimensions(newState).width, newState.longestLineWidth, newState.minimumSliderSize) || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || !sameValues(oldState.visibleLineIndices, newState.visibleLineIndices) || !sameValues(oldState.visibleViewLineIndices, newState.visibleViewLineIndices) || oldState.differences !== newState.differences && !sameValues(oldState.differences, newState.differences) || oldState.scrollBarHeight !== newState.scrollBarHeight || oldState.uri !== newState.uri || oldState.workspaceUri !== newState.workspaceUri || oldState.assetDir !== newState.assetDir || oldState.loadError !== newState.loadError || oldState.combineWhitespaceTokens !== newState.combineWhitespaceTokens || oldState.widgets?.length > 0 || newState.widgets?.length > 0 || Boolean(oldState.codeLensRows) || Boolean(newState.codeLensRows) || oldState.mergeConflicts.length > 0 || newState.mergeConflicts.length > 0 || !isEmpty(oldState.diagnostics) || !isEmpty(newState.diagnostics) || !isEmpty(oldState.textDecorationDom) || !isEmpty(newState.textDecorationDom) || !isEmpty(oldState.visualDecorations) || !isEmpty(newState.visualDecorations) || !isEmpty(oldState.bracketMatchInfos) || !isEmpty(newState.bracketMatchInfos) || !isEmpty(oldState.documentHighlightInfos) || !isEmpty(newState.documentHighlightInfos) || !isEmpty(oldState.endOfLineDecorations) || !isEmpty(newState.endOfLineDecorations) || !isEmpty(oldState.gutterDecorations) || !isEmpty(newState.gutterDecorations) || !isEmpty(oldState.breakPoints) || !isEmpty(newState.breakPoints)) {
|
|
26006
27174
|
return false;
|
|
26007
27175
|
}
|
|
26008
27176
|
return true;
|
|
@@ -26265,7 +27433,7 @@ const renderDirect = async (uid, preserveFocus) => {
|
|
|
26265
27433
|
// Widget creation/declarations and focus contexts must still pass through
|
|
26266
27434
|
// renderer-worker. Replace only DOM patches, preserving command order.
|
|
26267
27435
|
if (isConnected() && command[0] === 'Viewlet.setPatches' && command[1] === uid) {
|
|
26268
|
-
const transactionId = await invoke$
|
|
27436
|
+
const transactionId = await invoke$9('Viewlet.queueCommands', uid, [command]);
|
|
26269
27437
|
result.push(['Viewlet.commitPending', uid, transactionId]);
|
|
26270
27438
|
} else {
|
|
26271
27439
|
result.push(command);
|
|
@@ -26361,7 +27529,7 @@ const getEditorSourceActions = async editorId => {
|
|
|
26361
27529
|
const {
|
|
26362
27530
|
newState
|
|
26363
27531
|
} = get$a(editorId);
|
|
26364
|
-
const extensions = await invoke$
|
|
27532
|
+
const extensions = await invoke$8(newState.applicationId, 'Extensions.getAllExtensions', newState.assetDir, newState.platform);
|
|
26365
27533
|
return extensions.filter(extension => !extension.disabled).flatMap(extension => extension.codeActions || []).filter(action => action.languageId === newState.languageId);
|
|
26366
27534
|
};
|
|
26367
27535
|
|
|
@@ -27072,6 +28240,12 @@ const getQuickPickMenuEntries = () => {
|
|
|
27072
28240
|
}, {
|
|
27073
28241
|
id: 'Editor.unfold',
|
|
27074
28242
|
label: unfold$1()
|
|
28243
|
+
}, {
|
|
28244
|
+
id: 'Editor.foldAll',
|
|
28245
|
+
label: foldAll()
|
|
28246
|
+
}, {
|
|
28247
|
+
id: 'Editor.unfoldAll',
|
|
28248
|
+
label: unfoldAll$1()
|
|
27075
28249
|
}, {
|
|
27076
28250
|
id: 'Editor.deleteLine',
|
|
27077
28251
|
label: deleteLine()
|
|
@@ -27387,7 +28561,7 @@ const getHorizontalVirtualizationThreshold = value => {
|
|
|
27387
28561
|
return Math.floor(threshold);
|
|
27388
28562
|
};
|
|
27389
28563
|
const getEditorPreferences = async applicationId => {
|
|
27390
|
-
const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, formatActions, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, rtl, breadcrumbsEnabled, codeLensEnabled, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching, disableMonospaceOptimizations, syntaxHighlightingCacheEnabled] = await Promise.all([get$2('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$2('editor.formatOnSave', applicationId), get$2('editor.formatActions', applicationId), get$2('editor.hover', applicationId), get$2('editor.hoverDelay', applicationId), get$2('editor.horizontalVirtualizationThreshold', applicationId), get$2('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$2('editor.rtl', applicationId), get$2('breadcrumbs.enabled', applicationId), get$2('editor.extensionCodeLens', applicationId), get$2('editor.insertSpaces', applicationId), get$2('editor.dragAndDrop', applicationId), get$2('editor.roundedSelection', applicationId), get$2('editor.combineWhitespaceTokens', applicationId), get$2('editor.selectedTextOccurrenceMatching', applicationId), get$2('editor.disableMonospaceOptimizations', applicationId), get$2('editor.syntaxHighlightingCache', applicationId)]);
|
|
28564
|
+
const [diagnosticsEnabled, fontFamily, fontSize, fontWeight, formatOnSave, formatActions, hoverEnabled, hoverDelay, horizontalVirtualizationThreshold, messageDelay, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, highlightActiveLineNumber, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, mergeConflictActionsEnabled, rtl, breadcrumbsEnabled, codeLensEnabled, occurrencesHighlight, insertSpaces, dragAndDropEnabled, roundedSelection, combineWhitespaceTokens, selectedTextOccurrenceMatching, disableMonospaceOptimizations, syntaxHighlightingCacheEnabled, linkedEditingEnabled] = await Promise.all([get$2('editor.diagnostics', applicationId), getFontFamily(applicationId), getFontSize(applicationId), getFontWeight(applicationId), get$2('editor.formatOnSave', applicationId), get$2('editor.formatActions', applicationId), get$2('editor.hover', applicationId), get$2('editor.hoverDelay', applicationId), get$2('editor.horizontalVirtualizationThreshold', applicationId), get$2('editor.messageDelay', applicationId), isAutoClosingBracketsEnabled(applicationId), isAutoClosingQuotesEnabled(applicationId), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(applicationId), getLineNumbers(applicationId), getHighlightActiveLineNumber(applicationId), getRowHeight(applicationId), getTabSize(applicationId), getLetterSpacing(applicationId), getCompletionTriggerCharacters(), getMinimapEnabled(applicationId), getMergeConflictActionsEnabled(applicationId), get$2('editor.rtl', applicationId), get$2('breadcrumbs.enabled', applicationId), get$2('editor.extensionCodeLens', applicationId), get$2('editor.occurrencesHighlight', applicationId), get$2('editor.insertSpaces', applicationId), get$2('editor.dragAndDrop', applicationId), get$2('editor.roundedSelection', applicationId), get$2('editor.combineWhitespaceTokens', applicationId), get$2('editor.selectedTextOccurrenceMatching', applicationId), get$2('editor.disableMonospaceOptimizations', applicationId), get$2('editor.syntaxHighlightingCache', applicationId), get$2('editor.linkedEditing', applicationId)]);
|
|
27391
28565
|
return {
|
|
27392
28566
|
breadcrumbsEnabled: breadcrumbsEnabled ?? false,
|
|
27393
28567
|
codeLensEnabled: codeLensEnabled === true,
|
|
@@ -27395,6 +28569,7 @@ const getEditorPreferences = async applicationId => {
|
|
|
27395
28569
|
completionTriggerCharacters,
|
|
27396
28570
|
diagnosticsEnabled: diagnosticsEnabled ?? false,
|
|
27397
28571
|
disableMonospaceOptimizations: disableMonospaceOptimizations === true,
|
|
28572
|
+
documentHighlightsEnabled: occurrencesHighlight !== false && occurrencesHighlight !== 'false',
|
|
27398
28573
|
dragAndDropEnabled: dragAndDropEnabled ?? true,
|
|
27399
28574
|
fontFamily,
|
|
27400
28575
|
fontSize,
|
|
@@ -27412,6 +28587,7 @@ const getEditorPreferences = async applicationId => {
|
|
|
27412
28587
|
isQuickSuggestionsEnabled: isQuickSuggestionsEnabled$1,
|
|
27413
28588
|
letterSpacing,
|
|
27414
28589
|
lineNumbers,
|
|
28590
|
+
linkedEditingEnabled: linkedEditingEnabled !== false,
|
|
27415
28591
|
mergeConflictActionsEnabled,
|
|
27416
28592
|
messageDelay: getMessageDelay(messageDelay),
|
|
27417
28593
|
minimapEnabled,
|
|
@@ -27985,6 +29161,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
27985
29161
|
completionTriggerCharacters,
|
|
27986
29162
|
diagnosticsEnabled,
|
|
27987
29163
|
disableMonospaceOptimizations,
|
|
29164
|
+
documentHighlightsEnabled,
|
|
27988
29165
|
dragAndDropEnabled,
|
|
27989
29166
|
fontFamily,
|
|
27990
29167
|
fontSize,
|
|
@@ -28002,6 +29179,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
28002
29179
|
isQuickSuggestionsEnabled,
|
|
28003
29180
|
letterSpacing,
|
|
28004
29181
|
lineNumbers,
|
|
29182
|
+
linkedEditingEnabled,
|
|
28005
29183
|
mergeConflictActionsEnabled,
|
|
28006
29184
|
minimapEnabled,
|
|
28007
29185
|
roundedSelection,
|
|
@@ -28026,6 +29204,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
28026
29204
|
combineWhitespaceTokens,
|
|
28027
29205
|
completionTriggerCharacters,
|
|
28028
29206
|
diagnosticsEnabled,
|
|
29207
|
+
documentHighlightsEnabled,
|
|
28029
29208
|
dragAndDropEnabled,
|
|
28030
29209
|
...(explicitLanguageId && {
|
|
28031
29210
|
explicitLanguageId
|
|
@@ -28048,6 +29227,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
28048
29227
|
languageId: computedLanguageId,
|
|
28049
29228
|
letterSpacing,
|
|
28050
29229
|
lineNumbers,
|
|
29230
|
+
linkedEditingEnabled,
|
|
28051
29231
|
loadError: '',
|
|
28052
29232
|
mergeConflictActionsEnabled,
|
|
28053
29233
|
minimapEnabled,
|
|
@@ -28124,9 +29304,14 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
28124
29304
|
const newEditor3WithScroll = typeof savedDeltaY === 'number' && Number.isFinite(savedDeltaY) && savedDeltaY >= 0 ? await setDeltaYFixedValue(newEditor3, savedDeltaY) : newEditor3;
|
|
28125
29305
|
|
|
28126
29306
|
// Detect links and initialize decorations
|
|
28127
|
-
|
|
28128
|
-
const
|
|
29307
|
+
// Provider links of previously loaded content are stale; they are requested again after loading.
|
|
29308
|
+
const editorWithoutDocumentLinks = newEditor3WithScroll.documentLinks ? {
|
|
28129
29309
|
...newEditor3WithScroll,
|
|
29310
|
+
documentLinks: []
|
|
29311
|
+
} : newEditor3WithScroll;
|
|
29312
|
+
const linkDecorations = detectAllLinksAsDecorations(editorWithoutDocumentLinks);
|
|
29313
|
+
const newEditor3WithLinks = {
|
|
29314
|
+
...editorWithoutDocumentLinks,
|
|
28130
29315
|
decorations: linkDecorations
|
|
28131
29316
|
};
|
|
28132
29317
|
let documentSymbols = state.documentSymbols || [];
|
|
@@ -28335,10 +29520,11 @@ const renderDecorations = {
|
|
|
28335
29520
|
const textDecorationsDom = newState.textDecorationDom || [];
|
|
28336
29521
|
const diagnosticsDom = getDiagnosticsVirtualDom(newState.visualDecorations || []);
|
|
28337
29522
|
const bracketMatchesDom = getBracketMatchesVirtualDom(newState.bracketMatchInfos || []);
|
|
28338
|
-
const
|
|
29523
|
+
const documentHighlightsDom = getDocumentHighlightsVirtualDom(newState.documentHighlightInfos);
|
|
29524
|
+
const dom = [...diagnosticsDom, ...bracketMatchesDom, ...documentHighlightsDom, ...textDecorationsDom];
|
|
28339
29525
|
return ['setDecorationsDom', dom];
|
|
28340
29526
|
},
|
|
28341
|
-
isEqual: (oldState, newState) => oldState.visualDecorations === newState.visualDecorations && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.textDecorationDom === newState.textDecorationDom
|
|
29527
|
+
isEqual: (oldState, newState) => oldState.visualDecorations === newState.visualDecorations && oldState.bracketMatchInfos === newState.bracketMatchInfos && oldState.documentHighlightInfos === newState.documentHighlightInfos && oldState.textDecorationDom === newState.textDecorationDom
|
|
28342
29528
|
};
|
|
28343
29529
|
const renderGutterInfo = {
|
|
28344
29530
|
apply(oldState, newState) {
|
|
@@ -28865,6 +30051,7 @@ const commandMap = {
|
|
|
28865
30051
|
'Editor.expandSelection': wrapCommand(selectionGrow),
|
|
28866
30052
|
'Editor.findAllReferences': wrapCommand(findAllReferences$1),
|
|
28867
30053
|
'Editor.fold': wrapCommand(fold$1),
|
|
30054
|
+
'Editor.foldAll': wrapCommand(foldAll$1),
|
|
28868
30055
|
'Editor.format': wrapCommand(format),
|
|
28869
30056
|
'Editor.getCommandIds': getCommandIds,
|
|
28870
30057
|
'Editor.getCompletionContext': getCompletionContext,
|
|
@@ -29025,6 +30212,7 @@ const commandMap = {
|
|
|
29025
30212
|
'Editor.typeWithAutoClosing': typeWithAutoClosingCommand,
|
|
29026
30213
|
'Editor.undo': wrapCommand(undo),
|
|
29027
30214
|
'Editor.unfold': wrapCommand(unfold),
|
|
30215
|
+
'Editor.unfoldAll': wrapCommand(unfoldAll),
|
|
29028
30216
|
'Editor.unindent': wrapCommand(indentLess),
|
|
29029
30217
|
'Editor.unIndent': wrapCommand(editorUnindent),
|
|
29030
30218
|
'Editor.updateColorPickerValue': wrapCommand(updateColorPickerValue$1),
|