Skip to content

Unify indentation and formatting APIs #34621

Open
@borekb

Description

@borekb

Maybe this is wishful thinking but I am experiencing many subtle issues with the relatively new editor.autoIndent feature. It's a very useful one and I want to keep it but it misbehaves quite frequently, see e.g. issues #29390, #32333 and many others. Quite a good example is this (from #32835):

Indentation via Format Document:

const MyReactComponent = (props) => {
    return (
        <div>
            <Helmet titleTemplate='%s'>
                <title>Hello</title>
            </Helmet>
        </div>
    );
};

Formatting via Reindent Lines:

const MyReactComponent = (props) => {
    return (
        <div>
        <Helmet titleTemplate='%s'>
        <title>Hello</title>
        </Helmet>
        </div>
    );
};

It often seems to me that formatting API produces better results than indentation rules but even if that wasn't always the case it just seems logical to have a single API to power both features. It seems like this to me:

  1. Indenting functionality cares about the leading whitespaces.
  2. Formatting cares about the above plus anything after the first non-whitespace character.

So it's a subset / superset problem and I don't think it should be implemented twice, in a completely different manner. What do you think? Would there be a chance to unify the two APIs and eliminate some bugs along the way?


For reference, some key issues related to this:

Metadata

Metadata

Assignees

Labels

editor-autoindentEditor auto indentation issuesfeature-requestRequest for new features or functionalityunder-discussionIssue is under discussion for relevance, priority, approach

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions