Skip to content

Commit

Permalink
Re-enable support for editor.indentSize setting
Browse files Browse the repository at this point in the history
This change allows the indentation size to be distinct from the tab width,
when using spaces for indentation.

This commit simply reverts e2049cd and portions of a60beb9, which had
removed this feature.
  • Loading branch information
zeroimpl committed Jul 18, 2022
1 parent 0ea3709 commit 523743b
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 30 deletions.
28 changes: 14 additions & 14 deletions src/vs/editor/common/config/editorConfigurationSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const editorConfiguration: IConfigurationNode = {
minimum: 1,
markdownDescription: nls.localize('tabSize', "The number of spaces a tab is equal to. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
},
// 'editor.indentSize': {
// 'anyOf': [
// {
// type: 'string',
// enum: ['tabSize']
// },
// {
// type: 'number',
// minimum: 1
// }
// ],
// default: 'tabSize',
// markdownDescription: nls.localize('indentSize', "The number of spaces used for indentation or 'tabSize' to use the value from `#editor.tabSize#`. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
// },
'editor.indentSize': {
'anyOf': [
{
type: 'string',
enum: ['tabSize']
},
{
type: 'number',
minimum: 1
}
],
default: 'tabSize',
markdownDescription: nls.localize('indentSize', "The number of spaces used for indentation or 'tabSize' to use the value from `#editor.tabSize#`. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
},
'editor.insertSpaces': {
type: 'boolean',
default: EDITOR_MODEL_DEFAULTS.insertSpaces,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class TextModelResolvedOptions {
bracketPairColorizationOptions: BracketPairColorizationOptions;
}) {
this.tabSize = Math.max(1, src.tabSize | 0);
this.indentSize = src.tabSize | 0;
this.indentSize = Math.max(1, src.indentSize | 0);
this.insertSpaces = Boolean(src.insertSpaces);
this.defaultEOL = src.defaultEOL | 0;
this.trimAutoWhitespace = Boolean(src.trimAutoWhitespace);
Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/api/browser/mainThreadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class MainThreadTextEditorProperties {
return {
insertSpaces: modelOptions.insertSpaces,
tabSize: modelOptions.tabSize,
indentSize: modelOptions.indentSize,
cursorStyle: cursorStyle,
lineNumbers: lineNumbers
};
Expand Down Expand Up @@ -146,6 +147,7 @@ export class MainThreadTextEditorProperties {
}
return (
a.tabSize === b.tabSize
&& a.indentSize === b.indentSize
&& a.insertSpaces === b.insertSpaces
&& a.cursorStyle === b.cursorStyle
&& a.lineNumbers === b.lineNumbers
Expand Down Expand Up @@ -376,6 +378,13 @@ export class MainThreadTextEditor {
if (typeof newConfiguration.tabSize !== 'undefined') {
newOpts.tabSize = newConfiguration.tabSize;
}
if (typeof newConfiguration.indentSize !== 'undefined') {
if (newConfiguration.indentSize === 'tabSize') {
newOpts.indentSize = newOpts.tabSize || creationOpts.tabSize;
} else {
newOpts.indentSize = newConfiguration.indentSize;
}
}
this._model.updateOptions(newOpts);
}

Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ export interface MainThreadDocumentsShape extends IDisposable {

export interface ITextEditorConfigurationUpdate {
tabSize?: number | 'auto';
indentSize?: number | 'tabSize';
insertSpaces?: boolean | 'auto';
cursorStyle?: TextEditorCursorStyle;
lineNumbers?: RenderLineNumbersType;
}

export interface IResolvedTextEditorConfiguration {
tabSize: number;
indentSize: number;
insertSpaces: boolean;
cursorStyle: TextEditorCursorStyle;
lineNumbers: RenderLineNumbersType;
Expand Down
71 changes: 59 additions & 12 deletions src/vs/workbench/api/common/extHostTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class ExtHostTextEditorOptions {
private _logService: ILogService;

private _tabSize!: number;
private _indentSize!: number;
private _insertSpaces!: boolean;
private _cursorStyle!: TextEditorCursorStyle;
private _lineNumbers!: TextEditorLineNumbersStyle;
Expand All @@ -164,6 +165,12 @@ export class ExtHostTextEditorOptions {
set tabSize(value: number | string) {
that._setTabSize(value);
},
get indentSize(): number | string {
return that._indentSize;
},
set indentSize(value: number | string) {
that._setIndentSize(value);
},
get insertSpaces(): boolean | string {
return that._insertSpaces;
},
Expand All @@ -187,6 +194,7 @@ export class ExtHostTextEditorOptions {

public _accept(source: IResolvedTextEditorConfiguration): void {
this._tabSize = source.tabSize;
this._indentSize = source.indentSize;
this._insertSpaces = source.insertSpaces;
this._cursorStyle = source.cursorStyle;
this._lineNumbers = TypeConverters.TextEditorLineNumbersStyle.to(source.lineNumbers);
Expand Down Expand Up @@ -231,6 +239,45 @@ export class ExtHostTextEditorOptions {
}));
}

// --- internal: indentSize

private _validateIndentSize(value: number | string): number | 'tabSize' | null {
if (value === 'tabSize') {
return 'tabSize';
}
if (typeof value === 'number') {
const r = Math.floor(value);
return (r > 0 ? r : null);
}
if (typeof value === 'string') {
const r = parseInt(value, 10);
if (isNaN(r)) {
return null;
}
return (r > 0 ? r : null);
}
return null;
}

private _setIndentSize(value: number | string) {
const indentSize = this._validateIndentSize(value);
if (indentSize === null) {
// ignore invalid call
return;
}
if (typeof indentSize === 'number') {
if (this._indentSize === indentSize) {
// nothing to do
return;
}
// reflect the new indentSize value immediately
this._indentSize = indentSize;
}
this._warnOnError('setIndentSize', this._proxy.$trySetOptions(this._id, {
indentSize: indentSize
}));
}

// --- internal: insert spaces

private _validateInsertSpaces(value: boolean | string): boolean | 'auto' {
Expand Down Expand Up @@ -298,18 +345,18 @@ export class ExtHostTextEditorOptions {
}
}

// if (typeof newOptions.indentSize !== 'undefined') {
// const indentSize = this._validateIndentSize(newOptions.indentSize);
// if (indentSize === 'tabSize') {
// hasUpdate = true;
// bulkConfigurationUpdate.indentSize = indentSize;
// } else if (typeof indentSize === 'number' && this._indentSize !== indentSize) {
// // reflect the new indentSize value immediately
// this._indentSize = indentSize;
// hasUpdate = true;
// bulkConfigurationUpdate.indentSize = indentSize;
// }
// }
if (typeof newOptions.indentSize !== 'undefined') {
const indentSize = this._validateIndentSize(newOptions.indentSize);
if (indentSize === 'tabSize') {
hasUpdate = true;
bulkConfigurationUpdate.indentSize = indentSize;
} else if (typeof indentSize === 'number' && this._indentSize !== indentSize) {
// reflect the new indentSize value immediately
this._indentSize = indentSize;
hasUpdate = true;
bulkConfigurationUpdate.indentSize = indentSize;
}
}

if (typeof newOptions.insertSpaces !== 'undefined') {
const insertSpaces = this._validateInsertSpaces(newOptions.insertSpaces);
Expand Down
Loading

0 comments on commit 523743b

Please sign in to comment.