Comments (9)
I would like to know if this feature has already been implemented in the extension?
pycharm does something very similar.
from vsc-python-indent.
Interesting idea, thanks for posting. So you're thinking something like this?
# | indicates cursor location
# case 1, no f-string
s = "really long| string"
s = ("really long"
"| string")
# case 2, f-string
s = f"another {really} long| string"
s = (f"another {really} long"
f" string")
# note that r, u, rf, fr, b, rb, and br are all allowed prefixes
# and should be handled in the same way as f-strings
I don't remember if the python parser picks up on whether the string was prefixed with anything, but would probably not be terrible to add if not.
from vsc-python-indent.
Reading back through the parsing code I wrote, I'd have to add another tracker for any combination of f, r, u, rf, fr, b, rb, and br and keep it on hand if the next character turns out to start a string. The output of that parsing function would have to be updated with this information, as well as the string delimiter ('
, "
, '''
, """
).
from vsc-python-indent.
That's pretty much what I had in mind! Thanks for taking it under consideration.
If it makes it less complicated I would not necessarily consider adding the parentheses around the string as a "must have"... after all it is really easy to add parentheses around an expression by selecting it and hitting ( already.
So maybe the behavior should be like:
# | indicates cursor location
# case 1, no parentheses => no change in behavior
s = "really long| string"
s = "really long
| string"
# case 2, after adding parentheses => change in behavior
s = ("really long| string")
s = ("really long"
"| string")
from vsc-python-indent.
I looked into this a little more, and concluded that this would require a moderate change to the parser to keep track of what column the string started on.
from vsc-python-indent.
Thanks for looking into it. "Moderate" sounds like a decent amount of effort would be required.
from vsc-python-indent.
I think the crux of it would be adding several new pieces of information to the current parser. This is what it currently outputs:
export interface IParseOutput {
canHang: boolean;
dedentNext: boolean;
lastClosedRow: number[];
lastColonRow: number;
openBracketStack: number[][];
}
We'd need to add a something to track what column the string delimiter was on (null if we're not in a string), what the string delimiter was (so we know to add a single or double quote), whether the string had any prefixes (u
, f
, etc.), and possibly whether we're within a closing parentheses. So the interface would end up looking something like this:
export interface IParseOutput {
canHang: boolean;
dedentNext: boolean;
lastClosedRow: number[];
lastColonRow: number;
openBracketStack: number[][];
// Additional items
currentStringDelimiter?: string;
stringStartColumn?: number;
stringPrefix?: string;
insideParentheses: boolean; // maybe
}
from vsc-python-indent.
Does the plugin have to handle undo on its own, or is that taken care of by VSCode?
from vsc-python-indent.
The edits are bundled into a single "transaction" so that VSCode groups them into a single undo/redo action
from vsc-python-indent.
Related Issues (20)
- install extension offline, not compatible version HOT 1
- Extension causes high cpu load HOT 2
- Maybe adjust behavior of useTabOnHangingIndent? HOT 1
- keepHangingBracketOnLine doesn't seem to be working for square brackets HOT 3
- Automatic dedent for return doesn't always work HOT 12
- One space get inserted HOT 1
- # region Description invalid
- Connection to server got closed. Server will not be restarted. HOT 2
- Fail to generate Indentation for a specific file and code copied from that file HOT 1
- Causes big lags in the editor HOT 2
- Connection to server got closed. Server will not be restarted HOT 1
- Enter doesn't work HOT 4
- Enter when in a if-line HOT 1
- Which theme does demo.gif use? HOT 2
- Publish to open-vsx.org? HOT 3
- Extreme lag from pressing Enter to action when extension is running in remote (ssh) host. HOT 6
- multiple indent blank lines will not clear white space before line HOT 2
- Highlighting ` *` and pressing enter doesn't do anything. HOT 1
- python Indentation of the current line is automatically reduced after line wrap HOT 2
- Add extra 3 whitespaces when add new line and broke indent HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vsc-python-indent.