branch: elpa/swift-mode
commit 1c4253bcb322d348af609953e05a7593e4c0e010
Author: ap4y <[email protected]>
Commit: ap4y <[email protected]>
Improve indentation for nested hash/array statements
---
swift-mode.el | 6 ++++--
test/indentation-tests.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 3626fc6..9425fce 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -343,8 +343,10 @@
(`(:before . "(")
(if (smie-rule-next-p "[") (smie-rule-parent)))
(`(:before . "[")
- (if (smie-rule-prev-p "->") swift-indent-offset
- (smie-rule-parent)))
+ (cond
+ ((smie-rule-prev-p "->") swift-indent-offset)
+ ((smie-rule-parent-p "[") swift-indent-offset)
+ (t (smie-rule-parent))))
(`(:after . "->") swift-indent-offset)
;; Normalize behaviour with and without declaration specifier
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index c6a493d..03cbdd5 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -914,6 +914,54 @@ var result = Dictionary<String, V>()
var result = Dictionary<String, V>()
|foo
")
+(check-indentation indents-declaration/8
+ "
+let foo =
+|bar
+" "
+let foo =
+ |bar
+")
+
+(check-indentation indents-declaration/9
+ "
+let foo: Foo? =
+|bar
+" "
+let foo: Foo? =
+ |bar
+")
+
+(check-indentation indents-declaration/10
+ "
+let foo: Foo<A> =
+|bar
+" "
+let foo: Foo<A> =
+ |bar
+")
+
+(check-indentation indents-declaration/11
+ "
+let foo = [
+ foo:
+|bar
+]
+" "
+let foo = [
+ foo:
+ |bar
+]
+")
+
+(check-indentation indents-declaration/12
+ "
+let foo = [
+|[
+" "
+let foo = [
+ |[
+")
(check-indentation indents-multiline-expressions/1
"