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

Unexpected indentation #233700

Open
aiday-mar opened this issue Nov 12, 2024 · 3 comments
Open

Unexpected indentation #233700

aiday-mar opened this issue Nov 12, 2024 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues

Comments

@aiday-mar
Copy link
Contributor

There is unexpected indentation on the first comment line:

Image

from https://bsky.app/profile/hailey.at/post/3lahndapjdk2j

@aiday-mar aiday-mar added bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues labels Nov 12, 2024
@aiday-mar aiday-mar self-assigned this Nov 12, 2024
@aiday-mar
Copy link
Contributor Author

would be fixed using #208985

@amunger
Copy link
Contributor

amunger commented Nov 12, 2024

important to note that the indent is added even with a semicolon at the end. I would argue that without a semicolon, it should indent since it can't be determined that the statement is ended (the javascript parser wouldn't know at that point)

const check =
    'true' === 'true' ?
    'true' : 'false';

Pressing enter after the last line will add an indent. Also unexpected, is that pressing enter after the = wont add an indent.

@aiday-mar
Copy link
Contributor Author

Indentation here is determined by onEnter rules. We could add an onEnter rule to decrease indentation after having encountered a semi-colon but this would create the following false-positive case:

   const hi = `
   some text
   some text`;
const bye = 'bye';

Here the line bye is de-indented whereas it should not be. The reason this is happening is because our indentation logic relies on matching regex patterns against the current line and the previous line which misses context as to the lines prior to that. We need syntax based logic to determine reliable indentation patterns.

As for the = sign indentation, I could encode this in an onEnter rule so that this indents appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues
Projects
None yet
Development

No branches or pull requests

2 participants