-
Notifications
You must be signed in to change notification settings - Fork 588
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
[JavaScript] Code and Data specific indentation rules #4015
[JavaScript] Code and Data specific indentation rules #4015
Conversation
Fixes https://forum.sublimetext.com/t/sublime-text-on-the-word-default/72953 This commit applies dedicated (json) indentation rules to JavaScript mappings to avoid unexpected (un-)indenting of keys, which look like reserved control structure keywords (e.g.: case, default, if, else, ...).
Was curious if it changes the behavior I struggle with often. It looks like it does. It's not ideal either before or after but it does change the behavior. Is it intended? (to clarify, I'm pressing enter within an empty array) BeforeAfterPersonally I feel like the new behavior is easier to correct manually since I just need to press |
This change is intended to get the following: I now realize it is me seeing that due to a custom key binding of mine, to fix bracket behavior.
|
Same as for mappings, is true for lists. They can contain otherwise reserved words, which should not be treated by indentation rules.
This commit applies a key binding from JSON package to auto-indent content of lists when hitting enter var = [|] becomes: var = [ | ]
Added a commit to also exclude keyword indentation treatment from Can you check, whether it improves your situation, @rchl ? |
It does work nicely now. |
This commit... 1. extends selectors for each syntax (JS, JSX, TS, TSX) to choose correct indentation rules in nested mappings, lists or functions/lambdas. 2. Adds check for trailing `:` to case/default indentation rule patterns, as a function called `case()` in a mapping can't be prevented from being unindented via selectors.
Merge new tests into existing file
As we need to expect `:` after case/default, those tests no longer work by intent.
Well, this PR now requires It requires sublimehq/sublime_text#2152 in particular. |
This change is required for sublimehq#4015 to succeed. We can re-enable stable tests, once the next stable release is made.
This change is required for #4015 to succeed. Its indentation rule selectors make use of sublimehq/sublime_text#2152 to recursively select the correct ruleset in deeply nested alternating json objects/lists and function constructs. ```js var foo = { case: () => { // data: don't dedent switch () { case: // code: dedent var bar = { case: () => { // data: don't dedent ... } } } } ``` This is available as of ST4173. In all builds before, selectors match the outermost contexts only and thus indentation starts to fail in on of the inner object/function blocks.
Resolved a merge conflict in indentation rules. |
This commit... 1. fixes lines after single-line tagged template string being indented. before: var foo = html`<p>content</p>`; var bar = html`<p>content</p>`; var baz = html`<p>content</p>`: after: var foo = html`<p>content</p>`; var bar = html`<p>content</p>`; var baz = html`<p>content</p>`: 2. excludes content of plain string templates from auto-indentation. As their kind of content is undefined, normal indentation rules may cause false results. Tests are added to ensure normal JS statements keep untreated. Notes: First and last line of tagged templates is scoped `string.quoted.other` regardless of embedded syntax highlighting, if only opening or closing backticks appear. Hence increasing indentation of tagged template strings' content is handled by "Indentation Rules - Template Strings". Decreasing indentation of closing backtick is handled by normal "Indentation Rules" as those are the ones applied by ST. It just doesn't work otherwise. This circumstance helps to reliably distinguish opening and closing backticks and correctly in- or decrease indentation.
This commit aligns this PR with sublimehq#4022.
Not sure if this PR becomes to big, but it seems useful to also fix a tagged template string related indentation issue, I've come accross while testing things out. I found single line template strings to cause following lines to be increased in indentation by accident. |
Looks better now. I'd like to try this out and see if my idea to support arbitrary nesting of mapping literals and function definitions can also be achieved, but I can't promise when I'll find the time. Hopefully by the end of the week, though. |
This commit changes `enter` key binding to "Add Line in Braces" macro, as it indents line between backticks using indentation rules instead of forcing it to be indented via `\t`. This works also, if indentation rules decide not to indent backticked contents.
db36eca
to
a644c0e
Compare
By utilizing the improved selector scoring of build 4173, we can simply have the two rules override each other based on the last meta scope on the stack.
Finally found the time to test this and it was a success. You can find the commit (and cherry-pick it) here: FichteForks@dfad440 Alternatively I can also push it to your branch, I believe, but I wanted you to review it first. |
LGTM! PRs are a place for collaboration. Feel free to directly push. |
Fixes https://forum.sublimetext.com/t/sublime-text-on-the-word-default/72953
This commit applies dedicated (json) indentation rules to JavaScript mappings to avoid unexpected (un-)indenting of keys, which look like reserved control structure keywords (e.g.: case, default, if, else, ...).