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

Dedent else: #6333

Closed
brettcannon opened this issue Jun 25, 2019 · 8 comments
Closed

Dedent else: #6333

brettcannon opened this issue Jun 25, 2019 · 8 comments
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.

Comments

@brettcannon
Copy link
Member

E.g.

if True:
   print()
   else: # Pressing 'enter' should dedent this line.
@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug needs PR area-formatting labels Jun 25, 2019
@karrtikr
Copy link

Prescribed solution

  • Make sure vscode provides the functionality to - dedent the line we are editing.
  • If there is one, use it.

@ericsnowcurrently
Copy link
Member

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.

@ericsnowcurrently
Copy link
Member

upstream: microsoft/vscode#66235

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jun 26, 2019
@brettcannon brettcannon added this to the 2019 - June Sprint 13 milestone Jun 26, 2019
@brettcannon brettcannon added needs PR and removed triage-needed Needs assignment to the proper sub-team needs upstream fix labels Jun 27, 2019
@brettcannon
Copy link
Member Author

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).

@brettcannon
Copy link
Member Author

@brettcannon
Copy link
Member Author

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.

@ericsnowcurrently
Copy link
Member

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
    ...

@ghost ghost removed the needs PR label Jul 15, 2019
@ericsnowcurrently ericsnowcurrently removed their assignment Jul 15, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 22, 2019
@brettcannon brettcannon reopened this Sep 14, 2021
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 14, 2021
@brettcannon brettcannon added needs spike Label for issues that need investigation before they can be worked on. and removed triage-needed Needs assignment to the proper sub-team labels Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
Development

No branches or pull requests

5 participants