forked from sublimehq/Packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JavaScript] Improve indentation rules of tagged template strings
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.
- Loading branch information
Showing
3 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
JavaScript/Indentation Rules - Template Strings.tmPreferences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>scope</key> | ||
<string>string.quoted.other.js</string> | ||
<key>settings</key> | ||
<dict> | ||
<!-- | ||
Only first row containing opening backtick is included in auto-indentation. | ||
Content of plain tagged template strings is otherwise excluded. | ||
Note: | ||
Decreasing indentation of last row, containing stand-alone closing backtick | ||
is handled by normal indentation rules. | ||
--> | ||
|
||
<!-- | ||
<key>decreaseIndentPattern</key> | ||
<string>^\s*`</string> | ||
--> | ||
|
||
<key>increaseIndentPattern</key> | ||
<string>^[^`]*`\s*$</string> | ||
|
||
<key>unIndentedLinePattern</key> | ||
<string>^[^`]*$</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters