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

Allow setting indent size to an explicit number when it is computed from tab size #200368

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/vs/workbench/api/browser/mainThreadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class MainThreadTextEditorProperties {
insertSpaces: modelOptions.insertSpaces,
tabSize: modelOptions.tabSize,
indentSize: modelOptions.indentSize,
originalIndentSize: modelOptions.originalIndentSize,
cursorStyle: cursorStyle,
lineNumbers: lineNumbers
};
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export interface ITextEditorConfigurationUpdate {
export interface IResolvedTextEditorConfiguration {
tabSize: number;
indentSize: number;
originalIndentSize: number | 'tabSize';
insertSpaces: boolean;
cursorStyle: TextEditorCursorStyle;
lineNumbers: RenderLineNumbersType;
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/api/common/extHostTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class ExtHostTextEditorOptions {

private _tabSize!: number;
private _indentSize!: number;
private _originalIndentSize!: number | 'tabSize';
private _insertSpaces!: boolean;
private _cursorStyle!: TextEditorCursorStyle;
private _lineNumbers!: TextEditorLineNumbersStyle;
Expand Down Expand Up @@ -195,6 +196,7 @@ export class ExtHostTextEditorOptions {
public _accept(source: IResolvedTextEditorConfiguration): void {
this._tabSize = source.tabSize;
this._indentSize = source.indentSize;
this._originalIndentSize = source.originalIndentSize;
this._insertSpaces = source.insertSpaces;
this._cursorStyle = source.cursorStyle;
this._lineNumbers = TypeConverters.TextEditorLineNumbersStyle.to(source.lineNumbers);
Expand Down Expand Up @@ -266,12 +268,13 @@ export class ExtHostTextEditorOptions {
return;
}
if (typeof indentSize === 'number') {
if (this._indentSize === indentSize) {
if (this._originalIndentSize === indentSize) {
// nothing to do
return;
}
// reflect the new indentSize value immediately
this._indentSize = indentSize;
this._originalIndentSize = indentSize;
}
this._warnOnError('setIndentSize', this._proxy.$trySetOptions(this._id, {
indentSize: indentSize
Expand Down Expand Up @@ -350,9 +353,10 @@ export class ExtHostTextEditorOptions {
if (indentSize === 'tabSize') {
hasUpdate = true;
bulkConfigurationUpdate.indentSize = indentSize;
} else if (typeof indentSize === 'number' && this._indentSize !== indentSize) {
} else if (typeof indentSize === 'number' && this._originalIndentSize !== indentSize) {
// reflect the new indentSize value immediately
this._indentSize = indentSize;
this._originalIndentSize = indentSize;
hasUpdate = true;
bulkConfigurationUpdate.indentSize = indentSize;
}
Expand Down
11 changes: 6 additions & 5 deletions src/vs/workbench/api/test/browser/extHostTextEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ suite('ExtHostTextEditor', () => {
], '\n', 1, 'text', false);

setup(() => {
editor = new ExtHostTextEditor('fake', null!, new NullLogService(), new Lazy(() => doc.document), [], { cursorStyle: TextEditorCursorStyle.Line, insertSpaces: true, lineNumbers: 1, tabSize: 4, indentSize: 4 }, [], 1);
editor = new ExtHostTextEditor('fake', null!, new NullLogService(), new Lazy(() => doc.document), [], { cursorStyle: TextEditorCursorStyle.Line, insertSpaces: true, lineNumbers: 1, tabSize: 4, indentSize: 4, originalIndentSize: 'tabSize' }, [], 1);
});

test('disposed editor', () => {
Expand All @@ -48,7 +48,7 @@ suite('ExtHostTextEditor', () => {
applyCount += 1;
return Promise.resolve(true);
}
}, new NullLogService(), new Lazy(() => doc.document), [], { cursorStyle: TextEditorCursorStyle.Line, insertSpaces: true, lineNumbers: 1, tabSize: 4, indentSize: 4 }, [], 1);
}, new NullLogService(), new Lazy(() => doc.document), [], { cursorStyle: TextEditorCursorStyle.Line, insertSpaces: true, lineNumbers: 1, tabSize: 4, indentSize: 4, originalIndentSize: 'tabSize' }, [], 1);

await editor.value.edit(edit => { });
assert.strictEqual(applyCount, 0);
Expand Down Expand Up @@ -91,6 +91,7 @@ suite('ExtHostTextEditorOptions', () => {
opts = new ExtHostTextEditorOptions(mockProxy, '1', {
tabSize: 4,
indentSize: 4,
originalIndentSize: 'tabSize',
insertSpaces: false,
cursorStyle: TextEditorCursorStyle.Line,
lineNumbers: RenderLineNumbersType.On
Expand All @@ -102,7 +103,7 @@ suite('ExtHostTextEditorOptions', () => {
calls = null!;
});

function assertState(opts: ExtHostTextEditorOptions, expected: IResolvedTextEditorConfiguration): void {
function assertState(opts: ExtHostTextEditorOptions, expected: Omit<IResolvedTextEditorConfiguration, 'originalIndentSize'>): void {
const actual = {
tabSize: opts.value.tabSize,
indentSize: opts.value.indentSize,
Expand Down Expand Up @@ -230,7 +231,7 @@ suite('ExtHostTextEditorOptions', () => {
cursorStyle: TextEditorCursorStyle.Line,
lineNumbers: RenderLineNumbersType.On
});
assert.deepStrictEqual(calls, []);
assert.deepStrictEqual(calls, [{ indentSize: 4 }]);
});

test('can change indentSize to positive integer', () => {
Expand Down Expand Up @@ -464,7 +465,7 @@ suite('ExtHostTextEditorOptions', () => {
cursorStyle: TextEditorCursorStyle.Line,
lineNumbers: RenderLineNumbersType.On
});
assert.deepStrictEqual(calls, []);
assert.deepStrictEqual(calls, [{ indentSize: 4 }]);
});

test('can do bulk updates 1', () => {
Expand Down