Skip to content

Commit b286478

Browse files
committed
Merge branch 'main' into joh/exceptional-yak
2 parents 50e33ac + 363a88d commit b286478

File tree

6 files changed

+65
-8
lines changed

6 files changed

+65
-8
lines changed

src/vs/workbench/browser/workbench.contribution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
696696
'security.allowedUNCHosts': {
697697
'type': 'array',
698698
'items': {
699-
'type': 'string'
699+
'type': 'string',
700+
'pattern': '^[^\\\\]+$',
701+
'patternErrorMessage': localize('security.allowedUNCHosts.patternErrorMessage', 'UNC host names must not contain backslashes.')
700702
},
701703
'default': [],
702704
'markdownDescription': localize('security.allowedUNCHosts', 'A set of UNC host names (without leading or trailing backslash, for example `192.168.0.1` or `my-server`) to allow without user confirmation. If a UNC host is being accessed that is not allowed via this setting or has not been acknowledged via user confirmation, an error will occur and the operation stopped. A restart is required when changing this setting. Find out more about this setting at https://aka.ms/vscode-windows-unc.'),

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@ export class InteractiveEditorController implements IEditorContribution {
596596
}
597597
}
598598

599+
createSnapshot(): void {
600+
if (this._activeSession && !this._activeSession.textModel0.equalsTextBuffer(this._activeSession.textModelN.getTextBuffer())) {
601+
this._activeSession.createSnapshot();
602+
}
603+
}
604+
599605
async applyChanges(): Promise<EditResponse | void> {
600606
if (this._strategy) {
601607
const strategy = this._strategy;

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
88
import { Event } from 'vs/base/common/event';
99
import { ResourceEdit, ResourceFileEdit, ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService';
1010
import { TextEdit } from 'vs/editor/common/languages';
11-
import { ITextModel } from 'vs/editor/common/model';
11+
import { ITextModel, ITextSnapshot } from 'vs/editor/common/model';
1212
import { EditMode, IInteractiveEditorSessionProvider, IInteractiveEditorSession, IInteractiveEditorBulkEditResponse, IInteractiveEditorEditResponse, IInteractiveEditorMessageResponse, IInteractiveEditorResponse, IInteractiveEditorService } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
1313
import { IRange, Range } from 'vs/editor/common/core/range';
1414
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
@@ -58,6 +58,7 @@ export class Session {
5858

5959
private _lastInput: string | undefined;
6060
private _lastTextModelChanges: LineRangeMapping[] | undefined;
61+
private _lastSnapshot: ITextSnapshot | undefined;
6162
private readonly _exchange: SessionExchange[] = [];
6263
private readonly _startTime = new Date();
6364
private readonly _teldata: Partial<TelemetryData>;
@@ -89,11 +90,19 @@ export class Session {
8990
return this._lastInput;
9091
}
9192

93+
get lastSnapshot(): ITextSnapshot | undefined {
94+
return this._lastSnapshot;
95+
}
96+
9297
get wholeRange(): Range {
9398
return this.textModelN.getDecorationRange(this._wholeRangeMarkerId)!;
9499
// return new Range(1, 1, 1, 1);
95100
}
96101

102+
createSnapshot(): void {
103+
this._lastSnapshot = this.textModelN.createSnapshot();
104+
}
105+
97106
addExchange(exchange: SessionExchange): void {
98107
const newLen = this._exchange.push(exchange);
99108
this._teldata.rounds += `${newLen}|`;

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorStrategies.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
2323
import { InteractiveEditorFileCreatePreviewWidget, InteractiveEditorLivePreviewWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorLivePreviewWidget';
2424
import { EditResponse, Session } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
2525
import { InteractiveEditorWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget';
26+
import { getValueFromSnapshot } from 'vs/workbench/contrib/interactiveEditor/browser/utils';
2627
import { CTX_INTERACTIVE_EDITOR_INLNE_DIFF, CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
2728

2829
export abstract class EditModeStrategy {
@@ -213,7 +214,7 @@ export class LiveStrategy extends EditModeStrategy {
213214
@IContextKeyService contextKeyService: IContextKeyService,
214215
@IStorageService protected _storageService: IStorageService,
215216
@IBulkEditService protected readonly _bulkEditService: IBulkEditService,
216-
@IEditorWorkerService protected readonly _editorWorkerService: IEditorWorkerService
217+
@IEditorWorkerService protected readonly _editorWorkerService: IEditorWorkerService,
217218
) {
218219
super();
219220
this._inlineDiffDecorations = new InlineDiffDecorations(this._editor, this._inlineDiffEnabled);
@@ -264,11 +265,16 @@ export class LiveStrategy extends EditModeStrategy {
264265
}
265266

266267
async cancel() {
267-
const { textModelN: modelN, textModel0: model0 } = this._session;
268-
if (modelN.isDisposed() || model0.isDisposed()) {
268+
const { textModelN: modelN, textModel0: model0, lastSnapshot } = this._session;
269+
if (modelN.isDisposed() || (model0.isDisposed() && !lastSnapshot)) {
269270
return;
270271
}
271-
const edits = await this._editorWorkerService.computeMoreMinimalEdits(modelN.uri, [{ range: modelN.getFullModelRange(), text: model0.getValue() }]);
272+
273+
const newText = lastSnapshot
274+
? getValueFromSnapshot(lastSnapshot)
275+
: model0.getValue();
276+
277+
const edits = await this._editorWorkerService.computeMoreMinimalEdits(modelN.uri, [{ range: modelN.getFullModelRange(), text: newText }]);
272278
if (edits) {
273279
const operations = edits.map(e => EditOperation.replace(Range.lift(e.range), e.text));
274280
modelN.pushEditOperations(null, operations, () => null);

src/vs/workbench/contrib/interactiveEditor/browser/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { LineRange } from 'vs/editor/common/core/lineRange';
77
import { Range } from 'vs/editor/common/core/range';
8-
import { ITextModel } from 'vs/editor/common/model';
8+
import { ITextModel, ITextSnapshot } from 'vs/editor/common/model';
99

1010
export function invertLineRange(range: LineRange, model: ITextModel): LineRange[] {
1111
if (range.isEmpty) {
@@ -20,3 +20,15 @@ export function invertLineRange(range: LineRange, model: ITextModel): LineRange[
2020
export function lineRangeAsRange(r: LineRange): Range {
2121
return new Range(r.startLineNumber, 1, r.endLineNumberExclusive - 1, 1);
2222
}
23+
24+
export function getValueFromSnapshot(snapshot: ITextSnapshot): string {
25+
let result = '';
26+
while (true) {
27+
const chunk = snapshot.read();
28+
if (chunk === null) {
29+
break;
30+
}
31+
result += chunk;
32+
}
33+
return result;
34+
}

src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Iterable } from 'vs/base/common/iterator';
77
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
88
import { URI, UriComponents } from 'vs/base/common/uri';
99
import { CancellationTokenSource } from 'vs/base/common/cancellation';
10+
import { isEqual } from 'vs/base/common/resources';
1011
import { ITextModel } from 'vs/editor/common/model';
1112
import { Range } from 'vs/editor/common/core/range';
1213
import { ISelection } from 'vs/editor/common/core/selection';
@@ -31,6 +32,8 @@ import { Schemas } from 'vs/base/common/network';
3132
import { IDebugService } from 'vs/workbench/contrib/debug/common/debug';
3233
import { CTX_INTERACTIVE_EDITOR_FOCUSED, IInteractiveEditorRequest, IInteractiveEditorService } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
3334
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
35+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
36+
import { InteractiveEditorController } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController';
3437
import { EditOperation } from 'vs/editor/common/core/editOperation';
3538

3639
const EXECUTE_NOTEBOOK_COMMAND_ID = 'notebook.execute';
@@ -208,7 +211,26 @@ registerAction2(class ExecuteCell extends NotebookMultiCellAction {
208211
await context.notebookEditor.focusNotebookCell(context.cell, 'container', { skipReveal: true });
209212
}
210213

211-
return runCell(editorGroupsService, context);
214+
let foundEditor: ICodeEditor | undefined = undefined;
215+
for (const [, codeEditor] of context.notebookEditor.codeEditors) {
216+
if (isEqual(codeEditor.getModel()?.uri, (context.cell ?? context.selectedCells?.[0])?.uri)) {
217+
foundEditor = codeEditor;
218+
break;
219+
}
220+
}
221+
222+
await runCell(editorGroupsService, context);
223+
224+
if (!foundEditor) {
225+
return;
226+
}
227+
228+
const controller = InteractiveEditorController.get(foundEditor);
229+
if (!controller) {
230+
return;
231+
}
232+
233+
controller.createSnapshot();
212234
}
213235
});
214236

0 commit comments

Comments
 (0)