@codingame/monaco-vscode-notebook-service-override 15.0.2 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -11
- package/package.json +27 -26
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css +6 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +10 -10
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +22 -22
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.d.ts +1 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticEditorContrib.js +7 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticsActions.js +5 -5
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/diagnosticCellStatusBarContrib.js +7 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +3 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +7 -7
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +12 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +10 -10
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css +17 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +4 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +5 -5
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +2 -2
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/multicursor/notebookMulticursor.js +6 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +14 -14
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookInlineVariables.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +2 -2
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +2 -2
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +10 -10
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +13 -13
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +3 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +28 -28
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebook.chat.contribution.js +54 -31
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/editActions.js +25 -25
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +26 -26
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +25 -25
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +18 -18
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/notebookIndentationActions.js +7 -7
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.js +12 -12
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/variablesActions.js +2 -2
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +22 -22
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +72 -74
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.js +11 -11
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibleView.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +33 -33
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +2 -2
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +3 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +1 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +54 -12
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +4 -3
- package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.d.ts +2 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +42 -1
- package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +10 -2
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookCellMatching.d.ts +15 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookCellMatching.js +173 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/services/{notebookSimpleWorker.d.ts → notebookWebWorker.d.ts} +24 -6
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookWebWorker.js +366 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookWebWorkerMain.js +5 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +12 -12
- package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +1 -1
- package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.d.ts +2 -2
- package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +1 -1
- package/worker.js +1 -1
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/contribution.js +0 -10
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookCellDecorators.d.ts +0 -24
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookCellDecorators.js +0 -332
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatActionsOverlay.d.ts +0 -23
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatActionsOverlay.js +0 -299
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatEditController.d.ts +0 -9
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookChatEditController.js +0 -179
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalCellModelFactory.d.ts +0 -21
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalCellModelFactory.js +0 -42
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.d.ts +0 -25
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookOriginalModelRefFactory.js +0 -77
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizer.d.ts +0 -64
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizer.js +0 -443
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizerService.d.ts +0 -20
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/chatEdit/notebookSynchronizerService.js +0 -86
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +0 -6
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorker.js +0 -279
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorkerMain.d.ts +0 -1
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorkerMain.js +0 -5
- /package/vscode/src/vs/workbench/contrib/notebook/{browser/contrib/chatEdit/contribution.d.ts → common/services/notebookWebWorkerMain.d.ts} +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
|
|
2
|
+
import { computeLevenshteinDistance } from '@codingame/monaco-vscode-api/vscode/vs/base/common/diff/diff';
|
|
3
|
+
|
|
4
|
+
function matchCellBasedOnSimilarties(modifiedCells, originalCells) {
|
|
5
|
+
const cache = {
|
|
6
|
+
modifiedToOriginal: ( new Map()),
|
|
7
|
+
originalToModified: ( new Map()),
|
|
8
|
+
};
|
|
9
|
+
const results = [];
|
|
10
|
+
const mappedOriginalCellToModifiedCell = ( new Map());
|
|
11
|
+
const mappedModifiedIndexes = ( new Set());
|
|
12
|
+
const originalIndexWithMostEdits = ( new Map());
|
|
13
|
+
const canOriginalIndexBeMappedToModifiedIndex = (originalIndex, value) => {
|
|
14
|
+
if (( mappedOriginalCellToModifiedCell.has(originalIndex))) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const existingEdits = originalIndexWithMostEdits.get(originalIndex)?.dist ?? Number.MAX_SAFE_INTEGER;
|
|
18
|
+
return value.editCount < existingEdits;
|
|
19
|
+
};
|
|
20
|
+
const trackMappedIndexes = (modifiedIndex, originalIndex) => {
|
|
21
|
+
mappedOriginalCellToModifiedCell.set(originalIndex, modifiedIndex);
|
|
22
|
+
mappedModifiedIndexes.add(modifiedIndex);
|
|
23
|
+
};
|
|
24
|
+
for (let i = 0; i < modifiedCells.length; i++) {
|
|
25
|
+
const modifiedCell = modifiedCells[i];
|
|
26
|
+
const { index, editCount: dist, percentage } = computeClosestCell({ cell: modifiedCell, index: i }, originalCells, true, cache, canOriginalIndexBeMappedToModifiedIndex);
|
|
27
|
+
if (index >= 0 && dist === 0) {
|
|
28
|
+
trackMappedIndexes(i, index);
|
|
29
|
+
results.push({ modified: i, original: index, dist, percentage, possibleOriginal: index });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
originalIndexWithMostEdits.set(index, { dist: dist, modifiedIndex: i });
|
|
33
|
+
results.push({ modified: i, original: -1, dist: dist, percentage, possibleOriginal: index });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
results.forEach((result, i) => {
|
|
37
|
+
if (result.original >= 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const previousMatchedCell = i > 0 ? results.slice(0, i).reverse().find(r => r.original >= 0) : undefined;
|
|
41
|
+
const previousMatchedOriginalIndex = previousMatchedCell?.original ?? -1;
|
|
42
|
+
const previousMatchedModifiedIndex = previousMatchedCell?.modified ?? -1;
|
|
43
|
+
const matchedCell = results.slice(i + 1).find(r => r.original >= 0);
|
|
44
|
+
const unavailableIndexes = ( new Set());
|
|
45
|
+
const nextMatchedModifiedIndex = results.findIndex((item, idx) => idx > i && item.original >= 0);
|
|
46
|
+
const nextMatchedOriginalIndex = nextMatchedModifiedIndex >= 0 ? results[nextMatchedModifiedIndex].original : -1;
|
|
47
|
+
originalCells.forEach((_, i) => {
|
|
48
|
+
if (( mappedOriginalCellToModifiedCell.has(i))) {
|
|
49
|
+
unavailableIndexes.add(i);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (matchedCell && i >= matchedCell.original) {
|
|
53
|
+
unavailableIndexes.add(i);
|
|
54
|
+
}
|
|
55
|
+
if (nextMatchedOriginalIndex >= 0 && i > nextMatchedOriginalIndex) {
|
|
56
|
+
unavailableIndexes.add(i);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const modifiedCell = modifiedCells[i];
|
|
60
|
+
if (result.original === -1 && result.possibleOriginal >= 0 && !( unavailableIndexes.has(result.possibleOriginal)) && canOriginalIndexBeMappedToModifiedIndex(result.possibleOriginal, { editCount: result.dist })) {
|
|
61
|
+
trackMappedIndexes(i, result.possibleOriginal);
|
|
62
|
+
result.original = result.possibleOriginal;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (previousMatchedOriginalIndex > 0 && previousMatchedModifiedIndex > 0 && previousMatchedOriginalIndex === previousMatchedModifiedIndex) {
|
|
66
|
+
if ((nextMatchedModifiedIndex >= 0 ? nextMatchedModifiedIndex : modifiedCells.length - 1) === (nextMatchedOriginalIndex >= 0 ? nextMatchedOriginalIndex : originalCells.length - 1) && !( unavailableIndexes.has(i)) && i < originalCells.length) {
|
|
67
|
+
const remainingModifiedItems = (nextMatchedModifiedIndex >= 0 ? nextMatchedModifiedIndex : modifiedCells.length) - previousMatchedModifiedIndex;
|
|
68
|
+
const remainingOriginalItems = (nextMatchedOriginalIndex >= 0 ? nextMatchedOriginalIndex : originalCells.length) - previousMatchedOriginalIndex;
|
|
69
|
+
if (remainingModifiedItems === remainingOriginalItems && modifiedCell.cellKind === originalCells[i].cellKind) {
|
|
70
|
+
trackMappedIndexes(i, i);
|
|
71
|
+
result.original = i;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const { index, percentage } = computeClosestCell({ cell: modifiedCell, index: i }, originalCells, false, cache, (originalIndex, originalValue) => {
|
|
77
|
+
if (( unavailableIndexes.has(originalIndex))) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (nextMatchedModifiedIndex > 0 || previousMatchedOriginalIndex > 0) {
|
|
81
|
+
const matchesForThisOriginalIndex = cache.originalToModified.get(originalIndex);
|
|
82
|
+
if (matchesForThisOriginalIndex && previousMatchedOriginalIndex < originalIndex) {
|
|
83
|
+
const betterMatch = Array.from(matchesForThisOriginalIndex).find(([modifiedIndex, value]) => {
|
|
84
|
+
if (modifiedIndex === i) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (modifiedIndex >= nextMatchedModifiedIndex) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (( mappedModifiedIndexes.has(i))) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return value.editCount < originalValue.editCount;
|
|
94
|
+
});
|
|
95
|
+
if (betterMatch) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return !( unavailableIndexes.has(originalIndex));
|
|
101
|
+
});
|
|
102
|
+
if (index >= 0 && i > 0 && results[i - 1].original === index - 1) {
|
|
103
|
+
trackMappedIndexes(i, index);
|
|
104
|
+
results[i].original = index;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const nextOriginalCell = (i > 0 && originalCells.length > results[i - 1].original) ? results[i - 1].original + 1 : -1;
|
|
108
|
+
const nextOriginalCellValue = i > 0 && nextOriginalCell >= 0 && nextOriginalCell < originalCells.length ? originalCells[nextOriginalCell].getValue() : undefined;
|
|
109
|
+
if (index >= 0 && i > 0 && typeof nextOriginalCellValue === 'string' && !( mappedOriginalCellToModifiedCell.has(nextOriginalCell))) {
|
|
110
|
+
if (modifiedCell.getValue().includes(nextOriginalCellValue) || nextOriginalCellValue.includes(modifiedCell.getValue())) {
|
|
111
|
+
trackMappedIndexes(i, nextOriginalCell);
|
|
112
|
+
results[i].original = nextOriginalCell;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (percentage < 90 || (i === 0 && results.length === 1)) {
|
|
117
|
+
trackMappedIndexes(i, index);
|
|
118
|
+
results[i].original = index;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
function computeClosestCell({ cell, index: cellIndex }, arr, ignoreEmptyCells, cache, canOriginalIndexBeMappedToModifiedIndex) {
|
|
125
|
+
let min_edits = Infinity;
|
|
126
|
+
let min_index = -1;
|
|
127
|
+
const internalId = cell.internalMetadata?.internalId;
|
|
128
|
+
if (internalId) {
|
|
129
|
+
const internalIdIndex = arr.findIndex(cell => cell.internalMetadata?.internalId === internalId);
|
|
130
|
+
if (internalIdIndex >= 0) {
|
|
131
|
+
return { index: internalIdIndex, editCount: 0, percentage: Number.MAX_SAFE_INTEGER };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (let i = 0; i < arr.length; i++) {
|
|
135
|
+
if (arr[i].cellKind !== cell.cellKind) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const str = arr[i].getValue();
|
|
139
|
+
const cacheEntry = cache.modifiedToOriginal.get(cellIndex) ?? ( new Map());
|
|
140
|
+
const value = cacheEntry.get(i) ?? { editCount: computeNumberOfEdits(cell, arr[i]), };
|
|
141
|
+
cacheEntry.set(i, value);
|
|
142
|
+
cache.modifiedToOriginal.set(cellIndex, cacheEntry);
|
|
143
|
+
const originalCacheEntry = cache.originalToModified.get(i) ?? ( new Map());
|
|
144
|
+
originalCacheEntry.set(cellIndex, value);
|
|
145
|
+
cache.originalToModified.set(i, originalCacheEntry);
|
|
146
|
+
if (!canOriginalIndexBeMappedToModifiedIndex(i, value)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (str.length === 0 && ignoreEmptyCells) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (str === cell.getValue() && cell.getValue().length > 0) {
|
|
153
|
+
return { index: i, editCount: 0, percentage: 0 };
|
|
154
|
+
}
|
|
155
|
+
if (value.editCount < min_edits) {
|
|
156
|
+
min_edits = value.editCount;
|
|
157
|
+
min_index = i;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (min_index === -1) {
|
|
161
|
+
return { index: -1, editCount: Number.MAX_SAFE_INTEGER, percentage: Number.MAX_SAFE_INTEGER };
|
|
162
|
+
}
|
|
163
|
+
const percentage = !cell.getValue().length && !arr[min_index].getValue().length ? 0 : (cell.getValue().length ? (min_edits * 100 / cell.getValue().length) : Number.MAX_SAFE_INTEGER);
|
|
164
|
+
return { index: min_index, editCount: min_edits, percentage };
|
|
165
|
+
}
|
|
166
|
+
function computeNumberOfEdits(modified, original) {
|
|
167
|
+
if (modified.getValue() === original.getValue()) {
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
return computeLevenshteinDistance(modified.getValue(), original.getValue());
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { matchCellBasedOnSimilarties };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { IDiffResult } from "@codingame/monaco-vscode-api/vscode/vs/base/common/diff/diff";
|
|
2
1
|
import { IDisposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
3
2
|
import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri";
|
|
4
|
-
import {
|
|
3
|
+
import { IWebWorkerServerRequestHandler } from "@codingame/monaco-vscode-api/vscode/vs/base/common/worker/webWorker";
|
|
5
4
|
import { CellKind, IMainCellDto, INotebookDiffResult, IOutputDto, NotebookCellInternalMetadata, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellTextModelSplice, NotebookDocumentMetadata, TransientDocumentMetadata } from "@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon";
|
|
6
5
|
import { DefaultEndOfLine } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
|
|
7
6
|
import { IModelChangedEvent } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model/mirrorTextModel";
|
|
@@ -19,7 +18,8 @@ declare class MirrorCell {
|
|
|
19
18
|
constructor(handle: number, uri: URI, source: string[], _eol: string, versionId: number, language: string, cellKind: CellKind, outputs: IOutputDto[], metadata?: NotebookCellMetadata | undefined, internalMetadata?: NotebookCellInternalMetadata | undefined);
|
|
20
19
|
onEvents(e: IModelChangedEvent): void;
|
|
21
20
|
getValue(): string;
|
|
22
|
-
|
|
21
|
+
getLinesContent(): string[];
|
|
22
|
+
getComparisonValue(): number;
|
|
23
23
|
private _getHash;
|
|
24
24
|
}
|
|
25
25
|
declare class MirrorNotebookDocument {
|
|
@@ -32,7 +32,7 @@ declare class MirrorNotebookDocument {
|
|
|
32
32
|
private _assertIndex;
|
|
33
33
|
_spliceNotebookCells(splices: NotebookCellTextModelSplice<IMainCellDto>[]): void;
|
|
34
34
|
}
|
|
35
|
-
export declare class
|
|
35
|
+
export declare class NotebookWorker implements IWebWorkerServerRequestHandler, IDisposable {
|
|
36
36
|
_requestHandlerBrand: any;
|
|
37
37
|
private _models;
|
|
38
38
|
constructor();
|
|
@@ -42,9 +42,27 @@ export declare class NotebookEditorSimpleWorker implements IRequestHandler, IDis
|
|
|
42
42
|
$acceptCellModelChanged(strURL: string, handle: number, event: IModelChangedEvent): void;
|
|
43
43
|
$acceptRemovedModel(strURL: string): void;
|
|
44
44
|
$computeDiff(originalUrl: string, modifiedUrl: string): Promise<INotebookDiffResult>;
|
|
45
|
-
|
|
45
|
+
canComputeDiffWithCellIds(original: MirrorNotebookDocument, modified: MirrorNotebookDocument): boolean;
|
|
46
|
+
canComputeDiffWithCellInternalIds(original: MirrorNotebookDocument, modified: MirrorNotebookDocument): boolean;
|
|
47
|
+
canComputeDiffWithCellMetadataIds(original: MirrorNotebookDocument, modified: MirrorNotebookDocument): boolean;
|
|
48
|
+
isOriginalCellMatchedWithModifiedCell(originalCell: MirrorCell): boolean;
|
|
49
|
+
updateCellIdsBasedOnMappings(mappings: {
|
|
50
|
+
modified: number;
|
|
51
|
+
original: number;
|
|
52
|
+
}[], originalCells: MirrorCell[], modifiedCells: MirrorCell[]): boolean;
|
|
46
53
|
$canPromptRecommendation(modelUrl: string): boolean;
|
|
47
54
|
protected _getModel(uri: string): MirrorNotebookDocument;
|
|
48
55
|
}
|
|
49
|
-
export declare function create(
|
|
56
|
+
export declare function create(): IWebWorkerServerRequestHandler;
|
|
57
|
+
export type CellDiffInfo = {
|
|
58
|
+
originalCellIndex: number;
|
|
59
|
+
modifiedCellIndex: number;
|
|
60
|
+
type: "unchanged" | "modified";
|
|
61
|
+
} | {
|
|
62
|
+
originalCellIndex: number;
|
|
63
|
+
type: "delete";
|
|
64
|
+
} | {
|
|
65
|
+
modifiedCellIndex: number;
|
|
66
|
+
type: "insert";
|
|
67
|
+
};
|
|
50
68
|
export {};
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
|
|
2
|
+
import { LcsDiff } from '@codingame/monaco-vscode-api/vscode/vs/base/common/diff/diff';
|
|
3
|
+
import { numberHash, doHash, hash } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
|
|
4
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
5
|
+
import { PieceTreeTextBufferBuilder } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder';
|
|
6
|
+
import { NotebookCellsChangeType, CellKind } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
7
|
+
import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
|
|
8
|
+
import { SearchParams } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model/textModelSearch';
|
|
9
|
+
import { MirrorModel } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/textModelSync/textModelSync.impl';
|
|
10
|
+
import { DefaultEndOfLine } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model';
|
|
11
|
+
import { filter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
|
|
12
|
+
import { matchCellBasedOnSimilarties } from './notebookCellMatching.js';
|
|
13
|
+
import '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
|
|
14
|
+
import { DiffChange } from '@codingame/monaco-vscode-api/vscode/vs/base/common/diff/diffChange';
|
|
15
|
+
import { computeDiff } from '@codingame/monaco-vscode-9a6d8b6c-ad4c-5ea3-9558-f43d6dc4c0ad-common/vscode/vs/workbench/contrib/notebook/common/notebookDiff';
|
|
16
|
+
|
|
17
|
+
const PREFIX_FOR_UNMATCHED_ORIGINAL_CELLS = `unmatchedOriginalCell`;
|
|
18
|
+
class MirrorCell {
|
|
19
|
+
get eol() {
|
|
20
|
+
return this._eol === '\r\n' ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF;
|
|
21
|
+
}
|
|
22
|
+
constructor(handle, uri, source, _eol, versionId, language, cellKind, outputs, metadata, internalMetadata) {
|
|
23
|
+
this.handle = handle;
|
|
24
|
+
this._eol = _eol;
|
|
25
|
+
this.language = language;
|
|
26
|
+
this.cellKind = cellKind;
|
|
27
|
+
this.outputs = outputs;
|
|
28
|
+
this.metadata = metadata;
|
|
29
|
+
this.internalMetadata = internalMetadata;
|
|
30
|
+
this.textModel = ( new MirrorModel(uri, source, _eol, versionId));
|
|
31
|
+
}
|
|
32
|
+
onEvents(e) {
|
|
33
|
+
this.textModel.onEvents(e);
|
|
34
|
+
this._hash = undefined;
|
|
35
|
+
}
|
|
36
|
+
getValue() {
|
|
37
|
+
return this.textModel.getValue();
|
|
38
|
+
}
|
|
39
|
+
getLinesContent() {
|
|
40
|
+
return this.textModel.getLinesContent();
|
|
41
|
+
}
|
|
42
|
+
getComparisonValue() {
|
|
43
|
+
return this._hash ??= this._getHash();
|
|
44
|
+
}
|
|
45
|
+
_getHash() {
|
|
46
|
+
let hashValue = numberHash(104579, 0);
|
|
47
|
+
hashValue = doHash(this.language, hashValue);
|
|
48
|
+
hashValue = doHash(this.getValue(), hashValue);
|
|
49
|
+
hashValue = doHash(this.metadata, hashValue);
|
|
50
|
+
hashValue = doHash(this.internalMetadata?.internalId || '', hashValue);
|
|
51
|
+
for (const op of this.outputs) {
|
|
52
|
+
hashValue = doHash(op.metadata, hashValue);
|
|
53
|
+
for (const output of op.outputs) {
|
|
54
|
+
hashValue = doHash(output.mime, hashValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const digests = this.outputs.flatMap(op => ( op.outputs.map(o => hash(Array.from(o.data.buffer)))));
|
|
58
|
+
for (const digest of digests) {
|
|
59
|
+
hashValue = numberHash(digest, hashValue);
|
|
60
|
+
}
|
|
61
|
+
return hashValue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class MirrorNotebookDocument {
|
|
65
|
+
constructor(uri, cells, metadata, transientDocumentMetadata) {
|
|
66
|
+
this.uri = uri;
|
|
67
|
+
this.cells = cells;
|
|
68
|
+
this.metadata = metadata;
|
|
69
|
+
this.transientDocumentMetadata = transientDocumentMetadata;
|
|
70
|
+
}
|
|
71
|
+
acceptModelChanged(event) {
|
|
72
|
+
event.rawEvents.forEach(e => {
|
|
73
|
+
if (e.kind === NotebookCellsChangeType.ModelChange) {
|
|
74
|
+
this._spliceNotebookCells(e.changes);
|
|
75
|
+
}
|
|
76
|
+
else if (e.kind === NotebookCellsChangeType.Move) {
|
|
77
|
+
const cells = this.cells.splice(e.index, 1);
|
|
78
|
+
this.cells.splice(e.newIdx, 0, ...cells);
|
|
79
|
+
}
|
|
80
|
+
else if (e.kind === NotebookCellsChangeType.Output) {
|
|
81
|
+
const cell = this.cells[e.index];
|
|
82
|
+
cell.outputs = e.outputs;
|
|
83
|
+
}
|
|
84
|
+
else if (e.kind === NotebookCellsChangeType.ChangeCellLanguage) {
|
|
85
|
+
this._assertIndex(e.index);
|
|
86
|
+
const cell = this.cells[e.index];
|
|
87
|
+
cell.language = e.language;
|
|
88
|
+
}
|
|
89
|
+
else if (e.kind === NotebookCellsChangeType.ChangeCellMetadata) {
|
|
90
|
+
this._assertIndex(e.index);
|
|
91
|
+
const cell = this.cells[e.index];
|
|
92
|
+
cell.metadata = e.metadata;
|
|
93
|
+
}
|
|
94
|
+
else if (e.kind === NotebookCellsChangeType.ChangeCellInternalMetadata) {
|
|
95
|
+
this._assertIndex(e.index);
|
|
96
|
+
const cell = this.cells[e.index];
|
|
97
|
+
cell.internalMetadata = e.internalMetadata;
|
|
98
|
+
}
|
|
99
|
+
else if (e.kind === NotebookCellsChangeType.ChangeDocumentMetadata) {
|
|
100
|
+
this.metadata = e.metadata;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
_assertIndex(index) {
|
|
105
|
+
if (index < 0 || index >= this.cells.length) {
|
|
106
|
+
throw ( new Error(`Illegal index ${index}. Cells length: ${this.cells.length}`));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_spliceNotebookCells(splices) {
|
|
110
|
+
splices.reverse().forEach(splice => {
|
|
111
|
+
const cellDtos = splice[2];
|
|
112
|
+
const newCells = ( cellDtos.map(cell => {
|
|
113
|
+
return ( new MirrorCell(cell.handle, ( URI.parse(cell.url)), cell.source, cell.eol, cell.versionId, cell.language, cell.cellKind, cell.outputs, cell.metadata));
|
|
114
|
+
}));
|
|
115
|
+
this.cells.splice(splice[0], splice[1], ...newCells);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class CellSequence {
|
|
120
|
+
static create(textModel) {
|
|
121
|
+
const hashValue = ( textModel.cells.map(c => c.getComparisonValue()));
|
|
122
|
+
return ( new CellSequence(hashValue));
|
|
123
|
+
}
|
|
124
|
+
static createWithCellId(cells, includeCellContents) {
|
|
125
|
+
const hashValue = ( cells.map((c) => {
|
|
126
|
+
if (includeCellContents) {
|
|
127
|
+
return `${doHash(c.internalMetadata?.internalId, numberHash(104579, 0))}#${c.getComparisonValue()}`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return `${doHash(c.internalMetadata?.internalId, numberHash(104579, 0))}}`;
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
return ( new CellSequence(hashValue));
|
|
134
|
+
}
|
|
135
|
+
constructor(hashValue) {
|
|
136
|
+
this.hashValue = hashValue;
|
|
137
|
+
}
|
|
138
|
+
getElements() {
|
|
139
|
+
return this.hashValue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
class NotebookWorker {
|
|
143
|
+
constructor() {
|
|
144
|
+
this._models = Object.create(null);
|
|
145
|
+
}
|
|
146
|
+
dispose() {
|
|
147
|
+
}
|
|
148
|
+
$acceptNewModel(uri, metadata, transientDocumentMetadata, cells) {
|
|
149
|
+
this._models[uri] = ( new MirrorNotebookDocument(( URI.parse(uri)), ( cells.map(dto => ( new MirrorCell(dto.handle, ( URI.parse(dto.url)), dto.source, dto.eol, dto.versionId, dto.language, dto.cellKind, dto.outputs, dto.metadata, dto.internalMetadata)))), metadata, transientDocumentMetadata));
|
|
150
|
+
}
|
|
151
|
+
$acceptModelChanged(strURL, event) {
|
|
152
|
+
const model = this._models[strURL];
|
|
153
|
+
model?.acceptModelChanged(event);
|
|
154
|
+
}
|
|
155
|
+
$acceptCellModelChanged(strURL, handle, event) {
|
|
156
|
+
const model = this._models[strURL];
|
|
157
|
+
model.cells.find(cell => cell.handle === handle)?.onEvents(event);
|
|
158
|
+
}
|
|
159
|
+
$acceptRemovedModel(strURL) {
|
|
160
|
+
if (!this._models[strURL]) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
delete this._models[strURL];
|
|
164
|
+
}
|
|
165
|
+
async $computeDiff(originalUrl, modifiedUrl) {
|
|
166
|
+
const original = this._getModel(originalUrl);
|
|
167
|
+
const modified = this._getModel(modifiedUrl);
|
|
168
|
+
const originalModel = ( new NotebookTextModelFacade(original));
|
|
169
|
+
const modifiedModel = ( new NotebookTextModelFacade(modified));
|
|
170
|
+
const originalMetadata = filter(original.metadata, key => !original.transientDocumentMetadata[key]);
|
|
171
|
+
const modifiedMetadata = filter(modified.metadata, key => !modified.transientDocumentMetadata[key]);
|
|
172
|
+
const metadataChanged = JSON.stringify(originalMetadata) !== JSON.stringify(modifiedMetadata);
|
|
173
|
+
const originalDiff = ( new LcsDiff(CellSequence.create(original), CellSequence.create(modified))).ComputeDiff(false);
|
|
174
|
+
if (originalDiff.changes.length === 0) {
|
|
175
|
+
return {
|
|
176
|
+
metadataChanged,
|
|
177
|
+
cellsDiff: originalDiff
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const cellMapping = computeDiff(originalModel, modifiedModel, { cellsDiff: { changes: originalDiff.changes, quitEarly: false }}).cellDiffInfo;
|
|
181
|
+
if (cellMapping.every(c => c.type === 'modified')) {
|
|
182
|
+
return {
|
|
183
|
+
metadataChanged,
|
|
184
|
+
cellsDiff: originalDiff
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
let diffUsingCellIds = this.canComputeDiffWithCellIds(original, modified);
|
|
188
|
+
if (!diffUsingCellIds) {
|
|
189
|
+
const result = matchCellBasedOnSimilarties(modified.cells, original.cells);
|
|
190
|
+
if (( result.some(c => c.original !== -1))) {
|
|
191
|
+
this.updateCellIdsBasedOnMappings(result, original.cells, modified.cells);
|
|
192
|
+
diffUsingCellIds = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!diffUsingCellIds) {
|
|
196
|
+
return {
|
|
197
|
+
metadataChanged,
|
|
198
|
+
cellsDiff: originalDiff
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const cellsInsertedOrDeletedDiff = ( new LcsDiff(
|
|
202
|
+
CellSequence.createWithCellId(original.cells),
|
|
203
|
+
CellSequence.createWithCellId(modified.cells)
|
|
204
|
+
)).ComputeDiff(false);
|
|
205
|
+
const cellDiffInfo = computeDiff(originalModel, modifiedModel, { cellsDiff: { changes: cellsInsertedOrDeletedDiff.changes, quitEarly: false }}).cellDiffInfo;
|
|
206
|
+
let processedIndex = 0;
|
|
207
|
+
const changes = [];
|
|
208
|
+
cellsInsertedOrDeletedDiff.changes.forEach(change => {
|
|
209
|
+
if (!change.originalLength && change.modifiedLength) {
|
|
210
|
+
const changeIndex = cellDiffInfo.findIndex(c => c.type === 'insert' && c.modifiedCellIndex === change.modifiedStart);
|
|
211
|
+
cellDiffInfo.slice(processedIndex, changeIndex).forEach(c => {
|
|
212
|
+
if (c.type === 'unchanged' || c.type === 'modified') {
|
|
213
|
+
const originalCell = original.cells[c.originalCellIndex];
|
|
214
|
+
const modifiedCell = modified.cells[c.modifiedCellIndex];
|
|
215
|
+
const changed = c.type === 'modified' || originalCell.getComparisonValue() !== modifiedCell.getComparisonValue();
|
|
216
|
+
if (changed) {
|
|
217
|
+
changes.push(( new DiffChange(c.originalCellIndex, 1, c.modifiedCellIndex, 1)));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
changes.push(change);
|
|
222
|
+
processedIndex = changeIndex + 1;
|
|
223
|
+
}
|
|
224
|
+
else if (change.originalLength && !change.modifiedLength) {
|
|
225
|
+
const changeIndex = cellDiffInfo.findIndex(c => c.type === 'delete' && c.originalCellIndex === change.originalStart);
|
|
226
|
+
cellDiffInfo.slice(processedIndex, changeIndex).forEach(c => {
|
|
227
|
+
if (c.type === 'unchanged' || c.type === 'modified') {
|
|
228
|
+
const originalCell = original.cells[c.originalCellIndex];
|
|
229
|
+
const modifiedCell = modified.cells[c.modifiedCellIndex];
|
|
230
|
+
const changed = c.type === 'modified' || originalCell.getComparisonValue() !== modifiedCell.getComparisonValue();
|
|
231
|
+
if (changed) {
|
|
232
|
+
changes.push(( new DiffChange(c.originalCellIndex, 1, c.modifiedCellIndex, 1)));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
changes.push(change);
|
|
237
|
+
processedIndex = changeIndex + 1;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const changeIndex = cellDiffInfo.findIndex(c => (c.type === 'delete' && c.originalCellIndex === change.originalStart) || (c.type === 'insert' && c.modifiedCellIndex === change.modifiedStart));
|
|
241
|
+
cellDiffInfo.slice(processedIndex, changeIndex).forEach(c => {
|
|
242
|
+
if (c.type === 'unchanged' || c.type === 'modified') {
|
|
243
|
+
const originalCell = original.cells[c.originalCellIndex];
|
|
244
|
+
const modifiedCell = modified.cells[c.modifiedCellIndex];
|
|
245
|
+
const changed = c.type === 'modified' || originalCell.getComparisonValue() !== modifiedCell.getComparisonValue();
|
|
246
|
+
if (changed) {
|
|
247
|
+
changes.push(( new DiffChange(c.originalCellIndex, 1, c.modifiedCellIndex, 1)));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
changes.push(change);
|
|
252
|
+
processedIndex = changeIndex + 1;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
cellDiffInfo.slice(processedIndex).forEach(c => {
|
|
256
|
+
if (c.type === 'unchanged' || c.type === 'modified') {
|
|
257
|
+
const originalCell = original.cells[c.originalCellIndex];
|
|
258
|
+
const modifiedCell = modified.cells[c.modifiedCellIndex];
|
|
259
|
+
const changed = c.type === 'modified' || originalCell.getComparisonValue() !== modifiedCell.getComparisonValue();
|
|
260
|
+
if (changed) {
|
|
261
|
+
changes.push(( new DiffChange(c.originalCellIndex, 1, c.modifiedCellIndex, 1)));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return {
|
|
266
|
+
metadataChanged,
|
|
267
|
+
cellsDiff: {
|
|
268
|
+
changes,
|
|
269
|
+
quitEarly: false
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
canComputeDiffWithCellIds(original, modified) {
|
|
274
|
+
return this.canComputeDiffWithCellInternalIds(original, modified) || this.canComputeDiffWithCellMetadataIds(original, modified);
|
|
275
|
+
}
|
|
276
|
+
canComputeDiffWithCellInternalIds(original, modified) {
|
|
277
|
+
const originalCellIndexIds = ( original.cells.map(
|
|
278
|
+
(cell, index) => ({ index, id: (cell.internalMetadata?.internalId || '') })
|
|
279
|
+
));
|
|
280
|
+
const modifiedCellIndexIds = ( modified.cells.map(
|
|
281
|
+
(cell, index) => ({ index, id: (cell.internalMetadata?.internalId || '') })
|
|
282
|
+
));
|
|
283
|
+
if (( originalCellIndexIds.some(c => !c.id)) || ( modifiedCellIndexIds.some(c => !c.id))) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
return ( originalCellIndexIds.some(c => modifiedCellIndexIds.find(m => m.id === c.id)));
|
|
287
|
+
}
|
|
288
|
+
canComputeDiffWithCellMetadataIds(original, modified) {
|
|
289
|
+
const originalCellIndexIds = ( original.cells.map((cell, index) => ({ index, id: (cell.metadata?.id || '') })));
|
|
290
|
+
const modifiedCellIndexIds = ( modified.cells.map((cell, index) => ({ index, id: (cell.metadata?.id || '') })));
|
|
291
|
+
if (( originalCellIndexIds.some(c => !c.id)) || ( modifiedCellIndexIds.some(c => !c.id))) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
if (originalCellIndexIds.every(c => !modifiedCellIndexIds.find(m => m.id === c.id))) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
isOriginalCellMatchedWithModifiedCell(originalCell) {
|
|
300
|
+
return (originalCell.internalMetadata?.internalId || '').startsWith(PREFIX_FOR_UNMATCHED_ORIGINAL_CELLS);
|
|
301
|
+
}
|
|
302
|
+
updateCellIdsBasedOnMappings(mappings, originalCells, modifiedCells) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
$canPromptRecommendation(modelUrl) {
|
|
306
|
+
const model = this._getModel(modelUrl);
|
|
307
|
+
const cells = model.cells;
|
|
308
|
+
for (let i = 0; i < cells.length; i++) {
|
|
309
|
+
const cell = cells[i];
|
|
310
|
+
if (cell.cellKind === CellKind.Markup) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (cell.language !== 'python') {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const searchParams = ( new SearchParams('import\\s*pandas|from\\s*pandas', true, false, null));
|
|
317
|
+
const searchData = searchParams.parseSearchRequest();
|
|
318
|
+
if (!searchData) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const builder = ( new PieceTreeTextBufferBuilder());
|
|
322
|
+
builder.acceptChunk(cell.getValue());
|
|
323
|
+
const bufferFactory = builder.finish(true);
|
|
324
|
+
const textBuffer = bufferFactory.create(cell.eol).textBuffer;
|
|
325
|
+
const lineCount = textBuffer.getLineCount();
|
|
326
|
+
const maxLineCount = Math.min(lineCount, 20);
|
|
327
|
+
const range = ( new Range(1, 1, maxLineCount, textBuffer.getLineLength(maxLineCount) + 1));
|
|
328
|
+
const cellMatches = textBuffer.findMatchesLineByLine(range, searchData, true, 1);
|
|
329
|
+
if (cellMatches.length > 0) {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
_getModel(uri) {
|
|
336
|
+
return this._models[uri];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function create() {
|
|
340
|
+
return ( new NotebookWorker());
|
|
341
|
+
}
|
|
342
|
+
class NotebookTextModelFacade {
|
|
343
|
+
constructor(notebook) {
|
|
344
|
+
this.notebook = notebook;
|
|
345
|
+
this.cells = ( notebook.cells.map(cell => ( new NotebookCellTextModelFacade(cell))));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
class NotebookCellTextModelFacade {
|
|
349
|
+
get cellKind() {
|
|
350
|
+
return this.cell.cellKind;
|
|
351
|
+
}
|
|
352
|
+
constructor(cell) {
|
|
353
|
+
this.cell = cell;
|
|
354
|
+
}
|
|
355
|
+
getHashValue() {
|
|
356
|
+
return this.cell.getComparisonValue();
|
|
357
|
+
}
|
|
358
|
+
equal(cell) {
|
|
359
|
+
if (cell.cellKind !== this.cellKind) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
return this.getHashValue() === cell.getHashValue();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export { NotebookWorker, create };
|