Comments (7)
It seems like a nice-to-have feature.
In VS's C# formatting, does this have the same key combination as formatting selection?
We can do matching braces to capture a selection and feed in formatting selection. It seems that we can find a well-form expression from these delimiters.
More work has to be spent on setting correct caret and scrollbar positions in VS extension.
from fantomas.
there's not key combination for this. when you type a ;
or a }
and the previous block was not propertly formatted, it does that for you straight away. Sometimes I delete and retype a }
on purpose so just that the formatting kicks in as it's more pratical than selecting the whole block and pressing Ctrl+K F
from fantomas.
It's almost like formatting-as-you-type. In the long term, it would be nice to be able to do so.
Some immediate hinders are:
- Performance: Fantomas does both lexing and parsing whenever formatting a block. Some caching is needed to avoid lexing and parsing the same block again and again.
- UI interaction: My skills on VS extension and C# are quite limited, so it will take a lot of time to write UI interaction part.
In the mean time, we can implement "formatting a block around the caret". From the caret's position, we find first block of }
, ]
and )
and format them. We can reuse formatting selection and UI interaction is quite simple. I notice VS' C# formatting does this while Fantomas displays an error on empty selection.
What do you think?
from fantomas.
Yes, for starters having the Ctrl+K F work without a selection and finding the nearest block to the caret position would already be good. @jaredpar maybe you can help on this?
from fantomas.
It seems like you just want to trigger off certain keys being typed into the editor. If that is the case then you just need to look for those keys to be typed inside of StandardCommandDispatcher::Exec
. Key strokes are expressed as TYPECHAR
commands and they will go through every IOleCommandTarget::Exec
implementation. You can just look for one of those to go by and decide to format based on the character and context in which it is typed. This is exactly how C# and the like do their auto-formatting.
from fantomas.
@jaredpar Is there any particular place in VsVim
to gain understanding about this?
from fantomas.
Take a look at the following files
https://github.com/jaredpar/VsVim/blob/master/Src/VsVimShared/VsCommandTarget.cs
https://github.com/jaredpar/VsVim/blob/master/Src/VsVimShared/OleCommandUtil.cs
https://github.com/jaredpar/VsVim/blob/master/Src/VsVimShared/OleCommandData.cs
They are the core of the IOleCommandTarget handling logic.
from fantomas.
Related Issues (20)
- Add doc comments in SyntaxNode.fs giving an example of what each node looks like
- Process is reserved keyword
- Unable to format Fable line (cannot determine if Expr Paren Fantomas.Core.SyntaxOak+ExprParenNode is uppercase or lowercase) HOT 2
- Trivia after mutable keyword is missing HOT 1
- Formatting can depend on cursor position HOT 4
- Misplaced comment in "else if" HOT 3
- Fantomas does not support extended interpolated strings HOT 4
- Many Ifdefs seem to cause parse error HOT 1
- Unmatched '{' error when formatting the code HOT 2
- Using `--check` gives error "todo WhileBang" HOT 9
- Breaks shorthand lambda atomicity for lowercase method invocations
- Consider relaxing ASTTransformer treatment of ranges in record fields HOT 1
- Unable to format F# 8 extended interpolated strings with curly braces HOT 3
- Move editor config to library rather than tool HOT 6
- "Incomplete declaration of a static construct" which the F# compiler accepts HOT 2
- Multiline secondary constructor HOT 4
- Equals sign should only be on same line if last tuple is multiline HOT 2
- Return type should go on next line
- Invalid F# code after formatting HOT 1
- Formatting removes necessary additional closing brackets for multiline interpolated strings HOT 1
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 fantomas.