-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Close paren on type formatting reformats whole document instead of current expression #111
Comments
Interesting, in |
If there can have a bug, it should be |
Oh, it's a bug. I thought it's a feature that it reformat the whole document. |
I think I know where the bug come from. /**
* The position around which the on type formatting should happen.
* This is not necessarily the exact position where the character denoted
* by the property `ch` got typed.
*/
position: Position; The racket-langserver/text-document.rkt Line 524 in 45f5767
It uses In the example code, the position that the client passed is this:
Our code should not depend on the precise definition of |
Not quite? It says the position “not necessary” be the same, but it still is the same in most cases, where you point out the position is after the inserted, I think that’s correct. Maybe we can use pos-1 instead of pos? Another solution should be we stop using find parentheses, but the find prev sexp and find next sexp to detect the scope? |
No. The current code expects
This is the position of Suppose )))
^
ch It would be ambiguous. This is a problem. |
Yes, but I think a finite scope is still better than the whole file. |
I have an evil idea. We can save the position information in |
The second idea can have a condition, that if |
I prefer the evil solution. We just need to add a |
I was curious what other lang servers do for this case... Looking at Rust Analyzer, it seems like they assume that for on-type formatting, you can find a precise position by subtracting one character from the If we really can't depend on the |
Rust analyzer assume there has no other plugin will affect the position |
After some search, I found only a little editor supports
I think they all looked into vscode's implementation. So a possible solution is to assume it's cursor position. |
It's been 5 days since our last discussion. What are your thoughts? I think the solution that assuming it's the cursor position looks like a safe option. If you agree, I can do this today. It would be a small fix. |
Agree |
Sounds like a good approach to me, thanks for working on this. 😄 |
Here's an example demonstrating the issue:
If you remove and re-add the last closing paren in the file (for the
book
struct), you end up seeing thatdocument
struct earlier in the file gets reformatted, even though we are not working on that that expression. This behaviour is surprising and gets in the way when working on shared codebases that may use all sorts of different formatting styles. Ideally, only the actively edited expression would be reformatted when format on type is enabled.After typing the close paren, VS Code shows the following LSP traffic:
The confirms that
onTypeFormatting
support in the lang server reformatted the whole file.I suppose what's needed here is the lang server's
onTypeFomatting
support should specially handle the close paren character, and then look for the current expression, and only reformat that...?The text was updated successfully, but these errors were encountered: