Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no diff editor when just dealing with inserts #195910

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { LineRange } from 'vs/editor/common/core/lineRange';
import { DetailedLineRangeMapping } from 'vs/editor/common/diff/rangeMapping';
import { Position } from 'vs/editor/common/core/position';
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { IEditorDecorationsCollection, ScrollType } from 'vs/editor/common/editorCommon';
import { ILogService } from 'vs/platform/log/common/log';
import { lineRangeAsRange, invertLineRange } from 'vs/workbench/contrib/inlineChat/browser/utils';
import { ResourceLabel } from 'vs/workbench/browser/labels';
Expand All @@ -43,7 +43,9 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {

private readonly _elements = h('div.inline-chat-diff-widget@domNode');

private readonly _decorationCollection: IEditorDecorationsCollection;
private readonly _diffEditor: IDiffEditor;

private _dim: Dimension | undefined;
private _isVisible: boolean = false;

Expand All @@ -60,6 +62,8 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
super.create();
assertType(editor.hasModel());

this._decorationCollection = editor.createDecorationsCollection();

const diffContributions = EditorExtensionsRegistry
.getEditorContributions()
.filter(c => c.id !== INLINE_CHAT_ID && c.id !== FoldingController.ID);
Expand Down Expand Up @@ -137,6 +141,7 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
}

override hide(): void {
this._decorationCollection.clear();
this._cleanupFullDiff();
super.hide();
this._isVisible = false;
Expand All @@ -150,13 +155,17 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
const hasFocus = this._diffEditor.hasTextFocus();
this._isVisible = true;

if (changes.length === 0 || this._session.textModel0.getValueLength() === 0) {
const onlyInserts = changes.every(change => change.original.isEmpty);

if (onlyInserts || changes.length === 0 || this._session.textModel0.getValueLength() === 0) {
// no change or changes to an empty file
this._logService.debug('[IE] livePreview-mode: no diff');
this._cleanupFullDiff();
this._renderInsertWithHighlight(changes);
} else {
// complex changes
this._logService.debug('[IE] livePreview-mode: full diff');
this._decorationCollection.clear();
this._renderChangesWithFullDiff(changes);
}

Expand All @@ -170,6 +179,22 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
}


private _renderInsertWithHighlight(changes: readonly DetailedLineRangeMapping[]) {
assertType(this.editor.hasModel());

const ranges = this._computeHiddenRanges(this.editor.getModel(), changes);

this._decorationCollection.set([{
range: lineRangeAsRange(ranges.modifiedHidden),
options: {
description: 'inline-chat-insert',
showIfCollapsed: false,
isWholeLine: true,
className: 'inline-chat-lines-inserted-range',
}
}]);
}

// --- full diff

private _renderChangesWithFullDiff(changes: readonly DetailedLineRangeMapping[]) {
Expand Down