Skip to content

Dedent else: #6333

Closed
Closed

Description

E.g.

if True:
   print()
   else: # Pressing 'enter' should dedent this line.

Activity

  1. karrtikr commented on Jun 26, 2019

    @karrtikr

    Prescribed solution

    • Make sure vscode provides the functionality to - dedent the line we are editing.
    • If there is one, use it.
  2. ericsnowcurrently commented on Jun 26, 2019

    @ericsnowcurrently

    This may not be possible currently. VSCode has the following API that we use in extension.ts:

    https://code.visualstudio.com/api/references/vscode-api#LanguageConfiguration

    We currently use onEnterRules, but indentationRules is another option. However, neither lets you indent the current line.

  3. ericsnowcurrently commented on Jun 26, 2019

    @ericsnowcurrently
  4. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Jun 26, 2019
  5. brettcannon commented on Jul 2, 2019

    @brettcannon
    MemberAuthor

    Turns out that Ruby has support through their language configuration file. It seems if you define a symbol for both indent and dedent (e.g. elsif or else) it will dedent the line but then begin indenting the next line. Not sure if this will work with how we currently do it:

    onEnterRules: [
    {
    beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async)\b.*:\s*/,
    action: { indentAction: IndentAction.Indent }
    },
    {
    beforeText: /^(?!\s+\\)[^#\n]+\\\s*/,
    action: { indentAction: IndentAction.Indent }
    },
    {
    beforeText: /^\s*#.*/,
    afterText: /.+$/,
    action: { indentAction: IndentAction.None, appendText: '# ' }
    },
    {
    beforeText: /^\s+(continue|break|return)\b.*/,
    afterText: /\s+$/,
    action: { indentAction: IndentAction.Outdent }
    }
    ]

    If it won't work there then we should probably look at modernizing our configuration and switch over to the similar configuration file (the extension predates it).

  6. 4 remaining items

  7. brettcannon commented on Jul 12, 2019

    @brettcannon
    MemberAuthor

    We should open a bug against the VS Code docs to document the else trick so no one else has to try and discover that as well.

  8. ericsnowcurrently commented on Jul 15, 2019

    @ericsnowcurrently

    Looks good:

    # dedent
    
    if True:
        break
    if True:
        continue
    if True:
        pass
    if True:
        raise
    if True:
        raise spam
    if True:
        return
    if True:
        return None
    if True:
        return {}
    if True:
        return {
    
    # indent
    
    spam\
        eggs
        # keeps indenting
    if True:
        ...
    while True:
        ...
    for x in spam:
        ...
    try:
        ...
    with spam:
        ...
    def spam():
        ...
    def spam:  # no parens
        ...
    class spam:
        ...
    class spam():
        ...
    async def spam():
        ...
    async for x in spam:
        ...
    async with spam:
        ...
    
    # dedent + indent
    if True:
        ...
    elif False:  # dedented
        ...
    else:  # dedented
        ...
    try:
        ...
    except Exception:  # dedented
        ...
    except:  # dedented
        ...
    else:  # dedented
        ...
    for x in spam:
        ...
    else:  # dedented
        ...
    while True:
        ...
    else:  # dedented
        ...
  9. locked as resolved and limited conversation to collaborators on Jul 22, 2019
  10. added
    needs spikeLabel for issues that need investigation before they can be worked on.
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-formattingbugIssue identified by VS Code Team member as probable bugneeds spikeLabel for issues that need investigation before they can be worked on.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions