Skip to content

Commit 3b123d6

Browse files
authored
Merge pull request #2129 from DanielXMoore/keyword-indent
LSP: Don't indent after keyword property inside Object
2 parents a80ab57 + a914e3c commit 3b123d6

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lsp/vscode/e2e/indentation.test.civet

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ indentAfterEnter := async (content: string): Promise<number> =>
2828
newLineIndex := content.split('\n').length
2929
indentOf doc.lineAt(newLineIndex).text
3030

31+
// Open a doc, type text at end, and return the line that follows the original
32+
// content. Useful for decrease-indent cases that fire while typing the line.
33+
lineAfterTyping := async (content: string, text: string): Promise<string> =>
34+
{ doc } := await openCivetAtEnd content
35+
await vscode.commands.executeCommand 'type', { text }
36+
newLineIndex := content.split('\n').length
37+
doc.lineAt(newLineIndex).text
38+
3139
suite 'Auto-indent on Enter (issue #170)', =>
3240
test 'indents body after function declaration', async =>
3341
indent := await indentAfterEnter 'function foo()'
@@ -68,3 +76,11 @@ suite 'Auto-indent on Enter (issue #170)', =>
6876
test 'does NOT indent after an inline-then conditional', async =>
6977
indent := await indentAfterEnter 'if cond then x else y'
7078
assert indent is 0, `expected no indent after inline-then, got ${indent}`
79+
80+
test 'does NOT increase indent after a keyword object key', async =>
81+
indent := await indentAfterEnter 'qwe :=\n asd: 1\n class: 2'
82+
assert indent is 4, `expected object-key indent to stay at 4, got ${indent}`
83+
84+
test 'does NOT decrease indent while typing a keyword object key', async =>
85+
line := await lineAfterTyping 'qwe :=\n asd: 1', '\nelse: 2'
86+
assert line is ' else: 2', `expected object-key line to stay indented, got ${JSON.stringify line}`

lsp/vscode/syntaxes/civet-configuration.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
["`", "`"]
2929
],
3030
"indentationRules": {
31-
"increaseIndentPattern": "^(?:.*(?:[({\\[]|=>>|->>|=>|->|\\bdo\\b|\\btry\\b|\\belse\\b|\\bcatch\\b|\\bfinally\\b|\\bloop\\b|\\bthen\\b)\\s*$|\\s*(?:export\\s+|async\\s+|default\\s+){0,3}(?:if|unless|for|while|until|switch|class|interface|enum|function|namespace|module|when|case|else|catch|finally)\\b(?!.*\\bthen\\b).*$)",
32-
"decreaseIndentPattern": "^\\s*(?:else\\b|catch\\b|finally\\b|when\\b|case\\b|[)\\]}])"
31+
"increaseIndentPattern": "^(?:.*(?:[({\\[]|=>>|->>|=>|->|\\bdo\\b|\\btry\\b|\\belse\\b|\\bcatch\\b|\\bfinally\\b|\\bloop\\b|\\bthen\\b)\\s*$|\\s*(?:export\\s+|async\\s+|default\\s+){0,3}(?:if|unless|for|while|until|switch|class|interface|enum|function|namespace|module|when|case|else|catch|finally)\\b(?!.*\\bthen\\b)(?!\\s*:).*$)",
32+
"decreaseIndentPattern": "^\\s*(?:(?:else|catch|finally|when|case)\\b(?!\\s*:)|[)\\]}])"
3333
}
3434
}

0 commit comments

Comments
 (0)