mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 18:22:34 -05:00
Merge from vscode 718331d6f3ebd1b571530ab499edb266ddd493d5
This commit is contained in:
@@ -21,11 +21,10 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IProgress, IProgressStep, emptyProgress } from 'vs/platform/progress/common/progress';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
|
||||
import { Recording } from 'vs/workbench/services/bulkEdit/browser/conflicts';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
|
||||
type ValidationResult = { canApply: true } | { canApply: false, reason: URI };
|
||||
@@ -234,12 +233,10 @@ class BulkEdit {
|
||||
editor: ICodeEditor | undefined,
|
||||
progress: IProgress<IProgressStep> | undefined,
|
||||
edits: Edit[],
|
||||
@IInstantiationService private readonly _instaService: IInstantiationService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@ITextModelService private readonly _textModelService: ITextModelService,
|
||||
@IFileService private readonly _fileService: IFileService,
|
||||
@IEditorWorkerService private readonly _workerService: IEditorWorkerService,
|
||||
@ITextFileService private readonly _textFileService: ITextFileService,
|
||||
@ILabelService private readonly _uriLabelServie: ILabelService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
) {
|
||||
this._editor = editor;
|
||||
@@ -288,7 +285,7 @@ class BulkEdit {
|
||||
// for child operations
|
||||
this._progress.report({ total });
|
||||
|
||||
let progress: IProgress<void> = { report: _ => this._progress.report({ increment: 1 }) };
|
||||
const progress: IProgress<void> = { report: _ => this._progress.report({ increment: 1 }) };
|
||||
|
||||
// do it.
|
||||
for (const group of groups) {
|
||||
@@ -338,22 +335,11 @@ class BulkEdit {
|
||||
private async _performTextEdits(edits: WorkspaceTextEdit[], progress: IProgress<void>): Promise<void> {
|
||||
this._logService.debug('_performTextEdits', JSON.stringify(edits));
|
||||
|
||||
const recording = Recording.start(this._fileService);
|
||||
const model = new BulkEditModel(this._editor, progress, edits, this._workerService, this._textModelService);
|
||||
const model = this._instaService.createInstance(BulkEditModel, this._editor, progress, edits);
|
||||
|
||||
await model.prepare();
|
||||
|
||||
const conflicts = edits
|
||||
.filter(edit => recording.hasChanged(edit.resource))
|
||||
.map(edit => this._uriLabelServie.getUriLabel(edit.resource, { relative: true }));
|
||||
|
||||
recording.stop();
|
||||
|
||||
if (conflicts.length > 0) {
|
||||
model.dispose();
|
||||
throw new Error(localize('conflict', "These files have changed in the meantime: {0}", conflicts.join(', ')));
|
||||
}
|
||||
|
||||
// this._throwIfConflicts(conflicts);
|
||||
const validationResult = model.validate();
|
||||
if (validationResult.canApply === false) {
|
||||
model.dispose();
|
||||
@@ -372,15 +358,10 @@ export class BulkEditService implements IBulkEditService {
|
||||
private _previewHandler?: IBulkEditPreviewHandler;
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private readonly _instaService: IInstantiationService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@IModelService private readonly _modelService: IModelService,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@IEditorWorkerService private readonly _workerService: IEditorWorkerService,
|
||||
@ITextModelService private readonly _textModelService: ITextModelService,
|
||||
@IFileService private readonly _fileService: IFileService,
|
||||
@ITextFileService private readonly _textFileService: ITextFileService,
|
||||
@ILabelService private readonly _labelService: ILabelService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
) { }
|
||||
|
||||
setPreviewHandler(handler: IBulkEditPreviewHandler): IDisposable {
|
||||
@@ -392,6 +373,10 @@ export class BulkEditService implements IBulkEditService {
|
||||
});
|
||||
}
|
||||
|
||||
hasPreviewHandler(): boolean {
|
||||
return Boolean(this._previewHandler);
|
||||
}
|
||||
|
||||
async apply(edit: WorkspaceEdit, options?: IBulkEditOptions): Promise<IBulkEditResult> {
|
||||
|
||||
if (edit.edits.length === 0) {
|
||||
@@ -417,7 +402,6 @@ export class BulkEditService implements IBulkEditService {
|
||||
}
|
||||
|
||||
// try to find code editor
|
||||
// todo@joh, prefer editor that gets edited
|
||||
if (!codeEditor) {
|
||||
let candidate = this._editorService.activeTextEditorWidget;
|
||||
if (isCodeEditor(candidate)) {
|
||||
@@ -429,10 +413,7 @@ export class BulkEditService implements IBulkEditService {
|
||||
// If the code editor is readonly still allow bulk edits to be applied #68549
|
||||
codeEditor = undefined;
|
||||
}
|
||||
const bulkEdit = new BulkEdit(
|
||||
codeEditor, options?.progress, edits,
|
||||
this._logService, this._textModelService, this._fileService, this._workerService, this._textFileService, this._labelService, this._configurationService
|
||||
);
|
||||
const bulkEdit = this._instaService.createInstance(BulkEdit, codeEditor, options?.progress, edits);
|
||||
return bulkEdit.perform().then(() => {
|
||||
return { ariaSummary: bulkEdit.ariaMessage() };
|
||||
}).catch(err => {
|
||||
|
||||
@@ -10,31 +10,11 @@ import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { ResourceMap } from 'vs/base/common/map';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import type { ITextModel } from 'vs/editor/common/model';
|
||||
|
||||
export abstract class Recording {
|
||||
|
||||
static start(fileService: IFileService): Recording {
|
||||
|
||||
let _changes = new Set<string>();
|
||||
let subscription = fileService.onAfterOperation(e => {
|
||||
_changes.add(e.resource.toString());
|
||||
});
|
||||
|
||||
return {
|
||||
stop() { return subscription.dispose(); },
|
||||
hasChanged(resource) { return _changes.has(resource.toString()); }
|
||||
};
|
||||
}
|
||||
|
||||
abstract stop(): void;
|
||||
abstract hasChanged(resource: URI): boolean;
|
||||
}
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
|
||||
export class ConflictDetector {
|
||||
|
||||
private readonly _conflicts = new ResourceMap<boolean>();
|
||||
private readonly _changes = new ResourceMap<boolean>();
|
||||
private readonly _disposables = new DisposableStore();
|
||||
|
||||
private readonly _onDidConflict = new Emitter<this>();
|
||||
@@ -79,9 +59,6 @@ export class ConflictDetector {
|
||||
continue;
|
||||
}
|
||||
|
||||
// change
|
||||
this._changes.set(change.resource, true);
|
||||
|
||||
// conflict
|
||||
if (_workspaceEditResources.has(change.resource)) {
|
||||
this._conflicts.set(change.resource, true);
|
||||
@@ -92,8 +69,6 @@ export class ConflictDetector {
|
||||
|
||||
// listen to model changes...?
|
||||
const onDidChangeModel = (model: ITextModel) => {
|
||||
// change
|
||||
this._changes.set(model.uri, true);
|
||||
|
||||
// conflict
|
||||
if (_workspaceEditResources.has(model.uri)) {
|
||||
@@ -112,12 +87,10 @@ export class ConflictDetector {
|
||||
}
|
||||
|
||||
list(): URI[] {
|
||||
const result: URI[] = this._conflicts.keys();
|
||||
this._changes.forEach((_value, key) => {
|
||||
if (!this._conflicts.has(key)) {
|
||||
result.push(key);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
return this._conflicts.keys();
|
||||
}
|
||||
|
||||
hasConflicts(): boolean {
|
||||
return this._conflicts.size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user