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

Ignore the indentNextLinePattern rule when next line satisfies the increaseIndentPattern rule #209822

Closed
aiday-mar opened this issue Apr 8, 2024 · 7 comments
Assignees
Labels
editor-autoindent Editor auto indentation issues polish Cleanup and polish issue

Comments

@aiday-mar
Copy link
Contributor

This issue derives from the issue #209804 and #43244 (comment).

Recently we have modified the indentNextLinePattern pattern so that after a braceless if statement, on pressing Enter, we indent the next line as follows (here the dots signify white spaces):

if (true)
....

Some users have mentioned in the thread of the link above, that upon writing {} they would like the line to outdent, as follows:

if (true)
{}

We need to polish this.

@aiday-mar aiday-mar self-assigned this Apr 8, 2024
@aiday-mar aiday-mar added polish Cleanup and polish issue editor-autoindent Editor auto indentation issues labels Apr 8, 2024
@aiday-mar
Copy link
Contributor Author

aiday-mar commented Apr 8, 2024

After discussion with the team we decided not to pursue the idea in #209804.

Instead, we can solve the above problem the following way:

  1. Detect if the current line n satisfies the indentNextLinePattern pattern
  2. If the current line satisfies the pattern, find if the line n+1 satisfies the increaseIndentPattern pattern
  3. If the next line satisfies the increaseIndentPattern, then outdent line n
  4. Continue the indentation as per normal after this

@ciabaros
Copy link

ciabaros commented Apr 8, 2024

This looks like the ideal solution we're looking for, as long as standard intentation rules would apply (e.g. 2 space, 4 space, tab, etc.) and it would support auto indentation in the following cases:

// Single line brace-less
if( true )
    logic( );

// Same line brace
if( true ) {
    logic( );
    // etc.
}

// New line brace
if( true )
{
    logic( );
    // etc.
}

@heroboy
Copy link

heroboy commented Jun 25, 2024

Not sure I should report this here.
Recent vscode auto indent not working perfect for me .
code:

if (1)
    |

when input "{", code become:

if (1)
    {|}

It should unindent when input "{"

if (1)
{|}

@aiday-mar
Copy link
Contributor Author

aiday-mar commented Jun 25, 2024

Hi what is the indentation level on that line? It will not outdent if the indentation level is not the exact default indentation level because it will be assumed that the indentation is indentation.

Could you please show a video of this behavior? I can change the code if needed.

What version of VS code are you on? Are you on Insiders or Stable, the fix is not out on stable yet.

@heroboy
Copy link

heroboy commented Jun 25, 2024

@aiday-mar

Animation

{
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
}
Version: 1.90.2 (user setup)
Commit: 5437499feb04f7a586f677b155b039bc2b3669eb
Date: 2024-06-18T22:34:26.404Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.22631

@aiday-mar
Copy link
Contributor Author

Hi thank you for the quick response. You are on the latest stable release. A fix for this has been merged recently and is in the latest Insiders release. The next stable release will come out this week. The current behavior on the latest Insiders release is:

Screen.Recording.2024-06-25.at.11.18.52.mov

@aiday-mar
Copy link
Contributor Author

This issue will be closed, as the fix is in Insiders

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-autoindent Editor auto indentation issues polish Cleanup and polish issue
Projects
None yet
Development

No branches or pull requests

4 participants
@heroboy @ciabaros @aiday-mar and others