vsc-python-indent
vsc-python-indent copied to clipboard
Automatic dedent for return doesn't always work
What the code looks like before pressing Enter:
def foo():
return|
When I get to the above state by typing in the function from scratch, then pressing Enter produces this:
def foo():
return
|
However, if I subsequently reposition the cursor to just after return and then press Enter, I get the expected
def foo():
return
|
I also get the correct auto-dedent if I am typing from scratch but press Enter here (note the space between return and the cursor):
def foo():
return |
The same issue occurs if I'm returning an expression that ends with a variable or any of the constants None, True, or False:
def foo(x):
return 3 + x|
After Enter:
def foo(x):
return 3 + x
|
Before Enter (with space after x):
def foo(x):
return 3 + x |
After Enter:
def foo(x):
return 3 + x
|
The issue does not occur if the return expression ends with a numeric constant, string constant, or parenthesis:
def foo(x):
return x + 3|
After Enter:
def foo(x):
return x + 3
|
Before Enter:
def foo(x):
return 3 + (x)|
After Enter:
def foo(x):
return 3 + (x)
|
And to reiterate, the issue also does not occur, no matter what the return expression, if the return line was already previously typed, and I reposition the cursor back to the end of that line, and then press Enter.
I am also not noticing the issue with other keywords, such as pass, raise, break, or continue, which produce the correct auto-dedent without any extra spaces or cursor repositioning.
@jkyeung similar to your previous issue, I cannot reproduce. In an empty python file, if I type the characters
def foo():<enter>return<enter>
I get
def foo():
return
|
Could you list what other extensions you have installed? I'm wondering if something is interacting poorly.
Complete list of installed extensions:
- AutoHotkey Plus Plus
- Code for IBM i
- Code for IBM i Walkthroughs
- IBMi Languages
- Jupyter
- Jupyter Keymap
- Jupyter Notebook Renderers
- Overtype
- Pylance
- Python
- Python Indent
- RPGLE Free
- RPGLE language tools
None of those jump out at me, but could you also try to reproduce after toggling all other extensions else off (and restarting VS Code)?
Also just wanted to make sure you have the most up to date version of vsc-python-indent -- this happens to you in version 1.18?
I am using v1.18.0 of Python Indent. I've disabled everything except Pylance, Python, and Python Indent, restarted VS Code, and the behavior is still as I described above, as well as for #104.
Would it make a difference if I uninstalled, rather than just disable? Do you want to see my settings? Any other ideas?
Would it make a difference if I uninstalled, rather than just disable?
Maybe in very rare circumstances, but it shouldn't really.
Do you want to see my settings?
Sure, if you can copy your modified (non-default) settings here that'd be good. Be sure to include both User and Workspace settings if you have both.
Any other ideas?
Do you have access to another computer where you could try a fresh install of VS Code to see if it still happens? It's possible that the weirdness is actually happening on my side. But FWIW both my personal and work computers behave the same (expected, correct) way, but they're set up in very similar ways.
For reference, here's what it does on my machine.
https://user-images.githubusercontent.com/4053170/194189360-32060258-af88-4b84-88ce-b5dfd2919f7f.mov
Well, here is my user settings.json. I don't have any workspace settings.
{
"telemetry.telemetryLevel": "off",
"editor.fontFamily": "'JetBrains Mono NL ExtraLight', Consolas, monospace",
// "editor.fontFamily": "InputX, Consolas, 'Courier New', monospace",
"editor.fontSize": 16,
"editor.acceptSuggestionOnEnter": "off",
"editor.find.autoFindInSelection": "never",
"editor.rulers": [80],
"editor.stickyTabStops": true,
"editor.autoClosingOvertype": "always",
"workbench.editor.splitOnDragAndDrop": false,
"terminal.integrated.fontFamily": "Consolas",
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"python.terminal.executeInFileDir": true,
"pythonIndent.keepHangingBracketOnLine": true,
"pythonIndent.useTabOnHangingIndent": false,
"[python]": {
"editor.fontFamily": "InputX, 'JetBrains Mono NL ExtraLight', Consolas",
},
"[rpgle]": {
"editor.fontFamily": "'JetBrains Mono NL ExtraLight', Consolas",
"editor.stickyTabStops": false,
"editor.tabSize": 2,
"files.trimFinalNewlines": false,
"files.insertFinalNewline": false,
},
"[cl]": {
"editor.fontFamily": "'JetBrains Mono NL ExtraLight', Consolas",
"files.trimFinalNewlines": false,
"files.insertFinalNewline": false,
},
"code-for-ibmi.showConnectionButtons": true,
"code-for-ibmi.connectionSettings": [
{
"name": "MY_SYS",
"objectFilters": [
{
"name": "LIBRARY1 source",
"library": "LIBRARY1",
"object": "*",
"types": [
"*SRCPF"
],
"member": "*"
},
{
"name": "LIBRARY2 source",
"library": "LIBRARY2",
"object": "*",
"types": [
"*SRCPF"
],
"member": "*"
},
{
"name": "MY_USER source",
"library": "MY_USER",
"object": "*",
"types": [
"*SRCPF"
],
"member": "*"
}
],
"libraryList": [
"QGPL",
"QTEMP",
"LIBRARY1",
"LIBRARY2",
"QS36F",
"OTHER_LIB",
"XYZLIB"
],
"autoClearTempData": false,
"customVariables": [],
"connectionProfiles": [],
"ifsShortcuts": [
"/home/MY_USER"
],
"homeDirectory": "/home/MY_USER",
"enableSQL": false,
"tempLibrary": "ILEDITOR",
"tempDir": "/tmp",
"currentLibrary": "QGPL",
"sourceFileCCSID": "*FILE",
"autoConvertIFSccsid": false,
"hideCompileErrors": [],
"enableSourceDates": true,
"sourceDateGutter": true,
"clContentAssistEnabled": false,
"encodingFor5250": "default",
"terminalFor5250": "default",
"setDeviceNameFor5250": false,
"connectringStringFor5250": "localhost",
"autoSaveBeforeAction": false,
"sourceASP": null,
"databaseBrowserList": [
"MY_USER",
"LIBRARY2",
"QS36F"
]
}
],
"code-for-ibmi.connections": [
{
"name": "MY_SYS",
"host": "MY_HOST.COM",
"port": 22,
"username": "my_user",
"privateKey": null
}
],
"files.associations": {
"*.SQLSCRIPT": "sql",
"*.DDL": "sql",
"*.mac": "xml"
},
"vscode-rpgle.rpgleLinterSupportEnabled": true,
"vscode-rpgle.showFixedFormatOutline": true,
}
I will try a clean install when I get a chance.
I've just completely uninstalled VS Code on another computer, rebooted, and installed VS Code again. The only extensions I installed this time were Python (and the ones it installs automatically) and Python Indent. The behavior I've described above still happens.
That's pretty strange. I would guess that we'd see more activity on this issue if others were experiencing the same thing, but it's really weird that on a fresh install you see the same behavior.
If you're willing to dedicate more time to debugging, you could try cloning this repo and setting up a development environment (see the quickstart). That would let you set debug points.
E.g. the behavior you're seeing almost looks like the indentation parser isn't being fed all the text up to the point of your cursor. You could set a debug point here and inspect the content of the lines and position (0-indexed position of your cursor) variables to see if they look right.
Thanks for the tips. I would love to try setting up a development environment, but right now it's much more time-effective for me to just live with the quirks that I'm getting.
Once the Pylance extension gained the ability to do sophisticated indentation itself (with "editor.formatOnType": true), I disabled Python Indent and was pretty happy with what Pylance was doing.
Until recently. Its indentation behavior changed for no discernible benefit (depending on your preference, the new behavior was either identical to the old, or much worse).
So I've re-enabled Python Indent and interestingly, have not encountered this issue anymore! Since I can't reproduce it anymore, I'm closing this issue.
Closed as stale and unreproducible.
Thanks for the follow-up!
Unfortunately, this is happening for me again on the computer I use for work. Doesn't happen on my computer for home.
I'm not going to bother reopening this issue, since it's probably just as hard to reproduce or debug as before. I kind of just wanted to update how things stand.